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

taosdata / TDengine / #4506

15 Jul 2025 12:33AM UTC coverage: 62.026% (-0.7%) from 62.706%
#4506

push

travis-ci

web-flow
docs: update stream docs (#31874)

155391 of 320094 branches covered (48.55%)

Branch coverage included in aggregate %.

240721 of 318525 relevant lines covered (75.57%)

6529048.03 hits per line

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

41.01
/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) {
74,089,727✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
74,089,727✔
74
  int    segIdx = TMSG_SEG_CODE(type);
74,089,727✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
74,089,727!
76
    return type < tMsgRangeDict[segIdx];
74,094,745✔
77
  }
78
  return false;
1✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
3,071,744✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
3,025,367!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
6,097,111!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
9,318,878✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
9,318,878✔
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_MOUNT,
169
  TSDB_MGMT_TABLE_SSMIGRATE,
170
  TSDB_MGMT_TABLE_MAX,
171
} EShowType;
172

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

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

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

212
#define TSDB_KILL_MSG_LEN 30
213

214
#define TSDB_TABLE_NUM_UNIT 100000
215

216
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
217
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
218
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
219

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

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

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

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

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

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

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

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

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

523
typedef struct {
524
  int32_t     vgId;
525
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
526
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
527
  const char* dbFName;
528
  const char* tbName;
529
} SBuildTableInput;
530

531
typedef struct {
532
  char    db[TSDB_DB_FNAME_LEN];
533
  int64_t dbId;
534
  int32_t vgVersion;
535
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
536
  int64_t stateTs;
537
} SBuildUseDBInput;
538

539
typedef struct SField {
540
  char    name[TSDB_COL_NAME_LEN];
541
  uint8_t type;
542
  int8_t  flags;
543
  int32_t bytes;
544
} SField;
545
typedef struct SFieldWithOptions {
546
  char     name[TSDB_COL_NAME_LEN];
547
  uint8_t  type;
548
  int8_t   flags;
549
  int32_t  bytes;
550
  uint32_t compress;
551
  STypeMod typeMod;
552
} SFieldWithOptions;
553

554
typedef struct SRetention {
555
  int64_t freq;
556
  int64_t keep;
557
  int8_t  freqUnit;
558
  int8_t  keepUnit;
559
} SRetention;
560

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

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

570
typedef struct {
571
  int32_t contLen;
572
  int32_t vgId;
573
} SMsgHead;
574

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

586
// Submit message for this TSDB
587
typedef struct {
588
  SMsgHead header;
589
  int64_t  version;
590
  int32_t  length;
591
  int32_t  numOfBlocks;
592
  char     blocks[];
593
} SSubmitReq;
594

595
typedef struct {
596
  int32_t totalLen;
597
  int32_t len;
598
  STSRow* row;
599
} SSubmitBlkIter;
600

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

616
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
617
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
618
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
619
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
620
// for debug
621
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
622

623
typedef struct {
624
  bool     hasRef;
625
  col_id_t id;
626
  char     refDbName[TSDB_DB_NAME_LEN];
627
  char     refTableName[TSDB_TABLE_NAME_LEN];
628
  char     refColName[TSDB_COL_NAME_LEN];
629
} SColRef;
630

631
typedef struct {
632
  int32_t  nCols;
633
  int32_t  version;
634
  SColRef* pColRef;
635
} SColRefWrapper;
636

637
typedef struct {
638
  int32_t vgId;
639
  SColRef colRef;
640
} SColRefEx;
641

642
typedef struct {
643
  int16_t colId;
644
  char    refDbName[TSDB_DB_NAME_LEN];
645
  char    refTableName[TSDB_TABLE_NAME_LEN];
646
  char    refColName[TSDB_COL_NAME_LEN];
647
} SRefColInfo;
648

649
typedef struct SVCTableRefCols {
650
  uint64_t     uid;
651
  int32_t      numOfSrcTbls;
652
  int32_t      numOfColRefs;
653
  SRefColInfo* refCols;
654
} SVCTableRefCols;
655

656
typedef struct SVCTableMergeInfo {
657
  uint64_t uid;
658
  int32_t  numOfSrcTbls;
659
} SVCTableMergeInfo;
660

661
typedef struct {
662
  int32_t    nCols;
663
  SColRefEx* pColRefEx;
664
} SColRefExWrapper;
665

666
struct SSchema {
667
  int8_t   type;
668
  int8_t   flags;
669
  col_id_t colId;
670
  int32_t  bytes;
671
  char     name[TSDB_COL_NAME_LEN];
672
};
673
struct SSchemaExt {
674
  col_id_t colId;
675
  uint32_t compress;
676
  STypeMod typeMod;
677
};
678

679
//
680

681
struct SSchema2 {
682
  int8_t   type;
683
  int8_t   flags;
684
  col_id_t colId;
685
  int32_t  bytes;
686
  char     name[TSDB_COL_NAME_LEN];
687
  uint32_t compress;
688
};
689

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

713
typedef struct {
714
  int32_t        code;
715
  int64_t        uid;
716
  char*          tblFName;
717
  int32_t        numOfRows;
718
  int32_t        affectedRows;
719
  int64_t        sver;
720
  STableMetaRsp* pMeta;
721
} SSubmitBlkRsp;
722

723
typedef struct {
724
  int32_t numOfRows;
725
  int32_t affectedRows;
726
  int32_t nBlocks;
727
  union {
728
    SArray*        pArray;
729
    SSubmitBlkRsp* pBlocks;
730
  };
731
} SSubmitRsp;
732

733
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
734
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
735
// void    tFreeSSubmitBlkRsp(void* param);
736
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
737

738
#define COL_SMA_ON       ((int8_t)0x1)
739
#define COL_IDX_ON       ((int8_t)0x2)
740
#define COL_IS_KEY       ((int8_t)0x4)
741
#define COL_SET_NULL     ((int8_t)0x10)
742
#define COL_SET_VAL      ((int8_t)0x20)
743
#define COL_IS_SYSINFO   ((int8_t)0x40)
744
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
745

746
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
747
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
748

749
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
750
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
751
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
752

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

758
#define SSCHMEA_SET_IDX_OFF(s)   \
759
  do {                           \
760
    (s)->flags &= (~COL_IDX_ON); \
761
  } while (0)
762

763
#define SSCHEMA_SET_TYPE_MOD(s)     \
764
  do {                              \
765
    (s)->flags |= COL_HAS_TYPE_MOD; \
766
  } while (0)
767

768
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
769

770
#define SSCHMEA_TYPE(s)  ((s)->type)
771
#define SSCHMEA_FLAGS(s) ((s)->flags)
772
#define SSCHMEA_COLID(s) ((s)->colId)
773
#define SSCHMEA_BYTES(s) ((s)->bytes)
774
#define SSCHMEA_NAME(s)  ((s)->name)
775

776
typedef struct {
777
  bool    tsEnableMonitor;
778
  int32_t tsMonitorInterval;
779
  int32_t tsSlowLogThreshold;
780
  int32_t tsSlowLogMaxLen;
781
  int32_t tsSlowLogScope;
782
  int32_t tsSlowLogThresholdTest;  // Obsolete
783
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
784
} SMonitorParas;
785

786
typedef struct {
787
  STypeMod typeMod;
788
} SExtSchema;
789

790
bool hasExtSchema(const SExtSchema* pExtSchema);
791

792
typedef struct {
793
  int32_t  nCols;
794
  int32_t  version;
795
  SSchema* pSchema;
796
} SSchemaWrapper;
797

798
typedef struct {
799
  col_id_t id;
800
  uint32_t alg;
801
} SColCmpr;
802

803
typedef struct {
804
  int32_t   nCols;
805
  int32_t   version;
806
  SColCmpr* pColCmpr;
807
} SColCmprWrapper;
808

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

825
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
826
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
827
    terrno = TSDB_CODE_INVALID_PARA;
828
    return NULL;
829
  }
830

831
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
832
  if (pDstWrapper == NULL) {
833
    return NULL;
834
  }
835
  pDstWrapper->nCols = pSrcWrapper->nCols;
836
  pDstWrapper->version = pSrcWrapper->version;
837

838
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
839
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
840
  if (pDstWrapper->pColCmpr == NULL) {
841
    taosMemoryFree(pDstWrapper);
842
    return NULL;
843
  }
844
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
845

846
  return pDstWrapper;
847
}
848

849
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
850
  if (!(!pCmpr->pColCmpr)) {
13,929!
851
    return TSDB_CODE_INVALID_PARA;
×
852
  }
853
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
13,929!
854
  if (pCmpr->pColCmpr == NULL) {
13,929!
855
    return terrno;
×
856
  }
857
  pCmpr->nCols = nCols;
13,929✔
858
  return 0;
13,929✔
859
}
860

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

879
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
880
  if (pWrapper == NULL) return;
881

882
  taosMemoryFreeClear(pWrapper->pColCmpr);
883
  taosMemoryFreeClear(pWrapper);
884
}
885
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
886
  if (pSchemaWrapper->pSchema == NULL) return NULL;
3,167,123!
887

888
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
3,167,123!
889
  if (pSW == NULL) {
3,169,068!
890
    return NULL;
×
891
  }
892
  pSW->nCols = pSchemaWrapper->nCols;
3,169,068✔
893
  pSW->version = pSchemaWrapper->version;
3,169,068✔
894
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
3,169,068!
895
  if (pSW->pSchema == NULL) {
3,167,600!
896
    taosMemoryFree(pSW);
×
897
    return NULL;
×
898
  }
899

900
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
3,167,600✔
901
  return pSW;
3,167,600✔
902
}
903

904
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
585,697✔
905
  if (pSchemaWrapper) {
7,792,212!
906
    taosMemoryFree(pSchemaWrapper->pSchema);
3,433,837!
907
    taosMemoryFree(pSchemaWrapper);
3,433,877!
908
  }
909
}
7,674,562✔
910

911
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,042✔
912
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,042!
913
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,042!
914
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,042!
915
  }
916
}
1,042✔
917

918
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
919
  int32_t tlen = 0;
58,748✔
920
  tlen += taosEncodeFixedI8(buf, pSchema->type);
117,496✔
921
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
58,748!
922
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
58,748!
923
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
58,748!
924
  tlen += taosEncodeString(buf, pSchema->name);
58,748✔
925
  return tlen;
58,748✔
926
}
927

928
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
929
  buf = taosDecodeFixedI8(buf, &pSchema->type);
54,192✔
930
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
27,096✔
931
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
27,096!
932
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
27,096!
933
  buf = taosDecodeStringTo(buf, pSchema->name);
27,096✔
934
  return (void*)buf;
27,096✔
935
}
936

937
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
938
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
99,097,608!
939
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
151,094,158!
940
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
151,094,158!
941
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
151,094,158!
942
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
151,094,158!
943
  return 0;
75,547,079✔
944
}
945

946
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
947
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
160,395,437!
948
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
313,214,384!
949
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
312,694,889!
950
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
312,648,100!
951
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
156,457,623!
952
  return 0;
156,833,322✔
953
}
954

955
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
956
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
44,993,006!
957
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
44,993,006!
958
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
44,993,006!
959
  return 0;
22,496,503✔
960
}
961

962
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
963
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
5,834,909!
964
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
5,834,908!
965
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
5,834,906!
966
  return 0;
2,917,453✔
967
}
968

969
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
970
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
18,316!
971
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
18,316!
972
  if (pColRef->hasRef) {
9,158✔
973
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
10,232!
974
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
10,232!
975
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
10,232!
976
  }
977
  return 0;
9,158✔
978
}
979

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

989
  return 0;
10,812✔
990
}
991

992
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
993
  int32_t tlen = 0;
8,746✔
994
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,746✔
995
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,746✔
996
  for (int32_t i = 0; i < pSW->nCols; i++) {
67,494✔
997
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
117,496!
998
  }
999
  return tlen;
8,746✔
1000
}
1001

1002
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1003
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
4,059✔
1004
  buf = taosDecodeVariantI32(buf, &pSW->version);
4,059✔
1005
  if (pSW->nCols > 0) {
4,059✔
1006
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,965!
1007
    if (pSW->pSchema == NULL) {
2,965!
1008
      return NULL;
×
1009
    }
1010

1011
    for (int32_t i = 0; i < pSW->nCols; i++) {
30,061✔
1012
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
54,192✔
1013
    }
1014
  } else {
1015
    pSW->pSchema = NULL;
1,094✔
1016
  }
1017
  return (void*)buf;
4,059✔
1018
}
1019

1020
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1021
  if (pSW == NULL) {
742,302!
1022
    return TSDB_CODE_INVALID_PARA;
×
1023
  }
1024
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,484,604!
1025
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,484,604!
1026
  for (int32_t i = 0; i < pSW->nCols; i++) {
52,738,852!
1027
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
103,993,100!
1028
  }
1029
  return 0;
742,302✔
1030
}
1031

1032
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1033
  if (pSW == NULL) {
1,449,109!
1034
    return TSDB_CODE_INVALID_PARA;
×
1035
  }
1036
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,898,290!
1037
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,898,233!
1038

1039
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,449,052!
1040
  if (pSW->pSchema == NULL) {
1,449,170!
1041
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1042
  }
1043
  for (int32_t i = 0; i < pSW->nCols; i++) {
17,264,213!
1044
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
31,630,895!
1045
  }
1046

1047
  return 0;
1,448,361✔
1048
}
1049

1050
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1051
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
17,381,907!
1052
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
17,375,487!
1053

1054
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
8,687,518!
1055
  if (pSW->pSchema == NULL) {
8,690,178!
1056
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1057
  }
1058
  for (int32_t i = 0; i < pSW->nCols; i++) {
146,022,994!
1059
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
274,662,778!
1060
  }
1061

1062
  return 0;
8,693,032✔
1063
}
1064

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

1098
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1099
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1100
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1101

1102
typedef struct {
1103
  STableMetaRsp* pMeta;
1104
} SMCreateStbRsp;
1105

1106
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1107
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1108
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1109

1110
typedef struct {
1111
  char     name[TSDB_TABLE_FNAME_LEN];
1112
  int8_t   igNotExists;
1113
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1114
  int8_t   reserved[6];
1115
  tb_uid_t suid;
1116
  int32_t  sqlLen;
1117
  char*    sql;
1118
} SMDropStbReq;
1119

1120
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1121
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1122
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1123

1124
typedef struct {
1125
  char    name[TSDB_TABLE_FNAME_LEN];
1126
  int8_t  alterType;
1127
  int32_t numOfFields;
1128
  SArray* pFields;
1129
  int32_t ttl;
1130
  int32_t commentLen;
1131
  char*   comment;
1132
  int32_t sqlLen;
1133
  char*   sql;
1134
  int64_t keep;
1135
  SArray* pTypeMods;
1136
} SMAlterStbReq;
1137

1138
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1139
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1140
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1141

1142
typedef struct SEpSet {
1143
  int8_t inUse;
1144
  int8_t numOfEps;
1145
  SEp    eps[TSDB_MAX_REPLICA];
1146
} SEpSet;
1147

1148
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1149
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1150
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1151
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1152

1153
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1154
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1155

1156
typedef struct {
1157
  int8_t  connType;
1158
  int32_t pid;
1159
  char    app[TSDB_APP_NAME_LEN];
1160
  char    db[TSDB_DB_NAME_LEN];
1161
  char    user[TSDB_USER_LEN];
1162
  char    passwd[TSDB_PASSWORD_LEN];
1163
  int64_t startTime;
1164
  char    sVer[TSDB_VERSION_LEN];
1165
} SConnectReq;
1166

1167
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1168
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1169

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

1189
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1190
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1191

1192
typedef struct {
1193
  char    user[TSDB_USER_LEN];
1194
  char    pass[TSDB_PASSWORD_LEN];
1195
  int32_t maxUsers;
1196
  int32_t maxDbs;
1197
  int32_t maxTimeSeries;
1198
  int32_t maxStreams;
1199
  int32_t accessState;  // Configured only by command
1200
  int64_t maxStorage;
1201
} SCreateAcctReq, SAlterAcctReq;
1202

1203
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1204
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1205

1206
typedef struct {
1207
  char    user[TSDB_USER_LEN];
1208
  int32_t sqlLen;
1209
  char*   sql;
1210
} SDropUserReq, SDropAcctReq;
1211

1212
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1213
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1214
void    tFreeSDropUserReq(SDropUserReq* pReq);
1215

1216
typedef struct SIpV4Range {
1217
  uint32_t ip;
1218
  uint32_t mask;
1219
} SIpV4Range;
1220

1221
typedef struct SIpv6Range {
1222
  uint64_t addr[2];
1223
  uint32_t mask;
1224
} SIpV6Range;
1225

1226
typedef struct {
1227
  int8_t type;
1228
  union {
1229
    SIpV4Range ipV4;
1230
    SIpV6Range ipV6;
1231
  };
1232
} SIpRange;
1233

1234
typedef struct {
1235
  int32_t    num;
1236
  SIpV4Range pIpRange[];
1237
} SIpWhiteList;
1238

1239
typedef struct {
1240
  int32_t  num;
1241
  SIpRange pIpRanges[];
1242
} SIpWhiteListDual;
1243

1244
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1245
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1246
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1247
int32_t           createDefaultIp6Range(SIpRange* pRange);
1248
int32_t           createDefaultIp4Range(SIpRange* pRange);
1249

1250
typedef struct {
1251
  int8_t  createType;
1252
  int8_t  superUser;  // denote if it is a super user or not
1253
  int8_t  sysInfo;
1254
  int8_t  enable;
1255
  char    user[TSDB_USER_LEN];
1256
  char    pass[TSDB_USET_PASSWORD_LEN];
1257
  int32_t numIpRanges;
1258

1259
  SIpV4Range* pIpRanges;
1260
  int32_t     sqlLen;
1261
  char*       sql;
1262
  int8_t      isImport;
1263
  int8_t      createDb;
1264
  int8_t      passIsMd5;
1265
  SIpRange*   pIpDualRanges;
1266
} SCreateUserReq;
1267

1268
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1269
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1270
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1271

1272
typedef struct {
1273
  int32_t dnodeId;
1274
  int64_t analVer;
1275
} SRetrieveAnalyticsAlgoReq;
1276

1277
typedef struct {
1278
  int64_t   ver;
1279
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1280
} SRetrieveAnalyticAlgoRsp;
1281

1282
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1283
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1284
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1285
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1286
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1287

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

1316
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1317
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1318
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1319

1320
typedef struct {
1321
  char user[TSDB_USER_LEN];
1322
} SGetUserAuthReq;
1323

1324
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1325
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1326

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

1348
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1349
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1350
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1351

1352
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1353
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1354
typedef struct {
1355
  int64_t ver;
1356
  char    user[TSDB_USER_LEN];
1357
  int32_t numOfRange;
1358
  union {
1359
    SIpV4Range* pIpRanges;
1360
    SIpRange*   pIpDualRanges;
1361
  };
1362
} SUpdateUserIpWhite;
1363

1364
typedef struct {
1365
  int64_t             ver;
1366
  int                 numOfUser;
1367
  SUpdateUserIpWhite* pUserIpWhite;
1368
} SUpdateIpWhite;
1369

1370
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1371
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1372
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1373
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1374

1375
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1376
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1377
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1378

1379
typedef struct {
1380
  int64_t ipWhiteVer;
1381
} SRetrieveIpWhiteReq;
1382

1383
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1384
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1385
typedef struct {
1386
  char user[TSDB_USER_LEN];
1387
} SGetUserWhiteListReq;
1388

1389
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1390
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1391

1392
typedef struct {
1393
  char    user[TSDB_USER_LEN];
1394
  int32_t numWhiteLists;
1395
  union {
1396
    SIpV4Range* pWhiteLists;
1397
    SIpRange*   pWhiteListsDual;
1398
  };
1399
} SGetUserWhiteListRsp;
1400

1401
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1402
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1403
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1404
void    tIpRangeSetDefaultMask(SIpRange* range);
1405

1406
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1407
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1408
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1409

1410
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1411
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1412
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1413

1414
/*
1415
 * for client side struct, only column id, type, bytes are necessary
1416
 * But for data in vnode side, we need all the following information.
1417
 */
1418
typedef struct {
1419
  union {
1420
    col_id_t colId;
1421
    int16_t  slotId;
1422
  };
1423

1424
  uint8_t precision;
1425
  uint8_t scale;
1426
  int32_t bytes;
1427
  int8_t  type;
1428
  uint8_t pk;
1429
  bool    noData;
1430
} SColumnInfo;
1431

1432
typedef struct STimeWindow {
1433
  TSKEY skey;
1434
  TSKEY ekey;
1435
} STimeWindow;
1436

1437
typedef struct SQueryHint {
1438
  bool batchScan;
1439
} SQueryHint;
1440

1441
typedef struct {
1442
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1443
  int32_t tsLen;          // total length of ts comp block
1444
  int32_t tsNumOfBlocks;  // ts comp block numbers
1445
  int32_t tsOrder;        // ts comp block order
1446
} STsBufInfo;
1447

1448
typedef struct {
1449
  void*       timezone;
1450
  char        intervalUnit;
1451
  char        slidingUnit;
1452
  char        offsetUnit;
1453
  int8_t      precision;
1454
  int64_t     interval;
1455
  int64_t     sliding;
1456
  int64_t     offset;
1457
  STimeWindow timeRange;
1458
} SInterval;
1459

1460
typedef struct STbVerInfo {
1461
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1462
  int32_t sversion;
1463
  int32_t tversion;
1464
  int32_t rversion;  // virtual table's column ref's version
1465
} STbVerInfo;
1466

1467
typedef struct {
1468
  int32_t code;
1469
  int64_t affectedRows;
1470
  SArray* tbVerInfo;  // STbVerInfo
1471
} SQueryTableRsp;
1472

1473
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1474

1475
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1476

1477
typedef struct {
1478
  SMsgHead header;
1479
  char     dbFName[TSDB_DB_FNAME_LEN];
1480
  char     tbName[TSDB_TABLE_NAME_LEN];
1481
} STableCfgReq;
1482

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

1507
typedef STableCfg STableCfgRsp;
1508

1509
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1510
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1511

1512
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1513
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1514
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1515

1516
typedef struct {
1517
  SMsgHead header;
1518
  tb_uid_t suid;
1519
} SVSubTablesReq;
1520

1521
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1522
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1523

1524
typedef struct {
1525
  int32_t vgId;
1526
  SArray* pTables;  // SArray<SVCTableRefCols*>
1527
} SVSubTablesRsp;
1528

1529
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1530
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1531
void    tDestroySVSubTablesRsp(void* rsp);
1532

1533
typedef struct {
1534
  SMsgHead header;
1535
  tb_uid_t suid;
1536
} SVStbRefDbsReq;
1537

1538
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1539
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1540

1541
typedef struct {
1542
  int32_t vgId;
1543
  SArray* pDbs;  // SArray<char* (db name)>
1544
} SVStbRefDbsRsp;
1545

1546
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1547
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1548
void    tDestroySVStbRefDbsRsp(void* rsp);
1549

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

1599
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1600
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1601
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1602

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

1635
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1636
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1637
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1638

1639
typedef struct {
1640
  char    db[TSDB_DB_FNAME_LEN];
1641
  int8_t  ignoreNotExists;
1642
  int32_t sqlLen;
1643
  char*   sql;
1644
} SDropDbReq;
1645

1646
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1647
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1648
void    tFreeSDropDbReq(SDropDbReq* pReq);
1649

1650
typedef struct {
1651
  char    db[TSDB_DB_FNAME_LEN];
1652
  int64_t uid;
1653
} SDropDbRsp;
1654

1655
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1656
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1657

1658
typedef struct {
1659
  char    name[TSDB_MOUNT_NAME_LEN];
1660
  int64_t uid;
1661
} SDropMountRsp;
1662

1663
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1664
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1665

1666
typedef struct {
1667
  char    db[TSDB_DB_FNAME_LEN];
1668
  int64_t dbId;
1669
  int32_t vgVersion;
1670
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1671
  int64_t stateTs;     // ms
1672
} SUseDbReq;
1673

1674
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1675
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1676

1677
typedef struct {
1678
  char    db[TSDB_DB_FNAME_LEN];
1679
  int64_t uid;
1680
  int32_t vgVersion;
1681
  int32_t vgNum;
1682
  int16_t hashPrefix;
1683
  int16_t hashSuffix;
1684
  int8_t  hashMethod;
1685
  union {
1686
    uint8_t flags;
1687
    struct {
1688
      uint8_t isMount : 1;  // TS-5868
1689
      uint8_t padding : 7;
1690
    };
1691
  };
1692
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1693
  int32_t errCode;
1694
  int64_t stateTs;  // ms
1695
} SUseDbRsp;
1696

1697
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1698
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1699
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1700
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1701
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1702

1703
typedef struct {
1704
  char db[TSDB_DB_FNAME_LEN];
1705
} SDbCfgReq;
1706

1707
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1708
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1709

1710
typedef struct {
1711
  char    db[TSDB_DB_FNAME_LEN];
1712
  int32_t maxSpeed;
1713
} STrimDbReq;
1714

1715
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1716
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1717

1718
typedef struct {
1719
  int32_t timestamp;
1720
} SVTrimDbReq;
1721

1722
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1723
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1724

1725
typedef struct {
1726
  char db[TSDB_DB_FNAME_LEN];
1727
} SSsMigrateDbReq;
1728

1729
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1730
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1731

1732
typedef struct {
1733
  int32_t ssMigrateId;
1734
  bool    bAccepted;
1735
} SSsMigrateDbRsp;
1736

1737
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1738
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1739

1740
typedef struct {
1741
  int32_t ssMigrateId;
1742
  int32_t nodeId; // node id of the leader vnode
1743
  int64_t timestamp;
1744
} SSsMigrateVgroupReq;
1745

1746
int32_t tSerializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1747
int32_t tDeserializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1748

1749
typedef struct {
1750
  int32_t ssMigrateId;
1751
  int32_t vgId;   // vgroup id
1752
  int32_t nodeId; // node id of the leader vnode
1753
} SSsMigrateVgroupRsp;
1754

1755
int32_t tSerializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1756
int32_t tDeserializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1757

1758
typedef struct {
1759
  int32_t ssMigrateId;
1760
  int32_t vgId;
1761
} SQuerySsMigrateProgressReq;
1762

1763
int32_t tSerializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1764
int32_t tDeserializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1765

1766
#define FILE_SET_MIGRATE_STATE_IN_PROGRESS  0
1767
#define FILE_SET_MIGRATE_STATE_SUCCEEDED    1
1768
#define FILE_SET_MIGRATE_STATE_SKIPPED      2
1769
#define FILE_SET_MIGRATE_STATE_FAILED       3
1770

1771
typedef struct {
1772
  int32_t fid;  // file set id
1773
  int32_t state;
1774
} SFileSetSsMigrateState;
1775

1776
typedef struct {
1777
  // if all taosd were restarted during the migration, then vnode migrate id will be 0,
1778
  // that's mnode will repeatedly request the migration progress. to avoid this, we need
1779
  // to save mnode migrate id in the response, so that mnode can drop it.
1780
  int32_t mnodeMigrateId; // migrate id requested by mnode
1781
  int32_t vnodeMigrateId; // migrate id reponsed by vnode
1782
  int32_t dnodeId;
1783
  int32_t vgId;
1784
  int64_t startTimeSec;
1785
  SArray* pFileSetStates;
1786
} SVnodeSsMigrateState;
1787

1788
int32_t tSerializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1789
int32_t tDeserializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1790
void tFreeSVnodeSsMigrateState(SVnodeSsMigrateState* pState);
1791

1792
typedef SVnodeSsMigrateState SQuerySsMigrateProgressRsp;
1793
#define tSerializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1794
  tSerializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1795
#define tDeserializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1796
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1797
#define tFreeSQuerySsMigrateProgressRsp(pRsp) \
1798
  tFreeSVnodeSsMigrateState(pRsp)
1799

1800
typedef SVnodeSsMigrateState SFollowerSsMigrateReq;
1801
#define tSerializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1802
  tSerializeSVnodeSsMigrateState(buf, bufLen, pReq)
1803
#define tDeserializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1804
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pReq)
1805
#define tFreeSFollowerSsMigrateReq(pReq) \
1806
  tFreeSVnodeSsMigrateState(pReq)
1807

1808
typedef struct {
1809
  int32_t timestampSec;
1810
  int32_t ttlDropMaxCount;
1811
  int32_t nUids;
1812
  SArray* pTbUids;
1813
} SVDropTtlTableReq;
1814

1815
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1816
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1817

1818
typedef struct {
1819
  char    db[TSDB_DB_FNAME_LEN];
1820
  int64_t dbId;
1821
  int32_t cfgVersion;
1822
  int32_t numOfVgroups;
1823
  int32_t numOfStables;
1824
  int32_t buffer;
1825
  int32_t cacheSize;
1826
  int32_t pageSize;
1827
  int32_t pages;
1828
  int32_t daysPerFile;
1829
  int32_t daysToKeep0;
1830
  int32_t daysToKeep1;
1831
  int32_t daysToKeep2;
1832
  int32_t keepTimeOffset;
1833
  int32_t minRows;
1834
  int32_t maxRows;
1835
  int32_t walFsyncPeriod;
1836
  int16_t hashPrefix;
1837
  int16_t hashSuffix;
1838
  int8_t  hashMethod;
1839
  int8_t  walLevel;
1840
  int8_t  precision;
1841
  int8_t  compression;
1842
  int8_t  replications;
1843
  int8_t  strict;
1844
  int8_t  cacheLast;
1845
  int8_t  encryptAlgorithm;
1846
  int32_t ssChunkSize;
1847
  int32_t ssKeepLocal;
1848
  int8_t  ssCompact;
1849
  union {
1850
    uint8_t flags;
1851
    struct {
1852
      uint8_t isMount : 1;  // TS-5868
1853
      uint8_t padding : 7;
1854
    };
1855
  };
1856
  int8_t  compactTimeOffset;
1857
  int32_t compactInterval;
1858
  int32_t compactStartTime;
1859
  int32_t compactEndTime;
1860
  int32_t tsdbPageSize;
1861
  int32_t walRetentionPeriod;
1862
  int32_t walRollPeriod;
1863
  int64_t walRetentionSize;
1864
  int64_t walSegmentSize;
1865
  int32_t numOfRetensions;
1866
  SArray* pRetensions;
1867
  int8_t  schemaless;
1868
  int16_t sstTrigger;
1869
  int8_t  withArbitrator;
1870
} SDbCfgRsp;
1871

1872
typedef SDbCfgRsp SDbCfgInfo;
1873

1874
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1875
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1876
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1877
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1878
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1879

1880
typedef struct {
1881
  int32_t rowNum;
1882
} SQnodeListReq;
1883

1884
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1885
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1886

1887
typedef struct {
1888
  int32_t rowNum;
1889
} SDnodeListReq;
1890

1891
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1892

1893
typedef struct {
1894
  int32_t useless;  // useless
1895
} SServerVerReq;
1896

1897
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1898
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1899

1900
typedef struct {
1901
  char ver[TSDB_VERSION_LEN];
1902
} SServerVerRsp;
1903

1904
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1905
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1906

1907
typedef struct SQueryNodeAddr {
1908
  int32_t nodeId;  // vgId or qnodeId
1909
  SEpSet  epSet;
1910
} SQueryNodeAddr;
1911

1912
typedef struct {
1913
  SQueryNodeAddr addr;
1914
  uint64_t       load;
1915
} SQueryNodeLoad;
1916

1917
typedef struct {
1918
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1919
} SQnodeListRsp;
1920

1921
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1922
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1923
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1924

1925
typedef struct SDNodeAddr {
1926
  int32_t nodeId;  // dnodeId
1927
  SEpSet  epSet;
1928
} SDNodeAddr;
1929

1930
typedef struct {
1931
  SArray* dnodeList;  // SArray<SDNodeAddr>
1932
} SDnodeListRsp;
1933

1934
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1935
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1936
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1937

1938
typedef struct {
1939
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1940
} STableTSMAInfoRsp;
1941

1942
typedef struct {
1943
  SUseDbRsp*         useDbRsp;
1944
  SDbCfgRsp*         cfgRsp;
1945
  STableTSMAInfoRsp* pTsmaRsp;
1946
  int32_t            dbTsmaVersion;
1947
  char               db[TSDB_DB_FNAME_LEN];
1948
  int64_t            dbId;
1949
} SDbHbRsp;
1950

1951
typedef struct {
1952
  SArray* pArray;  // Array of SDbHbRsp
1953
} SDbHbBatchRsp;
1954

1955
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1956
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1957
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1958

1959
typedef struct {
1960
  SArray* pArray;  // Array of SGetUserAuthRsp
1961
} SUserAuthBatchRsp;
1962

1963
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1964
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1965
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1966

1967
typedef struct {
1968
  char        db[TSDB_DB_FNAME_LEN];
1969
  STimeWindow timeRange;
1970
  int32_t     sqlLen;
1971
  char*       sql;
1972
  SArray*     vgroupIds;
1973
  int8_t      metaOnly;
1974
} SCompactDbReq;
1975

1976
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1977
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1978
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1979

1980
typedef struct {
1981
  int32_t compactId;
1982
  int8_t  bAccepted;
1983
} SCompactDbRsp;
1984

1985
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1986
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1987

1988
typedef struct {
1989
  int32_t compactId;
1990
  int32_t sqlLen;
1991
  char*   sql;
1992
} SKillCompactReq;
1993

1994
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1995
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1996
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1997

1998
typedef struct {
1999
  char    name[TSDB_FUNC_NAME_LEN];
2000
  int8_t  igExists;
2001
  int8_t  funcType;
2002
  int8_t  scriptType;
2003
  int8_t  outputType;
2004
  int32_t outputLen;
2005
  int32_t bufSize;
2006
  int32_t codeLen;
2007
  int64_t signature;
2008
  char*   pComment;
2009
  char*   pCode;
2010
  int8_t  orReplace;
2011
} SCreateFuncReq;
2012

2013
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2014
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2015
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2016

2017
typedef struct {
2018
  char   name[TSDB_FUNC_NAME_LEN];
2019
  int8_t igNotExists;
2020
} SDropFuncReq;
2021

2022
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2023
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2024

2025
typedef struct {
2026
  int32_t numOfFuncs;
2027
  bool    ignoreCodeComment;
2028
  SArray* pFuncNames;
2029
} SRetrieveFuncReq;
2030

2031
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2032
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2033
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2034

2035
typedef struct {
2036
  char    name[TSDB_FUNC_NAME_LEN];
2037
  int8_t  funcType;
2038
  int8_t  scriptType;
2039
  int8_t  outputType;
2040
  int32_t outputLen;
2041
  int32_t bufSize;
2042
  int64_t signature;
2043
  int32_t commentSize;
2044
  int32_t codeSize;
2045
  char*   pComment;
2046
  char*   pCode;
2047
} SFuncInfo;
2048

2049
typedef struct {
2050
  int32_t funcVersion;
2051
  int64_t funcCreatedTime;
2052
} SFuncExtraInfo;
2053

2054
typedef struct {
2055
  int32_t numOfFuncs;
2056
  SArray* pFuncInfos;
2057
  SArray* pFuncExtraInfos;
2058
} SRetrieveFuncRsp;
2059

2060
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2061
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2062
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2063
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2064

2065
typedef struct {
2066
  int32_t       statusInterval;
2067
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2068
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2069
  char          locale[TD_LOCALE_LEN];      // tsLocale
2070
  char          charset[TD_LOCALE_LEN];     // tsCharset
2071
  int8_t        ttlChangeOnWrite;
2072
  int8_t        enableWhiteList;
2073
  int8_t        encryptionKeyStat;
2074
  uint32_t      encryptionKeyChksum;
2075
  SMonitorParas monitorParas;
2076
} SClusterCfg;
2077

2078
typedef struct {
2079
  int32_t openVnodes;
2080
  int32_t dropVnodes;
2081
  int32_t totalVnodes;
2082
  int32_t masterNum;
2083
  int64_t numOfSelectReqs;
2084
  int64_t numOfInsertReqs;
2085
  int64_t numOfInsertSuccessReqs;
2086
  int64_t numOfBatchInsertReqs;
2087
  int64_t numOfBatchInsertSuccessReqs;
2088
  int64_t errors;
2089
} SVnodesStat;
2090

2091
typedef struct {
2092
  int32_t vgId;
2093
  int8_t  syncState;
2094
  int8_t  syncRestore;
2095
  int64_t syncTerm;
2096
  int64_t roleTimeMs;
2097
  int64_t startTimeMs;
2098
  int8_t  syncCanRead;
2099
  int64_t cacheUsage;
2100
  int64_t numOfTables;
2101
  int64_t numOfTimeSeries;
2102
  int64_t totalStorage;
2103
  int64_t compStorage;
2104
  int64_t pointsWritten;
2105
  int64_t numOfSelectReqs;
2106
  int64_t numOfInsertReqs;
2107
  int64_t numOfInsertSuccessReqs;
2108
  int64_t numOfBatchInsertReqs;
2109
  int64_t numOfBatchInsertSuccessReqs;
2110
  int32_t numOfCachedTables;
2111
  int32_t learnerProgress;  // use one reservered
2112
  int64_t syncAppliedIndex;
2113
  int64_t syncCommitIndex;
2114
  int64_t bufferSegmentUsed;
2115
  int64_t bufferSegmentSize;
2116
} SVnodeLoad;
2117

2118
typedef struct {
2119
  int64_t total_requests;
2120
  int64_t total_rows;
2121
  int64_t total_bytes;
2122
  double  write_size;
2123
  double  cache_hit_ratio;
2124
  int64_t rpc_queue_wait;
2125
  int64_t preprocess_time;
2126

2127
  int64_t memory_table_size;
2128
  int64_t commit_count;
2129
  int64_t merge_count;
2130
  double  commit_time;
2131
  double  merge_time;
2132
  int64_t block_commit_time;
2133
  int64_t memtable_wait_time;
2134
} SVnodeMetrics;
2135

2136
typedef struct {
2137
  int32_t     vgId;
2138
  int64_t     numOfTables;
2139
  int64_t     memSize;
2140
  int64_t     l1Size;
2141
  int64_t     l2Size;
2142
  int64_t     l3Size;
2143
  int64_t     cacheSize;
2144
  int64_t     walSize;
2145
  int64_t     metaSize;
2146
  int64_t     rawDataSize;
2147
  int64_t     ssSize;
2148
  const char* dbname;
2149
} SDbSizeStatisInfo;
2150

2151
typedef struct {
2152
  int32_t vgId;
2153
  int64_t nTimeSeries;
2154
} SVnodeLoadLite;
2155

2156
typedef struct {
2157
  int8_t  syncState;
2158
  int64_t syncTerm;
2159
  int8_t  syncRestore;
2160
  int64_t roleTimeMs;
2161
} SMnodeLoad;
2162

2163
typedef struct {
2164
  int32_t dnodeId;
2165
  int64_t numOfProcessedQuery;
2166
  int64_t numOfProcessedCQuery;
2167
  int64_t numOfProcessedFetch;
2168
  int64_t numOfProcessedDrop;
2169
  int64_t numOfProcessedNotify;
2170
  int64_t numOfProcessedHb;
2171
  int64_t numOfProcessedDelete;
2172
  int64_t cacheDataSize;
2173
  int64_t numOfQueryInQueue;
2174
  int64_t numOfFetchInQueue;
2175
  int64_t timeInQueryQueue;
2176
  int64_t timeInFetchQueue;
2177
} SQnodeLoad;
2178

2179
typedef struct {
2180
  int32_t     sver;      // software version
2181
  int64_t     dnodeVer;  // dnode table version in sdb
2182
  int32_t     dnodeId;
2183
  int64_t     clusterId;
2184
  int64_t     rebootTime;
2185
  int64_t     updateTime;
2186
  float       numOfCores;
2187
  int32_t     numOfSupportVnodes;
2188
  int32_t     numOfDiskCfg;
2189
  int64_t     memTotal;
2190
  int64_t     memAvail;
2191
  char        dnodeEp[TSDB_EP_LEN];
2192
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2193
  SMnodeLoad  mload;
2194
  SQnodeLoad  qload;
2195
  SClusterCfg clusterCfg;
2196
  SArray*     pVloads;  // array of SVnodeLoad
2197
  int32_t     statusSeq;
2198
  int64_t     ipWhiteVer;
2199
  int64_t     analVer;
2200
  int64_t     timestamp;
2201
} SStatusReq;
2202

2203
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2204
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2205
void    tFreeSStatusReq(SStatusReq* pReq);
2206

2207
typedef struct {
2208
  int32_t forceReadConfig;
2209
  int32_t cver;
2210
  SArray* array;
2211
} SConfigReq;
2212

2213
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2214
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2215
void    tFreeSConfigReq(SConfigReq* pReq);
2216

2217
typedef struct {
2218
  int32_t dnodeId;
2219
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2220
} SDnodeInfoReq;
2221

2222
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2223
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2224

2225
typedef enum {
2226
  MONITOR_TYPE_COUNTER = 0,
2227
  MONITOR_TYPE_SLOW_LOG = 1,
2228
} MONITOR_TYPE;
2229

2230
typedef struct {
2231
  int32_t      contLen;
2232
  char*        pCont;
2233
  MONITOR_TYPE type;
2234
} SStatisReq;
2235

2236
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2237
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2238
void    tFreeSStatisReq(SStatisReq* pReq);
2239

2240
typedef struct {
2241
  char    db[TSDB_DB_FNAME_LEN];
2242
  char    table[TSDB_TABLE_NAME_LEN];
2243
  char    operation[AUDIT_OPERATION_LEN];
2244
  int32_t sqlLen;
2245
  char*   pSql;
2246
} SAuditReq;
2247
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2248
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2249
void    tFreeSAuditReq(SAuditReq* pReq);
2250

2251
typedef struct {
2252
  int32_t dnodeId;
2253
  int64_t clusterId;
2254
  SArray* pVloads;
2255
} SNotifyReq;
2256

2257
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2258
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2259
void    tFreeSNotifyReq(SNotifyReq* pReq);
2260

2261
typedef struct {
2262
  int32_t dnodeId;
2263
  int64_t clusterId;
2264
} SDnodeCfg;
2265

2266
typedef struct {
2267
  int32_t id;
2268
  int8_t  isMnode;
2269
  SEp     ep;
2270
} SDnodeEp;
2271

2272
typedef struct {
2273
  int32_t id;
2274
  int8_t  isMnode;
2275
  int8_t  offlineReason;
2276
  SEp     ep;
2277
  char    active[TSDB_ACTIVE_KEY_LEN];
2278
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2279
} SDnodeInfo;
2280

2281
typedef struct {
2282
  int64_t   dnodeVer;
2283
  SDnodeCfg dnodeCfg;
2284
  SArray*   pDnodeEps;  // Array of SDnodeEp
2285
  int32_t   statusSeq;
2286
  int64_t   ipWhiteVer;
2287
  int64_t   analVer;
2288
} SStatusRsp;
2289

2290
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2291
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2292
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2293

2294
typedef struct {
2295
  int32_t forceReadConfig;
2296
  int32_t isConifgVerified;
2297
  int32_t isVersionVerified;
2298
  int32_t cver;
2299
  SArray* array;
2300
} SConfigRsp;
2301

2302
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2303
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2304
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2305

2306
typedef struct {
2307
  int32_t reserved;
2308
} SMTimerReq;
2309

2310
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2311
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2312

2313
typedef struct SOrphanTask {
2314
  int64_t streamId;
2315
  int32_t taskId;
2316
  int32_t nodeId;
2317
} SOrphanTask;
2318

2319
typedef struct SMStreamDropOrphanMsg {
2320
  SArray* pList;  // SArray<SOrphanTask>
2321
} SMStreamDropOrphanMsg;
2322

2323
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2324
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2325
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2326

2327
typedef struct {
2328
  int32_t  id;
2329
  uint16_t port;                 // node sync Port
2330
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2331
} SReplica;
2332

2333
typedef struct {
2334
  int32_t  vgId;
2335
  char     db[TSDB_DB_FNAME_LEN];
2336
  int64_t  dbUid;
2337
  int32_t  vgVersion;
2338
  int32_t  numOfStables;
2339
  int32_t  buffer;
2340
  int32_t  pageSize;
2341
  int32_t  pages;
2342
  int32_t  cacheLastSize;
2343
  int32_t  daysPerFile;
2344
  int32_t  daysToKeep0;
2345
  int32_t  daysToKeep1;
2346
  int32_t  daysToKeep2;
2347
  int32_t  keepTimeOffset;
2348
  int32_t  minRows;
2349
  int32_t  maxRows;
2350
  int32_t  walFsyncPeriod;
2351
  uint32_t hashBegin;
2352
  uint32_t hashEnd;
2353
  int8_t   hashMethod;
2354
  int8_t   walLevel;
2355
  int8_t   precision;
2356
  int8_t   compression;
2357
  int8_t   strict;
2358
  int8_t   cacheLast;
2359
  int8_t   isTsma;
2360
  int8_t   replica;
2361
  int8_t   selfIndex;
2362
  SReplica replicas[TSDB_MAX_REPLICA];
2363
  int32_t  numOfRetensions;
2364
  SArray*  pRetensions;  // SRetention
2365
  void*    pTsma;
2366
  int32_t  walRetentionPeriod;
2367
  int64_t  walRetentionSize;
2368
  int32_t  walRollPeriod;
2369
  int64_t  walSegmentSize;
2370
  int16_t  sstTrigger;
2371
  int16_t  hashPrefix;
2372
  int16_t  hashSuffix;
2373
  int32_t  tsdbPageSize;
2374
  int32_t  ssChunkSize;
2375
  int32_t  ssKeepLocal;
2376
  int8_t   ssCompact;
2377
  int64_t  reserved[6];
2378
  int8_t   learnerReplica;
2379
  int8_t   learnerSelfIndex;
2380
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2381
  int32_t  changeVersion;
2382
  int8_t   encryptAlgorithm;
2383
} SCreateVnodeReq;
2384

2385
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2386
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2387
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2388

2389
typedef struct {
2390
  int32_t compactId;
2391
  int32_t vgId;
2392
  int32_t dnodeId;
2393
} SQueryCompactProgressReq;
2394

2395
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2396
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2397

2398
typedef struct {
2399
  int32_t compactId;
2400
  int32_t vgId;
2401
  int32_t dnodeId;
2402
  int32_t numberFileset;
2403
  int32_t finished;
2404
  int32_t progress;
2405
  int64_t remainingTime;
2406
} SQueryCompactProgressRsp;
2407

2408
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2409
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2410

2411
typedef struct {
2412
  int32_t vgId;
2413
  int32_t dnodeId;
2414
  int64_t dbUid;
2415
  char    db[TSDB_DB_FNAME_LEN];
2416
  int64_t reserved[8];
2417
} SDropVnodeReq;
2418

2419
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2420
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2421

2422
typedef struct {
2423
  char    colName[TSDB_COL_NAME_LEN];
2424
  char    stb[TSDB_TABLE_FNAME_LEN];
2425
  int64_t stbUid;
2426
  int64_t dbUid;
2427
  int64_t reserved[8];
2428
} SDropIndexReq;
2429

2430
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2431
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2432

2433
typedef struct {
2434
  int64_t     dbUid;
2435
  char        db[TSDB_DB_FNAME_LEN];
2436
  int64_t     compactStartTime;
2437
  STimeWindow tw;
2438
  int32_t     compactId;
2439
  int8_t      metaOnly;
2440
} SCompactVnodeReq;
2441

2442
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2443
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2444

2445
typedef struct {
2446
  int32_t compactId;
2447
  int32_t vgId;
2448
  int32_t dnodeId;
2449
} SVKillCompactReq;
2450

2451
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2452
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2453

2454
typedef struct {
2455
  int32_t vgVersion;
2456
  int32_t buffer;
2457
  int32_t pageSize;
2458
  int32_t pages;
2459
  int32_t cacheLastSize;
2460
  int32_t daysPerFile;
2461
  int32_t daysToKeep0;
2462
  int32_t daysToKeep1;
2463
  int32_t daysToKeep2;
2464
  int32_t keepTimeOffset;
2465
  int32_t walFsyncPeriod;
2466
  int8_t  walLevel;
2467
  int8_t  strict;
2468
  int8_t  cacheLast;
2469
  int64_t reserved[7];
2470
  // 1st modification
2471
  int16_t sttTrigger;
2472
  int32_t minRows;
2473
  // 2nd modification
2474
  int32_t walRetentionPeriod;
2475
  int32_t walRetentionSize;
2476
  int32_t ssKeepLocal;
2477
  int8_t  ssCompact;
2478
} SAlterVnodeConfigReq;
2479

2480
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2481
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2482

2483
typedef struct {
2484
  int32_t  vgId;
2485
  int8_t   strict;
2486
  int8_t   selfIndex;
2487
  int8_t   replica;
2488
  SReplica replicas[TSDB_MAX_REPLICA];
2489
  int64_t  reserved[8];
2490
  int8_t   learnerSelfIndex;
2491
  int8_t   learnerReplica;
2492
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2493
  int32_t  changeVersion;
2494
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2495

2496
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2497
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2498

2499
typedef struct {
2500
  int32_t vgId;
2501
  int8_t  disable;
2502
} SDisableVnodeWriteReq;
2503

2504
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2505
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2506

2507
typedef struct {
2508
  int32_t  srcVgId;
2509
  int32_t  dstVgId;
2510
  uint32_t hashBegin;
2511
  uint32_t hashEnd;
2512
  int32_t  changeVersion;
2513
  int32_t  reserved;
2514
} SAlterVnodeHashRangeReq;
2515

2516
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2517
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2518

2519
#define REQ_OPT_TBNAME 0x0
2520
#define REQ_OPT_TBUID  0x01
2521
typedef struct {
2522
  SMsgHead header;
2523
  char     dbFName[TSDB_DB_FNAME_LEN];
2524
  char     tbName[TSDB_TABLE_NAME_LEN];
2525
  uint8_t  option;
2526
  uint8_t  autoCreateCtb;
2527
} STableInfoReq;
2528

2529
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2530
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2531

2532
typedef struct {
2533
  int8_t  metaClone;  // create local clone of the cached table meta
2534
  int32_t numOfVgroups;
2535
  int32_t numOfTables;
2536
  int32_t numOfUdfs;
2537
  char    tableNames[];
2538
} SMultiTableInfoReq;
2539

2540
// todo refactor
2541
typedef struct SVgroupInfo {
2542
  int32_t  vgId;
2543
  uint32_t hashBegin;
2544
  uint32_t hashEnd;
2545
  SEpSet   epSet;
2546
  union {
2547
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2548
    int32_t taskId;      // used in stream
2549
  };
2550
} SVgroupInfo;
2551

2552
typedef struct {
2553
  int32_t     numOfVgroups;
2554
  SVgroupInfo vgroups[];
2555
} SVgroupsInfo;
2556

2557
typedef struct {
2558
  STableMetaRsp* pMeta;
2559
} SMAlterStbRsp;
2560

2561
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2562
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2563
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2564

2565
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2566
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2567
void    tFreeSTableMetaRsp(void* pRsp);
2568
void    tFreeSTableIndexRsp(void* info);
2569

2570
typedef struct {
2571
  SArray* pMetaRsp;   // Array of STableMetaRsp
2572
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2573
} SSTbHbRsp;
2574

2575
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2576
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2577
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2578

2579
typedef struct {
2580
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2581
} SViewHbRsp;
2582

2583
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2584
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2585
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2586

2587
typedef struct {
2588
  int32_t numOfTables;
2589
  int32_t numOfVgroup;
2590
  int32_t numOfUdf;
2591
  int32_t contLen;
2592
  int8_t  compressed;  // denote if compressed or not
2593
  int32_t rawLen;      // size before compress
2594
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2595
  char    meta[];
2596
} SMultiTableMeta;
2597

2598
typedef struct {
2599
  int32_t dataLen;
2600
  char    name[TSDB_TABLE_FNAME_LEN];
2601
  char*   data;
2602
} STagData;
2603

2604
typedef struct {
2605
  int32_t  opType;
2606
  uint32_t valLen;
2607
  char*    val;
2608
} SShowVariablesReq;
2609

2610
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2611
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2612
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2613

2614
typedef struct {
2615
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2616
  char value[TSDB_CONFIG_PATH_LEN + 1];
2617
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2618
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2619
  char info[TSDB_CONFIG_INFO_LEN + 1];
2620
} SVariablesInfo;
2621

2622
typedef struct {
2623
  SArray* variables;  // SArray<SVariablesInfo>
2624
} SShowVariablesRsp;
2625

2626
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2627
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2628

2629
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2630

2631
/*
2632
 * sql: show tables like '%a_%'
2633
 * payload is the query condition, e.g., '%a_%'
2634
 * payloadLen is the length of payload
2635
 */
2636
typedef struct {
2637
  int32_t type;
2638
  char    db[TSDB_DB_FNAME_LEN];
2639
  int32_t payloadLen;
2640
  char*   payload;
2641
} SShowReq;
2642

2643
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2644
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2645
void tFreeSShowReq(SShowReq* pReq);
2646

2647
typedef struct {
2648
  int64_t       showId;
2649
  STableMetaRsp tableMeta;
2650
} SShowRsp, SVShowTablesRsp;
2651

2652
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2653
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2654
// void    tFreeSShowRsp(SShowRsp* pRsp);
2655

2656
typedef struct {
2657
  char    db[TSDB_DB_FNAME_LEN];
2658
  char    tb[TSDB_TABLE_NAME_LEN];
2659
  char    user[TSDB_USER_LEN];
2660
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2661
  int64_t showId;
2662
  int64_t compactId;  // for compact
2663
  bool    withFull;   // for show users full
2664
} SRetrieveTableReq;
2665

2666
typedef struct SSysTableSchema {
2667
  int8_t   type;
2668
  col_id_t colId;
2669
  int32_t  bytes;
2670
} SSysTableSchema;
2671

2672
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2673
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2674

2675
#define RETRIEVE_TABLE_RSP_VERSION         0
2676
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2677
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2678

2679
typedef struct {
2680
  int64_t useconds;
2681
  int8_t  completed;  // all results are returned to client
2682
  int8_t  precision;
2683
  int8_t  compressed;
2684
  int8_t  streamBlockType;
2685
  int32_t payloadLen;
2686
  int32_t compLen;
2687
  int32_t numOfBlocks;
2688
  int64_t numOfRows;  // from int32_t change to int64_t
2689
  int64_t numOfCols;
2690
  int64_t skey;
2691
  int64_t ekey;
2692
  int64_t version;                         // for stream
2693
  TSKEY   watermark;                       // for stream
2694
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2695
  char    data[];
2696
} SRetrieveTableRsp;
2697

2698
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2699

2700
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2701
  do {                                          \
2702
    ((int32_t*)(_p))[0] = (_compLen);           \
2703
    ((int32_t*)(_p))[1] = (_fullLen);           \
2704
  } while (0);
2705

2706
typedef struct {
2707
  int64_t version;
2708
  int64_t numOfRows;
2709
  int8_t  compressed;
2710
  int8_t  precision;
2711
  char    data[];
2712
} SRetrieveTableRspForTmq;
2713

2714
typedef struct {
2715
  int64_t handle;
2716
  int64_t useconds;
2717
  int8_t  completed;  // all results are returned to client
2718
  int8_t  precision;
2719
  int8_t  compressed;
2720
  int32_t compLen;
2721
  int32_t numOfRows;
2722
  int32_t fullLen;
2723
  char    data[];
2724
} SRetrieveMetaTableRsp;
2725

2726
typedef struct SExplainExecInfo {
2727
  double   startupCost;
2728
  double   totalCost;
2729
  uint64_t numOfRows;
2730
  uint32_t verboseLen;
2731
  void*    verboseInfo;
2732
} SExplainExecInfo;
2733

2734
typedef struct {
2735
  int32_t           numOfPlans;
2736
  SExplainExecInfo* subplanInfo;
2737
} SExplainRsp;
2738

2739
typedef struct {
2740
  SExplainRsp rsp;
2741
  uint64_t    qId;
2742
  uint64_t    cId;
2743
  uint64_t    tId;
2744
  int64_t     rId;
2745
  int32_t     eId;
2746
} SExplainLocalRsp;
2747

2748
typedef struct STableScanAnalyzeInfo {
2749
  uint64_t totalRows;
2750
  uint64_t totalCheckedRows;
2751
  uint32_t totalBlocks;
2752
  uint32_t loadBlocks;
2753
  uint32_t loadBlockStatis;
2754
  uint32_t skipBlocks;
2755
  uint32_t filterOutBlocks;
2756
  double   elapsedTime;
2757
  double   filterTime;
2758
} STableScanAnalyzeInfo;
2759

2760
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2761
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2762
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2763

2764
typedef struct {
2765
  char    config[TSDB_DNODE_CONFIG_LEN];
2766
  char    value[TSDB_CLUSTER_VALUE_LEN];
2767
  int32_t sqlLen;
2768
  char*   sql;
2769
} SMCfgClusterReq;
2770

2771
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2772
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2773
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2774

2775
typedef struct {
2776
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2777
  int32_t port;
2778
  int32_t sqlLen;
2779
  char*   sql;
2780
} SCreateDnodeReq;
2781

2782
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2783
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2784
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2785

2786
typedef struct {
2787
  int32_t dnodeId;
2788
  char    fqdn[TSDB_FQDN_LEN];
2789
  int32_t port;
2790
  int8_t  force;
2791
  int8_t  unsafe;
2792
  int32_t sqlLen;
2793
  char*   sql;
2794
} SDropDnodeReq;
2795

2796
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2797
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2798
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2799

2800
enum {
2801
  RESTORE_TYPE__ALL = 1,
2802
  RESTORE_TYPE__MNODE,
2803
  RESTORE_TYPE__VNODE,
2804
  RESTORE_TYPE__QNODE,
2805
};
2806

2807
typedef struct {
2808
  int32_t dnodeId;
2809
  int8_t  restoreType;
2810
  int32_t sqlLen;
2811
  char*   sql;
2812
} SRestoreDnodeReq;
2813

2814
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2815
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2816
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2817

2818
typedef struct {
2819
  int32_t dnodeId;
2820
  char    config[TSDB_DNODE_CONFIG_LEN];
2821
  char    value[TSDB_DNODE_VALUE_LEN];
2822
  int32_t sqlLen;
2823
  char*   sql;
2824
} SMCfgDnodeReq;
2825

2826
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2827
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2828
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2829

2830
typedef struct {
2831
  char    config[TSDB_DNODE_CONFIG_LEN];
2832
  char    value[TSDB_DNODE_VALUE_LEN];
2833
  int32_t version;
2834
} SDCfgDnodeReq;
2835

2836
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2837
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2838

2839
typedef struct {
2840
  int32_t dnodeId;
2841
  int32_t sqlLen;
2842
  char*   sql;
2843
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2844
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2845

2846
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2847
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2848
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2849
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2850
typedef struct {
2851
  int8_t   replica;
2852
  SReplica replicas[TSDB_MAX_REPLICA];
2853
  int8_t   learnerReplica;
2854
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2855
  int64_t  lastIndex;
2856
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2857

2858
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2859
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2860

2861
typedef struct {
2862
  int32_t urlLen;
2863
  int32_t sqlLen;
2864
  char*   url;
2865
  char*   sql;
2866
} SMCreateAnodeReq;
2867

2868
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2869
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2870
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2871

2872
typedef struct {
2873
  int32_t anodeId;
2874
  int32_t sqlLen;
2875
  char*   sql;
2876
} SMDropAnodeReq, SMUpdateAnodeReq;
2877

2878
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2879
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2880
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2881
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2882
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2883
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2884

2885
typedef struct {
2886
  int32_t dnodeId;
2887
  int32_t bnodeProto;
2888
  int32_t sqlLen;
2889
  char*   sql;
2890
} SMCreateBnodeReq, SDCreateBnodeReq;
2891

2892
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2893
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2894
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
2895

2896
typedef struct {
2897
  int32_t dnodeId;
2898
  int32_t sqlLen;
2899
  char*   sql;
2900
} SMDropBnodeReq, SDDropBnodeReq;
2901

2902
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2903
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2904
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
2905

2906
typedef struct {
2907
  int32_t vgId;
2908
  int32_t hbSeq;
2909
} SVArbHbReqMember;
2910

2911
typedef struct {
2912
  int32_t dnodeId;
2913
  char*   arbToken;
2914
  int64_t arbTerm;
2915
  SArray* hbMembers;  // SVArbHbReqMember
2916
} SVArbHeartBeatReq;
2917

2918
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2919
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2920
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2921

2922
typedef struct {
2923
  int32_t vgId;
2924
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2925
  int32_t hbSeq;
2926
} SVArbHbRspMember;
2927

2928
typedef struct {
2929
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2930
  int32_t dnodeId;
2931
  SArray* hbMembers;  // SVArbHbRspMember
2932
} SVArbHeartBeatRsp;
2933

2934
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2935
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2936
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2937

2938
typedef struct {
2939
  char*   arbToken;
2940
  int64_t arbTerm;
2941
  char*   member0Token;
2942
  char*   member1Token;
2943
} SVArbCheckSyncReq;
2944

2945
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2946
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2947
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2948

2949
typedef struct {
2950
  char*   arbToken;
2951
  char*   member0Token;
2952
  char*   member1Token;
2953
  int32_t vgId;
2954
  int32_t errCode;
2955
} SVArbCheckSyncRsp;
2956

2957
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2958
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2959
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2960

2961
typedef struct {
2962
  char*   arbToken;
2963
  int64_t arbTerm;
2964
  char*   memberToken;
2965
  int8_t  force;
2966
} SVArbSetAssignedLeaderReq;
2967

2968
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2969
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2970
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2971

2972
typedef struct {
2973
  char*   arbToken;
2974
  char*   memberToken;
2975
  int32_t vgId;
2976
} SVArbSetAssignedLeaderRsp;
2977

2978
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2979
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2980
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2981

2982
typedef struct {
2983
  int32_t dnodeId;
2984
  char*   token;
2985
} SMArbUpdateGroupMember;
2986

2987
typedef struct {
2988
  int32_t dnodeId;
2989
  char*   token;
2990
  int8_t  acked;
2991
} SMArbUpdateGroupAssigned;
2992

2993
typedef struct {
2994
  int32_t                  vgId;
2995
  int64_t                  dbUid;
2996
  SMArbUpdateGroupMember   members[2];
2997
  int8_t                   isSync;
2998
  int8_t                   assignedAcked;
2999
  SMArbUpdateGroupAssigned assignedLeader;
3000
  int64_t                  version;
3001
  int32_t                  code;
3002
  int64_t                  updateTimeMs;
3003
} SMArbUpdateGroup;
3004

3005
typedef struct {
3006
  SArray* updateArray;  // SMArbUpdateGroup
3007
} SMArbUpdateGroupBatchReq;
3008

3009
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3010
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3011
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3012

3013
typedef struct {
3014
  char queryStrId[TSDB_QUERY_ID_LEN];
3015
} SKillQueryReq;
3016

3017
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3018
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3019

3020
typedef struct {
3021
  uint32_t connId;
3022
} SKillConnReq;
3023

3024
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3025
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3026

3027
typedef struct {
3028
  int32_t transId;
3029
} SKillTransReq;
3030

3031
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3032
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3033

3034
typedef struct {
3035
  int32_t useless;  // useless
3036
  int32_t sqlLen;
3037
  char*   sql;
3038
} SBalanceVgroupReq;
3039

3040
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3041
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3042
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3043

3044
typedef struct {
3045
  int32_t useless;  // useless
3046
  int32_t sqlLen;
3047
  char*   sql;
3048
} SAssignLeaderReq;
3049

3050
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3051
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3052
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3053
typedef struct {
3054
  int32_t vgId1;
3055
  int32_t vgId2;
3056
} SMergeVgroupReq;
3057

3058
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3059
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3060

3061
typedef struct {
3062
  int32_t vgId;
3063
  int32_t dnodeId1;
3064
  int32_t dnodeId2;
3065
  int32_t dnodeId3;
3066
  int32_t sqlLen;
3067
  char*   sql;
3068
} SRedistributeVgroupReq;
3069

3070
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3071
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3072
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3073

3074
typedef struct {
3075
  int32_t reserved;
3076
  int32_t vgId;
3077
  int32_t sqlLen;
3078
  char*   sql;
3079
  char    db[TSDB_DB_FNAME_LEN];
3080
} SBalanceVgroupLeaderReq;
3081

3082
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3083
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3084
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3085

3086
typedef struct {
3087
  int32_t vgId;
3088
} SForceBecomeFollowerReq;
3089

3090
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3091
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3092

3093
typedef struct {
3094
  int32_t vgId;
3095
} SSplitVgroupReq;
3096

3097
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3098
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3099

3100
typedef struct {
3101
  char user[TSDB_USER_LEN];
3102
  char spi;
3103
  char encrypt;
3104
  char secret[TSDB_PASSWORD_LEN];
3105
  char ckey[TSDB_PASSWORD_LEN];
3106
} SAuthReq, SAuthRsp;
3107

3108
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3109
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3110

3111
typedef struct {
3112
  int32_t statusCode;
3113
  char    details[1024];
3114
} SServerStatusRsp;
3115

3116
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3117
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3118

3119
/**
3120
 * The layout of the query message payload is as following:
3121
 * +--------------------+---------------------------------+
3122
 * |Sql statement       | Physical plan                   |
3123
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3124
 * +--------------------+---------------------------------+
3125
 */
3126
typedef struct SSubQueryMsg {
3127
  SMsgHead header;
3128
  uint64_t sId;
3129
  uint64_t queryId;
3130
  uint64_t clientId;
3131
  uint64_t taskId;
3132
  int64_t  refId;
3133
  int32_t  execId;
3134
  int32_t  msgMask;
3135
  int8_t   taskType;
3136
  int8_t   explain;
3137
  int8_t   needFetch;
3138
  int8_t   compress;
3139
  uint32_t sqlLen;
3140
  char*    sql;
3141
  uint32_t msgLen;
3142
  char*    msg;
3143
} SSubQueryMsg;
3144

3145
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3146
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3147
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3148

3149
typedef struct {
3150
  SMsgHead header;
3151
  uint64_t sId;
3152
  uint64_t queryId;
3153
  uint64_t taskId;
3154
} SSinkDataReq;
3155

3156
typedef struct {
3157
  SMsgHead header;
3158
  uint64_t sId;
3159
  uint64_t queryId;
3160
  uint64_t clientId;
3161
  uint64_t taskId;
3162
  int32_t  execId;
3163
} SQueryContinueReq;
3164

3165
typedef struct {
3166
  SMsgHead header;
3167
  uint64_t sId;
3168
  uint64_t queryId;
3169
  uint64_t taskId;
3170
} SResReadyReq;
3171

3172
typedef struct {
3173
  int32_t code;
3174
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3175
  int32_t sversion;
3176
  int32_t tversion;
3177
} SResReadyRsp;
3178

3179
typedef struct SOperatorParam {
3180
  int32_t opType;
3181
  int32_t downstreamIdx;
3182
  void*   value;
3183
  SArray* pChildren;  // SArray<SOperatorParam*>
3184
  bool    reUse;
3185
} SOperatorParam;
3186

3187
typedef struct SColIdNameKV {
3188
  col_id_t colId;
3189
  char     colName[TSDB_COL_NAME_LEN];
3190
} SColIdNameKV;
3191

3192
typedef struct SColIdPair {
3193
  col_id_t vtbColId;
3194
  col_id_t orgColId;
3195
} SColIdPair;
3196

3197
typedef struct SOrgTbInfo {
3198
  int32_t vgId;
3199
  char    tbName[TSDB_TABLE_FNAME_LEN];
3200
  SArray* colMap;  // SArray<SColIdNameKV>
3201
} SOrgTbInfo;
3202

3203
typedef struct STableScanOperatorParam {
3204
  bool        tableSeq;
3205
  SArray*     pUidList;
3206
  SOrgTbInfo* pOrgTbInfo;
3207
  STimeWindow window;
3208
} STableScanOperatorParam;
3209

3210
typedef struct SVTableScanOperatorParam {
3211
  uint64_t uid;
3212
  SArray*  pOpParamArray;  // SArray<SOperatorParam>
3213
} SVTableScanOperatorParam;
3214

3215
typedef struct {
3216
  SMsgHead        header;
3217
  uint64_t        sId;
3218
  uint64_t        queryId;
3219
  uint64_t        clientId;
3220
  uint64_t        taskId;
3221
  int32_t         execId;
3222
  SOperatorParam* pOpParam;
3223
} SResFetchReq;
3224

3225
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3226
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3227

3228
typedef struct {
3229
  SMsgHead header;
3230
  uint64_t clientId;
3231
} SSchTasksStatusReq;
3232

3233
typedef struct {
3234
  uint64_t queryId;
3235
  uint64_t clientId;
3236
  uint64_t taskId;
3237
  int64_t  refId;
3238
  int32_t  execId;
3239
  int8_t   status;
3240
} STaskStatus;
3241

3242
typedef struct {
3243
  int64_t refId;
3244
  SArray* taskStatus;  // SArray<STaskStatus>
3245
} SSchedulerStatusRsp;
3246

3247
typedef struct {
3248
  uint64_t queryId;
3249
  uint64_t taskId;
3250
  int8_t   action;
3251
} STaskAction;
3252

3253
typedef struct SQueryNodeEpId {
3254
  int32_t nodeId;  // vgId or qnodeId
3255
  SEp     ep;
3256
} SQueryNodeEpId;
3257

3258
typedef struct {
3259
  SMsgHead       header;
3260
  uint64_t       clientId;
3261
  SQueryNodeEpId epId;
3262
  SArray*        taskAction;  // SArray<STaskAction>
3263
} SSchedulerHbReq;
3264

3265
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3266
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3267
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3268

3269
typedef struct {
3270
  SQueryNodeEpId epId;
3271
  SArray*        taskStatus;  // SArray<STaskStatus>
3272
} SSchedulerHbRsp;
3273

3274
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3275
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3276
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3277

3278
typedef struct {
3279
  SMsgHead header;
3280
  uint64_t sId;
3281
  uint64_t queryId;
3282
  uint64_t clientId;
3283
  uint64_t taskId;
3284
  int64_t  refId;
3285
  int32_t  execId;
3286
} STaskCancelReq;
3287

3288
typedef struct {
3289
  int32_t code;
3290
} STaskCancelRsp;
3291

3292
typedef struct {
3293
  SMsgHead header;
3294
  uint64_t sId;
3295
  uint64_t queryId;
3296
  uint64_t clientId;
3297
  uint64_t taskId;
3298
  int64_t  refId;
3299
  int32_t  execId;
3300
} STaskDropReq;
3301

3302
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3303
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3304

3305
typedef enum {
3306
  TASK_NOTIFY_FINISHED = 1,
3307
} ETaskNotifyType;
3308

3309
typedef struct {
3310
  SMsgHead        header;
3311
  uint64_t        sId;
3312
  uint64_t        queryId;
3313
  uint64_t        clientId;
3314
  uint64_t        taskId;
3315
  int64_t         refId;
3316
  int32_t         execId;
3317
  ETaskNotifyType type;
3318
} STaskNotifyReq;
3319

3320
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3321
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3322

3323
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3324
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3325

3326
typedef struct {
3327
  int32_t code;
3328
} STaskDropRsp;
3329

3330
#define STREAM_TRIGGER_AT_ONCE                 1
3331
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3332
#define STREAM_TRIGGER_MAX_DELAY               3
3333
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3334
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3335

3336
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3337
#define STREAM_FILL_HISTORY_ON        1
3338
#define STREAM_FILL_HISTORY_OFF       0
3339
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3340
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3341
#define STREAM_CREATE_STABLE_TRUE     1
3342
#define STREAM_CREATE_STABLE_FALSE    0
3343

3344
typedef struct SColLocation {
3345
  int16_t  slotId;
3346
  col_id_t colId;
3347
  int8_t   type;
3348
} SColLocation;
3349

3350
typedef struct SVgroupVer {
3351
  int32_t vgId;
3352
  int64_t ver;
3353
} SVgroupVer;
3354

3355
typedef struct {
3356
  char    name[TSDB_STREAM_FNAME_LEN];
3357
  char    sourceDB[TSDB_DB_FNAME_LEN];
3358
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3359
  char*   sql;
3360
  char*   ast;
3361
  int8_t  igExists;
3362
  int8_t  triggerType;
3363
  int8_t  igExpired;
3364
  int8_t  fillHistory;  // process data inserted before creating stream
3365
  int64_t maxDelay;
3366
  int64_t watermark;
3367
  int32_t numOfTags;
3368
  SArray* pTags;  // array of SField
3369
  // 3.0.20
3370
  int64_t checkpointFreq;  // ms
3371
  // 3.0.2.3
3372
  int8_t   createStb;
3373
  uint64_t targetStbUid;
3374
  SArray*  fillNullCols;  // array of SColLocation
3375
  int64_t  deleteMark;
3376
  int8_t   igUpdate;
3377
  int64_t  lastTs;
3378
  SArray*  pVgroupVerList;
3379
  // 3.3.0.0
3380
  SArray* pCols;  // array of SField
3381
  int64_t smaId;
3382
  // 3.3.6.0
3383
  SArray* pNotifyAddrUrls;
3384
  int32_t notifyEventTypes;
3385
  int32_t notifyErrorHandle;
3386
  int8_t  notifyHistory;
3387
  int64_t recalculateInterval;
3388
  char    pWstartName[TSDB_COL_NAME_LEN];
3389
  char    pWendName[TSDB_COL_NAME_LEN];
3390
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3391
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3392
  SArray* pVSubTables;  // array of SVSubTablesRsp
3393
} SCMCreateStreamReq;
3394

3395
typedef struct STaskNotifyEventStat {
3396
  int64_t notifyEventAddTimes;     // call times of add function
3397
  int64_t notifyEventAddElems;     // elements added by add function
3398
  double  notifyEventAddCostSec;   // time cost of add function
3399
  int64_t notifyEventPushTimes;    // call times of push function
3400
  int64_t notifyEventPushElems;    // elements pushed by push function
3401
  double  notifyEventPushCostSec;  // time cost of push function
3402
  int64_t notifyEventPackTimes;    // call times of pack function
3403
  int64_t notifyEventPackElems;    // elements packed by pack function
3404
  double  notifyEventPackCostSec;  // time cost of pack function
3405
  int64_t notifyEventSendTimes;    // call times of send function
3406
  int64_t notifyEventSendElems;    // elements sent by send function
3407
  double  notifyEventSendCostSec;  // time cost of send function
3408
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3409
} STaskNotifyEventStat;
3410

3411
typedef struct {
3412
  int64_t streamId;
3413
} SCMCreateStreamRsp;
3414

3415
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3416
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3417
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3418

3419
enum {
3420
  TOPIC_SUB_TYPE__DB = 1,
3421
  TOPIC_SUB_TYPE__TABLE,
3422
  TOPIC_SUB_TYPE__COLUMN,
3423
};
3424

3425
#define DEFAULT_MAX_POLL_INTERVAL  300000
3426
#define DEFAULT_SESSION_TIMEOUT    12000
3427
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3428
#define DEFAULT_MIN_POLL_ROWS      4096
3429

3430
typedef struct {
3431
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3432
  int8_t igExists;
3433
  int8_t subType;
3434
  int8_t withMeta;
3435
  char*  sql;
3436
  char   subDbName[TSDB_DB_FNAME_LEN];
3437
  char*  ast;
3438
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3439
} SCMCreateTopicReq;
3440

3441
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3442
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3443
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3444

3445
typedef struct {
3446
  int64_t consumerId;
3447
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3448

3449
typedef struct {
3450
  int64_t consumerId;
3451
  char    cgroup[TSDB_CGROUP_LEN];
3452
  char    clientId[TSDB_CLIENT_ID_LEN];
3453
  char    user[TSDB_USER_LEN];
3454
  char    fqdn[TSDB_FQDN_LEN];
3455
  SArray* topicNames;  // SArray<char**>
3456

3457
  int8_t  withTbName;
3458
  int8_t  autoCommit;
3459
  int32_t autoCommitInterval;
3460
  int8_t  resetOffsetCfg;
3461
  int8_t  enableReplay;
3462
  int8_t  enableBatchMeta;
3463
  int32_t sessionTimeoutMs;
3464
  int32_t maxPollIntervalMs;
3465
} SCMSubscribeReq;
3466

3467
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3468
  int32_t tlen = 0;
2,460✔
3469
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,460!
3470
  tlen += taosEncodeString(buf, pReq->cgroup);
2,460✔
3471
  tlen += taosEncodeString(buf, pReq->clientId);
2,460✔
3472

3473
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,460!
3474
  tlen += taosEncodeFixedI32(buf, topicNum);
2,460✔
3475

3476
  for (int32_t i = 0; i < topicNum; i++) {
3,488✔
3477
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,056✔
3478
  }
3479

3480
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,460!
3481
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,460!
3482
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,460!
3483
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,460!
3484
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,460!
3485
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,460!
3486
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,460!
3487
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,460!
3488
  tlen += taosEncodeString(buf, pReq->user);
2,460✔
3489
  tlen += taosEncodeString(buf, pReq->fqdn);
2,460✔
3490

3491
  return tlen;
2,460✔
3492
}
3493

3494
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3495
  void* start = buf;
1,346✔
3496
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,346!
3497
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,346✔
3498
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,346✔
3499

3500
  int32_t topicNum = 0;
1,346!
3501
  buf = taosDecodeFixedI32(buf, &topicNum);
1,346✔
3502

3503
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,346✔
3504
  if (pReq->topicNames == NULL) {
1,346!
3505
    return terrno;
×
3506
  }
3507
  for (int32_t i = 0; i < topicNum; i++) {
1,970✔
3508
    char* name = NULL;
624✔
3509
    buf = taosDecodeString(buf, &name);
624✔
3510
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,248!
3511
      return terrno;
×
3512
    }
3513
  }
3514

3515
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,346✔
3516
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,346✔
3517
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,346!
3518
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,346✔
3519
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,346✔
3520
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,346✔
3521
  if ((char*)buf - (char*)start < len) {
1,346!
3522
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,346!
3523
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,346!
3524
    buf = taosDecodeStringTo(buf, pReq->user);
1,346✔
3525
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,692✔
3526
  } else {
3527
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3528
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3529
  }
3530

3531
  return 0;
1,346✔
3532
}
3533

3534
typedef struct {
3535
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3536
  SArray* removedConsumers;  // SArray<int64_t>
3537
  SArray* newConsumers;      // SArray<int64_t>
3538
} SMqRebInfo;
3539

3540
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3541
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,320!
3542
  if (pRebInfo == NULL) {
1,320!
3543
    return NULL;
×
3544
  }
3545
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,320✔
3546
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3547
  if (pRebInfo->removedConsumers == NULL) {
1,320!
3548
    goto _err;
×
3549
  }
3550
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3551
  if (pRebInfo->newConsumers == NULL) {
1,320!
3552
    goto _err;
×
3553
  }
3554
  return pRebInfo;
1,320✔
3555
_err:
×
3556
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3557
  taosArrayDestroy(pRebInfo->newConsumers);
×
3558
  taosMemoryFreeClear(pRebInfo);
×
3559
  return NULL;
×
3560
}
3561

3562
typedef struct {
3563
  int64_t streamId;
3564
  int64_t checkpointId;
3565
  char    streamName[TSDB_STREAM_FNAME_LEN];
3566
} SMStreamDoCheckpointMsg;
3567

3568
typedef struct {
3569
  int64_t status;
3570
} SMVSubscribeRsp;
3571

3572
typedef struct {
3573
  char    name[TSDB_TOPIC_FNAME_LEN];
3574
  int8_t  igNotExists;
3575
  int32_t sqlLen;
3576
  char*   sql;
3577
  int8_t  force;
3578
} SMDropTopicReq;
3579

3580
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3581
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3582
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3583

3584
typedef struct {
3585
  char   topic[TSDB_TOPIC_FNAME_LEN];
3586
  char   cgroup[TSDB_CGROUP_LEN];
3587
  int8_t igNotExists;
3588
  int8_t force;
3589
} SMDropCgroupReq;
3590

3591
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3592
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3593

3594
typedef struct {
3595
  int8_t reserved;
3596
} SMDropCgroupRsp;
3597

3598
typedef struct {
3599
  char    name[TSDB_TABLE_FNAME_LEN];
3600
  int8_t  alterType;
3601
  SSchema schema;
3602
} SAlterTopicReq;
3603

3604
typedef struct {
3605
  SMsgHead head;
3606
  char     name[TSDB_TABLE_FNAME_LEN];
3607
  int64_t  tuid;
3608
  int32_t  sverson;
3609
  int32_t  execLen;
3610
  char*    executor;
3611
  int32_t  sqlLen;
3612
  char*    sql;
3613
} SDCreateTopicReq;
3614

3615
typedef struct {
3616
  SMsgHead head;
3617
  char     name[TSDB_TABLE_FNAME_LEN];
3618
  int64_t  tuid;
3619
} SDDropTopicReq;
3620

3621
typedef struct {
3622
  int64_t maxdelay[2];
3623
  int64_t watermark[2];
3624
  int64_t deleteMark[2];
3625
  int32_t qmsgLen[2];
3626
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3627
} SRSmaParam;
3628

3629
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3630
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3631

3632
// TDMT_VND_CREATE_STB ==============
3633
typedef struct SVCreateStbReq {
3634
  char*           name;
3635
  tb_uid_t        suid;
3636
  int8_t          rollup;
3637
  SSchemaWrapper  schemaRow;
3638
  SSchemaWrapper  schemaTag;
3639
  SRSmaParam      rsmaParam;
3640
  int32_t         alterOriDataLen;
3641
  void*           alterOriData;
3642
  int8_t          source;
3643
  int8_t          colCmpred;
3644
  SColCmprWrapper colCmpr;
3645
  int64_t         keep;
3646
  SExtSchema*     pExtSchemas;
3647
  int8_t          virtualStb;
3648
} SVCreateStbReq;
3649

3650
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3651
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3652

3653
// TDMT_VND_DROP_STB ==============
3654
typedef struct SVDropStbReq {
3655
  char*    name;
3656
  tb_uid_t suid;
3657
} SVDropStbReq;
3658

3659
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3660
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3661

3662
// TDMT_VND_CREATE_TABLE ==============
3663
#define TD_CREATE_IF_NOT_EXISTS 0x1
3664
typedef struct SVCreateTbReq {
3665
  int32_t  flags;
3666
  char*    name;
3667
  tb_uid_t uid;
3668
  int64_t  btime;
3669
  int32_t  ttl;
3670
  int32_t  commentLen;
3671
  char*    comment;
3672
  int8_t   type;
3673
  union {
3674
    struct {
3675
      char*    stbName;  // super table name
3676
      uint8_t  tagNum;
3677
      tb_uid_t suid;
3678
      SArray*  tagName;
3679
      uint8_t* pTag;
3680
    } ctb;
3681
    struct {
3682
      SSchemaWrapper schemaRow;
3683
    } ntb;
3684
  };
3685
  int32_t         sqlLen;
3686
  char*           sql;
3687
  SColCmprWrapper colCmpr;
3688
  SExtSchema*     pExtSchemas;
3689
  SColRefWrapper  colRef;  // col reference for virtual table
3690
} SVCreateTbReq;
3691

3692
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3693
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3694
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3695

3696
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
2,463✔
3697
  if (NULL == req) {
6,091,787!
3698
    return;
5,840,705✔
3699
  }
3700

3701
  taosMemoryFreeClear(req->sql);
251,082!
3702
  taosMemoryFreeClear(req->name);
251,082!
3703
  taosMemoryFreeClear(req->comment);
251,129!
3704
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
251,129!
3705
    taosMemoryFreeClear(req->ctb.pTag);
237,033!
3706
    taosMemoryFreeClear(req->ctb.stbName);
237,105!
3707
    taosArrayDestroy(req->ctb.tagName);
237,102✔
3708
    req->ctb.tagName = NULL;
237,033✔
3709
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,096!
3710
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,096!
3711
  }
3712
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
251,129!
3713
  taosMemoryFreeClear(req->pExtSchemas);
251,129!
3714
  taosMemoryFreeClear(req->colRef.pColRef);
251,129!
3715
}
3716

3717
typedef struct {
3718
  int32_t nReqs;
3719
  union {
3720
    SVCreateTbReq* pReqs;
3721
    SArray*        pArray;
3722
  };
3723
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3724
} SVCreateTbBatchReq;
3725

3726
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3727
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3728
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3729

3730
typedef struct {
3731
  int32_t        code;
3732
  STableMetaRsp* pMeta;
3733
} SVCreateTbRsp, SVUpdateTbRsp;
3734

3735
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3736
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3737
void tFreeSVCreateTbRsp(void* param);
3738

3739
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3740
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3741

3742
typedef struct {
3743
  int32_t nRsps;
3744
  union {
3745
    SVCreateTbRsp* pRsps;
3746
    SArray*        pArray;
3747
  };
3748
} SVCreateTbBatchRsp;
3749

3750
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3751
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3752

3753
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3754
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3755

3756
// TDMT_VND_DROP_TABLE =================
3757
typedef struct {
3758
  char*    name;
3759
  uint64_t suid;  // for tmq in wal format
3760
  int64_t  uid;
3761
  int8_t   igNotExists;
3762
  int8_t   isVirtual;
3763
} SVDropTbReq;
3764

3765
typedef struct {
3766
  int32_t code;
3767
} SVDropTbRsp;
3768

3769
typedef struct {
3770
  int32_t nReqs;
3771
  union {
3772
    SVDropTbReq* pReqs;
3773
    SArray*      pArray;
3774
  };
3775
} SVDropTbBatchReq;
3776

3777
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3778
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3779

3780
typedef struct {
3781
  int32_t nRsps;
3782
  union {
3783
    SVDropTbRsp* pRsps;
3784
    SArray*      pArray;
3785
  };
3786
} SVDropTbBatchRsp;
3787

3788
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3789
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3790

3791
// TDMT_VND_ALTER_TABLE =====================
3792
typedef struct SMultiTagUpateVal {
3793
  char*    tagName;
3794
  int32_t  colId;
3795
  int8_t   tagType;
3796
  int8_t   tagFree;
3797
  uint32_t nTagVal;
3798
  uint8_t* pTagVal;
3799
  int8_t   isNull;
3800
  SArray*  pTagArray;
3801
} SMultiTagUpateVal;
3802
typedef struct SVAlterTbReq {
3803
  char*   tbName;
3804
  int8_t  action;
3805
  char*   colName;
3806
  int32_t colId;
3807
  // TSDB_ALTER_TABLE_ADD_COLUMN
3808
  int8_t  type;
3809
  int8_t  flags;
3810
  int32_t bytes;
3811
  // TSDB_ALTER_TABLE_DROP_COLUMN
3812
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3813
  int8_t   colModType;
3814
  int32_t  colModBytes;
3815
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3816
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3817
  int8_t   isNull;
3818
  int8_t   tagType;
3819
  int8_t   tagFree;
3820
  uint32_t nTagVal;
3821
  uint8_t* pTagVal;
3822
  SArray*  pTagArray;
3823
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3824
  int8_t   updateTTL;
3825
  int32_t  newTTL;
3826
  int32_t  newCommentLen;
3827
  char*    newComment;
3828
  int64_t  ctimeMs;    // fill by vnode
3829
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3830
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3831
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3832
  // for Add column
3833
  STypeMod typeMod;
3834
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3835
  char* refDbName;
3836
  char* refTbName;
3837
  char* refColName;
3838
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3839
} SVAlterTbReq;
3840

3841
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3842
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3843
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3844
void    tfreeMultiTagUpateVal(void* pMultiTag);
3845

3846
typedef struct {
3847
  int32_t        code;
3848
  STableMetaRsp* pMeta;
3849
} SVAlterTbRsp;
3850

3851
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3852
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3853
// ======================
3854

3855
typedef struct {
3856
  SMsgHead head;
3857
  int64_t  uid;
3858
  int32_t  tid;
3859
  int16_t  tversion;
3860
  int16_t  colId;
3861
  int8_t   type;
3862
  int16_t  bytes;
3863
  int32_t  tagValLen;
3864
  int16_t  numOfTags;
3865
  int32_t  schemaLen;
3866
  char     data[];
3867
} SUpdateTagValReq;
3868

3869
typedef struct {
3870
  SMsgHead head;
3871
} SUpdateTagValRsp;
3872

3873
typedef struct {
3874
  SMsgHead head;
3875
} SVShowTablesReq;
3876

3877
typedef struct {
3878
  SMsgHead head;
3879
  int32_t  id;
3880
} SVShowTablesFetchReq;
3881

3882
typedef struct {
3883
  int64_t useconds;
3884
  int8_t  completed;  // all results are returned to client
3885
  int8_t  precision;
3886
  int8_t  compressed;
3887
  int32_t compLen;
3888
  int32_t numOfRows;
3889
  char    data[];
3890
} SVShowTablesFetchRsp;
3891

3892
typedef struct {
3893
  int64_t consumerId;
3894
  int32_t epoch;
3895
  char    cgroup[TSDB_CGROUP_LEN];
3896
} SMqAskEpReq;
3897

3898
typedef struct {
3899
  int32_t key;
3900
  int32_t valueLen;
3901
  void*   value;
3902
} SKv;
3903

3904
typedef struct {
3905
  int64_t tscRid;
3906
  int8_t  connType;
3907
} SClientHbKey;
3908

3909
typedef struct {
3910
  int64_t tid;
3911
  char    status[TSDB_JOB_STATUS_LEN];
3912
} SQuerySubDesc;
3913

3914
typedef struct {
3915
  char     sql[TSDB_SHOW_SQL_LEN];
3916
  uint64_t queryId;
3917
  int64_t  useconds;
3918
  int64_t  stime;  // timestamp precision ms
3919
  int64_t  reqRid;
3920
  bool     stableQuery;
3921
  bool     isSubQuery;
3922
  char     fqdn[TSDB_FQDN_LEN];
3923
  int32_t  subPlanNum;
3924
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3925
} SQueryDesc;
3926

3927
typedef struct {
3928
  uint32_t connId;
3929
  SArray*  queryDesc;  // SArray<SQueryDesc>
3930
} SQueryHbReqBasic;
3931

3932
typedef struct {
3933
  uint32_t connId;
3934
  uint64_t killRid;
3935
  int32_t  totalDnodes;
3936
  int32_t  onlineDnodes;
3937
  int8_t   killConnection;
3938
  int8_t   align[3];
3939
  SEpSet   epSet;
3940
  SArray*  pQnodeList;
3941
} SQueryHbRspBasic;
3942

3943
typedef struct SAppClusterSummary {
3944
  uint64_t numOfInsertsReq;
3945
  uint64_t numOfInsertRows;
3946
  uint64_t insertElapsedTime;
3947
  uint64_t insertBytes;  // submit to tsdb since launched.
3948

3949
  uint64_t fetchBytes;
3950
  uint64_t numOfQueryReq;
3951
  uint64_t queryElapsedTime;
3952
  uint64_t numOfSlowQueries;
3953
  uint64_t totalRequests;
3954
  uint64_t currentRequests;  // the number of SRequestObj
3955
} SAppClusterSummary;
3956

3957
typedef struct {
3958
  int64_t            appId;
3959
  int32_t            pid;
3960
  char               name[TSDB_APP_NAME_LEN];
3961
  int64_t            startTime;
3962
  SAppClusterSummary summary;
3963
} SAppHbReq;
3964

3965
typedef struct {
3966
  SClientHbKey      connKey;
3967
  int64_t           clusterId;
3968
  SAppHbReq         app;
3969
  SQueryHbReqBasic* query;
3970
  SHashObj*         info;  // hash<Skv.key, Skv>
3971
  char              userApp[TSDB_APP_NAME_LEN];
3972
  uint32_t          userIp;
3973
  SIpRange          userDualIp;
3974
} SClientHbReq;
3975

3976
typedef struct {
3977
  int64_t reqId;
3978
  SArray* reqs;  // SArray<SClientHbReq>
3979
  int64_t ipWhiteListVer;
3980
} SClientHbBatchReq;
3981

3982
typedef struct {
3983
  SClientHbKey      connKey;
3984
  int32_t           status;
3985
  SQueryHbRspBasic* query;
3986
  SArray*           info;  // Array<Skv>
3987
} SClientHbRsp;
3988

3989
typedef struct {
3990
  int64_t       reqId;
3991
  int64_t       rspId;
3992
  int32_t       svrTimestamp;
3993
  SArray*       rsps;  // SArray<SClientHbRsp>
3994
  SMonitorParas monitorParas;
3995
  int8_t        enableAuditDelete;
3996
  int8_t        enableStrongPass;
3997
} SClientHbBatchRsp;
3998

3999
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
227,863✔
4000

4001
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4002
  void* pIter = taosHashIterate(info, NULL);
122,664✔
4003
  while (pIter != NULL) {
244,155!
4004
    SKv* kv = (SKv*)pIter;
121,491✔
4005
    taosMemoryFreeClear(kv->value);
121,491!
4006
    pIter = taosHashIterate(info, pIter);
121,491✔
4007
  }
4008
}
122,664✔
4009

4010
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
65,507✔
4011
  SQueryDesc* desc = (SQueryDesc*)pDesc;
65,507✔
4012
  if (desc->subDesc) {
65,507✔
4013
    taosArrayDestroy(desc->subDesc);
57,299✔
4014
    desc->subDesc = NULL;
57,299✔
4015
  }
4016
}
65,507✔
4017

4018
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
168,883✔
4019
  SClientHbReq* req = (SClientHbReq*)pReq;
193,952✔
4020
  if (req->query) {
193,952!
4021
    if (req->query->queryDesc) {
156,177!
4022
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
44,963✔
4023
    }
4024
    taosMemoryFreeClear(req->query);
156,177!
4025
  }
4026

4027
  if (req->info) {
193,952!
4028
    tFreeReqKvHash(req->info);
122,664✔
4029
    taosHashCleanup(req->info);
122,664✔
4030
    req->info = NULL;
122,664✔
4031
  }
4032
}
106,781✔
4033

4034
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4035
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4036

4037
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4038
  if (pReq == NULL) return;
52,229!
4039
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
52,229✔
4040
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
52,229✔
4041
  taosMemoryFree(pReq);
52,229!
4042
}
4043

4044
static FORCE_INLINE void tFreeClientKv(void* pKv) {
45,977✔
4045
  SKv* kv = (SKv*)pKv;
45,977✔
4046
  if (kv) {
45,977!
4047
    taosMemoryFreeClear(kv->value);
45,977!
4048
  }
4049
}
45,977✔
4050

4051
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
165,118✔
4052
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
165,118✔
4053
  if (rsp->query) {
165,118✔
4054
    taosArrayDestroy(rsp->query->pQnodeList);
152,475✔
4055
    taosMemoryFreeClear(rsp->query);
152,475!
4056
  }
4057
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
165,118!
4058
}
83,408✔
4059

4060
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4061
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
100,077✔
4062
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
100,077✔
4063
}
100,077✔
4064

4065
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4066
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4067
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4068

4069
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4070
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
342,424!
4071
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
342,424!
4072
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
342,424!
4073
  return 0;
171,212✔
4074
}
4075

4076
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4077
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
163,680!
4078
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
163,680!
4079
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
81,840!
4080
  if (pKv->value == NULL) {
81,841!
4081
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4082
  }
4083
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
81,841!
4084
  return 0;
81,840✔
4085
}
4086

4087
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4088
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
675,332!
4089
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
675,332!
4090
  return 0;
337,666✔
4091
}
4092

4093
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4094
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
330,143!
4095
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
330,145!
4096
  return 0;
165,073✔
4097
}
4098

4099
typedef struct {
4100
  int32_t vgId;
4101
  // TODO stas
4102
} SMqReportVgInfo;
4103

4104
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4105
  int32_t tlen = 0;
4106
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4107
  return tlen;
4108
}
4109

4110
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4111
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4112
  return buf;
4113
}
4114

4115
typedef struct {
4116
  int32_t epoch;
4117
  int64_t topicUid;
4118
  char    name[TSDB_TOPIC_FNAME_LEN];
4119
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4120
} SMqTopicInfo;
4121

4122
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4123
  int32_t tlen = 0;
4124
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4125
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4126
  tlen += taosEncodeString(buf, pTopicInfo->name);
4127
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4128
  tlen += taosEncodeFixedI32(buf, sz);
4129
  for (int32_t i = 0; i < sz; i++) {
4130
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4131
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4132
  }
4133
  return tlen;
4134
}
4135

4136
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4137
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4138
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4139
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4140
  int32_t sz;
4141
  buf = taosDecodeFixedI32(buf, &sz);
4142
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4143
    return NULL;
4144
  }
4145
  for (int32_t i = 0; i < sz; i++) {
4146
    SMqReportVgInfo vgInfo;
4147
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4148
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4149
      return NULL;
4150
    }
4151
  }
4152
  return buf;
4153
}
4154

4155
typedef struct {
4156
  int32_t status;  // ask hb endpoint
4157
  int32_t epoch;
4158
  int64_t consumerId;
4159
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4160
} SMqReportReq;
4161

4162
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4163
  int32_t tlen = 0;
4164
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4165
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4166
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4167
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4168
  tlen += taosEncodeFixedI32(buf, sz);
4169
  for (int32_t i = 0; i < sz; i++) {
4170
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4171
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4172
  }
4173
  return tlen;
4174
}
4175

4176
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4177
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4178
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4179
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4180
  int32_t sz;
4181
  buf = taosDecodeFixedI32(buf, &sz);
4182
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4183
    return NULL;
4184
  }
4185
  for (int32_t i = 0; i < sz; i++) {
4186
    SMqTopicInfo topicInfo;
4187
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4188
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4189
      return NULL;
4190
    }
4191
  }
4192
  return buf;
4193
}
4194

4195
typedef struct {
4196
  SMsgHead head;
4197
  int64_t  leftForVer;
4198
  int32_t  vgId;
4199
  int64_t  consumerId;
4200
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4201
} SMqVDeleteReq;
4202

4203
typedef struct {
4204
  int8_t reserved;
4205
} SMqVDeleteRsp;
4206

4207
typedef struct {
4208
  char    name[TSDB_STREAM_FNAME_LEN];
4209
  int8_t  igNotExists;
4210
  int32_t sqlLen;
4211
  char*   sql;
4212
} SMDropStreamReq;
4213

4214
typedef struct {
4215
  int8_t reserved;
4216
} SMDropStreamRsp;
4217

4218
typedef struct {
4219
  SMsgHead head;
4220
  int64_t  resetRelHalt;  // reset related stream task halt status
4221
  int64_t  streamId;
4222
  int32_t  taskId;
4223
} SVDropStreamTaskReq;
4224

4225
typedef struct {
4226
  int8_t reserved;
4227
} SVDropStreamTaskRsp;
4228

4229
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4230
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4231
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4232

4233
typedef struct SVUpdateCheckpointInfoReq {
4234
  SMsgHead head;
4235
  int64_t  streamId;
4236
  int32_t  taskId;
4237
  int64_t  checkpointId;
4238
  int64_t  checkpointVer;
4239
  int64_t  checkpointTs;
4240
  int32_t  transId;
4241
  int64_t  hStreamId;  // add encode/decode
4242
  int64_t  hTaskId;
4243
  int8_t   dropRelHTask;
4244
} SVUpdateCheckpointInfoReq;
4245

4246
typedef struct {
4247
  int64_t leftForVer;
4248
  int32_t vgId;
4249
  int64_t oldConsumerId;
4250
  int64_t newConsumerId;
4251
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4252
  int8_t  subType;
4253
  int8_t  withMeta;
4254
  char*   qmsg;  // SubPlanToString
4255
  int64_t suid;
4256
} SMqRebVgReq;
4257

4258
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4259
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4260

4261
typedef struct {
4262
  char    topic[TSDB_TOPIC_FNAME_LEN];
4263
  int64_t ntbUid;
4264
  SArray* colIdList;  // SArray<int16_t>
4265
} STqCheckInfo;
4266

4267
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4268
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4269
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4270

4271
// tqOffset
4272
enum {
4273
  TMQ_OFFSET__RESET_NONE = -3,
4274
  TMQ_OFFSET__RESET_EARLIEST = -2,
4275
  TMQ_OFFSET__RESET_LATEST = -1,
4276
  TMQ_OFFSET__LOG = 1,
4277
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4278
  TMQ_OFFSET__SNAPSHOT_META = 3,
4279
};
4280

4281
enum {
4282
  WITH_DATA = 0,
4283
  WITH_META = 1,
4284
  ONLY_META = 2,
4285
};
4286

4287
#define TQ_OFFSET_VERSION 1
4288

4289
typedef struct {
4290
  int8_t type;
4291
  union {
4292
    // snapshot
4293
    struct {
4294
      int64_t uid;
4295
      int64_t ts;
4296
      SValue  primaryKey;
4297
    };
4298
    // log
4299
    struct {
4300
      int64_t version;
4301
    };
4302
  };
4303
} STqOffsetVal;
4304

4305
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4306
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,380✔
4307
  pOffsetVal->uid = uid;
26,380✔
4308
  pOffsetVal->ts = ts;
26,380✔
4309
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,380!
4310
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4311
  }
4312
  pOffsetVal->primaryKey = primaryKey;
26,385✔
4313
}
26,385✔
4314

4315
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4316
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
4317
  pOffsetVal->uid = uid;
148✔
4318
}
148✔
4319

4320
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4321
  pOffsetVal->type = TMQ_OFFSET__LOG;
551,464✔
4322
  pOffsetVal->version = ver;
551,464✔
4323
}
551,464✔
4324

4325
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4326
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4327
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4328
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4329
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4330
void    tOffsetDestroy(void* pVal);
4331

4332
typedef struct {
4333
  STqOffsetVal val;
4334
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4335
} STqOffset;
4336

4337
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4338
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4339
void    tDeleteSTqOffset(void* val);
4340

4341
typedef struct SMqVgOffset {
4342
  int64_t   consumerId;
4343
  STqOffset offset;
4344
} SMqVgOffset;
4345

4346
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4347
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4348

4349
typedef struct {
4350
  SMsgHead head;
4351
  int64_t  streamId;
4352
  int32_t  taskId;
4353
} SVPauseStreamTaskReq;
4354

4355
typedef struct {
4356
  SMsgHead head;
4357
  int64_t  streamId;
4358
  int32_t  taskId;
4359
  int64_t  chkptId;
4360
} SVResetStreamTaskReq;
4361

4362
typedef struct {
4363
  char   name[TSDB_STREAM_FNAME_LEN];
4364
  int8_t igNotExists;
4365
} SMPauseStreamReq;
4366

4367
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4368
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4369

4370
typedef struct {
4371
  SMsgHead head;
4372
  int32_t  taskId;
4373
  int64_t  streamId;
4374
  int8_t   igUntreated;
4375
} SVResumeStreamTaskReq;
4376

4377
typedef struct {
4378
  int8_t reserved;
4379
} SVResumeStreamTaskRsp;
4380

4381
typedef struct {
4382
  char   name[TSDB_STREAM_FNAME_LEN];
4383
  int8_t igNotExists;
4384
  int8_t igUntreated;
4385
} SMResumeStreamReq;
4386

4387
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4388
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4389

4390
typedef struct {
4391
  char   name[TSDB_STREAM_FNAME_LEN];
4392
  int8_t igNotExists;
4393
  int8_t igUntreated;
4394
} SMResetStreamReq;
4395

4396
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4397
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4398

4399
typedef struct {
4400
  char    name[TSDB_TABLE_FNAME_LEN];
4401
  char    stb[TSDB_TABLE_FNAME_LEN];
4402
  int8_t  igExists;
4403
  int8_t  intervalUnit;
4404
  int8_t  slidingUnit;
4405
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4406
  int32_t dstVgId;   // for stream
4407
  int64_t interval;
4408
  int64_t offset;
4409
  int64_t sliding;
4410
  int64_t maxDelay;
4411
  int64_t watermark;
4412
  int32_t exprLen;        // strlen + 1
4413
  int32_t tagsFilterLen;  // strlen + 1
4414
  int32_t sqlLen;         // strlen + 1
4415
  int32_t astLen;         // strlen + 1
4416
  char*   expr;
4417
  char*   tagsFilter;
4418
  char*   sql;
4419
  char*   ast;
4420
  int64_t deleteMark;
4421
  int64_t lastTs;
4422
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4423
  SArray* pVgroupVerList;
4424
  int8_t  recursiveTsma;
4425
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4426
} SMCreateSmaReq;
4427

4428
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4429
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4430
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4431

4432
typedef struct {
4433
  char   name[TSDB_TABLE_FNAME_LEN];
4434
  int8_t igNotExists;
4435
} SMDropSmaReq;
4436

4437
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4438
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4439

4440
typedef struct {
4441
  char   dbFName[TSDB_DB_FNAME_LEN];
4442
  char   stbName[TSDB_TABLE_NAME_LEN];
4443
  char   colName[TSDB_COL_NAME_LEN];
4444
  char   idxName[TSDB_INDEX_FNAME_LEN];
4445
  int8_t idxType;
4446
} SCreateTagIndexReq;
4447

4448
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4449
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4450

4451
typedef SMDropSmaReq SDropTagIndexReq;
4452

4453
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4454
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4455

4456
typedef struct {
4457
  int8_t         version;       // for compatibility(default 0)
4458
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4459
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4460
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4461
  int32_t        dstVgId;
4462
  char           indexName[TSDB_INDEX_NAME_LEN];
4463
  int32_t        exprLen;
4464
  int32_t        tagsFilterLen;
4465
  int64_t        indexUid;
4466
  tb_uid_t       tableUid;  // super/child/common table uid
4467
  tb_uid_t       dstTbUid;  // for dstVgroup
4468
  int64_t        interval;
4469
  int64_t        offset;  // use unit by precision of DB
4470
  int64_t        sliding;
4471
  char*          dstTbName;  // for dstVgroup
4472
  char*          expr;       // sma expression
4473
  char*          tagsFilter;
4474
  SSchemaWrapper schemaRow;  // for dstVgroup
4475
  SSchemaWrapper schemaTag;  // for dstVgroup
4476
} STSma;                     // Time-range-wise SMA
4477

4478
typedef STSma SVCreateTSmaReq;
4479

4480
typedef struct {
4481
  int8_t  type;  // 0 status report, 1 update data
4482
  int64_t indexUid;
4483
  int64_t skey;  // start TS key of interval/sliding window
4484
} STSmaMsg;
4485

4486
typedef struct {
4487
  int64_t indexUid;
4488
  char    indexName[TSDB_INDEX_NAME_LEN];
4489
} SVDropTSmaReq;
4490

4491
typedef struct {
4492
  int tmp;  // TODO: to avoid compile error
4493
} SVCreateTSmaRsp, SVDropTSmaRsp;
4494

4495
#if 0
4496
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4497
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4498
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4499
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4500
#endif
4501

4502
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4503
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4504
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4505
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4506

4507
typedef struct {
4508
  int32_t number;
4509
  STSma*  tSma;
4510
} STSmaWrapper;
4511

4512
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4513
  if (pSma) {
×
4514
    taosMemoryFreeClear(pSma->dstTbName);
×
4515
    taosMemoryFreeClear(pSma->expr);
×
4516
    taosMemoryFreeClear(pSma->tagsFilter);
×
4517
  }
4518
}
×
4519

4520
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4521
  if (pSW) {
×
4522
    if (pSW->tSma) {
×
4523
      if (deepCopy) {
×
4524
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4525
          tDestroyTSma(pSW->tSma + i);
×
4526
        }
4527
      }
4528
      taosMemoryFreeClear(pSW->tSma);
×
4529
    }
4530
  }
4531
}
×
4532

4533
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4534
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4535
  taosMemoryFreeClear(pSW);
×
4536
  return NULL;
×
4537
}
4538

4539
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4540
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4541

4542
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4543
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4544

4545
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4546
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4547
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4548
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4549
  }
4550
  return 0;
×
4551
}
4552

4553
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4554
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4555
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4556
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4557
  }
4558
  return 0;
×
4559
}
4560

4561
typedef struct {
4562
  int idx;
4563
} SMCreateFullTextReq;
4564

4565
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4566
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4567
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4568

4569
typedef struct {
4570
  char   name[TSDB_TABLE_FNAME_LEN];
4571
  int8_t igNotExists;
4572
} SMDropFullTextReq;
4573

4574
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4575
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4576

4577
typedef struct {
4578
  char indexFName[TSDB_INDEX_FNAME_LEN];
4579
} SUserIndexReq;
4580

4581
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4582
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4583

4584
typedef struct {
4585
  char dbFName[TSDB_DB_FNAME_LEN];
4586
  char tblFName[TSDB_TABLE_FNAME_LEN];
4587
  char colName[TSDB_COL_NAME_LEN];
4588
  char indexType[TSDB_INDEX_TYPE_LEN];
4589
  char indexExts[TSDB_INDEX_EXTS_LEN];
4590
} SUserIndexRsp;
4591

4592
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4593
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4594

4595
typedef struct {
4596
  char tbFName[TSDB_TABLE_FNAME_LEN];
4597
} STableIndexReq;
4598

4599
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4600
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4601

4602
typedef struct {
4603
  int8_t  intervalUnit;
4604
  int8_t  slidingUnit;
4605
  int64_t interval;
4606
  int64_t offset;
4607
  int64_t sliding;
4608
  int64_t dstTbUid;
4609
  int32_t dstVgId;
4610
  SEpSet  epSet;
4611
  char*   expr;
4612
} STableIndexInfo;
4613

4614
typedef struct {
4615
  char     tbName[TSDB_TABLE_NAME_LEN];
4616
  char     dbFName[TSDB_DB_FNAME_LEN];
4617
  uint64_t suid;
4618
  int32_t  version;
4619
  int32_t  indexSize;
4620
  SArray*  pIndex;  // STableIndexInfo
4621
} STableIndexRsp;
4622

4623
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4624
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4625
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4626

4627
void tFreeSTableIndexInfo(void* pInfo);
4628

4629
typedef struct {
4630
  int8_t  mqMsgType;
4631
  int32_t code;
4632
  int32_t epoch;
4633
  int64_t consumerId;
4634
  int64_t walsver;
4635
  int64_t walever;
4636
} SMqRspHead;
4637

4638
typedef struct {
4639
  SMsgHead     head;
4640
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4641
  int8_t       withTbName;
4642
  int8_t       useSnapshot;
4643
  int32_t      epoch;
4644
  uint64_t     reqId;
4645
  int64_t      consumerId;
4646
  int64_t      timeout;
4647
  STqOffsetVal reqOffset;
4648
  int8_t       enableReplay;
4649
  int8_t       sourceExcluded;
4650
  int8_t       rawData;
4651
  int32_t      minPollRows;
4652
  int8_t       enableBatchMeta;
4653
  SHashObj*    uidHash;  // to find if uid is duplicated
4654
} SMqPollReq;
4655

4656
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4657
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4658
void    tDestroySMqPollReq(SMqPollReq* pReq);
4659

4660
typedef struct {
4661
  int32_t vgId;
4662
  int64_t offset;
4663
  SEpSet  epSet;
4664
} SMqSubVgEp;
4665

4666
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4667
  int32_t tlen = 0;
8,734✔
4668
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,734✔
4669
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,734✔
4670
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,734✔
4671
  return tlen;
8,734✔
4672
}
4673

4674
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4675
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,168!
4676
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,168!
4677
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,168✔
4678
  return buf;
4,168✔
4679
}
4680

4681
typedef struct {
4682
  char           topic[TSDB_TOPIC_FNAME_LEN];
4683
  char           db[TSDB_DB_FNAME_LEN];
4684
  SArray*        vgs;  // SArray<SMqSubVgEp>
4685
  SSchemaWrapper schema;
4686
} SMqSubTopicEp;
4687

4688
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4689
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4690
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4691

4692
typedef struct {
4693
  SMqRspHead   head;
4694
  STqOffsetVal rspOffset;
4695
  int16_t      resMsgType;
4696
  int32_t      metaRspLen;
4697
  void*        metaRsp;
4698
} SMqMetaRsp;
4699

4700
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4701
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4702
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4703

4704
#define MQ_DATA_RSP_VERSION 100
4705

4706
typedef struct {
4707
  SMqRspHead   head;
4708
  STqOffsetVal rspOffset;
4709
  STqOffsetVal reqOffset;
4710
  int32_t      blockNum;
4711
  int8_t       withTbName;
4712
  int8_t       withSchema;
4713
  SArray*      blockDataLen;
4714
  SArray*      blockData;
4715
  SArray*      blockTbName;
4716
  SArray*      blockSchema;
4717

4718
  union {
4719
    struct {
4720
      int64_t sleepTime;
4721
    };
4722
    struct {
4723
      int32_t createTableNum;
4724
      SArray* createTableLen;
4725
      SArray* createTableReq;
4726
    };
4727
    struct {
4728
      int32_t len;
4729
      void*   rawData;
4730
    };
4731
  };
4732
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4733
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4734
} SMqDataRsp;
4735

4736
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4737
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4738
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4739
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4740
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4741

4742
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4743
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4744
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4745

4746
typedef struct SMqBatchMetaRsp {
4747
  SMqRspHead   head;  // not serialize
4748
  STqOffsetVal rspOffset;
4749
  SArray*      batchMetaLen;
4750
  SArray*      batchMetaReq;
4751
  void*        pMetaBuff;    // not serialize
4752
  uint32_t     metaBuffLen;  // not serialize
4753
} SMqBatchMetaRsp;
4754

4755
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4756
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4757
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4758
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4759

4760
typedef struct {
4761
  SMqRspHead head;
4762
  char       cgroup[TSDB_CGROUP_LEN];
4763
  SArray*    topics;  // SArray<SMqSubTopicEp>
4764
} SMqAskEpRsp;
4765

4766
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4767
  int32_t tlen = 0;
17,866✔
4768
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4769
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,866!
4770
  tlen += taosEncodeFixedI32(buf, sz);
17,867✔
4771
  for (int32_t i = 0; i < sz; i++) {
24,722✔
4772
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,854✔
4773
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,854✔
4774
  }
4775
  return tlen;
17,868✔
4776
}
4777

4778
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4779
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4780
  int32_t sz;
4781
  buf = taosDecodeFixedI32(buf, &sz);
8,128✔
4782
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,128✔
4783
  if (pRsp->topics == NULL) {
8,128!
4784
    return NULL;
×
4785
  }
4786
  for (int32_t i = 0; i < sz; i++) {
11,444✔
4787
    SMqSubTopicEp topicEp;
4788
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,316✔
4789
    if (buf == NULL) {
3,316!
4790
      return NULL;
×
4791
    }
4792
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,632!
4793
      return NULL;
×
4794
    }
4795
  }
4796
  return buf;
8,128✔
4797
}
4798

4799
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4800
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,108✔
4801
}
20,108✔
4802

4803
typedef struct {
4804
  int32_t      vgId;
4805
  STqOffsetVal offset;
4806
  int64_t      rows;
4807
  int64_t      ever;
4808
} OffsetRows;
4809

4810
typedef struct {
4811
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4812
  SArray* offsetRows;
4813
} TopicOffsetRows;
4814

4815
typedef struct {
4816
  int64_t consumerId;
4817
  int32_t epoch;
4818
  SArray* topics;
4819
  int8_t  pollFlag;
4820
} SMqHbReq;
4821

4822
typedef struct {
4823
  char   topic[TSDB_TOPIC_FNAME_LEN];
4824
  int8_t noPrivilege;
4825
} STopicPrivilege;
4826

4827
typedef struct {
4828
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4829
  int32_t debugFlag;
4830
} SMqHbRsp;
4831

4832
typedef struct {
4833
  SMsgHead head;
4834
  int64_t  consumerId;
4835
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4836
} SMqSeekReq;
4837

4838
#define TD_AUTO_CREATE_TABLE 0x1
4839
typedef struct {
4840
  int64_t       suid;
4841
  int64_t       uid;
4842
  int32_t       sver;
4843
  uint32_t      nData;
4844
  uint8_t*      pData;
4845
  SVCreateTbReq cTbReq;
4846
} SVSubmitBlk;
4847

4848
typedef struct {
4849
  SMsgHead header;
4850
  uint64_t sId;
4851
  uint64_t queryId;
4852
  uint64_t clientId;
4853
  uint64_t taskId;
4854
  uint32_t sqlLen;
4855
  uint32_t phyLen;
4856
  char*    sql;
4857
  char*    msg;
4858
  int8_t   source;
4859
} SVDeleteReq;
4860

4861
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4862
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4863

4864
typedef struct {
4865
  int64_t affectedRows;
4866
} SVDeleteRsp;
4867

4868
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4869
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4870

4871
typedef struct SDeleteRes {
4872
  uint64_t suid;
4873
  SArray*  uidList;
4874
  int64_t  skey;
4875
  int64_t  ekey;
4876
  int64_t  affectedRows;
4877
  char     tableFName[TSDB_TABLE_NAME_LEN];
4878
  char     tsColName[TSDB_COL_NAME_LEN];
4879
  int64_t  ctimeMs;  // fill by vnode
4880
  int8_t   source;
4881
} SDeleteRes;
4882

4883
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4884
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4885

4886
typedef struct {
4887
  // int64_t uid;
4888
  char    tbname[TSDB_TABLE_NAME_LEN];
4889
  int64_t startTs;
4890
  int64_t endTs;
4891
} SSingleDeleteReq;
4892

4893
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4894
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4895

4896
typedef struct {
4897
  int64_t suid;
4898
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4899
  int64_t ctimeMs;     // fill by vnode
4900
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4901
} SBatchDeleteReq;
4902

4903
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4904
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4905
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4906

4907
typedef struct {
4908
  int32_t msgIdx;
4909
  int32_t msgType;
4910
  int32_t msgLen;
4911
  void*   msg;
4912
} SBatchMsg;
4913

4914
typedef struct {
4915
  SMsgHead header;
4916
  SArray*  pMsgs;  // SArray<SBatchMsg>
4917
} SBatchReq;
4918

4919
typedef struct {
4920
  int32_t reqType;
4921
  int32_t msgIdx;
4922
  int32_t msgLen;
4923
  int32_t rspCode;
4924
  void*   msg;
4925
} SBatchRspMsg;
4926

4927
typedef struct {
4928
  SArray* pRsps;  // SArray<SBatchRspMsg>
4929
} SBatchRsp;
4930

4931
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4932
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4933
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
399,853✔
4934
  if (NULL == msg) {
399,853!
4935
    return;
×
4936
  }
4937
  SBatchMsg* pMsg = (SBatchMsg*)msg;
399,853✔
4938
  taosMemoryFree(pMsg->msg);
399,853!
4939
}
4940

4941
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4942
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4943

4944
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
526,097✔
4945
  if (NULL == p) {
526,097!
4946
    return;
×
4947
  }
4948

4949
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
526,097✔
4950
  taosMemoryFree(pRsp->msg);
526,097!
4951
}
4952

4953
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4954
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4955
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4956
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4957
void    tDestroySMqHbReq(SMqHbReq* pReq);
4958

4959
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4960
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4961
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4962

4963
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4964
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4965

4966
#define TD_REQ_FROM_APP               0x0
4967
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4968
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4969
#define SUBMIT_REQ_FROM_FILE          0x4
4970
#define TD_REQ_FROM_TAOX              0x8
4971
#define TD_REQ_FROM_SML               0x10
4972
#define SUBMIT_REQUEST_VERSION        (1)
4973

4974
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4975

4976
typedef struct {
4977
  int32_t        flags;
4978
  SVCreateTbReq* pCreateTbReq;
4979
  int64_t        suid;
4980
  int64_t        uid;
4981
  int32_t        sver;
4982
  union {
4983
    SArray* aRowP;
4984
    SArray* aCol;
4985
  };
4986
  int64_t ctimeMs;
4987
} SSubmitTbData;
4988

4989
typedef struct {
4990
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4991
  bool    raw;
4992
} SSubmitReq2;
4993

4994
typedef struct {
4995
  SMsgHead header;
4996
  int64_t  version;
4997
  char     data[];  // SSubmitReq2
4998
} SSubmitReq2Msg;
4999

5000
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5001
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5002
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5003
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5004
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5005

5006
typedef struct {
5007
  int32_t affectedRows;
5008
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5009
} SSubmitRsp2;
5010

5011
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5012
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5013
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5014

5015
#define TSDB_MSG_FLG_ENCODE 0x1
5016
#define TSDB_MSG_FLG_DECODE 0x2
5017
#define TSDB_MSG_FLG_CMPT   0x3
5018

5019
typedef struct {
5020
  union {
5021
    struct {
5022
      void*   msgStr;
5023
      int32_t msgLen;
5024
      int64_t ver;
5025
    };
5026
    void* pDataBlock;
5027
  };
5028
} SPackedData;
5029

5030
typedef struct {
5031
  char     fullname[TSDB_VIEW_FNAME_LEN];
5032
  char     name[TSDB_VIEW_NAME_LEN];
5033
  char     dbFName[TSDB_DB_FNAME_LEN];
5034
  char*    querySql;
5035
  char*    sql;
5036
  int8_t   orReplace;
5037
  int8_t   precision;
5038
  int32_t  numOfCols;
5039
  SSchema* pSchema;
5040
} SCMCreateViewReq;
5041

5042
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5043
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5044
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5045

5046
typedef struct {
5047
  char   fullname[TSDB_VIEW_FNAME_LEN];
5048
  char   name[TSDB_VIEW_NAME_LEN];
5049
  char   dbFName[TSDB_DB_FNAME_LEN];
5050
  char*  sql;
5051
  int8_t igNotExists;
5052
} SCMDropViewReq;
5053

5054
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5055
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5056
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5057

5058
typedef struct {
5059
  char fullname[TSDB_VIEW_FNAME_LEN];
5060
} SViewMetaReq;
5061
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5062
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5063

5064
typedef struct {
5065
  char     name[TSDB_VIEW_NAME_LEN];
5066
  char     dbFName[TSDB_DB_FNAME_LEN];
5067
  char*    user;
5068
  uint64_t dbId;
5069
  uint64_t viewId;
5070
  char*    querySql;
5071
  int8_t   precision;
5072
  int8_t   type;
5073
  int32_t  version;
5074
  int32_t  numOfCols;
5075
  SSchema* pSchema;
5076
} SViewMetaRsp;
5077
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5078
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5079
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5080
typedef struct {
5081
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5082
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5083
} STableTSMAInfoReq;
5084

5085
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5086
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5087

5088
typedef struct {
5089
  int32_t  funcId;
5090
  col_id_t colId;
5091
} STableTSMAFuncInfo;
5092

5093
typedef struct {
5094
  char     name[TSDB_TABLE_NAME_LEN];
5095
  uint64_t tsmaId;
5096
  char     targetTb[TSDB_TABLE_NAME_LEN];
5097
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5098
  char     tb[TSDB_TABLE_NAME_LEN];
5099
  char     dbFName[TSDB_DB_FNAME_LEN];
5100
  uint64_t suid;
5101
  uint64_t destTbUid;
5102
  uint64_t dbId;
5103
  int32_t  version;
5104
  int64_t  interval;
5105
  int8_t   unit;
5106
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5107
  SArray*  pTags;      // SArray<SSchema>
5108
  SArray*  pUsedCols;  // SArray<SSchema>
5109
  char*    ast;
5110

5111
  int64_t streamUid;
5112
  int64_t reqTs;
5113
  int64_t rspTs;
5114
  int64_t delayDuration;  // ms
5115
  bool    fillHistoryFinished;
5116
} STableTSMAInfo;
5117

5118
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5119
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5120
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5121
void    tFreeTableTSMAInfo(void* p);
5122
void    tFreeAndClearTableTSMAInfo(void* p);
5123
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5124

5125
#define STSMAHbRsp            STableTSMAInfoRsp
5126
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5127
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5128
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5129

5130
typedef struct SStreamProgressReq {
5131
  int64_t streamId;
5132
  int32_t vgId;
5133
  int32_t fetchIdx;
5134
  int32_t subFetchIdx;
5135
} SStreamProgressReq;
5136

5137
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
5138
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
5139

5140
typedef struct SStreamProgressRsp {
5141
  int64_t streamId;
5142
  int32_t vgId;
5143
  bool    fillHisFinished;
5144
  int64_t progressDelay;
5145
  int32_t fetchIdx;
5146
  int32_t subFetchIdx;
5147
} SStreamProgressRsp;
5148

5149
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
5150
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
5151

5152
typedef struct SDropCtbWithTsmaSingleVgReq {
5153
  SVgroupInfo vgInfo;
5154
  SArray*     pTbs;  // SVDropTbReq
5155
} SMDropTbReqsOnSingleVg;
5156

5157
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5158
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5159
void    tFreeSMDropTbReqOnSingleVg(void* p);
5160

5161
typedef struct SDropTbsReq {
5162
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5163
} SMDropTbsReq;
5164

5165
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5166
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5167
void    tFreeSMDropTbsReq(void*);
5168

5169
typedef struct SVFetchTtlExpiredTbsRsp {
5170
  SArray* pExpiredTbs;  // SVDropTbReq
5171
  int32_t vgId;
5172
} SVFetchTtlExpiredTbsRsp;
5173

5174
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5175
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5176

5177
void tFreeFetchTtlExpiredTbsRsp(void* p);
5178

5179
void setDefaultOptionsForField(SFieldWithOptions* field);
5180
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5181

5182
#ifdef USE_MOUNT
5183
typedef struct {
5184
  char     mountName[TSDB_MOUNT_NAME_LEN];
5185
  int8_t   ignoreExist;
5186
  int16_t  nMounts;
5187
  int32_t* dnodeIds;
5188
  char**   mountPaths;
5189
  int32_t  sqlLen;
5190
  char*    sql;
5191
} SCreateMountReq;
5192

5193
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5194
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5195
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5196

5197
typedef struct {
5198
  char    mountName[TSDB_MOUNT_NAME_LEN];
5199
  int8_t  ignoreNotExists;
5200
  int32_t sqlLen;
5201
  char*   sql;
5202
} SDropMountReq;
5203

5204
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5205
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5206
void    tFreeSDropMountReq(SDropMountReq* pReq);
5207

5208
typedef struct {
5209
  char     mountName[TSDB_MOUNT_NAME_LEN];
5210
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5211
  int64_t  mountUid;
5212
  int32_t  dnodeId;
5213
  uint32_t valLen;
5214
  int8_t   ignoreExist;
5215
  void*    pVal;
5216
} SRetrieveMountPathReq;
5217

5218
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5219
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5220

5221
typedef struct {
5222
  // path
5223
  int32_t diskPrimary;
5224
  // vgInfo
5225
  int32_t  vgId;
5226
  int32_t  cacheLastSize;
5227
  int32_t  szPage;
5228
  int32_t  szCache;
5229
  uint64_t szBuf;
5230
  int8_t   cacheLast;
5231
  int8_t   standby;
5232
  int8_t   hashMethod;
5233
  uint32_t hashBegin;
5234
  uint32_t hashEnd;
5235
  int16_t  hashPrefix;
5236
  int16_t  hashSuffix;
5237
  int16_t  sttTrigger;
5238
  // syncInfo
5239
  int32_t replications;
5240
  // tsdbInfo
5241
  int8_t  precision;
5242
  int8_t  compression;
5243
  int8_t  slLevel;
5244
  int32_t daysPerFile;
5245
  int32_t keep0;
5246
  int32_t keep1;
5247
  int32_t keep2;
5248
  int32_t keepTimeOffset;
5249
  int32_t minRows;
5250
  int32_t maxRows;
5251
  int32_t tsdbPageSize;
5252
  int32_t ssChunkSize;
5253
  int32_t ssKeepLocal;
5254
  int8_t  ssCompact;
5255
  // walInfo
5256
  int32_t walFsyncPeriod;      // millisecond
5257
  int32_t walRetentionPeriod;  // secs
5258
  int32_t walRollPeriod;       // secs
5259
  int64_t walRetentionSize;
5260
  int64_t walSegSize;
5261
  int32_t walLevel;
5262
  // encryptInfo
5263
  int32_t encryptAlgorithm;
5264
  // SVState
5265
  int64_t committed;
5266
  int64_t commitID;
5267
  int64_t commitTerm;
5268
  // stats
5269
  int64_t numOfSTables;
5270
  int64_t numOfCTables;
5271
  int64_t numOfNTables;
5272
  // dbInfo
5273
  uint64_t dbId;
5274
} SMountVgInfo;
5275

5276
typedef struct {
5277
  SMCreateStbReq req;
5278
  SArray*        pColExts;  // element: column id
5279
  SArray*        pTagExts;  // element: tag id
5280
} SMountStbInfo;
5281

5282
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5283
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5284

5285
typedef struct {
5286
  char     dbName[TSDB_DB_FNAME_LEN];
5287
  uint64_t dbId;
5288
  SArray*  pVgs;      // SMountVgInfo
5289
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5290
} SMountDbInfo;
5291

5292
typedef struct {
5293
  // common fields
5294
  char     mountName[TSDB_MOUNT_NAME_LEN];
5295
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5296
  int8_t   ignoreExist;
5297
  int64_t  mountUid;
5298
  int64_t  clusterId;
5299
  int32_t  dnodeId;
5300
  uint32_t valLen;
5301
  void*    pVal;
5302

5303
  // response fields
5304
  SArray* pDbs;  // SMountDbInfo
5305

5306
  // memory fields, no serialized
5307
  SArray*   pDisks[TFS_MAX_TIERS];
5308
  TdFilePtr pFile;
5309
} SMountInfo;
5310

5311
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5312
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5313
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5314

5315
typedef struct {
5316
  SCreateVnodeReq createReq;
5317
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5318
  char            mountName[TSDB_MOUNT_NAME_LEN];
5319
  int64_t         mountId;
5320
  int32_t         diskPrimary;
5321
  int32_t         mountVgId;
5322
  int64_t         committed;
5323
  int64_t         commitID;
5324
  int64_t         commitTerm;
5325
  int64_t         numOfSTables;
5326
  int64_t         numOfCTables;
5327
  int64_t         numOfNTables;
5328
} SMountVnodeReq;
5329

5330
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5331
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5332
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5333

5334
#endif  // USE_MOUNT
5335

5336
#pragma pack(pop)
5337

5338
#ifdef __cplusplus
5339
}
5340
#endif
5341

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