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

taosdata / TDengine / #4404

30 Jun 2025 02:45AM UTC coverage: 62.241% (-0.4%) from 62.635%
#4404

push

travis-ci

web-flow
Merge pull request #31480 from taosdata/docs/3.0/TD-34215

add stmt2 docs

153837 of 315978 branches covered (48.69%)

Branch coverage included in aggregate %.

238272 of 314005 relevant lines covered (75.88%)

6134648.6 hits per line

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

40.93
/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,406,865✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
71,406,865✔
74
  int    segIdx = TMSG_SEG_CODE(type);
71,406,865✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
71,406,865✔
76
    return type < tMsgRangeDict[segIdx];
71,412,814✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,884,071✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,841,436✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
5,725,507!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
8,457,775✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
8,457,775✔
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_BACKUP_NODE,  // no longer used
128
  TSDB_MGMT_TABLE_CLUSTER,
129
  TSDB_MGMT_TABLE_DB,
130
  TSDB_MGMT_TABLE_FUNC,
131
  TSDB_MGMT_TABLE_INDEX,
132
  TSDB_MGMT_TABLE_STB,
133
  TSDB_MGMT_TABLE_STREAMS,
134
  TSDB_MGMT_TABLE_TABLE,
135
  TSDB_MGMT_TABLE_TAG,
136
  TSDB_MGMT_TABLE_COL,
137
  TSDB_MGMT_TABLE_USER,
138
  TSDB_MGMT_TABLE_GRANTS,
139
  TSDB_MGMT_TABLE_VGROUP,
140
  TSDB_MGMT_TABLE_TOPICS,
141
  TSDB_MGMT_TABLE_CONSUMERS,
142
  TSDB_MGMT_TABLE_SUBSCRIPTIONS,
143
  TSDB_MGMT_TABLE_TRANS,
144
  TSDB_MGMT_TABLE_SMAS,
145
  TSDB_MGMT_TABLE_CONFIGS,
146
  TSDB_MGMT_TABLE_CONNS,
147
  TSDB_MGMT_TABLE_QUERIES,
148
  TSDB_MGMT_TABLE_VNODES,
149
  TSDB_MGMT_TABLE_APPS,
150
  TSDB_MGMT_TABLE_STREAM_TASKS,
151
  TSDB_MGMT_TABLE_PRIVILEGES,
152
  TSDB_MGMT_TABLE_VIEWS,
153
  TSDB_MGMT_TABLE_TSMAS,
154
  TSDB_MGMT_TABLE_COMPACT,
155
  TSDB_MGMT_TABLE_COMPACT_DETAIL,
156
  TSDB_MGMT_TABLE_GRANTS_FULL,
157
  TSDB_MGMT_TABLE_GRANTS_LOGS,
158
  TSDB_MGMT_TABLE_MACHINES,
159
  TSDB_MGMT_TABLE_ARBGROUP,
160
  TSDB_MGMT_TABLE_ENCRYPTIONS,
161
  TSDB_MGMT_TABLE_USER_FULL,
162
  TSDB_MGMT_TABLE_ANODE,
163
  TSDB_MGMT_TABLE_ANODE_FULL,
164
  TSDB_MGMT_TABLE_USAGE,
165
  TSDB_MGMT_TABLE_FILESETS,
166
  TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
167
  TSDB_MGMT_TABLE_BNODE,
168
  TSDB_MGMT_TABLE_MAX,
169
} EShowType;
170

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

190
#define TSDB_FILL_NONE        0
191
#define TSDB_FILL_NULL        1
192
#define TSDB_FILL_NULL_F      2
193
#define TSDB_FILL_SET_VALUE   3
194
#define TSDB_FILL_SET_VALUE_F 4
195
#define TSDB_FILL_LINEAR      5
196
#define TSDB_FILL_PREV        6
197
#define TSDB_FILL_NEXT        7
198
#define TSDB_FILL_NEAR        8
199

200
#define TSDB_ALTER_USER_PASSWD          0x1
201
#define TSDB_ALTER_USER_SUPERUSER       0x2
202
#define TSDB_ALTER_USER_ENABLE          0x3
203
#define TSDB_ALTER_USER_SYSINFO         0x4
204
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
205
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
206
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
207
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
208
#define TSDB_ALTER_USER_CREATEDB        0x9
209

210
#define TSDB_KILL_MSG_LEN 30
211

212
#define TSDB_TABLE_NUM_UNIT 100000
213

214
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
215
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
216
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
217

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

224
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
225
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
226
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
227
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
228

229
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
230
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
231
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
232
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
233
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
234

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

282
  // Statement nodes are used in parser and planner module.
283
  QUERY_NODE_SET_OPERATOR = 100,
284
  QUERY_NODE_SELECT_STMT,
285
  QUERY_NODE_VNODE_MODIFY_STMT,
286
  QUERY_NODE_CREATE_DATABASE_STMT,
287
  QUERY_NODE_DROP_DATABASE_STMT,
288
  QUERY_NODE_ALTER_DATABASE_STMT,
289
  QUERY_NODE_FLUSH_DATABASE_STMT,
290
  QUERY_NODE_TRIM_DATABASE_STMT,
291
  QUERY_NODE_CREATE_TABLE_STMT,
292
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
293
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
294
  QUERY_NODE_DROP_TABLE_CLAUSE,
295
  QUERY_NODE_DROP_TABLE_STMT,
296
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
297
  QUERY_NODE_ALTER_TABLE_STMT,
298
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
299
  QUERY_NODE_CREATE_USER_STMT,
300
  QUERY_NODE_ALTER_USER_STMT,
301
  QUERY_NODE_DROP_USER_STMT,
302
  QUERY_NODE_USE_DATABASE_STMT,
303
  QUERY_NODE_CREATE_DNODE_STMT,
304
  QUERY_NODE_DROP_DNODE_STMT,
305
  QUERY_NODE_ALTER_DNODE_STMT,
306
  QUERY_NODE_CREATE_INDEX_STMT,
307
  QUERY_NODE_DROP_INDEX_STMT,
308
  QUERY_NODE_CREATE_QNODE_STMT,
309
  QUERY_NODE_DROP_QNODE_STMT,
310
  QUERY_NODE_CREATE_BACKUP_NODE_STMT, // no longer used
311
  QUERY_NODE_DROP_BACKUP_NODE_STMT,   // no longer used
312
  QUERY_NODE_CREATE_SNODE_STMT,
313
  QUERY_NODE_DROP_SNODE_STMT,
314
  QUERY_NODE_CREATE_MNODE_STMT,
315
  QUERY_NODE_DROP_MNODE_STMT,
316
  QUERY_NODE_CREATE_TOPIC_STMT,
317
  QUERY_NODE_DROP_TOPIC_STMT,
318
  QUERY_NODE_DROP_CGROUP_STMT,
319
  QUERY_NODE_ALTER_LOCAL_STMT,
320
  QUERY_NODE_EXPLAIN_STMT,
321
  QUERY_NODE_DESCRIBE_STMT,
322
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
323
  QUERY_NODE_COMPACT_DATABASE_STMT,
324
  QUERY_NODE_COMPACT_VGROUPS_STMT,
325
  QUERY_NODE_CREATE_FUNCTION_STMT,
326
  QUERY_NODE_DROP_FUNCTION_STMT,
327
  QUERY_NODE_CREATE_STREAM_STMT,
328
  QUERY_NODE_DROP_STREAM_STMT,
329
  QUERY_NODE_BALANCE_VGROUP_STMT,
330
  QUERY_NODE_MERGE_VGROUP_STMT,
331
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
332
  QUERY_NODE_SPLIT_VGROUP_STMT,
333
  QUERY_NODE_SYNCDB_STMT,
334
  QUERY_NODE_GRANT_STMT,
335
  QUERY_NODE_REVOKE_STMT,
336
  QUERY_NODE_ALTER_CLUSTER_STMT,
337
  QUERY_NODE_S3MIGRATE_DATABASE_STMT,
338
  QUERY_NODE_CREATE_TSMA_STMT,
339
  QUERY_NODE_DROP_TSMA_STMT,
340
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
341
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
342
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
343
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
344

345
  // placeholder for [154, 180]
346
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
347
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
348
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
349
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
350
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
351
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
352
  QUERY_NODE_SHOW_SCORES_STMT,
353
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
354
  QUERY_NODE_KILL_CONNECTION_STMT,
355
  QUERY_NODE_KILL_QUERY_STMT,
356
  QUERY_NODE_KILL_TRANSACTION_STMT,
357
  QUERY_NODE_KILL_COMPACT_STMT,
358
  QUERY_NODE_DELETE_STMT,
359
  QUERY_NODE_INSERT_STMT,
360
  QUERY_NODE_QUERY,
361
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
362
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
363
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
364
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
365
  QUERY_NODE_RESTORE_DNODE_STMT,
366
  QUERY_NODE_RESTORE_QNODE_STMT,
367
  QUERY_NODE_RESTORE_MNODE_STMT,
368
  QUERY_NODE_RESTORE_VNODE_STMT,
369
  QUERY_NODE_PAUSE_STREAM_STMT,
370
  QUERY_NODE_RESUME_STREAM_STMT,
371
  QUERY_NODE_CREATE_VIEW_STMT,
372
  QUERY_NODE_DROP_VIEW_STMT,
373
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
374
  QUERY_NODE_CREATE_ANODE_STMT,
375
  QUERY_NODE_DROP_ANODE_STMT,
376
  QUERY_NODE_UPDATE_ANODE_STMT,
377
  QUERY_NODE_ASSIGN_LEADER_STMT,
378
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
379
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
380
  QUERY_NODE_CREATE_BNODE_STMT,
381
  QUERY_NODE_DROP_BNODE_STMT,
382

383
  // show statement nodes
384
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
385
  QUERY_NODE_SHOW_DNODES_STMT = 400,
386
  QUERY_NODE_SHOW_MNODES_STMT,
387
  QUERY_NODE_SHOW_MODULES_STMT,
388
  QUERY_NODE_SHOW_QNODES_STMT,
389
  QUERY_NODE_SHOW_SNODES_STMT,
390
  QUERY_NODE_SHOW_BACKUP_NODES_STMT, // no longer used
391
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
392
  QUERY_NODE_SHOW_CLUSTER_STMT,
393
  QUERY_NODE_SHOW_DATABASES_STMT,
394
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
395
  QUERY_NODE_SHOW_INDEXES_STMT,
396
  QUERY_NODE_SHOW_STABLES_STMT,
397
  QUERY_NODE_SHOW_STREAMS_STMT,
398
  QUERY_NODE_SHOW_TABLES_STMT,
399
  QUERY_NODE_SHOW_TAGS_STMT,
400
  QUERY_NODE_SHOW_USERS_STMT,
401
  QUERY_NODE_SHOW_USERS_FULL_STMT,
402
  QUERY_NODE_SHOW_LICENCES_STMT,
403
  QUERY_NODE_SHOW_VGROUPS_STMT,
404
  QUERY_NODE_SHOW_TOPICS_STMT,
405
  QUERY_NODE_SHOW_CONSUMERS_STMT,
406
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
407
  QUERY_NODE_SHOW_QUERIES_STMT,
408
  QUERY_NODE_SHOW_APPS_STMT,
409
  QUERY_NODE_SHOW_VARIABLES_STMT,
410
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
411
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
412
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
413
  QUERY_NODE_SHOW_VNODES_STMT,
414
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
415
  QUERY_NODE_SHOW_VIEWS_STMT,
416
  QUERY_NODE_SHOW_COMPACTS_STMT,
417
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
418
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
419
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
420
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
421
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
422
  QUERY_NODE_SHOW_TSMAS_STMT,
423
  QUERY_NODE_SHOW_ANODES_STMT,
424
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
425
  QUERY_NODE_SHOW_USAGE_STMT,
426
  QUERY_NODE_SHOW_FILESETS_STMT,
427
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
428
  QUERY_NODE_SHOW_VTABLES_STMT,
429
  QUERY_NODE_SHOW_BNODES_STMT,
430

431
  // logic plan node
432
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
433
  QUERY_NODE_LOGIC_PLAN_JOIN,
434
  QUERY_NODE_LOGIC_PLAN_AGG,
435
  QUERY_NODE_LOGIC_PLAN_PROJECT,
436
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
437
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
438
  QUERY_NODE_LOGIC_PLAN_MERGE,
439
  QUERY_NODE_LOGIC_PLAN_WINDOW,
440
  QUERY_NODE_LOGIC_PLAN_FILL,
441
  QUERY_NODE_LOGIC_PLAN_SORT,
442
  QUERY_NODE_LOGIC_PLAN_PARTITION,
443
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
444
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
445
  QUERY_NODE_LOGIC_SUBPLAN,
446
  QUERY_NODE_LOGIC_PLAN,
447
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
448
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
449
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
450
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
451

452
  // physical plan node
453
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
454
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
455
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
456
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
457
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
458
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
459
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
460
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
461
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
462
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
463
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
464
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
465
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
466
  QUERY_NODE_PHYSICAL_PLAN_SORT,
467
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
468
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
469
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
470
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
471
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
472
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
473
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
474
  QUERY_NODE_PHYSICAL_PLAN_FILL,
475
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL,
476
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
477
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION,
478
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION,
479
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION,
480
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
481
  QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
482
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
483
  QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION,
484
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
485
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
486
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
487
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
488
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
489
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
490
  QUERY_NODE_PHYSICAL_SUBPLAN,
491
  QUERY_NODE_PHYSICAL_PLAN,
492
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
493
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
494
  QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT,
495
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
496
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
497
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
498
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
499
  QUERY_NODE_PHYSICAL_PLAN_STREAM_COUNT,
500
  QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL,
501
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_INTERVAL,
502
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
503
  QUERY_NODE_PHYSICAL_PLAN_STREAM_ANOMALY,
504
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
505
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC,
506
  QUERY_NODE_RESET_STREAM_STMT,
507
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SEMI_INTERVAL,
508
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_FINAL_INTERVAL,
509
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SESSION,
510
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SEMI_SESSION,
511
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_FINAL_SESSION,
512
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_STATE,
513
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_EVENT,
514
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_COUNT,
515
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
516
} ENodeType;
517

518
typedef struct {
519
  int32_t     vgId;
520
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
521
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
522
  const char* dbFName;
523
  const char* tbName;
524
} SBuildTableInput;
525

526
typedef struct {
527
  char    db[TSDB_DB_FNAME_LEN];
528
  int64_t dbId;
529
  int32_t vgVersion;
530
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
531
  int64_t stateTs;
532
} SBuildUseDBInput;
533

534
typedef struct SField {
535
  char    name[TSDB_COL_NAME_LEN];
536
  uint8_t type;
537
  int8_t  flags;
538
  int32_t bytes;
539
} SField;
540
typedef struct SFieldWithOptions {
541
  char     name[TSDB_COL_NAME_LEN];
542
  uint8_t  type;
543
  int8_t   flags;
544
  int32_t  bytes;
545
  uint32_t compress;
546
  STypeMod typeMod;
547
} SFieldWithOptions;
548

549
typedef struct SRetention {
550
  int64_t freq;
551
  int64_t keep;
552
  int8_t  freqUnit;
553
  int8_t  keepUnit;
554
} SRetention;
555

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

558
#pragma pack(push, 1)
559
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
560
typedef struct SEp {
561
  char     fqdn[TSDB_FQDN_LEN];
562
  uint16_t port;
563
} SEp;
564

565
typedef struct {
566
  int32_t contLen;
567
  int32_t vgId;
568
} SMsgHead;
569

570
// Submit message for one table
571
typedef struct SSubmitBlk {
572
  int64_t uid;        // table unique id
573
  int64_t suid;       // stable id
574
  int32_t sversion;   // data schema version
575
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
576
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
577
  int32_t numOfRows;  // total number of rows in current submit block
578
  char    data[];
579
} SSubmitBlk;
580

581
// Submit message for this TSDB
582
typedef struct {
583
  SMsgHead header;
584
  int64_t  version;
585
  int32_t  length;
586
  int32_t  numOfBlocks;
587
  char     blocks[];
588
} SSubmitReq;
589

590
typedef struct {
591
  int32_t totalLen;
592
  int32_t len;
593
  STSRow* row;
594
} SSubmitBlkIter;
595

596
typedef struct {
597
  int32_t totalLen;
598
  int32_t len;
599
  // head of SSubmitBlk
600
  int64_t uid;        // table unique id
601
  int64_t suid;       // stable id
602
  int32_t sversion;   // data schema version
603
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
604
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
605
  int32_t numOfRows;  // total number of rows in current submit block
606
  // head of SSubmitBlk
607
  int32_t     numOfBlocks;
608
  const void* pMsg;
609
} SSubmitMsgIter;
610

611
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
612
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
613
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
614
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
615
// for debug
616
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
617

618
typedef struct {
619
  bool     hasRef;
620
  col_id_t id;
621
  char     refDbName[TSDB_DB_NAME_LEN];
622
  char     refTableName[TSDB_TABLE_NAME_LEN];
623
  char     refColName[TSDB_COL_NAME_LEN];
624
} SColRef;
625

626
typedef struct {
627
  int32_t  nCols;
628
  int32_t  version;
629
  SColRef* pColRef;
630
} SColRefWrapper;
631

632
typedef struct {
633
  int32_t vgId;
634
  SColRef colRef;
635
} SColRefEx;
636

637
typedef struct {
638
  int16_t colId;
639
  char    refDbName[TSDB_DB_NAME_LEN];
640
  char    refTableName[TSDB_TABLE_NAME_LEN];
641
  char    refColName[TSDB_COL_NAME_LEN];
642
} SRefColInfo;
643

644
typedef struct SVCTableRefCols {
645
  uint64_t     uid;
646
  int32_t      numOfSrcTbls;
647
  int32_t      numOfColRefs;
648
  SRefColInfo* refCols;
649
} SVCTableRefCols;
650

651
typedef struct SVCTableMergeInfo {
652
  uint64_t uid;
653
  int32_t  numOfSrcTbls;
654
} SVCTableMergeInfo;
655

656
typedef struct {
657
  int32_t    nCols;
658
  SColRefEx* pColRefEx;
659
} SColRefExWrapper;
660

661
struct SSchema {
662
  int8_t   type;
663
  int8_t   flags;
664
  col_id_t colId;
665
  int32_t  bytes;
666
  char     name[TSDB_COL_NAME_LEN];
667
};
668
struct SSchemaExt {
669
  col_id_t colId;
670
  uint32_t compress;
671
  STypeMod typeMod;
672
};
673

674
//
675

676
struct SSchema2 {
677
  int8_t   type;
678
  int8_t   flags;
679
  col_id_t colId;
680
  int32_t  bytes;
681
  char     name[TSDB_COL_NAME_LEN];
682
  uint32_t compress;
683
};
684

685
typedef struct {
686
  char        tbName[TSDB_TABLE_NAME_LEN];
687
  char        stbName[TSDB_TABLE_NAME_LEN];
688
  char        dbFName[TSDB_DB_FNAME_LEN];
689
  int64_t     dbId;
690
  int32_t     numOfTags;
691
  int32_t     numOfColumns;
692
  int8_t      precision;
693
  int8_t      tableType;
694
  int32_t     sversion;
695
  int32_t     tversion;
696
  int32_t     rversion;
697
  uint64_t    suid;
698
  uint64_t    tuid;
699
  int32_t     vgId;
700
  int8_t      sysInfo;
701
  SSchema*    pSchemas;
702
  SSchemaExt* pSchemaExt;
703
  int8_t      virtualStb;
704
  int32_t     numOfColRefs;
705
  SColRef*    pColRefs;
706
} STableMetaRsp;
707

708
typedef struct {
709
  int32_t        code;
710
  int64_t        uid;
711
  char*          tblFName;
712
  int32_t        numOfRows;
713
  int32_t        affectedRows;
714
  int64_t        sver;
715
  STableMetaRsp* pMeta;
716
} SSubmitBlkRsp;
717

718
typedef struct {
719
  int32_t numOfRows;
720
  int32_t affectedRows;
721
  int32_t nBlocks;
722
  union {
723
    SArray*        pArray;
724
    SSubmitBlkRsp* pBlocks;
725
  };
726
} SSubmitRsp;
727

728
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
729
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
730
// void    tFreeSSubmitBlkRsp(void* param);
731
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
732

733
#define COL_SMA_ON       ((int8_t)0x1)
734
#define COL_IDX_ON       ((int8_t)0x2)
735
#define COL_IS_KEY       ((int8_t)0x4)
736
#define COL_SET_NULL     ((int8_t)0x10)
737
#define COL_SET_VAL      ((int8_t)0x20)
738
#define COL_IS_SYSINFO   ((int8_t)0x40)
739
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
740

741
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
742
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
743

744
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
745
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
746
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
747

748
#define SSCHMEA_SET_IDX_ON(s) \
749
  do {                        \
750
    (s)->flags |= COL_IDX_ON; \
751
  } while (0)
752

753
#define SSCHMEA_SET_IDX_OFF(s)   \
754
  do {                           \
755
    (s)->flags &= (~COL_IDX_ON); \
756
  } while (0)
757

758
#define SSCHEMA_SET_TYPE_MOD(s)     \
759
  do {                              \
760
    (s)->flags |= COL_HAS_TYPE_MOD; \
761
  } while (0)
762

763
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
764

765
#define SSCHMEA_TYPE(s)  ((s)->type)
766
#define SSCHMEA_FLAGS(s) ((s)->flags)
767
#define SSCHMEA_COLID(s) ((s)->colId)
768
#define SSCHMEA_BYTES(s) ((s)->bytes)
769
#define SSCHMEA_NAME(s)  ((s)->name)
770

771
typedef struct {
772
  bool    tsEnableMonitor;
773
  int32_t tsMonitorInterval;
774
  int32_t tsSlowLogThreshold;
775
  int32_t tsSlowLogMaxLen;
776
  int32_t tsSlowLogScope;
777
  int32_t tsSlowLogThresholdTest;  // Obsolete
778
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
779
} SMonitorParas;
780

781
typedef struct {
782
  STypeMod typeMod;
783
} SExtSchema;
784

785
bool hasExtSchema(const SExtSchema* pExtSchema);
786

787
typedef struct {
788
  int32_t  nCols;
789
  int32_t  version;
790
  SSchema* pSchema;
791
} SSchemaWrapper;
792

793
typedef struct {
794
  col_id_t id;
795
  uint32_t alg;
796
} SColCmpr;
797

798
typedef struct {
799
  int32_t   nCols;
800
  int32_t   version;
801
  SColCmpr* pColCmpr;
802
} SColCmprWrapper;
803

804
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
805
  if (pRef->pColRef) {
302!
806
    return TSDB_CODE_INVALID_PARA;
×
807
  }
808
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
302!
809
  if (pRef->pColRef == NULL) {
302!
810
    return terrno;
×
811
  }
812
  pRef->nCols = nCols;
302✔
813
  for (int32_t i = 0; i < nCols; i++) {
4,271✔
814
    pRef->pColRef[i].hasRef = false;
3,969✔
815
    pRef->pColRef[i].id = (col_id_t)(i + 1);
3,969✔
816
  }
817
  return 0;
302✔
818
}
819

820
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
821
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
822
    terrno = TSDB_CODE_INVALID_PARA;
823
    return NULL;
824
  }
825

826
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
827
  if (pDstWrapper == NULL) {
828
    return NULL;
829
  }
830
  pDstWrapper->nCols = pSrcWrapper->nCols;
831
  pDstWrapper->version = pSrcWrapper->version;
832

833
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
834
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
835
  if (pDstWrapper->pColCmpr == NULL) {
836
    taosMemoryFree(pDstWrapper);
837
    return NULL;
838
  }
839
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
840

841
  return pDstWrapper;
842
}
843

844
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
845
  if (!(!pCmpr->pColCmpr)) {
14,132!
846
    return TSDB_CODE_INVALID_PARA;
×
847
  }
848
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
14,132!
849
  if (pCmpr->pColCmpr == NULL) {
14,132!
850
    return terrno;
×
851
  }
852
  pCmpr->nCols = nCols;
14,132✔
853
  return 0;
14,132✔
854
}
855

856
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
857
  pCmpr->nCols = pSchema->nCols;
858
  if (!(!pCmpr->pColCmpr)) {
859
    return TSDB_CODE_INVALID_PARA;
860
  }
861
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
862
  if (pCmpr->pColCmpr == NULL) {
863
    return terrno;
864
  }
865
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
866
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
867
    SSchema*  pColSchema = &pSchema->pSchema[i];
868
    pColCmpr->id = pColSchema->colId;
869
    pColCmpr->alg = 0;
870
  }
871
  return 0;
872
}
873

874
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
875
  if (pWrapper == NULL) return;
876

877
  taosMemoryFreeClear(pWrapper->pColCmpr);
878
  taosMemoryFreeClear(pWrapper);
879
}
880
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
881
  if (pSchemaWrapper->pSchema == NULL) return NULL;
3,073,413!
882

883
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
3,073,413!
884
  if (pSW == NULL) {
3,073,566!
885
    return NULL;
×
886
  }
887
  pSW->nCols = pSchemaWrapper->nCols;
3,073,566✔
888
  pSW->version = pSchemaWrapper->version;
3,073,566✔
889
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
3,073,566!
890
  if (pSW->pSchema == NULL) {
3,072,618!
891
    taosMemoryFree(pSW);
×
892
    return NULL;
×
893
  }
894

895
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
3,072,618✔
896
  return pSW;
3,072,618✔
897
}
898

899
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
590,555✔
900
  if (pSchemaWrapper) {
7,600,614!
901
    taosMemoryFree(pSchemaWrapper->pSchema);
3,350,824!
902
    taosMemoryFree(pSchemaWrapper);
3,350,828!
903
  }
904
}
7,482,666✔
905

906
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,038✔
907
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,038!
908
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,038!
909
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,038!
910
  }
911
}
1,038✔
912

913
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
914
  int32_t tlen = 0;
58,608✔
915
  tlen += taosEncodeFixedI8(buf, pSchema->type);
117,216✔
916
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
58,608!
917
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
58,608!
918
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
58,608!
919
  tlen += taosEncodeString(buf, pSchema->name);
58,608✔
920
  return tlen;
58,608✔
921
}
922

923
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
924
  buf = taosDecodeFixedI8(buf, &pSchema->type);
55,306✔
925
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
27,653✔
926
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
27,653!
927
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
27,653!
928
  buf = taosDecodeStringTo(buf, pSchema->name);
27,653✔
929
  return (void*)buf;
27,653✔
930
}
931

932
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
933
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
34,457,194!
934
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
54,632,390!
935
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
54,632,390!
936
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
54,632,390!
937
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
54,632,390!
938
  return 0;
27,316,195✔
939
}
940

941
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
942
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
141,268,332!
943
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
274,312,257!
944
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
274,056,574!
945
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
274,053,148!
946
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
137,100,282!
947
  return 0;
137,232,500✔
948
}
949

950
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
951
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
12,404,880!
952
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
12,404,880!
953
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
12,404,880!
954
  return 0;
6,202,440✔
955
}
956

957
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
958
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
6,630,021!
959
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
6,630,019!
960
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
6,630,017!
961
  return 0;
3,315,008✔
962
}
963

964
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
965
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
804!
966
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
804!
967
  if (pColRef->hasRef) {
402✔
968
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
488!
969
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
488!
970
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
488!
971
  }
972
  return 0;
402✔
973
}
974

975
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
976
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
21,624!
977
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
21,624!
978
  if (pColRef->hasRef) {
10,812✔
979
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
6,827!
980
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
6,827!
981
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
6,827!
982
  }
983

984
  return 0;
10,812✔
985
}
986

987
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
988
  int32_t tlen = 0;
8,762✔
989
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,762✔
990
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,762✔
991
  for (int32_t i = 0; i < pSW->nCols; i++) {
67,370✔
992
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
117,216!
993
  }
994
  return tlen;
8,762✔
995
}
996

997
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
998
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
4,094✔
999
  buf = taosDecodeVariantI32(buf, &pSW->version);
4,094✔
1000
  if (pSW->nCols > 0) {
4,094✔
1001
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
3,000!
1002
    if (pSW->pSchema == NULL) {
3,000!
1003
      return NULL;
×
1004
    }
1005

1006
    for (int32_t i = 0; i < pSW->nCols; i++) {
30,653✔
1007
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
55,306✔
1008
    }
1009
  } else {
1010
    pSW->pSchema = NULL;
1,094✔
1011
  }
1012
  return (void*)buf;
4,094✔
1013
}
1014

1015
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1016
  if (pSW == NULL) {
685,646!
1017
    return TSDB_CODE_INVALID_PARA;
×
1018
  }
1019
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,371,292!
1020
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,371,292!
1021
  for (int32_t i = 0; i < pSW->nCols; i++) {
20,860,842!
1022
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
40,350,392!
1023
  }
1024
  return 0;
685,646✔
1025
}
1026

1027
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1028
  if (pSW == NULL) {
1,445,347!
1029
    return TSDB_CODE_INVALID_PARA;
×
1030
  }
1031
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,890,689!
1032
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,890,668!
1033

1034
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,445,326!
1035
  if (pSW->pSchema == NULL) {
1,445,437!
1036
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1037
  }
1038
  for (int32_t i = 0; i < pSW->nCols; i++) {
17,207,769!
1039
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
31,525,432!
1040
  }
1041

1042
  return 0;
1,444,669✔
1043
}
1044

1045
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1046
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
16,373,809!
1047
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
16,390,814!
1048

1049
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
8,195,956!
1050
  if (pSW->pSchema == NULL) {
8,198,457!
1051
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1052
  }
1053
  for (int32_t i = 0; i < pSW->nCols; i++) {
125,608,848!
1054
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
234,848,300!
1055
  }
1056

1057
  return 0;
8,170,939✔
1058
}
1059

1060
typedef struct {
1061
  char     name[TSDB_TABLE_FNAME_LEN];
1062
  int8_t   igExists;
1063
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1064
  int8_t   reserved[6];
1065
  tb_uid_t suid;
1066
  int64_t  delay1;
1067
  int64_t  delay2;
1068
  int64_t  watermark1;
1069
  int64_t  watermark2;
1070
  int32_t  ttl;
1071
  int32_t  colVer;
1072
  int32_t  tagVer;
1073
  int32_t  numOfColumns;
1074
  int32_t  numOfTags;
1075
  int32_t  numOfFuncs;
1076
  int32_t  commentLen;
1077
  int32_t  ast1Len;
1078
  int32_t  ast2Len;
1079
  SArray*  pColumns;  // array of SFieldWithOptions
1080
  SArray*  pTags;     // array of SField
1081
  SArray*  pFuncs;
1082
  char*    pComment;
1083
  char*    pAst1;
1084
  char*    pAst2;
1085
  int64_t  deleteMark1;
1086
  int64_t  deleteMark2;
1087
  int32_t  sqlLen;
1088
  char*    sql;
1089
  int64_t  keep;
1090
  int8_t   virtualStb;
1091
} SMCreateStbReq;
1092

1093
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1094
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1095
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1096

1097
typedef struct {
1098
  STableMetaRsp* pMeta;
1099
} SMCreateStbRsp;
1100

1101
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1102
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1103
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1104

1105
typedef struct {
1106
  char     name[TSDB_TABLE_FNAME_LEN];
1107
  int8_t   igNotExists;
1108
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1109
  int8_t   reserved[6];
1110
  tb_uid_t suid;
1111
  int32_t  sqlLen;
1112
  char*    sql;
1113
} SMDropStbReq;
1114

1115
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1116
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1117
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1118

1119
typedef struct {
1120
  char    name[TSDB_TABLE_FNAME_LEN];
1121
  int8_t  alterType;
1122
  int32_t numOfFields;
1123
  SArray* pFields;
1124
  int32_t ttl;
1125
  int32_t commentLen;
1126
  char*   comment;
1127
  int32_t sqlLen;
1128
  char*   sql;
1129
  int64_t keep;
1130
  SArray* pTypeMods;
1131
} SMAlterStbReq;
1132

1133
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1134
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1135
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1136

1137
typedef struct SEpSet {
1138
  int8_t inUse;
1139
  int8_t numOfEps;
1140
  SEp    eps[TSDB_MAX_REPLICA];
1141
} SEpSet;
1142

1143
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1144
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1145
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1146
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1147

1148
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1149
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1150

1151
typedef struct {
1152
  int8_t  connType;
1153
  int32_t pid;
1154
  char    app[TSDB_APP_NAME_LEN];
1155
  char    db[TSDB_DB_NAME_LEN];
1156
  char    user[TSDB_USER_LEN];
1157
  char    passwd[TSDB_PASSWORD_LEN];
1158
  int64_t startTime;
1159
  char    sVer[TSDB_VERSION_LEN];
1160
} SConnectReq;
1161

1162
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1163
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1164

1165
typedef struct {
1166
  int32_t       acctId;
1167
  int64_t       clusterId;
1168
  uint32_t      connId;
1169
  int32_t       dnodeNum;
1170
  int8_t        superUser;
1171
  int8_t        sysInfo;
1172
  int8_t        connType;
1173
  SEpSet        epSet;
1174
  int32_t       svrTimestamp;
1175
  int32_t       passVer;
1176
  int32_t       authVer;
1177
  char          sVer[TSDB_VERSION_LEN];
1178
  char          sDetailVer[128];
1179
  int64_t       whiteListVer;
1180
  SMonitorParas monitorParas;
1181
  int8_t        enableAuditDelete;
1182
} SConnectRsp;
1183

1184
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1185
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1186

1187
typedef struct {
1188
  char    user[TSDB_USER_LEN];
1189
  char    pass[TSDB_PASSWORD_LEN];
1190
  int32_t maxUsers;
1191
  int32_t maxDbs;
1192
  int32_t maxTimeSeries;
1193
  int32_t maxStreams;
1194
  int32_t accessState;  // Configured only by command
1195
  int64_t maxStorage;
1196
} SCreateAcctReq, SAlterAcctReq;
1197

1198
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1199
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1200

1201
typedef struct {
1202
  char    user[TSDB_USER_LEN];
1203
  int32_t sqlLen;
1204
  char*   sql;
1205
} SDropUserReq, SDropAcctReq;
1206

1207
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1208
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1209
void    tFreeSDropUserReq(SDropUserReq* pReq);
1210

1211
typedef struct SIpV4Range {
1212
  uint32_t ip;
1213
  uint32_t mask;
1214
} SIpV4Range;
1215

1216
typedef struct SIpv6Range {
1217
  uint64_t addr[2];
1218
  uint32_t mask;
1219
} SIpV6Range;
1220

1221
typedef struct {
1222
  int8_t type;
1223
  union {
1224
    SIpV4Range ipV4;
1225
    SIpV6Range ipV6;
1226
  };
1227
} SIpRange;
1228

1229
typedef struct {
1230
  int32_t    num;
1231
  SIpV4Range pIpRange[];
1232
} SIpWhiteList;
1233

1234
typedef struct {
1235
  int32_t  num;
1236
  SIpRange pIpRanges[];
1237
} SIpWhiteListDual;
1238

1239
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1240
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1241
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1242
int32_t           createDefaultIp6Range(SIpRange* pRange);
1243
int32_t           createDefaultIp4Range(SIpRange* pRange);
1244

1245
typedef struct {
1246
  int8_t  createType;
1247
  int8_t  superUser;  // denote if it is a super user or not
1248
  int8_t  sysInfo;
1249
  int8_t  enable;
1250
  char    user[TSDB_USER_LEN];
1251
  char    pass[TSDB_USET_PASSWORD_LEN];
1252
  int32_t numIpRanges;
1253

1254
  SIpV4Range* pIpRanges;
1255
  int32_t     sqlLen;
1256
  char*       sql;
1257
  int8_t      isImport;
1258
  int8_t      createDb;
1259
  int8_t      passIsMd5;
1260
  SIpRange*   pIpDualRanges;
1261
} SCreateUserReq;
1262

1263
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1264
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1265
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1266

1267
typedef struct {
1268
  int32_t dnodeId;
1269
  int64_t analVer;
1270
} SRetrieveAnalyticsAlgoReq;
1271

1272
typedef struct {
1273
  int64_t   ver;
1274
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1275
} SRetrieveAnalyticAlgoRsp;
1276

1277
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1278
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1279
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1280
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1281
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1282

1283
typedef struct {
1284
  int8_t alterType;
1285
  int8_t superUser;
1286
  int8_t sysInfo;
1287
  int8_t enable;
1288
  int8_t isView;
1289
  union {
1290
    uint8_t flag;
1291
    struct {
1292
      uint8_t createdb : 1;
1293
      uint8_t reserve : 7;
1294
    };
1295
  };
1296
  char        user[TSDB_USER_LEN];
1297
  char        pass[TSDB_USET_PASSWORD_LEN];
1298
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1299
  char        tabName[TSDB_TABLE_NAME_LEN];
1300
  char*       tagCond;
1301
  int32_t     tagCondLen;
1302
  int32_t     numIpRanges;
1303
  SIpV4Range* pIpRanges;
1304
  int64_t     privileges;
1305
  int32_t     sqlLen;
1306
  char*       sql;
1307
  int8_t      passIsMd5;
1308
  SIpRange*   pIpDualRanges;
1309
} SAlterUserReq;
1310

1311
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1312
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1313
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1314

1315
typedef struct {
1316
  char user[TSDB_USER_LEN];
1317
} SGetUserAuthReq;
1318

1319
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1320
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1321

1322
typedef struct {
1323
  char      user[TSDB_USER_LEN];
1324
  int32_t   version;
1325
  int32_t   passVer;
1326
  int8_t    superAuth;
1327
  int8_t    sysInfo;
1328
  int8_t    enable;
1329
  int8_t    dropped;
1330
  SHashObj* createdDbs;
1331
  SHashObj* readDbs;
1332
  SHashObj* writeDbs;
1333
  SHashObj* readTbs;
1334
  SHashObj* writeTbs;
1335
  SHashObj* alterTbs;
1336
  SHashObj* readViews;
1337
  SHashObj* writeViews;
1338
  SHashObj* alterViews;
1339
  SHashObj* useDbs;
1340
  int64_t   whiteListVer;
1341
} SGetUserAuthRsp;
1342

1343
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1344
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1345
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1346

1347
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1348
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1349
typedef struct {
1350
  int64_t ver;
1351
  char    user[TSDB_USER_LEN];
1352
  int32_t numOfRange;
1353
  union {
1354
    SIpV4Range* pIpRanges;
1355
    SIpRange*   pIpDualRanges;
1356
  };
1357
} SUpdateUserIpWhite;
1358

1359
typedef struct {
1360
  int64_t             ver;
1361
  int                 numOfUser;
1362
  SUpdateUserIpWhite* pUserIpWhite;
1363
} SUpdateIpWhite;
1364

1365
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1366
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1367
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1368
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1369

1370
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1371
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1372
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1373

1374
typedef struct {
1375
  int64_t ipWhiteVer;
1376
} SRetrieveIpWhiteReq;
1377

1378
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1379
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1380
typedef struct {
1381
  char user[TSDB_USER_LEN];
1382
} SGetUserWhiteListReq;
1383

1384
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1385
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1386

1387
typedef struct {
1388
  char    user[TSDB_USER_LEN];
1389
  int32_t numWhiteLists;
1390
  union {
1391
    SIpV4Range* pWhiteLists;
1392
    SIpRange*   pWhiteListsDual;
1393
  };
1394
} SGetUserWhiteListRsp;
1395

1396
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1397
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1398
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1399
void    tIpRangeSetDefaultMask(SIpRange* range);
1400

1401
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1402
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1403
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1404

1405
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1406
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1407
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1408

1409
/*
1410
 * for client side struct, only column id, type, bytes are necessary
1411
 * But for data in vnode side, we need all the following information.
1412
 */
1413
typedef struct {
1414
  union {
1415
    col_id_t colId;
1416
    int16_t  slotId;
1417
  };
1418

1419
  uint8_t precision;
1420
  uint8_t scale;
1421
  int32_t bytes;
1422
  int8_t  type;
1423
  uint8_t pk;
1424
  bool    noData;
1425
} SColumnInfo;
1426

1427
typedef struct STimeWindow {
1428
  TSKEY skey;
1429
  TSKEY ekey;
1430
} STimeWindow;
1431

1432
typedef struct SQueryHint {
1433
  bool batchScan;
1434
} SQueryHint;
1435

1436
typedef struct {
1437
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1438
  int32_t tsLen;          // total length of ts comp block
1439
  int32_t tsNumOfBlocks;  // ts comp block numbers
1440
  int32_t tsOrder;        // ts comp block order
1441
} STsBufInfo;
1442

1443
typedef struct {
1444
  void*       timezone;
1445
  char        intervalUnit;
1446
  char        slidingUnit;
1447
  char        offsetUnit;
1448
  int8_t      precision;
1449
  int64_t     interval;
1450
  int64_t     sliding;
1451
  int64_t     offset;
1452
  STimeWindow timeRange;
1453
} SInterval;
1454

1455
typedef struct STbVerInfo {
1456
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1457
  int32_t sversion;
1458
  int32_t tversion;
1459
  int32_t rversion;  // virtual table's column ref's version
1460
} STbVerInfo;
1461

1462
typedef struct {
1463
  int32_t code;
1464
  int64_t affectedRows;
1465
  SArray* tbVerInfo;  // STbVerInfo
1466
} SQueryTableRsp;
1467

1468
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1469

1470
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1471

1472
typedef struct {
1473
  SMsgHead header;
1474
  char     dbFName[TSDB_DB_FNAME_LEN];
1475
  char     tbName[TSDB_TABLE_NAME_LEN];
1476
} STableCfgReq;
1477

1478
typedef struct {
1479
  char        tbName[TSDB_TABLE_NAME_LEN];
1480
  char        stbName[TSDB_TABLE_NAME_LEN];
1481
  char        dbFName[TSDB_DB_FNAME_LEN];
1482
  int32_t     numOfTags;
1483
  int32_t     numOfColumns;
1484
  int8_t      tableType;
1485
  int64_t     delay1;
1486
  int64_t     delay2;
1487
  int64_t     watermark1;
1488
  int64_t     watermark2;
1489
  int32_t     ttl;
1490
  int32_t     keep;
1491
  SArray*     pFuncs;
1492
  int32_t     commentLen;
1493
  char*       pComment;
1494
  SSchema*    pSchemas;
1495
  int32_t     tagsLen;
1496
  char*       pTags;
1497
  SSchemaExt* pSchemaExt;
1498
  int8_t      virtualStb;
1499
  SColRef*    pColRefs;
1500
} STableCfg;
1501

1502
typedef STableCfg STableCfgRsp;
1503

1504
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1505
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1506

1507
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1508
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1509
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1510

1511
typedef struct {
1512
  SMsgHead header;
1513
  tb_uid_t suid;
1514
} SVSubTablesReq;
1515

1516
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1517
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1518

1519
typedef struct {
1520
  int32_t vgId;
1521
  SArray* pTables;  // SArray<SVCTableRefCols*>
1522
} SVSubTablesRsp;
1523

1524
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1525
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1526
void    tDestroySVSubTablesRsp(void* rsp);
1527

1528
typedef struct {
1529
  SMsgHead header;
1530
  tb_uid_t suid;
1531
} SVStbRefDbsReq;
1532

1533
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1534
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1535

1536
typedef struct {
1537
  int32_t vgId;
1538
  SArray* pDbs;  // SArray<char* (db name)>
1539
} SVStbRefDbsRsp;
1540

1541
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1542
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1543
void    tDestroySVStbRefDbsRsp(void* rsp);
1544

1545
typedef struct {
1546
  char    db[TSDB_DB_FNAME_LEN];
1547
  int32_t numOfVgroups;
1548
  int32_t numOfStables;  // single_stable
1549
  int32_t buffer;        // MB
1550
  int32_t pageSize;
1551
  int32_t pages;
1552
  int32_t cacheLastSize;
1553
  int32_t daysPerFile;
1554
  int32_t daysToKeep0;
1555
  int32_t daysToKeep1;
1556
  int32_t daysToKeep2;
1557
  int32_t keepTimeOffset;
1558
  int32_t minRows;
1559
  int32_t maxRows;
1560
  int32_t walFsyncPeriod;
1561
  int8_t  walLevel;
1562
  int8_t  precision;  // time resolution
1563
  int8_t  compression;
1564
  int8_t  replications;
1565
  int8_t  strict;
1566
  int8_t  cacheLast;
1567
  int8_t  schemaless;
1568
  int8_t  ignoreExist;
1569
  int32_t numOfRetensions;
1570
  SArray* pRetensions;  // SRetention
1571
  int32_t walRetentionPeriod;
1572
  int64_t walRetentionSize;
1573
  int32_t walRollPeriod;
1574
  int64_t walSegmentSize;
1575
  int32_t sstTrigger;
1576
  int16_t hashPrefix;
1577
  int16_t hashSuffix;
1578
  int32_t s3ChunkSize;
1579
  int32_t s3KeepLocal;
1580
  int8_t  s3Compact;
1581
  int32_t tsdbPageSize;
1582
  int32_t sqlLen;
1583
  char*   sql;
1584
  int8_t  withArbitrator;
1585
  int8_t  encryptAlgorithm;
1586
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1587
  // 1. add auto-compact parameters
1588
  int32_t compactInterval;    // minutes
1589
  int32_t compactStartTime;   // minutes
1590
  int32_t compactEndTime;     // minutes
1591
  int8_t  compactTimeOffset;  // hour
1592
} SCreateDbReq;
1593

1594
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1595
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1596
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1597

1598
typedef struct {
1599
  char    db[TSDB_DB_FNAME_LEN];
1600
  int32_t buffer;
1601
  int32_t pageSize;
1602
  int32_t pages;
1603
  int32_t cacheLastSize;
1604
  int32_t daysPerFile;
1605
  int32_t daysToKeep0;
1606
  int32_t daysToKeep1;
1607
  int32_t daysToKeep2;
1608
  int32_t keepTimeOffset;
1609
  int32_t walFsyncPeriod;
1610
  int8_t  walLevel;
1611
  int8_t  strict;
1612
  int8_t  cacheLast;
1613
  int8_t  replications;
1614
  int32_t sstTrigger;
1615
  int32_t minRows;
1616
  int32_t walRetentionPeriod;
1617
  int32_t walRetentionSize;
1618
  int32_t s3KeepLocal;
1619
  int8_t  s3Compact;
1620
  int32_t sqlLen;
1621
  char*   sql;
1622
  int8_t  withArbitrator;
1623
  // 1. add auto-compact parameters
1624
  int32_t compactInterval;
1625
  int32_t compactStartTime;
1626
  int32_t compactEndTime;
1627
  int8_t  compactTimeOffset;
1628
} SAlterDbReq;
1629

1630
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1631
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1632
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1633

1634
typedef struct {
1635
  char    db[TSDB_DB_FNAME_LEN];
1636
  int8_t  ignoreNotExists;
1637
  int32_t sqlLen;
1638
  char*   sql;
1639
} SDropDbReq;
1640

1641
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1642
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1643
void    tFreeSDropDbReq(SDropDbReq* pReq);
1644

1645
typedef struct {
1646
  char    db[TSDB_DB_FNAME_LEN];
1647
  int64_t uid;
1648
} SDropDbRsp;
1649

1650
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1651
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1652

1653
typedef struct {
1654
  char    db[TSDB_DB_FNAME_LEN];
1655
  int64_t dbId;
1656
  int32_t vgVersion;
1657
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1658
  int64_t stateTs;     // ms
1659
} SUseDbReq;
1660

1661
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1662
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1663

1664
typedef struct {
1665
  char    db[TSDB_DB_FNAME_LEN];
1666
  int64_t uid;
1667
  int32_t vgVersion;
1668
  int32_t vgNum;
1669
  int16_t hashPrefix;
1670
  int16_t hashSuffix;
1671
  int8_t  hashMethod;
1672
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1673
  int32_t errCode;
1674
  int64_t stateTs;  // ms
1675
} SUseDbRsp;
1676

1677
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1678
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1679
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1680
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1681
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1682

1683
typedef struct {
1684
  char db[TSDB_DB_FNAME_LEN];
1685
} SDbCfgReq;
1686

1687
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1688
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1689

1690
typedef struct {
1691
  char    db[TSDB_DB_FNAME_LEN];
1692
  int32_t maxSpeed;
1693
} STrimDbReq;
1694

1695
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1696
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1697

1698
typedef struct {
1699
  int32_t timestamp;
1700
} SVTrimDbReq;
1701

1702
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1703
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1704

1705
typedef struct {
1706
  char db[TSDB_DB_FNAME_LEN];
1707
} SS3MigrateDbReq;
1708

1709
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1710
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1711

1712
typedef struct {
1713
  int32_t timestamp;
1714
} SVS3MigrateDbReq;
1715

1716
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1717
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1718

1719
typedef struct {
1720
  int32_t timestampSec;
1721
  int32_t ttlDropMaxCount;
1722
  int32_t nUids;
1723
  SArray* pTbUids;
1724
} SVDropTtlTableReq;
1725

1726
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1727
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1728

1729
typedef struct {
1730
  char    db[TSDB_DB_FNAME_LEN];
1731
  int64_t dbId;
1732
  int32_t cfgVersion;
1733
  int32_t numOfVgroups;
1734
  int32_t numOfStables;
1735
  int32_t buffer;
1736
  int32_t cacheSize;
1737
  int32_t pageSize;
1738
  int32_t pages;
1739
  int32_t daysPerFile;
1740
  int32_t daysToKeep0;
1741
  int32_t daysToKeep1;
1742
  int32_t daysToKeep2;
1743
  int32_t keepTimeOffset;
1744
  int32_t minRows;
1745
  int32_t maxRows;
1746
  int32_t walFsyncPeriod;
1747
  int16_t hashPrefix;
1748
  int16_t hashSuffix;
1749
  int8_t  hashMethod;
1750
  int8_t  walLevel;
1751
  int8_t  precision;
1752
  int8_t  compression;
1753
  int8_t  replications;
1754
  int8_t  strict;
1755
  int8_t  cacheLast;
1756
  int8_t  encryptAlgorithm;
1757
  int32_t s3ChunkSize;
1758
  int32_t s3KeepLocal;
1759
  int8_t  s3Compact;
1760
  int8_t  compactTimeOffset;
1761
  int32_t compactInterval;
1762
  int32_t compactStartTime;
1763
  int32_t compactEndTime;
1764
  int32_t tsdbPageSize;
1765
  int32_t walRetentionPeriod;
1766
  int32_t walRollPeriod;
1767
  int64_t walRetentionSize;
1768
  int64_t walSegmentSize;
1769
  int32_t numOfRetensions;
1770
  SArray* pRetensions;
1771
  int8_t  schemaless;
1772
  int16_t sstTrigger;
1773
  int8_t  withArbitrator;
1774
} SDbCfgRsp;
1775

1776
typedef SDbCfgRsp SDbCfgInfo;
1777

1778
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1779
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1780
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1781
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1782
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1783

1784
typedef struct {
1785
  int32_t rowNum;
1786
} SQnodeListReq;
1787

1788
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1789
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1790

1791
typedef struct {
1792
  int32_t rowNum;
1793
} SDnodeListReq;
1794

1795
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1796

1797
typedef struct {
1798
  int32_t useless;  // useless
1799
} SServerVerReq;
1800

1801
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1802
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1803

1804
typedef struct {
1805
  char ver[TSDB_VERSION_LEN];
1806
} SServerVerRsp;
1807

1808
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1809
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1810

1811
typedef struct SQueryNodeAddr {
1812
  int32_t nodeId;  // vgId or qnodeId
1813
  SEpSet  epSet;
1814
} SQueryNodeAddr;
1815

1816
typedef struct {
1817
  SQueryNodeAddr addr;
1818
  uint64_t       load;
1819
} SQueryNodeLoad;
1820

1821
typedef struct {
1822
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1823
} SQnodeListRsp;
1824

1825
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1826
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1827
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1828

1829
typedef struct SDNodeAddr {
1830
  int32_t nodeId;  // dnodeId
1831
  SEpSet  epSet;
1832
} SDNodeAddr;
1833

1834
typedef struct {
1835
  SArray* dnodeList;  // SArray<SDNodeAddr>
1836
} SDnodeListRsp;
1837

1838
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1839
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1840
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1841

1842
typedef struct {
1843
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1844
} STableTSMAInfoRsp;
1845

1846
typedef struct {
1847
  SUseDbRsp*         useDbRsp;
1848
  SDbCfgRsp*         cfgRsp;
1849
  STableTSMAInfoRsp* pTsmaRsp;
1850
  int32_t            dbTsmaVersion;
1851
  char               db[TSDB_DB_FNAME_LEN];
1852
  int64_t            dbId;
1853
} SDbHbRsp;
1854

1855
typedef struct {
1856
  SArray* pArray;  // Array of SDbHbRsp
1857
} SDbHbBatchRsp;
1858

1859
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1860
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1861
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1862

1863
typedef struct {
1864
  SArray* pArray;  // Array of SGetUserAuthRsp
1865
} SUserAuthBatchRsp;
1866

1867
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1868
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1869
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1870

1871
typedef struct {
1872
  char        db[TSDB_DB_FNAME_LEN];
1873
  STimeWindow timeRange;
1874
  int32_t     sqlLen;
1875
  char*       sql;
1876
  SArray*     vgroupIds;
1877
  int8_t      metaOnly;
1878
} SCompactDbReq;
1879

1880
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1881
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1882
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1883

1884
typedef struct {
1885
  int32_t compactId;
1886
  int8_t  bAccepted;
1887
} SCompactDbRsp;
1888

1889
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1890
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1891

1892
typedef struct {
1893
  int32_t compactId;
1894
  int32_t sqlLen;
1895
  char*   sql;
1896
} SKillCompactReq;
1897

1898
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1899
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1900
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1901

1902
typedef struct {
1903
  char    name[TSDB_FUNC_NAME_LEN];
1904
  int8_t  igExists;
1905
  int8_t  funcType;
1906
  int8_t  scriptType;
1907
  int8_t  outputType;
1908
  int32_t outputLen;
1909
  int32_t bufSize;
1910
  int32_t codeLen;
1911
  int64_t signature;
1912
  char*   pComment;
1913
  char*   pCode;
1914
  int8_t  orReplace;
1915
} SCreateFuncReq;
1916

1917
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1918
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1919
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1920

1921
typedef struct {
1922
  char   name[TSDB_FUNC_NAME_LEN];
1923
  int8_t igNotExists;
1924
} SDropFuncReq;
1925

1926
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1927
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1928

1929
typedef struct {
1930
  int32_t numOfFuncs;
1931
  bool    ignoreCodeComment;
1932
  SArray* pFuncNames;
1933
} SRetrieveFuncReq;
1934

1935
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1936
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1937
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1938

1939
typedef struct {
1940
  char    name[TSDB_FUNC_NAME_LEN];
1941
  int8_t  funcType;
1942
  int8_t  scriptType;
1943
  int8_t  outputType;
1944
  int32_t outputLen;
1945
  int32_t bufSize;
1946
  int64_t signature;
1947
  int32_t commentSize;
1948
  int32_t codeSize;
1949
  char*   pComment;
1950
  char*   pCode;
1951
} SFuncInfo;
1952

1953
typedef struct {
1954
  int32_t funcVersion;
1955
  int64_t funcCreatedTime;
1956
} SFuncExtraInfo;
1957

1958
typedef struct {
1959
  int32_t numOfFuncs;
1960
  SArray* pFuncInfos;
1961
  SArray* pFuncExtraInfos;
1962
} SRetrieveFuncRsp;
1963

1964
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1965
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1966
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1967
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1968

1969
typedef struct {
1970
  int32_t       statusInterval;
1971
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1972
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1973
  char          locale[TD_LOCALE_LEN];      // tsLocale
1974
  char          charset[TD_LOCALE_LEN];     // tsCharset
1975
  int8_t        ttlChangeOnWrite;
1976
  int8_t        enableWhiteList;
1977
  int8_t        encryptionKeyStat;
1978
  uint32_t      encryptionKeyChksum;
1979
  SMonitorParas monitorParas;
1980
} SClusterCfg;
1981

1982
typedef struct {
1983
  int32_t openVnodes;
1984
  int32_t dropVnodes;
1985
  int32_t totalVnodes;
1986
  int32_t masterNum;
1987
  int64_t numOfSelectReqs;
1988
  int64_t numOfInsertReqs;
1989
  int64_t numOfInsertSuccessReqs;
1990
  int64_t numOfBatchInsertReqs;
1991
  int64_t numOfBatchInsertSuccessReqs;
1992
  int64_t errors;
1993
} SVnodesStat;
1994

1995
typedef struct {
1996
  int32_t vgId;
1997
  int8_t  syncState;
1998
  int8_t  syncRestore;
1999
  int64_t syncTerm;
2000
  int64_t roleTimeMs;
2001
  int64_t startTimeMs;
2002
  int8_t  syncCanRead;
2003
  int64_t cacheUsage;
2004
  int64_t numOfTables;
2005
  int64_t numOfTimeSeries;
2006
  int64_t totalStorage;
2007
  int64_t compStorage;
2008
  int64_t pointsWritten;
2009
  int64_t numOfSelectReqs;
2010
  int64_t numOfInsertReqs;
2011
  int64_t numOfInsertSuccessReqs;
2012
  int64_t numOfBatchInsertReqs;
2013
  int64_t numOfBatchInsertSuccessReqs;
2014
  int32_t numOfCachedTables;
2015
  int32_t learnerProgress;  // use one reservered
2016
  int64_t syncAppliedIndex;
2017
  int64_t syncCommitIndex;
2018
  int64_t bufferSegmentUsed;
2019
  int64_t bufferSegmentSize;
2020
} SVnodeLoad;
2021

2022
typedef struct {
2023
  int64_t total_requests;
2024
  int64_t total_rows;
2025
  int64_t total_bytes;
2026
  double  write_size;
2027
  double  cache_hit_ratio;
2028
  int64_t rpc_queue_wait;
2029
  int64_t preprocess_time;
2030

2031
  int64_t memory_table_size;
2032
  int64_t commit_count;
2033
  int64_t merge_count;
2034
  double  commit_time;
2035
  double  merge_time;
2036
  int64_t block_commit_time;
2037
  int64_t memtable_wait_time;
2038
} SVnodeMetrics;
2039

2040
typedef struct {
2041
  int32_t     vgId;
2042
  int64_t     numOfTables;
2043
  int64_t     memSize;
2044
  int64_t     l1Size;
2045
  int64_t     l2Size;
2046
  int64_t     l3Size;
2047
  int64_t     cacheSize;
2048
  int64_t     walSize;
2049
  int64_t     metaSize;
2050
  int64_t     rawDataSize;
2051
  int64_t     s3Size;
2052
  const char* dbname;
2053
} SDbSizeStatisInfo;
2054

2055
typedef struct {
2056
  int32_t vgId;
2057
  int64_t nTimeSeries;
2058
} SVnodeLoadLite;
2059

2060
typedef struct {
2061
  int8_t  syncState;
2062
  int64_t syncTerm;
2063
  int8_t  syncRestore;
2064
  int64_t roleTimeMs;
2065
} SMnodeLoad;
2066

2067
typedef struct {
2068
  int32_t dnodeId;
2069
  int64_t numOfProcessedQuery;
2070
  int64_t numOfProcessedCQuery;
2071
  int64_t numOfProcessedFetch;
2072
  int64_t numOfProcessedDrop;
2073
  int64_t numOfProcessedNotify;
2074
  int64_t numOfProcessedHb;
2075
  int64_t numOfProcessedDelete;
2076
  int64_t cacheDataSize;
2077
  int64_t numOfQueryInQueue;
2078
  int64_t numOfFetchInQueue;
2079
  int64_t timeInQueryQueue;
2080
  int64_t timeInFetchQueue;
2081
} SQnodeLoad;
2082

2083
typedef struct {
2084
  int32_t     sver;      // software version
2085
  int64_t     dnodeVer;  // dnode table version in sdb
2086
  int32_t     dnodeId;
2087
  int64_t     clusterId;
2088
  int64_t     rebootTime;
2089
  int64_t     updateTime;
2090
  float       numOfCores;
2091
  int32_t     numOfSupportVnodes;
2092
  int32_t     numOfDiskCfg;
2093
  int64_t     memTotal;
2094
  int64_t     memAvail;
2095
  char        dnodeEp[TSDB_EP_LEN];
2096
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2097
  SMnodeLoad  mload;
2098
  SQnodeLoad  qload;
2099
  SClusterCfg clusterCfg;
2100
  SArray*     pVloads;  // array of SVnodeLoad
2101
  int32_t     statusSeq;
2102
  int64_t     ipWhiteVer;
2103
  int64_t     analVer;
2104
  int64_t     timestamp;
2105
} SStatusReq;
2106

2107
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2108
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2109
void    tFreeSStatusReq(SStatusReq* pReq);
2110

2111
typedef struct {
2112
  int32_t forceReadConfig;
2113
  int32_t cver;
2114
  SArray* array;
2115
} SConfigReq;
2116

2117
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2118
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2119
void    tFreeSConfigReq(SConfigReq* pReq);
2120

2121
typedef struct {
2122
  int32_t dnodeId;
2123
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2124
} SDnodeInfoReq;
2125

2126
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2127
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2128

2129
typedef enum {
2130
  MONITOR_TYPE_COUNTER = 0,
2131
  MONITOR_TYPE_SLOW_LOG = 1,
2132
} MONITOR_TYPE;
2133

2134
typedef struct {
2135
  int32_t      contLen;
2136
  char*        pCont;
2137
  MONITOR_TYPE type;
2138
} SStatisReq;
2139

2140
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2141
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2142
void    tFreeSStatisReq(SStatisReq* pReq);
2143

2144
typedef struct {
2145
  char    db[TSDB_DB_FNAME_LEN];
2146
  char    table[TSDB_TABLE_NAME_LEN];
2147
  char    operation[AUDIT_OPERATION_LEN];
2148
  int32_t sqlLen;
2149
  char*   pSql;
2150
} SAuditReq;
2151
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2152
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2153
void    tFreeSAuditReq(SAuditReq* pReq);
2154

2155
typedef struct {
2156
  int32_t dnodeId;
2157
  int64_t clusterId;
2158
  SArray* pVloads;
2159
} SNotifyReq;
2160

2161
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2162
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2163
void    tFreeSNotifyReq(SNotifyReq* pReq);
2164

2165
typedef struct {
2166
  int32_t dnodeId;
2167
  int64_t clusterId;
2168
} SDnodeCfg;
2169

2170
typedef struct {
2171
  int32_t id;
2172
  int8_t  isMnode;
2173
  SEp     ep;
2174
} SDnodeEp;
2175

2176
typedef struct {
2177
  int32_t id;
2178
  int8_t  isMnode;
2179
  int8_t  offlineReason;
2180
  SEp     ep;
2181
  char    active[TSDB_ACTIVE_KEY_LEN];
2182
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2183
} SDnodeInfo;
2184

2185
typedef struct {
2186
  int64_t   dnodeVer;
2187
  SDnodeCfg dnodeCfg;
2188
  SArray*   pDnodeEps;  // Array of SDnodeEp
2189
  int32_t   statusSeq;
2190
  int64_t   ipWhiteVer;
2191
  int64_t   analVer;
2192
} SStatusRsp;
2193

2194
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2195
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2196
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2197

2198
typedef struct {
2199
  int32_t forceReadConfig;
2200
  int32_t isConifgVerified;
2201
  int32_t isVersionVerified;
2202
  int32_t cver;
2203
  SArray* array;
2204
} SConfigRsp;
2205

2206
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2207
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2208
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2209

2210
typedef struct {
2211
  int32_t reserved;
2212
} SMTimerReq;
2213

2214
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2215
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2216

2217
typedef struct SOrphanTask {
2218
  int64_t streamId;
2219
  int32_t taskId;
2220
  int32_t nodeId;
2221
} SOrphanTask;
2222

2223
typedef struct SMStreamDropOrphanMsg {
2224
  SArray* pList;  // SArray<SOrphanTask>
2225
} SMStreamDropOrphanMsg;
2226

2227
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2228
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2229
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2230

2231
typedef struct {
2232
  int32_t  id;
2233
  uint16_t port;                 // node sync Port
2234
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2235
} SReplica;
2236

2237
typedef struct {
2238
  int32_t  vgId;
2239
  char     db[TSDB_DB_FNAME_LEN];
2240
  int64_t  dbUid;
2241
  int32_t  vgVersion;
2242
  int32_t  numOfStables;
2243
  int32_t  buffer;
2244
  int32_t  pageSize;
2245
  int32_t  pages;
2246
  int32_t  cacheLastSize;
2247
  int32_t  daysPerFile;
2248
  int32_t  daysToKeep0;
2249
  int32_t  daysToKeep1;
2250
  int32_t  daysToKeep2;
2251
  int32_t  keepTimeOffset;
2252
  int32_t  minRows;
2253
  int32_t  maxRows;
2254
  int32_t  walFsyncPeriod;
2255
  uint32_t hashBegin;
2256
  uint32_t hashEnd;
2257
  int8_t   hashMethod;
2258
  int8_t   walLevel;
2259
  int8_t   precision;
2260
  int8_t   compression;
2261
  int8_t   strict;
2262
  int8_t   cacheLast;
2263
  int8_t   isTsma;
2264
  int8_t   replica;
2265
  int8_t   selfIndex;
2266
  SReplica replicas[TSDB_MAX_REPLICA];
2267
  int32_t  numOfRetensions;
2268
  SArray*  pRetensions;  // SRetention
2269
  void*    pTsma;
2270
  int32_t  walRetentionPeriod;
2271
  int64_t  walRetentionSize;
2272
  int32_t  walRollPeriod;
2273
  int64_t  walSegmentSize;
2274
  int16_t  sstTrigger;
2275
  int16_t  hashPrefix;
2276
  int16_t  hashSuffix;
2277
  int32_t  tsdbPageSize;
2278
  int32_t  s3ChunkSize;
2279
  int32_t  s3KeepLocal;
2280
  int8_t   s3Compact;
2281
  int64_t  reserved[6];
2282
  int8_t   learnerReplica;
2283
  int8_t   learnerSelfIndex;
2284
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2285
  int32_t  changeVersion;
2286
  int8_t   encryptAlgorithm;
2287
} SCreateVnodeReq;
2288

2289
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2290
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2291
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2292

2293
typedef struct {
2294
  int32_t compactId;
2295
  int32_t vgId;
2296
  int32_t dnodeId;
2297
} SQueryCompactProgressReq;
2298

2299
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2300
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2301

2302
typedef struct {
2303
  int32_t compactId;
2304
  int32_t vgId;
2305
  int32_t dnodeId;
2306
  int32_t numberFileset;
2307
  int32_t finished;
2308
  int32_t progress;
2309
  int64_t remainingTime;
2310
} SQueryCompactProgressRsp;
2311

2312
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2313
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2314

2315
typedef struct {
2316
  int32_t vgId;
2317
  int32_t dnodeId;
2318
  int64_t dbUid;
2319
  char    db[TSDB_DB_FNAME_LEN];
2320
  int64_t reserved[8];
2321
} SDropVnodeReq;
2322

2323
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2324
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2325

2326
typedef struct {
2327
  char    colName[TSDB_COL_NAME_LEN];
2328
  char    stb[TSDB_TABLE_FNAME_LEN];
2329
  int64_t stbUid;
2330
  int64_t dbUid;
2331
  int64_t reserved[8];
2332
} SDropIndexReq;
2333

2334
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2335
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2336

2337
typedef struct {
2338
  int64_t     dbUid;
2339
  char        db[TSDB_DB_FNAME_LEN];
2340
  int64_t     compactStartTime;
2341
  STimeWindow tw;
2342
  int32_t     compactId;
2343
  int8_t      metaOnly;
2344
} SCompactVnodeReq;
2345

2346
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2347
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2348

2349
typedef struct {
2350
  int32_t compactId;
2351
  int32_t vgId;
2352
  int32_t dnodeId;
2353
} SVKillCompactReq;
2354

2355
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2356
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2357

2358
typedef struct {
2359
  int32_t vgVersion;
2360
  int32_t buffer;
2361
  int32_t pageSize;
2362
  int32_t pages;
2363
  int32_t cacheLastSize;
2364
  int32_t daysPerFile;
2365
  int32_t daysToKeep0;
2366
  int32_t daysToKeep1;
2367
  int32_t daysToKeep2;
2368
  int32_t keepTimeOffset;
2369
  int32_t walFsyncPeriod;
2370
  int8_t  walLevel;
2371
  int8_t  strict;
2372
  int8_t  cacheLast;
2373
  int64_t reserved[7];
2374
  // 1st modification
2375
  int16_t sttTrigger;
2376
  int32_t minRows;
2377
  // 2nd modification
2378
  int32_t walRetentionPeriod;
2379
  int32_t walRetentionSize;
2380
  int32_t s3KeepLocal;
2381
  int8_t  s3Compact;
2382
} SAlterVnodeConfigReq;
2383

2384
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2385
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2386

2387
typedef struct {
2388
  int32_t  vgId;
2389
  int8_t   strict;
2390
  int8_t   selfIndex;
2391
  int8_t   replica;
2392
  SReplica replicas[TSDB_MAX_REPLICA];
2393
  int64_t  reserved[8];
2394
  int8_t   learnerSelfIndex;
2395
  int8_t   learnerReplica;
2396
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2397
  int32_t  changeVersion;
2398
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2399

2400
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2401
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2402

2403
typedef struct {
2404
  int32_t vgId;
2405
  int8_t  disable;
2406
} SDisableVnodeWriteReq;
2407

2408
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2409
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2410

2411
typedef struct {
2412
  int32_t  srcVgId;
2413
  int32_t  dstVgId;
2414
  uint32_t hashBegin;
2415
  uint32_t hashEnd;
2416
  int32_t  changeVersion;
2417
  int32_t  reserved;
2418
} SAlterVnodeHashRangeReq;
2419

2420
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2421
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2422

2423
#define REQ_OPT_TBNAME 0x0
2424
#define REQ_OPT_TBUID  0x01
2425
typedef struct {
2426
  SMsgHead header;
2427
  char     dbFName[TSDB_DB_FNAME_LEN];
2428
  char     tbName[TSDB_TABLE_NAME_LEN];
2429
  uint8_t  option;
2430
  uint8_t  autoCreateCtb;
2431
} STableInfoReq;
2432

2433
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2434
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2435

2436
typedef struct {
2437
  int8_t  metaClone;  // create local clone of the cached table meta
2438
  int32_t numOfVgroups;
2439
  int32_t numOfTables;
2440
  int32_t numOfUdfs;
2441
  char    tableNames[];
2442
} SMultiTableInfoReq;
2443

2444
// todo refactor
2445
typedef struct SVgroupInfo {
2446
  int32_t  vgId;
2447
  uint32_t hashBegin;
2448
  uint32_t hashEnd;
2449
  SEpSet   epSet;
2450
  union {
2451
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2452
    int32_t taskId;      // used in stream
2453
  };
2454
} SVgroupInfo;
2455

2456
typedef struct {
2457
  int32_t     numOfVgroups;
2458
  SVgroupInfo vgroups[];
2459
} SVgroupsInfo;
2460

2461
typedef struct {
2462
  STableMetaRsp* pMeta;
2463
} SMAlterStbRsp;
2464

2465
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2466
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2467
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2468

2469
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2470
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2471
void    tFreeSTableMetaRsp(void* pRsp);
2472
void    tFreeSTableIndexRsp(void* info);
2473

2474
typedef struct {
2475
  SArray* pMetaRsp;   // Array of STableMetaRsp
2476
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2477
} SSTbHbRsp;
2478

2479
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2480
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2481
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2482

2483
typedef struct {
2484
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2485
} SViewHbRsp;
2486

2487
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2488
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2489
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2490

2491
typedef struct {
2492
  int32_t numOfTables;
2493
  int32_t numOfVgroup;
2494
  int32_t numOfUdf;
2495
  int32_t contLen;
2496
  int8_t  compressed;  // denote if compressed or not
2497
  int32_t rawLen;      // size before compress
2498
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2499
  char    meta[];
2500
} SMultiTableMeta;
2501

2502
typedef struct {
2503
  int32_t dataLen;
2504
  char    name[TSDB_TABLE_FNAME_LEN];
2505
  char*   data;
2506
} STagData;
2507

2508
typedef struct {
2509
  int32_t  opType;
2510
  uint32_t valLen;
2511
  char*    val;
2512
} SShowVariablesReq;
2513

2514
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2515
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2516
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2517

2518
typedef struct {
2519
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2520
  char value[TSDB_CONFIG_PATH_LEN + 1];
2521
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2522
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2523
  char info[TSDB_CONFIG_INFO_LEN + 1];
2524
} SVariablesInfo;
2525

2526
typedef struct {
2527
  SArray* variables;  // SArray<SVariablesInfo>
2528
} SShowVariablesRsp;
2529

2530
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2531
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2532

2533
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2534

2535
/*
2536
 * sql: show tables like '%a_%'
2537
 * payload is the query condition, e.g., '%a_%'
2538
 * payloadLen is the length of payload
2539
 */
2540
typedef struct {
2541
  int32_t type;
2542
  char    db[TSDB_DB_FNAME_LEN];
2543
  int32_t payloadLen;
2544
  char*   payload;
2545
} SShowReq;
2546

2547
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2548
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2549
void tFreeSShowReq(SShowReq* pReq);
2550

2551
typedef struct {
2552
  int64_t       showId;
2553
  STableMetaRsp tableMeta;
2554
} SShowRsp, SVShowTablesRsp;
2555

2556
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2557
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2558
// void    tFreeSShowRsp(SShowRsp* pRsp);
2559

2560
typedef struct {
2561
  char    db[TSDB_DB_FNAME_LEN];
2562
  char    tb[TSDB_TABLE_NAME_LEN];
2563
  char    user[TSDB_USER_LEN];
2564
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2565
  int64_t showId;
2566
  int64_t compactId;  // for compact
2567
  bool    withFull;   // for show users full
2568
} SRetrieveTableReq;
2569

2570
typedef struct SSysTableSchema {
2571
  int8_t   type;
2572
  col_id_t colId;
2573
  int32_t  bytes;
2574
} SSysTableSchema;
2575

2576
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2577
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2578

2579
#define RETRIEVE_TABLE_RSP_VERSION         0
2580
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2581
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2582

2583
typedef struct {
2584
  int64_t useconds;
2585
  int8_t  completed;  // all results are returned to client
2586
  int8_t  precision;
2587
  int8_t  compressed;
2588
  int8_t  streamBlockType;
2589
  int32_t payloadLen;
2590
  int32_t compLen;
2591
  int32_t numOfBlocks;
2592
  int64_t numOfRows;  // from int32_t change to int64_t
2593
  int64_t numOfCols;
2594
  int64_t skey;
2595
  int64_t ekey;
2596
  int64_t version;                         // for stream
2597
  TSKEY   watermark;                       // for stream
2598
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2599
  char    data[];
2600
} SRetrieveTableRsp;
2601

2602
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2603

2604
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2605
  do {                                          \
2606
    ((int32_t*)(_p))[0] = (_compLen);           \
2607
    ((int32_t*)(_p))[1] = (_fullLen);           \
2608
  } while (0);
2609

2610
typedef struct {
2611
  int64_t version;
2612
  int64_t numOfRows;
2613
  int8_t  compressed;
2614
  int8_t  precision;
2615
  char    data[];
2616
} SRetrieveTableRspForTmq;
2617

2618
typedef struct {
2619
  int64_t handle;
2620
  int64_t useconds;
2621
  int8_t  completed;  // all results are returned to client
2622
  int8_t  precision;
2623
  int8_t  compressed;
2624
  int32_t compLen;
2625
  int32_t numOfRows;
2626
  int32_t fullLen;
2627
  char    data[];
2628
} SRetrieveMetaTableRsp;
2629

2630
typedef struct SExplainExecInfo {
2631
  double   startupCost;
2632
  double   totalCost;
2633
  uint64_t numOfRows;
2634
  uint32_t verboseLen;
2635
  void*    verboseInfo;
2636
} SExplainExecInfo;
2637

2638
typedef struct {
2639
  int32_t           numOfPlans;
2640
  SExplainExecInfo* subplanInfo;
2641
} SExplainRsp;
2642

2643
typedef struct {
2644
  SExplainRsp rsp;
2645
  uint64_t    qId;
2646
  uint64_t    cId;
2647
  uint64_t    tId;
2648
  int64_t     rId;
2649
  int32_t     eId;
2650
} SExplainLocalRsp;
2651

2652
typedef struct STableScanAnalyzeInfo {
2653
  uint64_t totalRows;
2654
  uint64_t totalCheckedRows;
2655
  uint32_t totalBlocks;
2656
  uint32_t loadBlocks;
2657
  uint32_t loadBlockStatis;
2658
  uint32_t skipBlocks;
2659
  uint32_t filterOutBlocks;
2660
  double   elapsedTime;
2661
  double   filterTime;
2662
} STableScanAnalyzeInfo;
2663

2664
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2665
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2666
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2667

2668
typedef struct {
2669
  char    config[TSDB_DNODE_CONFIG_LEN];
2670
  char    value[TSDB_CLUSTER_VALUE_LEN];
2671
  int32_t sqlLen;
2672
  char*   sql;
2673
} SMCfgClusterReq;
2674

2675
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2676
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2677
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2678

2679
typedef struct {
2680
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2681
  int32_t port;
2682
  int32_t sqlLen;
2683
  char*   sql;
2684
} SCreateDnodeReq;
2685

2686
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2687
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2688
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2689

2690
typedef struct {
2691
  int32_t dnodeId;
2692
  char    fqdn[TSDB_FQDN_LEN];
2693
  int32_t port;
2694
  int8_t  force;
2695
  int8_t  unsafe;
2696
  int32_t sqlLen;
2697
  char*   sql;
2698
} SDropDnodeReq;
2699

2700
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2701
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2702
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2703

2704
enum {
2705
  RESTORE_TYPE__ALL = 1,
2706
  RESTORE_TYPE__MNODE,
2707
  RESTORE_TYPE__VNODE,
2708
  RESTORE_TYPE__QNODE,
2709
};
2710

2711
typedef struct {
2712
  int32_t dnodeId;
2713
  int8_t  restoreType;
2714
  int32_t sqlLen;
2715
  char*   sql;
2716
} SRestoreDnodeReq;
2717

2718
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2719
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2720
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2721

2722
typedef struct {
2723
  int32_t dnodeId;
2724
  char    config[TSDB_DNODE_CONFIG_LEN];
2725
  char    value[TSDB_DNODE_VALUE_LEN];
2726
  int32_t sqlLen;
2727
  char*   sql;
2728
} SMCfgDnodeReq;
2729

2730
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2731
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2732
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2733

2734
typedef struct {
2735
  char    config[TSDB_DNODE_CONFIG_LEN];
2736
  char    value[TSDB_DNODE_VALUE_LEN];
2737
  int32_t version;
2738
} SDCfgDnodeReq;
2739

2740
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2741
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2742

2743
typedef struct {
2744
  int32_t dnodeId;
2745
  int32_t sqlLen;
2746
  char*   sql;
2747
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2748
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2749

2750
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2751
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2752
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2753
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2754
typedef struct {
2755
  int8_t   replica;
2756
  SReplica replicas[TSDB_MAX_REPLICA];
2757
  int8_t   learnerReplica;
2758
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2759
  int64_t  lastIndex;
2760
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2761

2762
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2763
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2764

2765
typedef struct {
2766
  int32_t urlLen;
2767
  int32_t sqlLen;
2768
  char*   url;
2769
  char*   sql;
2770
} SMCreateAnodeReq;
2771

2772
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2773
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2774
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2775

2776
typedef struct {
2777
  int32_t anodeId;
2778
  int32_t sqlLen;
2779
  char*   sql;
2780
} SMDropAnodeReq, SMUpdateAnodeReq;
2781

2782
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2783
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2784
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2785
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2786
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2787
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2788

2789
typedef struct {
2790
  int32_t dnodeId;
2791
  int32_t bnodeProto;
2792
  int32_t sqlLen;
2793
  char*   sql;
2794
} SMCreateBnodeReq, SDCreateBnodeReq;
2795

2796
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2797
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2798
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
2799

2800
typedef struct {
2801
  int32_t dnodeId;
2802
  int32_t sqlLen;
2803
  char*   sql;
2804
} SMDropBnodeReq, SDDropBnodeReq;
2805

2806
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2807
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2808
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
2809

2810
typedef struct {
2811
  int32_t vgId;
2812
  int32_t hbSeq;
2813
} SVArbHbReqMember;
2814

2815
typedef struct {
2816
  int32_t dnodeId;
2817
  char*   arbToken;
2818
  int64_t arbTerm;
2819
  SArray* hbMembers;  // SVArbHbReqMember
2820
} SVArbHeartBeatReq;
2821

2822
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2823
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2824
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2825

2826
typedef struct {
2827
  int32_t vgId;
2828
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2829
  int32_t hbSeq;
2830
} SVArbHbRspMember;
2831

2832
typedef struct {
2833
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2834
  int32_t dnodeId;
2835
  SArray* hbMembers;  // SVArbHbRspMember
2836
} SVArbHeartBeatRsp;
2837

2838
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2839
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2840
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2841

2842
typedef struct {
2843
  char*   arbToken;
2844
  int64_t arbTerm;
2845
  char*   member0Token;
2846
  char*   member1Token;
2847
} SVArbCheckSyncReq;
2848

2849
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2850
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2851
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2852

2853
typedef struct {
2854
  char*   arbToken;
2855
  char*   member0Token;
2856
  char*   member1Token;
2857
  int32_t vgId;
2858
  int32_t errCode;
2859
} SVArbCheckSyncRsp;
2860

2861
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2862
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2863
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2864

2865
typedef struct {
2866
  char*   arbToken;
2867
  int64_t arbTerm;
2868
  char*   memberToken;
2869
  int8_t  force;
2870
} SVArbSetAssignedLeaderReq;
2871

2872
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2873
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2874
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2875

2876
typedef struct {
2877
  char*   arbToken;
2878
  char*   memberToken;
2879
  int32_t vgId;
2880
} SVArbSetAssignedLeaderRsp;
2881

2882
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2883
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2884
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2885

2886
typedef struct {
2887
  int32_t dnodeId;
2888
  char*   token;
2889
} SMArbUpdateGroupMember;
2890

2891
typedef struct {
2892
  int32_t dnodeId;
2893
  char*   token;
2894
  int8_t  acked;
2895
} SMArbUpdateGroupAssigned;
2896

2897
typedef struct {
2898
  int32_t                  vgId;
2899
  int64_t                  dbUid;
2900
  SMArbUpdateGroupMember   members[2];
2901
  int8_t                   isSync;
2902
  int8_t                   assignedAcked;
2903
  SMArbUpdateGroupAssigned assignedLeader;
2904
  int64_t                  version;
2905
  int32_t                  code;
2906
  int64_t                  updateTimeMs;
2907
} SMArbUpdateGroup;
2908

2909
typedef struct {
2910
  SArray* updateArray;  // SMArbUpdateGroup
2911
} SMArbUpdateGroupBatchReq;
2912

2913
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2914
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2915
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2916

2917
typedef struct {
2918
  char queryStrId[TSDB_QUERY_ID_LEN];
2919
} SKillQueryReq;
2920

2921
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2922
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2923

2924
typedef struct {
2925
  uint32_t connId;
2926
} SKillConnReq;
2927

2928
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2929
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2930

2931
typedef struct {
2932
  int32_t transId;
2933
} SKillTransReq;
2934

2935
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2936
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2937

2938
typedef struct {
2939
  int32_t useless;  // useless
2940
  int32_t sqlLen;
2941
  char*   sql;
2942
} SBalanceVgroupReq;
2943

2944
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2945
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2946
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2947

2948
typedef struct {
2949
  int32_t useless;  // useless
2950
  int32_t sqlLen;
2951
  char*   sql;
2952
} SAssignLeaderReq;
2953

2954
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2955
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2956
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2957
typedef struct {
2958
  int32_t vgId1;
2959
  int32_t vgId2;
2960
} SMergeVgroupReq;
2961

2962
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2963
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2964

2965
typedef struct {
2966
  int32_t vgId;
2967
  int32_t dnodeId1;
2968
  int32_t dnodeId2;
2969
  int32_t dnodeId3;
2970
  int32_t sqlLen;
2971
  char*   sql;
2972
} SRedistributeVgroupReq;
2973

2974
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2975
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2976
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2977

2978
typedef struct {
2979
  int32_t reserved;
2980
  int32_t vgId;
2981
  int32_t sqlLen;
2982
  char*   sql;
2983
  char    db[TSDB_DB_FNAME_LEN];
2984
} SBalanceVgroupLeaderReq;
2985

2986
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2987
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2988
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2989

2990
typedef struct {
2991
  int32_t vgId;
2992
} SForceBecomeFollowerReq;
2993

2994
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2995
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2996

2997
typedef struct {
2998
  int32_t vgId;
2999
} SSplitVgroupReq;
3000

3001
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3002
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3003

3004
typedef struct {
3005
  char user[TSDB_USER_LEN];
3006
  char spi;
3007
  char encrypt;
3008
  char secret[TSDB_PASSWORD_LEN];
3009
  char ckey[TSDB_PASSWORD_LEN];
3010
} SAuthReq, SAuthRsp;
3011

3012
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3013
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3014

3015
typedef struct {
3016
  int32_t statusCode;
3017
  char    details[1024];
3018
} SServerStatusRsp;
3019

3020
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3021
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3022

3023
/**
3024
 * The layout of the query message payload is as following:
3025
 * +--------------------+---------------------------------+
3026
 * |Sql statement       | Physical plan                   |
3027
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3028
 * +--------------------+---------------------------------+
3029
 */
3030
typedef struct SSubQueryMsg {
3031
  SMsgHead header;
3032
  uint64_t sId;
3033
  uint64_t queryId;
3034
  uint64_t clientId;
3035
  uint64_t taskId;
3036
  int64_t  refId;
3037
  int32_t  execId;
3038
  int32_t  msgMask;
3039
  int8_t   taskType;
3040
  int8_t   explain;
3041
  int8_t   needFetch;
3042
  int8_t   compress;
3043
  uint32_t sqlLen;
3044
  char*    sql;
3045
  uint32_t msgLen;
3046
  char*    msg;
3047
} SSubQueryMsg;
3048

3049
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3050
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3051
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3052

3053
typedef struct {
3054
  SMsgHead header;
3055
  uint64_t sId;
3056
  uint64_t queryId;
3057
  uint64_t taskId;
3058
} SSinkDataReq;
3059

3060
typedef struct {
3061
  SMsgHead header;
3062
  uint64_t sId;
3063
  uint64_t queryId;
3064
  uint64_t clientId;
3065
  uint64_t taskId;
3066
  int32_t  execId;
3067
} SQueryContinueReq;
3068

3069
typedef struct {
3070
  SMsgHead header;
3071
  uint64_t sId;
3072
  uint64_t queryId;
3073
  uint64_t taskId;
3074
} SResReadyReq;
3075

3076
typedef struct {
3077
  int32_t code;
3078
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3079
  int32_t sversion;
3080
  int32_t tversion;
3081
} SResReadyRsp;
3082

3083
typedef struct SOperatorParam {
3084
  int32_t opType;
3085
  int32_t downstreamIdx;
3086
  void*   value;
3087
  SArray* pChildren;  // SArray<SOperatorParam*>
3088
  bool    reUse;
3089
} SOperatorParam;
3090

3091
typedef struct SColIdNameKV {
3092
  col_id_t colId;
3093
  char     colName[TSDB_COL_NAME_LEN];
3094
} SColIdNameKV;
3095

3096
typedef struct SColIdPair {
3097
  col_id_t vtbColId;
3098
  col_id_t orgColId;
3099
} SColIdPair;
3100

3101
typedef struct SOrgTbInfo {
3102
  int32_t vgId;
3103
  char    tbName[TSDB_TABLE_FNAME_LEN];
3104
  SArray* colMap;  // SArray<SColIdNameKV>
3105
} SOrgTbInfo;
3106

3107
typedef struct STableScanOperatorParam {
3108
  bool        tableSeq;
3109
  SArray*     pUidList;
3110
  SOrgTbInfo* pOrgTbInfo;
3111
  STimeWindow window;
3112
} STableScanOperatorParam;
3113

3114
typedef struct SVTableScanOperatorParam {
3115
  uint64_t uid;
3116
  SArray*  pOpParamArray;  // SArray<SOperatorParam>
3117
} SVTableScanOperatorParam;
3118

3119
typedef struct {
3120
  SMsgHead        header;
3121
  uint64_t        sId;
3122
  uint64_t        queryId;
3123
  uint64_t        clientId;
3124
  uint64_t        taskId;
3125
  int32_t         execId;
3126
  SOperatorParam* pOpParam;
3127
} SResFetchReq;
3128

3129
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3130
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3131

3132
typedef struct {
3133
  SMsgHead header;
3134
  uint64_t clientId;
3135
} SSchTasksStatusReq;
3136

3137
typedef struct {
3138
  uint64_t queryId;
3139
  uint64_t clientId;
3140
  uint64_t taskId;
3141
  int64_t  refId;
3142
  int32_t  execId;
3143
  int8_t   status;
3144
} STaskStatus;
3145

3146
typedef struct {
3147
  int64_t refId;
3148
  SArray* taskStatus;  // SArray<STaskStatus>
3149
} SSchedulerStatusRsp;
3150

3151
typedef struct {
3152
  uint64_t queryId;
3153
  uint64_t taskId;
3154
  int8_t   action;
3155
} STaskAction;
3156

3157
typedef struct SQueryNodeEpId {
3158
  int32_t nodeId;  // vgId or qnodeId
3159
  SEp     ep;
3160
} SQueryNodeEpId;
3161

3162
typedef struct {
3163
  SMsgHead       header;
3164
  uint64_t       clientId;
3165
  SQueryNodeEpId epId;
3166
  SArray*        taskAction;  // SArray<STaskAction>
3167
} SSchedulerHbReq;
3168

3169
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3170
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3171
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3172

3173
typedef struct {
3174
  SQueryNodeEpId epId;
3175
  SArray*        taskStatus;  // SArray<STaskStatus>
3176
} SSchedulerHbRsp;
3177

3178
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3179
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3180
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3181

3182
typedef struct {
3183
  SMsgHead header;
3184
  uint64_t sId;
3185
  uint64_t queryId;
3186
  uint64_t clientId;
3187
  uint64_t taskId;
3188
  int64_t  refId;
3189
  int32_t  execId;
3190
} STaskCancelReq;
3191

3192
typedef struct {
3193
  int32_t code;
3194
} STaskCancelRsp;
3195

3196
typedef struct {
3197
  SMsgHead header;
3198
  uint64_t sId;
3199
  uint64_t queryId;
3200
  uint64_t clientId;
3201
  uint64_t taskId;
3202
  int64_t  refId;
3203
  int32_t  execId;
3204
} STaskDropReq;
3205

3206
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3207
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3208

3209
typedef enum {
3210
  TASK_NOTIFY_FINISHED = 1,
3211
} ETaskNotifyType;
3212

3213
typedef struct {
3214
  SMsgHead        header;
3215
  uint64_t        sId;
3216
  uint64_t        queryId;
3217
  uint64_t        clientId;
3218
  uint64_t        taskId;
3219
  int64_t         refId;
3220
  int32_t         execId;
3221
  ETaskNotifyType type;
3222
} STaskNotifyReq;
3223

3224
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3225
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3226

3227
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3228
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3229

3230
typedef struct {
3231
  int32_t code;
3232
} STaskDropRsp;
3233

3234
#define STREAM_TRIGGER_AT_ONCE                 1
3235
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3236
#define STREAM_TRIGGER_MAX_DELAY               3
3237
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3238
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3239

3240
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3241
#define STREAM_FILL_HISTORY_ON        1
3242
#define STREAM_FILL_HISTORY_OFF       0
3243
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3244
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3245
#define STREAM_CREATE_STABLE_TRUE     1
3246
#define STREAM_CREATE_STABLE_FALSE    0
3247

3248
typedef struct SColLocation {
3249
  int16_t  slotId;
3250
  col_id_t colId;
3251
  int8_t   type;
3252
} SColLocation;
3253

3254
typedef struct SVgroupVer {
3255
  int32_t vgId;
3256
  int64_t ver;
3257
} SVgroupVer;
3258

3259
typedef struct {
3260
  char    name[TSDB_STREAM_FNAME_LEN];
3261
  char    sourceDB[TSDB_DB_FNAME_LEN];
3262
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3263
  char*   sql;
3264
  char*   ast;
3265
  int8_t  igExists;
3266
  int8_t  triggerType;
3267
  int8_t  igExpired;
3268
  int8_t  fillHistory;  // process data inserted before creating stream
3269
  int64_t maxDelay;
3270
  int64_t watermark;
3271
  int32_t numOfTags;
3272
  SArray* pTags;  // array of SField
3273
  // 3.0.20
3274
  int64_t checkpointFreq;  // ms
3275
  // 3.0.2.3
3276
  int8_t   createStb;
3277
  uint64_t targetStbUid;
3278
  SArray*  fillNullCols;  // array of SColLocation
3279
  int64_t  deleteMark;
3280
  int8_t   igUpdate;
3281
  int64_t  lastTs;
3282
  SArray*  pVgroupVerList;
3283
  // 3.3.0.0
3284
  SArray* pCols;  // array of SField
3285
  int64_t smaId;
3286
  // 3.3.6.0
3287
  SArray* pNotifyAddrUrls;
3288
  int32_t notifyEventTypes;
3289
  int32_t notifyErrorHandle;
3290
  int8_t  notifyHistory;
3291
  int64_t recalculateInterval;
3292
  char    pWstartName[TSDB_COL_NAME_LEN];
3293
  char    pWendName[TSDB_COL_NAME_LEN];
3294
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3295
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3296
  SArray* pVSubTables;  // array of SVSubTablesRsp
3297
} SCMCreateStreamReq;
3298

3299
typedef struct STaskNotifyEventStat {
3300
  int64_t notifyEventAddTimes;     // call times of add function
3301
  int64_t notifyEventAddElems;     // elements added by add function
3302
  double  notifyEventAddCostSec;   // time cost of add function
3303
  int64_t notifyEventPushTimes;    // call times of push function
3304
  int64_t notifyEventPushElems;    // elements pushed by push function
3305
  double  notifyEventPushCostSec;  // time cost of push function
3306
  int64_t notifyEventPackTimes;    // call times of pack function
3307
  int64_t notifyEventPackElems;    // elements packed by pack function
3308
  double  notifyEventPackCostSec;  // time cost of pack function
3309
  int64_t notifyEventSendTimes;    // call times of send function
3310
  int64_t notifyEventSendElems;    // elements sent by send function
3311
  double  notifyEventSendCostSec;  // time cost of send function
3312
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3313
} STaskNotifyEventStat;
3314

3315
typedef struct {
3316
  int64_t streamId;
3317
} SCMCreateStreamRsp;
3318

3319
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3320
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3321
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3322

3323
enum {
3324
  TOPIC_SUB_TYPE__DB = 1,
3325
  TOPIC_SUB_TYPE__TABLE,
3326
  TOPIC_SUB_TYPE__COLUMN,
3327
};
3328

3329
#define DEFAULT_MAX_POLL_INTERVAL  300000
3330
#define DEFAULT_SESSION_TIMEOUT    12000
3331
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3332
#define DEFAULT_MIN_POLL_ROWS      4096
3333

3334
typedef struct {
3335
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3336
  int8_t igExists;
3337
  int8_t subType;
3338
  int8_t withMeta;
3339
  char*  sql;
3340
  char   subDbName[TSDB_DB_FNAME_LEN];
3341
  char*  ast;
3342
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3343
} SCMCreateTopicReq;
3344

3345
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3346
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3347
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3348

3349
typedef struct {
3350
  int64_t consumerId;
3351
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3352

3353
typedef struct {
3354
  int64_t consumerId;
3355
  char    cgroup[TSDB_CGROUP_LEN];
3356
  char    clientId[TSDB_CLIENT_ID_LEN];
3357
  char    user[TSDB_USER_LEN];
3358
  char    fqdn[TSDB_FQDN_LEN];
3359
  SArray* topicNames;  // SArray<char**>
3360

3361
  int8_t  withTbName;
3362
  int8_t  autoCommit;
3363
  int32_t autoCommitInterval;
3364
  int8_t  resetOffsetCfg;
3365
  int8_t  enableReplay;
3366
  int8_t  enableBatchMeta;
3367
  int32_t sessionTimeoutMs;
3368
  int32_t maxPollIntervalMs;
3369
} SCMSubscribeReq;
3370

3371
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3372
  int32_t tlen = 0;
2,465✔
3373
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,465!
3374
  tlen += taosEncodeString(buf, pReq->cgroup);
2,465✔
3375
  tlen += taosEncodeString(buf, pReq->clientId);
2,465✔
3376

3377
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,465!
3378
  tlen += taosEncodeFixedI32(buf, topicNum);
2,464✔
3379

3380
  for (int32_t i = 0; i < topicNum; i++) {
3,480✔
3381
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,032✔
3382
  }
3383

3384
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,464!
3385
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,464!
3386
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,464!
3387
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,464!
3388
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,464!
3389
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,464!
3390
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,464!
3391
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,464!
3392
  tlen += taosEncodeString(buf, pReq->user);
2,464✔
3393
  tlen += taosEncodeString(buf, pReq->fqdn);
2,464✔
3394

3395
  return tlen;
2,464✔
3396
}
3397

3398
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3399
  void* start = buf;
1,306✔
3400
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,306!
3401
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,306✔
3402
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,306✔
3403

3404
  int32_t topicNum = 0;
1,306!
3405
  buf = taosDecodeFixedI32(buf, &topicNum);
1,306✔
3406

3407
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,306✔
3408
  if (pReq->topicNames == NULL) {
1,306!
3409
    return terrno;
×
3410
  }
3411
  for (int32_t i = 0; i < topicNum; i++) {
1,906✔
3412
    char* name = NULL;
600✔
3413
    buf = taosDecodeString(buf, &name);
600✔
3414
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,200!
3415
      return terrno;
×
3416
    }
3417
  }
3418

3419
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,306✔
3420
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,306✔
3421
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,306!
3422
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,306✔
3423
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,306✔
3424
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,306✔
3425
  if ((char*)buf - (char*)start < len) {
1,306!
3426
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,306!
3427
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,306!
3428
    buf = taosDecodeStringTo(buf, pReq->user);
1,306✔
3429
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,612✔
3430
  } else {
3431
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3432
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3433
  }
3434

3435
  return 0;
1,306✔
3436
}
3437

3438
typedef struct {
3439
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3440
  SArray* removedConsumers;  // SArray<int64_t>
3441
  SArray* newConsumers;      // SArray<int64_t>
3442
} SMqRebInfo;
3443

3444
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3445
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,279!
3446
  if (pRebInfo == NULL) {
1,279!
3447
    return NULL;
×
3448
  }
3449
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,279✔
3450
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,279✔
3451
  if (pRebInfo->removedConsumers == NULL) {
1,279!
3452
    goto _err;
×
3453
  }
3454
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,279✔
3455
  if (pRebInfo->newConsumers == NULL) {
1,279!
3456
    goto _err;
×
3457
  }
3458
  return pRebInfo;
1,279✔
3459
_err:
×
3460
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3461
  taosArrayDestroy(pRebInfo->newConsumers);
×
3462
  taosMemoryFreeClear(pRebInfo);
×
3463
  return NULL;
×
3464
}
3465

3466
typedef struct {
3467
  int64_t streamId;
3468
  int64_t checkpointId;
3469
  char    streamName[TSDB_STREAM_FNAME_LEN];
3470
} SMStreamDoCheckpointMsg;
3471

3472
typedef struct {
3473
  int64_t status;
3474
} SMVSubscribeRsp;
3475

3476
typedef struct {
3477
  char    name[TSDB_TOPIC_FNAME_LEN];
3478
  int8_t  igNotExists;
3479
  int32_t sqlLen;
3480
  char*   sql;
3481
  int8_t  force;
3482
} SMDropTopicReq;
3483

3484
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3485
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3486
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3487

3488
typedef struct {
3489
  char   topic[TSDB_TOPIC_FNAME_LEN];
3490
  char   cgroup[TSDB_CGROUP_LEN];
3491
  int8_t igNotExists;
3492
  int8_t force;
3493
} SMDropCgroupReq;
3494

3495
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3496
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3497

3498
typedef struct {
3499
  int8_t reserved;
3500
} SMDropCgroupRsp;
3501

3502
typedef struct {
3503
  char    name[TSDB_TABLE_FNAME_LEN];
3504
  int8_t  alterType;
3505
  SSchema schema;
3506
} SAlterTopicReq;
3507

3508
typedef struct {
3509
  SMsgHead head;
3510
  char     name[TSDB_TABLE_FNAME_LEN];
3511
  int64_t  tuid;
3512
  int32_t  sverson;
3513
  int32_t  execLen;
3514
  char*    executor;
3515
  int32_t  sqlLen;
3516
  char*    sql;
3517
} SDCreateTopicReq;
3518

3519
typedef struct {
3520
  SMsgHead head;
3521
  char     name[TSDB_TABLE_FNAME_LEN];
3522
  int64_t  tuid;
3523
} SDDropTopicReq;
3524

3525
typedef struct {
3526
  int64_t maxdelay[2];
3527
  int64_t watermark[2];
3528
  int64_t deleteMark[2];
3529
  int32_t qmsgLen[2];
3530
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3531
} SRSmaParam;
3532

3533
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3534
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3535

3536
// TDMT_VND_CREATE_STB ==============
3537
typedef struct SVCreateStbReq {
3538
  char*           name;
3539
  tb_uid_t        suid;
3540
  int8_t          rollup;
3541
  SSchemaWrapper  schemaRow;
3542
  SSchemaWrapper  schemaTag;
3543
  SRSmaParam      rsmaParam;
3544
  int32_t         alterOriDataLen;
3545
  void*           alterOriData;
3546
  int8_t          source;
3547
  int8_t          colCmpred;
3548
  SColCmprWrapper colCmpr;
3549
  int64_t         keep;
3550
  SExtSchema*     pExtSchemas;
3551
  int8_t          virtualStb;
3552
} SVCreateStbReq;
3553

3554
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3555
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3556

3557
// TDMT_VND_DROP_STB ==============
3558
typedef struct SVDropStbReq {
3559
  char*    name;
3560
  tb_uid_t suid;
3561
} SVDropStbReq;
3562

3563
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3564
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3565

3566
// TDMT_VND_CREATE_TABLE ==============
3567
#define TD_CREATE_IF_NOT_EXISTS 0x1
3568
typedef struct SVCreateTbReq {
3569
  int32_t  flags;
3570
  char*    name;
3571
  tb_uid_t uid;
3572
  int64_t  btime;
3573
  int32_t  ttl;
3574
  int32_t  commentLen;
3575
  char*    comment;
3576
  int8_t   type;
3577
  union {
3578
    struct {
3579
      char*    stbName;  // super table name
3580
      uint8_t  tagNum;
3581
      tb_uid_t suid;
3582
      SArray*  tagName;
3583
      uint8_t* pTag;
3584
    } ctb;
3585
    struct {
3586
      SSchemaWrapper schemaRow;
3587
    } ntb;
3588
  };
3589
  int32_t         sqlLen;
3590
  char*           sql;
3591
  SColCmprWrapper colCmpr;
3592
  SExtSchema*     pExtSchemas;
3593
  SColRefWrapper  colRef;  // col reference for virtual table
3594
} SVCreateTbReq;
3595

3596
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3597
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3598
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3599

3600
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
2,455✔
3601
  if (NULL == req) {
6,099,573!
3602
    return;
5,848,059✔
3603
  }
3604

3605
  taosMemoryFreeClear(req->sql);
251,514!
3606
  taosMemoryFreeClear(req->name);
251,514!
3607
  taosMemoryFreeClear(req->comment);
251,528!
3608
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
251,528!
3609
    taosMemoryFreeClear(req->ctb.pTag);
237,229!
3610
    taosMemoryFreeClear(req->ctb.stbName);
237,282!
3611
    taosArrayDestroy(req->ctb.tagName);
237,284✔
3612
    req->ctb.tagName = NULL;
237,245✔
3613
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,299!
3614
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,299!
3615
  }
3616
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
251,544!
3617
  taosMemoryFreeClear(req->pExtSchemas);
251,544!
3618
  taosMemoryFreeClear(req->colRef.pColRef);
251,544!
3619
}
3620

3621
typedef struct {
3622
  int32_t nReqs;
3623
  union {
3624
    SVCreateTbReq* pReqs;
3625
    SArray*        pArray;
3626
  };
3627
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3628
} SVCreateTbBatchReq;
3629

3630
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3631
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3632
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3633

3634
typedef struct {
3635
  int32_t        code;
3636
  STableMetaRsp* pMeta;
3637
} SVCreateTbRsp, SVUpdateTbRsp;
3638

3639
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3640
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3641
void tFreeSVCreateTbRsp(void* param);
3642

3643
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3644
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3645

3646
typedef struct {
3647
  int32_t nRsps;
3648
  union {
3649
    SVCreateTbRsp* pRsps;
3650
    SArray*        pArray;
3651
  };
3652
} SVCreateTbBatchRsp;
3653

3654
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3655
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3656

3657
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3658
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3659

3660
// TDMT_VND_DROP_TABLE =================
3661
typedef struct {
3662
  char*    name;
3663
  uint64_t suid;  // for tmq in wal format
3664
  int64_t  uid;
3665
  int8_t   igNotExists;
3666
  int8_t   isVirtual;
3667
} SVDropTbReq;
3668

3669
typedef struct {
3670
  int32_t code;
3671
} SVDropTbRsp;
3672

3673
typedef struct {
3674
  int32_t nReqs;
3675
  union {
3676
    SVDropTbReq* pReqs;
3677
    SArray*      pArray;
3678
  };
3679
} SVDropTbBatchReq;
3680

3681
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3682
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3683

3684
typedef struct {
3685
  int32_t nRsps;
3686
  union {
3687
    SVDropTbRsp* pRsps;
3688
    SArray*      pArray;
3689
  };
3690
} SVDropTbBatchRsp;
3691

3692
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3693
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3694

3695
// TDMT_VND_ALTER_TABLE =====================
3696
typedef struct SMultiTagUpateVal {
3697
  char*    tagName;
3698
  int32_t  colId;
3699
  int8_t   tagType;
3700
  int8_t   tagFree;
3701
  uint32_t nTagVal;
3702
  uint8_t* pTagVal;
3703
  int8_t   isNull;
3704
  SArray*  pTagArray;
3705
} SMultiTagUpateVal;
3706
typedef struct SVAlterTbReq {
3707
  char*   tbName;
3708
  int8_t  action;
3709
  char*   colName;
3710
  int32_t colId;
3711
  // TSDB_ALTER_TABLE_ADD_COLUMN
3712
  int8_t  type;
3713
  int8_t  flags;
3714
  int32_t bytes;
3715
  // TSDB_ALTER_TABLE_DROP_COLUMN
3716
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3717
  int8_t   colModType;
3718
  int32_t  colModBytes;
3719
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3720
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3721
  int8_t   isNull;
3722
  int8_t   tagType;
3723
  int8_t   tagFree;
3724
  uint32_t nTagVal;
3725
  uint8_t* pTagVal;
3726
  SArray*  pTagArray;
3727
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3728
  int8_t   updateTTL;
3729
  int32_t  newTTL;
3730
  int32_t  newCommentLen;
3731
  char*    newComment;
3732
  int64_t  ctimeMs;    // fill by vnode
3733
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3734
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3735
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3736
  // for Add column
3737
  STypeMod typeMod;
3738
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3739
  char* refDbName;
3740
  char* refTbName;
3741
  char* refColName;
3742
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3743
} SVAlterTbReq;
3744

3745
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3746
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3747
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3748
void    tfreeMultiTagUpateVal(void* pMultiTag);
3749

3750
typedef struct {
3751
  int32_t        code;
3752
  STableMetaRsp* pMeta;
3753
} SVAlterTbRsp;
3754

3755
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3756
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3757
// ======================
3758

3759
typedef struct {
3760
  SMsgHead head;
3761
  int64_t  uid;
3762
  int32_t  tid;
3763
  int16_t  tversion;
3764
  int16_t  colId;
3765
  int8_t   type;
3766
  int16_t  bytes;
3767
  int32_t  tagValLen;
3768
  int16_t  numOfTags;
3769
  int32_t  schemaLen;
3770
  char     data[];
3771
} SUpdateTagValReq;
3772

3773
typedef struct {
3774
  SMsgHead head;
3775
} SUpdateTagValRsp;
3776

3777
typedef struct {
3778
  SMsgHead head;
3779
} SVShowTablesReq;
3780

3781
typedef struct {
3782
  SMsgHead head;
3783
  int32_t  id;
3784
} SVShowTablesFetchReq;
3785

3786
typedef struct {
3787
  int64_t useconds;
3788
  int8_t  completed;  // all results are returned to client
3789
  int8_t  precision;
3790
  int8_t  compressed;
3791
  int32_t compLen;
3792
  int32_t numOfRows;
3793
  char    data[];
3794
} SVShowTablesFetchRsp;
3795

3796
typedef struct {
3797
  int64_t consumerId;
3798
  int32_t epoch;
3799
  char    cgroup[TSDB_CGROUP_LEN];
3800
} SMqAskEpReq;
3801

3802
typedef struct {
3803
  int32_t key;
3804
  int32_t valueLen;
3805
  void*   value;
3806
} SKv;
3807

3808
typedef struct {
3809
  int64_t tscRid;
3810
  int8_t  connType;
3811
} SClientHbKey;
3812

3813
typedef struct {
3814
  int64_t tid;
3815
  char    status[TSDB_JOB_STATUS_LEN];
3816
} SQuerySubDesc;
3817

3818
typedef struct {
3819
  char     sql[TSDB_SHOW_SQL_LEN];
3820
  uint64_t queryId;
3821
  int64_t  useconds;
3822
  int64_t  stime;  // timestamp precision ms
3823
  int64_t  reqRid;
3824
  bool     stableQuery;
3825
  bool     isSubQuery;
3826
  char     fqdn[TSDB_FQDN_LEN];
3827
  int32_t  subPlanNum;
3828
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3829
} SQueryDesc;
3830

3831
typedef struct {
3832
  uint32_t connId;
3833
  SArray*  queryDesc;  // SArray<SQueryDesc>
3834
} SQueryHbReqBasic;
3835

3836
typedef struct {
3837
  uint32_t connId;
3838
  uint64_t killRid;
3839
  int32_t  totalDnodes;
3840
  int32_t  onlineDnodes;
3841
  int8_t   killConnection;
3842
  int8_t   align[3];
3843
  SEpSet   epSet;
3844
  SArray*  pQnodeList;
3845
} SQueryHbRspBasic;
3846

3847
typedef struct SAppClusterSummary {
3848
  uint64_t numOfInsertsReq;
3849
  uint64_t numOfInsertRows;
3850
  uint64_t insertElapsedTime;
3851
  uint64_t insertBytes;  // submit to tsdb since launched.
3852

3853
  uint64_t fetchBytes;
3854
  uint64_t numOfQueryReq;
3855
  uint64_t queryElapsedTime;
3856
  uint64_t numOfSlowQueries;
3857
  uint64_t totalRequests;
3858
  uint64_t currentRequests;  // the number of SRequestObj
3859
} SAppClusterSummary;
3860

3861
typedef struct {
3862
  int64_t            appId;
3863
  int32_t            pid;
3864
  char               name[TSDB_APP_NAME_LEN];
3865
  int64_t            startTime;
3866
  SAppClusterSummary summary;
3867
} SAppHbReq;
3868

3869
typedef struct {
3870
  SClientHbKey      connKey;
3871
  int64_t           clusterId;
3872
  SAppHbReq         app;
3873
  SQueryHbReqBasic* query;
3874
  SHashObj*         info;  // hash<Skv.key, Skv>
3875
  char              userApp[TSDB_APP_NAME_LEN];
3876
  uint32_t          userIp;
3877
  SIpRange          userDualIp;
3878
} SClientHbReq;
3879

3880
typedef struct {
3881
  int64_t reqId;
3882
  SArray* reqs;  // SArray<SClientHbReq>
3883
  int64_t ipWhiteListVer;
3884
} SClientHbBatchReq;
3885

3886
typedef struct {
3887
  SClientHbKey      connKey;
3888
  int32_t           status;
3889
  SQueryHbRspBasic* query;
3890
  SArray*           info;  // Array<Skv>
3891
} SClientHbRsp;
3892

3893
typedef struct {
3894
  int64_t       reqId;
3895
  int64_t       rspId;
3896
  int32_t       svrTimestamp;
3897
  SArray*       rsps;  // SArray<SClientHbRsp>
3898
  SMonitorParas monitorParas;
3899
  int8_t        enableAuditDelete;
3900
  int8_t        enableStrongPass;
3901
} SClientHbBatchRsp;
3902

3903
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
211,262✔
3904

3905
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3906
  void* pIter = taosHashIterate(info, NULL);
100,757✔
3907
  while (pIter != NULL) {
214,561!
3908
    SKv* kv = (SKv*)pIter;
113,804✔
3909
    taosMemoryFreeClear(kv->value);
113,804!
3910
    pIter = taosHashIterate(info, pIter);
113,804✔
3911
  }
3912
}
100,757✔
3913

3914
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
54,060✔
3915
  SQueryDesc* desc = (SQueryDesc*)pDesc;
54,060✔
3916
  if (desc->subDesc) {
54,060✔
3917
    taosArrayDestroy(desc->subDesc);
45,751✔
3918
    desc->subDesc = NULL;
45,751✔
3919
  }
3920
}
54,060✔
3921

3922
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
131,208✔
3923
  SClientHbReq* req = (SClientHbReq*)pReq;
156,657✔
3924
  if (req->query) {
156,657!
3925
    if (req->query->queryDesc) {
118,926!
3926
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
39,288✔
3927
    }
3928
    taosMemoryFreeClear(req->query);
118,926!
3929
  }
3930

3931
  if (req->info) {
156,657!
3932
    tFreeReqKvHash(req->info);
100,757✔
3933
    taosHashCleanup(req->info);
100,757✔
3934
    req->info = NULL;
100,756✔
3935
  }
3936
}
86,176✔
3937

3938
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3939
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3940

3941
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3942
  if (pReq == NULL) return;
51,222!
3943
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
51,222✔
3944
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
51,222✔
3945
  taosMemoryFree(pReq);
51,222!
3946
}
3947

3948
static FORCE_INLINE void tFreeClientKv(void* pKv) {
43,479✔
3949
  SKv* kv = (SKv*)pKv;
43,479✔
3950
  if (kv) {
43,479!
3951
    taosMemoryFreeClear(kv->value);
43,479!
3952
  }
3953
}
43,479✔
3954

3955
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
127,472✔
3956
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
127,472✔
3957
  if (rsp->query) {
127,472✔
3958
    taosArrayDestroy(rsp->query->pQnodeList);
115,263✔
3959
    taosMemoryFreeClear(rsp->query);
115,265!
3960
  }
3961
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
127,474!
3962
}
66,747✔
3963

3964
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3965
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
93,675✔
3966
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
93,675✔
3967
}
93,675✔
3968

3969
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3970
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3971
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3972

3973
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3974
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
328,468!
3975
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
328,468!
3976
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
328,468!
3977
  return 0;
164,234✔
3978
}
3979

3980
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3981
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
150,087!
3982
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
150,086!
3983
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
75,043!
3984
  if (pKv->value == NULL) {
75,043!
3985
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3986
  }
3987
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
75,043!
3988
  return 0;
75,043✔
3989
}
3990

3991
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3992
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
524,388!
3993
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
524,388!
3994
  return 0;
262,194✔
3995
}
3996

3997
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3998
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
254,719!
3999
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
254,722!
4000
  return 0;
127,362✔
4001
}
4002

4003
typedef struct {
4004
  int32_t vgId;
4005
  // TODO stas
4006
} SMqReportVgInfo;
4007

4008
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4009
  int32_t tlen = 0;
4010
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4011
  return tlen;
4012
}
4013

4014
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4015
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4016
  return buf;
4017
}
4018

4019
typedef struct {
4020
  int32_t epoch;
4021
  int64_t topicUid;
4022
  char    name[TSDB_TOPIC_FNAME_LEN];
4023
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4024
} SMqTopicInfo;
4025

4026
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4027
  int32_t tlen = 0;
4028
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4029
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4030
  tlen += taosEncodeString(buf, pTopicInfo->name);
4031
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4032
  tlen += taosEncodeFixedI32(buf, sz);
4033
  for (int32_t i = 0; i < sz; i++) {
4034
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4035
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4036
  }
4037
  return tlen;
4038
}
4039

4040
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4041
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4042
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4043
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4044
  int32_t sz;
4045
  buf = taosDecodeFixedI32(buf, &sz);
4046
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4047
    return NULL;
4048
  }
4049
  for (int32_t i = 0; i < sz; i++) {
4050
    SMqReportVgInfo vgInfo;
4051
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4052
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4053
      return NULL;
4054
    }
4055
  }
4056
  return buf;
4057
}
4058

4059
typedef struct {
4060
  int32_t status;  // ask hb endpoint
4061
  int32_t epoch;
4062
  int64_t consumerId;
4063
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4064
} SMqReportReq;
4065

4066
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4067
  int32_t tlen = 0;
4068
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4069
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4070
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4071
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4072
  tlen += taosEncodeFixedI32(buf, sz);
4073
  for (int32_t i = 0; i < sz; i++) {
4074
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4075
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4076
  }
4077
  return tlen;
4078
}
4079

4080
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4081
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4082
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4083
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4084
  int32_t sz;
4085
  buf = taosDecodeFixedI32(buf, &sz);
4086
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4087
    return NULL;
4088
  }
4089
  for (int32_t i = 0; i < sz; i++) {
4090
    SMqTopicInfo topicInfo;
4091
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4092
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4093
      return NULL;
4094
    }
4095
  }
4096
  return buf;
4097
}
4098

4099
typedef struct {
4100
  SMsgHead head;
4101
  int64_t  leftForVer;
4102
  int32_t  vgId;
4103
  int64_t  consumerId;
4104
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4105
} SMqVDeleteReq;
4106

4107
typedef struct {
4108
  int8_t reserved;
4109
} SMqVDeleteRsp;
4110

4111
typedef struct {
4112
  char    name[TSDB_STREAM_FNAME_LEN];
4113
  int8_t  igNotExists;
4114
  int32_t sqlLen;
4115
  char*   sql;
4116
} SMDropStreamReq;
4117

4118
typedef struct {
4119
  int8_t reserved;
4120
} SMDropStreamRsp;
4121

4122
typedef struct {
4123
  SMsgHead head;
4124
  int64_t  resetRelHalt;  // reset related stream task halt status
4125
  int64_t  streamId;
4126
  int32_t  taskId;
4127
} SVDropStreamTaskReq;
4128

4129
typedef struct {
4130
  int8_t reserved;
4131
} SVDropStreamTaskRsp;
4132

4133
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4134
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4135
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4136

4137
typedef struct SVUpdateCheckpointInfoReq {
4138
  SMsgHead head;
4139
  int64_t  streamId;
4140
  int32_t  taskId;
4141
  int64_t  checkpointId;
4142
  int64_t  checkpointVer;
4143
  int64_t  checkpointTs;
4144
  int32_t  transId;
4145
  int64_t  hStreamId;  // add encode/decode
4146
  int64_t  hTaskId;
4147
  int8_t   dropRelHTask;
4148
} SVUpdateCheckpointInfoReq;
4149

4150
typedef struct {
4151
  int64_t leftForVer;
4152
  int32_t vgId;
4153
  int64_t oldConsumerId;
4154
  int64_t newConsumerId;
4155
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4156
  int8_t  subType;
4157
  int8_t  withMeta;
4158
  char*   qmsg;  // SubPlanToString
4159
  int64_t suid;
4160
} SMqRebVgReq;
4161

4162
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4163
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4164

4165
typedef struct {
4166
  char    topic[TSDB_TOPIC_FNAME_LEN];
4167
  int64_t ntbUid;
4168
  SArray* colIdList;  // SArray<int16_t>
4169
} STqCheckInfo;
4170

4171
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4172
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4173
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4174

4175
// tqOffset
4176
enum {
4177
  TMQ_OFFSET__RESET_NONE = -3,
4178
  TMQ_OFFSET__RESET_EARLIEST = -2,
4179
  TMQ_OFFSET__RESET_LATEST = -1,
4180
  TMQ_OFFSET__LOG = 1,
4181
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4182
  TMQ_OFFSET__SNAPSHOT_META = 3,
4183
};
4184

4185
enum {
4186
  WITH_DATA = 0,
4187
  WITH_META = 1,
4188
  ONLY_META = 2,
4189
};
4190

4191
#define TQ_OFFSET_VERSION 1
4192

4193
typedef struct {
4194
  int8_t type;
4195
  union {
4196
    // snapshot
4197
    struct {
4198
      int64_t uid;
4199
      int64_t ts;
4200
      SValue  primaryKey;
4201
    };
4202
    // log
4203
    struct {
4204
      int64_t version;
4205
    };
4206
  };
4207
} STqOffsetVal;
4208

4209
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4210
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
20,256✔
4211
  pOffsetVal->uid = uid;
20,256✔
4212
  pOffsetVal->ts = ts;
20,256✔
4213
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
20,256!
4214
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4215
  }
4216
  pOffsetVal->primaryKey = primaryKey;
20,277✔
4217
}
20,277✔
4218

4219
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4220
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
4221
  pOffsetVal->uid = uid;
148✔
4222
}
148✔
4223

4224
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4225
  pOffsetVal->type = TMQ_OFFSET__LOG;
556,743✔
4226
  pOffsetVal->version = ver;
556,743✔
4227
}
556,743✔
4228

4229
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4230
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4231
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4232
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4233
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4234
void    tOffsetDestroy(void* pVal);
4235

4236
typedef struct {
4237
  STqOffsetVal val;
4238
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4239
} STqOffset;
4240

4241
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4242
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4243
void    tDeleteSTqOffset(void* val);
4244

4245
typedef struct SMqVgOffset {
4246
  int64_t   consumerId;
4247
  STqOffset offset;
4248
} SMqVgOffset;
4249

4250
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4251
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4252

4253
typedef struct {
4254
  SMsgHead head;
4255
  int64_t  streamId;
4256
  int32_t  taskId;
4257
} SVPauseStreamTaskReq;
4258

4259
typedef struct {
4260
  SMsgHead head;
4261
  int64_t  streamId;
4262
  int32_t  taskId;
4263
  int64_t  chkptId;
4264
} SVResetStreamTaskReq;
4265

4266
typedef struct {
4267
  char   name[TSDB_STREAM_FNAME_LEN];
4268
  int8_t igNotExists;
4269
} SMPauseStreamReq;
4270

4271
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4272
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4273

4274
typedef struct {
4275
  SMsgHead head;
4276
  int32_t  taskId;
4277
  int64_t  streamId;
4278
  int8_t   igUntreated;
4279
} SVResumeStreamTaskReq;
4280

4281
typedef struct {
4282
  int8_t reserved;
4283
} SVResumeStreamTaskRsp;
4284

4285
typedef struct {
4286
  char   name[TSDB_STREAM_FNAME_LEN];
4287
  int8_t igNotExists;
4288
  int8_t igUntreated;
4289
} SMResumeStreamReq;
4290

4291
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4292
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4293

4294
typedef struct {
4295
  char   name[TSDB_STREAM_FNAME_LEN];
4296
  int8_t igNotExists;
4297
  int8_t igUntreated;
4298
} SMResetStreamReq;
4299

4300
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4301
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4302

4303
typedef struct {
4304
  char    name[TSDB_TABLE_FNAME_LEN];
4305
  char    stb[TSDB_TABLE_FNAME_LEN];
4306
  int8_t  igExists;
4307
  int8_t  intervalUnit;
4308
  int8_t  slidingUnit;
4309
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4310
  int32_t dstVgId;   // for stream
4311
  int64_t interval;
4312
  int64_t offset;
4313
  int64_t sliding;
4314
  int64_t maxDelay;
4315
  int64_t watermark;
4316
  int32_t exprLen;        // strlen + 1
4317
  int32_t tagsFilterLen;  // strlen + 1
4318
  int32_t sqlLen;         // strlen + 1
4319
  int32_t astLen;         // strlen + 1
4320
  char*   expr;
4321
  char*   tagsFilter;
4322
  char*   sql;
4323
  char*   ast;
4324
  int64_t deleteMark;
4325
  int64_t lastTs;
4326
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4327
  SArray* pVgroupVerList;
4328
  int8_t  recursiveTsma;
4329
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4330
} SMCreateSmaReq;
4331

4332
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4333
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4334
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4335

4336
typedef struct {
4337
  char   name[TSDB_TABLE_FNAME_LEN];
4338
  int8_t igNotExists;
4339
} SMDropSmaReq;
4340

4341
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4342
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4343

4344
typedef struct {
4345
  char   dbFName[TSDB_DB_FNAME_LEN];
4346
  char   stbName[TSDB_TABLE_NAME_LEN];
4347
  char   colName[TSDB_COL_NAME_LEN];
4348
  char   idxName[TSDB_INDEX_FNAME_LEN];
4349
  int8_t idxType;
4350
} SCreateTagIndexReq;
4351

4352
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4353
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4354

4355
typedef SMDropSmaReq SDropTagIndexReq;
4356

4357
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4358
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4359

4360
typedef struct {
4361
  int8_t         version;       // for compatibility(default 0)
4362
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4363
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4364
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4365
  int32_t        dstVgId;
4366
  char           indexName[TSDB_INDEX_NAME_LEN];
4367
  int32_t        exprLen;
4368
  int32_t        tagsFilterLen;
4369
  int64_t        indexUid;
4370
  tb_uid_t       tableUid;  // super/child/common table uid
4371
  tb_uid_t       dstTbUid;  // for dstVgroup
4372
  int64_t        interval;
4373
  int64_t        offset;  // use unit by precision of DB
4374
  int64_t        sliding;
4375
  char*          dstTbName;  // for dstVgroup
4376
  char*          expr;       // sma expression
4377
  char*          tagsFilter;
4378
  SSchemaWrapper schemaRow;  // for dstVgroup
4379
  SSchemaWrapper schemaTag;  // for dstVgroup
4380
} STSma;                     // Time-range-wise SMA
4381

4382
typedef STSma SVCreateTSmaReq;
4383

4384
typedef struct {
4385
  int8_t  type;  // 0 status report, 1 update data
4386
  int64_t indexUid;
4387
  int64_t skey;  // start TS key of interval/sliding window
4388
} STSmaMsg;
4389

4390
typedef struct {
4391
  int64_t indexUid;
4392
  char    indexName[TSDB_INDEX_NAME_LEN];
4393
} SVDropTSmaReq;
4394

4395
typedef struct {
4396
  int tmp;  // TODO: to avoid compile error
4397
} SVCreateTSmaRsp, SVDropTSmaRsp;
4398

4399
#if 0
4400
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4401
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4402
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4403
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4404
#endif
4405

4406
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4407
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4408
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4409
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4410

4411
typedef struct {
4412
  int32_t number;
4413
  STSma*  tSma;
4414
} STSmaWrapper;
4415

4416
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4417
  if (pSma) {
×
4418
    taosMemoryFreeClear(pSma->dstTbName);
×
4419
    taosMemoryFreeClear(pSma->expr);
×
4420
    taosMemoryFreeClear(pSma->tagsFilter);
×
4421
  }
4422
}
×
4423

4424
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4425
  if (pSW) {
×
4426
    if (pSW->tSma) {
×
4427
      if (deepCopy) {
×
4428
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4429
          tDestroyTSma(pSW->tSma + i);
×
4430
        }
4431
      }
4432
      taosMemoryFreeClear(pSW->tSma);
×
4433
    }
4434
  }
4435
}
×
4436

4437
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4438
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4439
  taosMemoryFreeClear(pSW);
×
4440
  return NULL;
×
4441
}
4442

4443
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4444
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4445

4446
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4447
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4448

4449
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4450
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4451
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4452
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4453
  }
4454
  return 0;
×
4455
}
4456

4457
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4458
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4459
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4460
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4461
  }
4462
  return 0;
×
4463
}
4464

4465
typedef struct {
4466
  int idx;
4467
} SMCreateFullTextReq;
4468

4469
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4470
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4471
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4472

4473
typedef struct {
4474
  char   name[TSDB_TABLE_FNAME_LEN];
4475
  int8_t igNotExists;
4476
} SMDropFullTextReq;
4477

4478
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4479
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4480

4481
typedef struct {
4482
  char indexFName[TSDB_INDEX_FNAME_LEN];
4483
} SUserIndexReq;
4484

4485
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4486
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4487

4488
typedef struct {
4489
  char dbFName[TSDB_DB_FNAME_LEN];
4490
  char tblFName[TSDB_TABLE_FNAME_LEN];
4491
  char colName[TSDB_COL_NAME_LEN];
4492
  char indexType[TSDB_INDEX_TYPE_LEN];
4493
  char indexExts[TSDB_INDEX_EXTS_LEN];
4494
} SUserIndexRsp;
4495

4496
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4497
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4498

4499
typedef struct {
4500
  char tbFName[TSDB_TABLE_FNAME_LEN];
4501
} STableIndexReq;
4502

4503
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4504
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4505

4506
typedef struct {
4507
  int8_t  intervalUnit;
4508
  int8_t  slidingUnit;
4509
  int64_t interval;
4510
  int64_t offset;
4511
  int64_t sliding;
4512
  int64_t dstTbUid;
4513
  int32_t dstVgId;
4514
  SEpSet  epSet;
4515
  char*   expr;
4516
} STableIndexInfo;
4517

4518
typedef struct {
4519
  char     tbName[TSDB_TABLE_NAME_LEN];
4520
  char     dbFName[TSDB_DB_FNAME_LEN];
4521
  uint64_t suid;
4522
  int32_t  version;
4523
  int32_t  indexSize;
4524
  SArray*  pIndex;  // STableIndexInfo
4525
} STableIndexRsp;
4526

4527
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4528
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4529
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4530

4531
void tFreeSTableIndexInfo(void* pInfo);
4532

4533
typedef struct {
4534
  int8_t  mqMsgType;
4535
  int32_t code;
4536
  int32_t epoch;
4537
  int64_t consumerId;
4538
  int64_t walsver;
4539
  int64_t walever;
4540
} SMqRspHead;
4541

4542
typedef struct {
4543
  SMsgHead     head;
4544
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4545
  int8_t       withTbName;
4546
  int8_t       useSnapshot;
4547
  int32_t      epoch;
4548
  uint64_t     reqId;
4549
  int64_t      consumerId;
4550
  int64_t      timeout;
4551
  STqOffsetVal reqOffset;
4552
  int8_t       enableReplay;
4553
  int8_t       sourceExcluded;
4554
  int8_t       rawData;
4555
  int32_t      minPollRows;
4556
  int8_t       enableBatchMeta;
4557
  SHashObj*    uidHash;  // to find if uid is duplicated
4558
} SMqPollReq;
4559

4560
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4561
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4562
void    tDestroySMqPollReq(SMqPollReq* pReq);
4563

4564
typedef struct {
4565
  int32_t vgId;
4566
  int64_t offset;
4567
  SEpSet  epSet;
4568
} SMqSubVgEp;
4569

4570
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4571
  int32_t tlen = 0;
8,640✔
4572
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,640✔
4573
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,640✔
4574
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,640✔
4575
  return tlen;
8,640✔
4576
}
4577

4578
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4579
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,252!
4580
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,252!
4581
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,252✔
4582
  return buf;
4,252✔
4583
}
4584

4585
typedef struct {
4586
  char           topic[TSDB_TOPIC_FNAME_LEN];
4587
  char           db[TSDB_DB_FNAME_LEN];
4588
  SArray*        vgs;  // SArray<SMqSubVgEp>
4589
  SSchemaWrapper schema;
4590
} SMqSubTopicEp;
4591

4592
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4593
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4594
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4595

4596
typedef struct {
4597
  SMqRspHead   head;
4598
  STqOffsetVal rspOffset;
4599
  int16_t      resMsgType;
4600
  int32_t      metaRspLen;
4601
  void*        metaRsp;
4602
} SMqMetaRsp;
4603

4604
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4605
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4606
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4607

4608
#define MQ_DATA_RSP_VERSION 100
4609

4610
typedef struct {
4611
  SMqRspHead   head;
4612
  STqOffsetVal rspOffset;
4613
  STqOffsetVal reqOffset;
4614
  int32_t      blockNum;
4615
  int8_t       withTbName;
4616
  int8_t       withSchema;
4617
  SArray*      blockDataLen;
4618
  SArray*      blockData;
4619
  SArray*      blockTbName;
4620
  SArray*      blockSchema;
4621

4622
  union {
4623
    struct {
4624
      int64_t sleepTime;
4625
    };
4626
    struct {
4627
      int32_t createTableNum;
4628
      SArray* createTableLen;
4629
      SArray* createTableReq;
4630
    };
4631
    struct {
4632
      int32_t len;
4633
      void*   rawData;
4634
    };
4635
  };
4636
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4637
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4638
} SMqDataRsp;
4639

4640
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4641
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4642
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4643
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4644
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4645

4646
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4647
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4648
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4649

4650
typedef struct SMqBatchMetaRsp {
4651
  SMqRspHead   head;  // not serialize
4652
  STqOffsetVal rspOffset;
4653
  SArray*      batchMetaLen;
4654
  SArray*      batchMetaReq;
4655
  void*        pMetaBuff;    // not serialize
4656
  uint32_t     metaBuffLen;  // not serialize
4657
} SMqBatchMetaRsp;
4658

4659
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4660
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4661
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4662
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4663

4664
typedef struct {
4665
  SMqRspHead head;
4666
  char       cgroup[TSDB_CGROUP_LEN];
4667
  SArray*    topics;  // SArray<SMqSubTopicEp>
4668
} SMqAskEpRsp;
4669

4670
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4671
  int32_t tlen = 0;
18,514✔
4672
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4673
  int32_t sz = taosArrayGetSize(pRsp->topics);
18,514!
4674
  tlen += taosEncodeFixedI32(buf, sz);
18,514✔
4675
  for (int32_t i = 0; i < sz; i++) {
25,444✔
4676
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,930✔
4677
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,930✔
4678
  }
4679
  return tlen;
18,514✔
4680
}
4681

4682
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4683
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4684
  int32_t sz;
4685
  buf = taosDecodeFixedI32(buf, &sz);
8,372✔
4686
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,372✔
4687
  if (pRsp->topics == NULL) {
8,372!
4688
    return NULL;
×
4689
  }
4690
  for (int32_t i = 0; i < sz; i++) {
11,745✔
4691
    SMqSubTopicEp topicEp;
4692
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,373✔
4693
    if (buf == NULL) {
3,373!
4694
      return NULL;
×
4695
    }
4696
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,746!
4697
      return NULL;
×
4698
    }
4699
  }
4700
  return buf;
8,372✔
4701
}
4702

4703
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4704
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,798✔
4705
}
20,798✔
4706

4707
typedef struct {
4708
  int32_t      vgId;
4709
  STqOffsetVal offset;
4710
  int64_t      rows;
4711
  int64_t      ever;
4712
} OffsetRows;
4713

4714
typedef struct {
4715
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4716
  SArray* offsetRows;
4717
} TopicOffsetRows;
4718

4719
typedef struct {
4720
  int64_t consumerId;
4721
  int32_t epoch;
4722
  SArray* topics;
4723
  int8_t  pollFlag;
4724
} SMqHbReq;
4725

4726
typedef struct {
4727
  char   topic[TSDB_TOPIC_FNAME_LEN];
4728
  int8_t noPrivilege;
4729
} STopicPrivilege;
4730

4731
typedef struct {
4732
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4733
  int32_t debugFlag;
4734
} SMqHbRsp;
4735

4736
typedef struct {
4737
  SMsgHead head;
4738
  int64_t  consumerId;
4739
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4740
} SMqSeekReq;
4741

4742
#define TD_AUTO_CREATE_TABLE 0x1
4743
typedef struct {
4744
  int64_t       suid;
4745
  int64_t       uid;
4746
  int32_t       sver;
4747
  uint32_t      nData;
4748
  uint8_t*      pData;
4749
  SVCreateTbReq cTbReq;
4750
} SVSubmitBlk;
4751

4752
typedef struct {
4753
  SMsgHead header;
4754
  uint64_t sId;
4755
  uint64_t queryId;
4756
  uint64_t clientId;
4757
  uint64_t taskId;
4758
  uint32_t sqlLen;
4759
  uint32_t phyLen;
4760
  char*    sql;
4761
  char*    msg;
4762
  int8_t   source;
4763
} SVDeleteReq;
4764

4765
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4766
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4767

4768
typedef struct {
4769
  int64_t affectedRows;
4770
} SVDeleteRsp;
4771

4772
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4773
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4774

4775
typedef struct SDeleteRes {
4776
  uint64_t suid;
4777
  SArray*  uidList;
4778
  int64_t  skey;
4779
  int64_t  ekey;
4780
  int64_t  affectedRows;
4781
  char     tableFName[TSDB_TABLE_NAME_LEN];
4782
  char     tsColName[TSDB_COL_NAME_LEN];
4783
  int64_t  ctimeMs;  // fill by vnode
4784
  int8_t   source;
4785
} SDeleteRes;
4786

4787
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4788
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4789

4790
typedef struct {
4791
  // int64_t uid;
4792
  char    tbname[TSDB_TABLE_NAME_LEN];
4793
  int64_t startTs;
4794
  int64_t endTs;
4795
} SSingleDeleteReq;
4796

4797
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4798
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4799

4800
typedef struct {
4801
  int64_t suid;
4802
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4803
  int64_t ctimeMs;     // fill by vnode
4804
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4805
} SBatchDeleteReq;
4806

4807
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4808
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4809
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4810

4811
typedef struct {
4812
  int32_t msgIdx;
4813
  int32_t msgType;
4814
  int32_t msgLen;
4815
  void*   msg;
4816
} SBatchMsg;
4817

4818
typedef struct {
4819
  SMsgHead header;
4820
  SArray*  pMsgs;  // SArray<SBatchMsg>
4821
} SBatchReq;
4822

4823
typedef struct {
4824
  int32_t reqType;
4825
  int32_t msgIdx;
4826
  int32_t msgLen;
4827
  int32_t rspCode;
4828
  void*   msg;
4829
} SBatchRspMsg;
4830

4831
typedef struct {
4832
  SArray* pRsps;  // SArray<SBatchRspMsg>
4833
} SBatchRsp;
4834

4835
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4836
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4837
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
370,752✔
4838
  if (NULL == msg) {
370,752!
4839
    return;
×
4840
  }
4841
  SBatchMsg* pMsg = (SBatchMsg*)msg;
370,752✔
4842
  taosMemoryFree(pMsg->msg);
370,752!
4843
}
4844

4845
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4846
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4847

4848
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
503,224✔
4849
  if (NULL == p) {
503,224!
4850
    return;
×
4851
  }
4852

4853
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
503,224✔
4854
  taosMemoryFree(pRsp->msg);
503,224!
4855
}
4856

4857
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4858
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4859
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4860
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4861
void    tDestroySMqHbReq(SMqHbReq* pReq);
4862

4863
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4864
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4865
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4866

4867
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4868
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4869

4870
#define TD_REQ_FROM_APP               0x0
4871
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4872
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4873
#define SUBMIT_REQ_FROM_FILE          0x4
4874
#define TD_REQ_FROM_TAOX              0x8
4875
#define SUBMIT_REQUEST_VERSION        (1)
4876

4877
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4878

4879
typedef struct {
4880
  int32_t        flags;
4881
  SVCreateTbReq* pCreateTbReq;
4882
  int64_t        suid;
4883
  int64_t        uid;
4884
  int32_t        sver;
4885
  union {
4886
    SArray* aRowP;
4887
    SArray* aCol;
4888
  };
4889
  int64_t ctimeMs;
4890
} SSubmitTbData;
4891

4892
typedef struct {
4893
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4894
  bool    raw;
4895
} SSubmitReq2;
4896

4897
typedef struct {
4898
  SMsgHead header;
4899
  int64_t  version;
4900
  char     data[];  // SSubmitReq2
4901
} SSubmitReq2Msg;
4902

4903
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4904
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4905
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4906
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4907
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4908

4909
typedef struct {
4910
  int32_t affectedRows;
4911
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4912
} SSubmitRsp2;
4913

4914
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4915
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4916
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4917

4918
#define TSDB_MSG_FLG_ENCODE 0x1
4919
#define TSDB_MSG_FLG_DECODE 0x2
4920
#define TSDB_MSG_FLG_CMPT   0x3
4921

4922
typedef struct {
4923
  union {
4924
    struct {
4925
      void*   msgStr;
4926
      int32_t msgLen;
4927
      int64_t ver;
4928
    };
4929
    void* pDataBlock;
4930
  };
4931
} SPackedData;
4932

4933
typedef struct {
4934
  char     fullname[TSDB_VIEW_FNAME_LEN];
4935
  char     name[TSDB_VIEW_NAME_LEN];
4936
  char     dbFName[TSDB_DB_FNAME_LEN];
4937
  char*    querySql;
4938
  char*    sql;
4939
  int8_t   orReplace;
4940
  int8_t   precision;
4941
  int32_t  numOfCols;
4942
  SSchema* pSchema;
4943
} SCMCreateViewReq;
4944

4945
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4946
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4947
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4948

4949
typedef struct {
4950
  char   fullname[TSDB_VIEW_FNAME_LEN];
4951
  char   name[TSDB_VIEW_NAME_LEN];
4952
  char   dbFName[TSDB_DB_FNAME_LEN];
4953
  char*  sql;
4954
  int8_t igNotExists;
4955
} SCMDropViewReq;
4956

4957
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4958
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4959
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4960

4961
typedef struct {
4962
  char fullname[TSDB_VIEW_FNAME_LEN];
4963
} SViewMetaReq;
4964
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4965
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4966

4967
typedef struct {
4968
  char     name[TSDB_VIEW_NAME_LEN];
4969
  char     dbFName[TSDB_DB_FNAME_LEN];
4970
  char*    user;
4971
  uint64_t dbId;
4972
  uint64_t viewId;
4973
  char*    querySql;
4974
  int8_t   precision;
4975
  int8_t   type;
4976
  int32_t  version;
4977
  int32_t  numOfCols;
4978
  SSchema* pSchema;
4979
} SViewMetaRsp;
4980
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4981
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4982
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4983
typedef struct {
4984
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4985
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4986
} STableTSMAInfoReq;
4987

4988
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4989
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4990

4991
typedef struct {
4992
  int32_t  funcId;
4993
  col_id_t colId;
4994
} STableTSMAFuncInfo;
4995

4996
typedef struct {
4997
  char     name[TSDB_TABLE_NAME_LEN];
4998
  uint64_t tsmaId;
4999
  char     targetTb[TSDB_TABLE_NAME_LEN];
5000
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5001
  char     tb[TSDB_TABLE_NAME_LEN];
5002
  char     dbFName[TSDB_DB_FNAME_LEN];
5003
  uint64_t suid;
5004
  uint64_t destTbUid;
5005
  uint64_t dbId;
5006
  int32_t  version;
5007
  int64_t  interval;
5008
  int8_t   unit;
5009
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5010
  SArray*  pTags;      // SArray<SSchema>
5011
  SArray*  pUsedCols;  // SArray<SSchema>
5012
  char*    ast;
5013

5014
  int64_t streamUid;
5015
  int64_t reqTs;
5016
  int64_t rspTs;
5017
  int64_t delayDuration;  // ms
5018
  bool    fillHistoryFinished;
5019
} STableTSMAInfo;
5020

5021
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5022
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5023
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5024
void    tFreeTableTSMAInfo(void* p);
5025
void    tFreeAndClearTableTSMAInfo(void* p);
5026
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5027

5028
#define STSMAHbRsp            STableTSMAInfoRsp
5029
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5030
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5031
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5032

5033
typedef struct SStreamProgressReq {
5034
  int64_t streamId;
5035
  int32_t vgId;
5036
  int32_t fetchIdx;
5037
  int32_t subFetchIdx;
5038
} SStreamProgressReq;
5039

5040
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
5041
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
5042

5043
typedef struct SStreamProgressRsp {
5044
  int64_t streamId;
5045
  int32_t vgId;
5046
  bool    fillHisFinished;
5047
  int64_t progressDelay;
5048
  int32_t fetchIdx;
5049
  int32_t subFetchIdx;
5050
} SStreamProgressRsp;
5051

5052
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
5053
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
5054

5055
typedef struct SDropCtbWithTsmaSingleVgReq {
5056
  SVgroupInfo vgInfo;
5057
  SArray*     pTbs;  // SVDropTbReq
5058
} SMDropTbReqsOnSingleVg;
5059

5060
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5061
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5062
void    tFreeSMDropTbReqOnSingleVg(void* p);
5063

5064
typedef struct SDropTbsReq {
5065
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5066
} SMDropTbsReq;
5067

5068
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5069
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5070
void    tFreeSMDropTbsReq(void*);
5071

5072
typedef struct SVFetchTtlExpiredTbsRsp {
5073
  SArray* pExpiredTbs;  // SVDropTbReq
5074
  int32_t vgId;
5075
} SVFetchTtlExpiredTbsRsp;
5076

5077
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5078
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5079

5080
void tFreeFetchTtlExpiredTbsRsp(void* p);
5081

5082
void setDefaultOptionsForField(SFieldWithOptions* field);
5083
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5084

5085
#pragma pack(pop)
5086

5087
#ifdef __cplusplus
5088
}
5089
#endif
5090

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