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

taosdata / TDengine / #4488

12 Jul 2025 07:47AM UTC coverage: 62.207% (-0.7%) from 62.948%
#4488

push

travis-ci

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

157961 of 324087 branches covered (48.74%)

Branch coverage included in aggregate %.

244465 of 322830 relevant lines covered (75.73%)

6561668.76 hits per line

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

41.39
/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) {
72,652,803✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
72,652,803✔
74
  int    segIdx = TMSG_SEG_CODE(type);
72,652,803✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
72,652,803!
76
    return type < tMsgRangeDict[segIdx];
72,659,885✔
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) {
2,962,500✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,916,365!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
5,878,865✔
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
9,496,620✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
9,496,620✔
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_MAX,
170
} EShowType;
171

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

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

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

211
#define TSDB_KILL_MSG_LEN 30
212

213
#define TSDB_TABLE_NUM_UNIT 100000
214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

678
//
679

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

789
bool hasExtSchema(const SExtSchema* pExtSchema);
790

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

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

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

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

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

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

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

845
  return pDstWrapper;
846
}
847

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

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

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

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

887
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
3,108,692!
888
  if (pSW == NULL) {
3,110,151!
889
    return NULL;
×
890
  }
891
  pSW->nCols = pSchemaWrapper->nCols;
3,110,151✔
892
  pSW->version = pSchemaWrapper->version;
3,110,151✔
893
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
3,110,151!
894
  if (pSW->pSchema == NULL) {
3,109,299!
895
    taosMemoryFree(pSW);
×
896
    return NULL;
×
897
  }
898

899
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
3,109,299✔
900
  return pSW;
3,109,299✔
901
}
902

903
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
587,107✔
904
  if (pSchemaWrapper) {
7,681,008!
905
    taosMemoryFree(pSchemaWrapper->pSchema);
3,378,133!
906
    taosMemoryFree(pSchemaWrapper);
3,378,145!
907
  }
908
}
7,563,413✔
909

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

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

927
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
928
  buf = taosDecodeFixedI8(buf, &pSchema->type);
57,464✔
929
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
28,732✔
930
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
28,732!
931
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
28,732!
932
  buf = taosDecodeStringTo(buf, pSchema->name);
28,732✔
933
  return (void*)buf;
28,732✔
934
}
935

936
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
37,749,083!
938
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
57,053,594!
939
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
57,053,594!
940
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
57,053,594!
941
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
57,053,594!
942
  return 0;
28,526,797✔
943
}
944

945
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
946
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
143,967,043!
947
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
279,873,359!
948
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
279,344,156!
949
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
279,311,411!
950
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
139,800,361!
951
  return 0;
140,115,872✔
952
}
953

954
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
955
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
14,562,290!
956
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
14,562,290!
957
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
14,562,290!
958
  return 0;
7,281,145✔
959
}
960

961
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
962
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
6,239,707!
963
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
6,239,705!
964
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
6,239,696!
965
  return 0;
3,119,845✔
966
}
967

968
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
969
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
17,692!
970
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
17,692!
971
  if (pColRef->hasRef) {
8,846✔
972
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
9,028!
973
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
9,028!
974
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
9,028!
975
  }
976
  return 0;
8,846✔
977
}
978

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

988
  return 0;
10,812✔
989
}
990

991
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
992
  int32_t tlen = 0;
9,356✔
993
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
9,356✔
994
  tlen += taosEncodeVariantI32(buf, pSW->version);
9,356✔
995
  for (int32_t i = 0; i < pSW->nCols; i++) {
70,624✔
996
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
122,536!
997
  }
998
  return tlen;
9,356✔
999
}
1000

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

1010
    for (int32_t i = 0; i < pSW->nCols; i++) {
31,823✔
1011
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
57,464✔
1012
    }
1013
  } else {
1014
    pSW->pSchema = NULL;
1,297✔
1015
  }
1016
  return (void*)buf;
4,388✔
1017
}
1018

1019
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1020
  if (pSW == NULL) {
737,420!
1021
    return TSDB_CODE_INVALID_PARA;
×
1022
  }
1023
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,474,840!
1024
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,474,840!
1025
  for (int32_t i = 0; i < pSW->nCols; i++) {
20,041,931!
1026
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,609,022!
1027
  }
1028
  return 0;
737,420✔
1029
}
1030

1031
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1032
  if (pSW == NULL) {
1,448,888!
1033
    return TSDB_CODE_INVALID_PARA;
×
1034
  }
1035
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,897,816!
1036
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,897,748!
1037

1038
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,448,820!
1039
  if (pSW->pSchema == NULL) {
1,448,941!
1040
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1041
  }
1042
  for (int32_t i = 0; i < pSW->nCols; i++) {
17,260,333!
1043
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
31,623,871!
1044
  }
1045

1046
  return 0;
1,447,854✔
1047
}
1048

1049
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1050
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
17,195,798!
1051
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
17,201,634!
1052

1053
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
8,600,136!
1054
  if (pSW->pSchema == NULL) {
8,603,502!
1055
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1056
  }
1057
  for (int32_t i = 0; i < pSW->nCols; i++) {
128,981,187!
1058
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
240,762,475!
1059
  }
1060

1061
  return 0;
8,596,397✔
1062
}
1063

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1506
typedef STableCfg STableCfgRsp;
1507

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1724
typedef struct {
1725
  char db[TSDB_DB_FNAME_LEN];
1726
} SS3MigrateDbReq;
1727

1728
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1729
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1730

1731
typedef struct {
1732
  int32_t timestamp;
1733
} SVS3MigrateDbReq;
1734

1735
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1736
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1737

1738
typedef struct {
1739
  int32_t timestampSec;
1740
  int32_t ttlDropMaxCount;
1741
  int32_t nUids;
1742
  SArray* pTbUids;
1743
} SVDropTtlTableReq;
1744

1745
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1746
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1747

1748
typedef struct {
1749
  char    db[TSDB_DB_FNAME_LEN];
1750
  int64_t dbId;
1751
  int32_t cfgVersion;
1752
  int32_t numOfVgroups;
1753
  int32_t numOfStables;
1754
  int32_t buffer;
1755
  int32_t cacheSize;
1756
  int32_t pageSize;
1757
  int32_t pages;
1758
  int32_t daysPerFile;
1759
  int32_t daysToKeep0;
1760
  int32_t daysToKeep1;
1761
  int32_t daysToKeep2;
1762
  int32_t keepTimeOffset;
1763
  int32_t minRows;
1764
  int32_t maxRows;
1765
  int32_t walFsyncPeriod;
1766
  int16_t hashPrefix;
1767
  int16_t hashSuffix;
1768
  int8_t  hashMethod;
1769
  int8_t  walLevel;
1770
  int8_t  precision;
1771
  int8_t  compression;
1772
  int8_t  replications;
1773
  int8_t  strict;
1774
  int8_t  cacheLast;
1775
  int8_t  encryptAlgorithm;
1776
  int32_t s3ChunkSize;
1777
  int32_t s3KeepLocal;
1778
  int8_t  s3Compact;
1779
  union {
1780
    uint8_t flags;
1781
    struct {
1782
      uint8_t isMount : 1;  // TS-5868
1783
      uint8_t padding : 7;
1784
    };
1785
  };
1786
  int8_t  compactTimeOffset;
1787
  int32_t compactInterval;
1788
  int32_t compactStartTime;
1789
  int32_t compactEndTime;
1790
  int32_t tsdbPageSize;
1791
  int32_t walRetentionPeriod;
1792
  int32_t walRollPeriod;
1793
  int64_t walRetentionSize;
1794
  int64_t walSegmentSize;
1795
  int32_t numOfRetensions;
1796
  SArray* pRetensions;
1797
  int8_t  schemaless;
1798
  int16_t sstTrigger;
1799
  int8_t  withArbitrator;
1800
} SDbCfgRsp;
1801

1802
typedef SDbCfgRsp SDbCfgInfo;
1803

1804
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1805
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1806
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1807
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1808
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1809

1810
typedef struct {
1811
  int32_t rowNum;
1812
} SQnodeListReq;
1813

1814
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1815
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1816

1817
typedef struct {
1818
  int32_t rowNum;
1819
} SDnodeListReq;
1820

1821
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1822

1823
typedef struct {
1824
  int32_t useless;  // useless
1825
} SServerVerReq;
1826

1827
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1828
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1829

1830
typedef struct {
1831
  char ver[TSDB_VERSION_LEN];
1832
} SServerVerRsp;
1833

1834
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1835
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1836

1837
typedef struct SQueryNodeAddr {
1838
  int32_t nodeId;  // vgId or qnodeId
1839
  SEpSet  epSet;
1840
} SQueryNodeAddr;
1841

1842
typedef struct {
1843
  SQueryNodeAddr addr;
1844
  uint64_t       load;
1845
} SQueryNodeLoad;
1846

1847
typedef struct {
1848
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1849
} SQnodeListRsp;
1850

1851
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1852
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1853
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1854

1855
typedef struct SDNodeAddr {
1856
  int32_t nodeId;  // dnodeId
1857
  SEpSet  epSet;
1858
} SDNodeAddr;
1859

1860
typedef struct {
1861
  SArray* dnodeList;  // SArray<SDNodeAddr>
1862
} SDnodeListRsp;
1863

1864
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1865
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1866
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1867

1868
typedef struct {
1869
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1870
} STableTSMAInfoRsp;
1871

1872
typedef struct {
1873
  SUseDbRsp*         useDbRsp;
1874
  SDbCfgRsp*         cfgRsp;
1875
  STableTSMAInfoRsp* pTsmaRsp;
1876
  int32_t            dbTsmaVersion;
1877
  char               db[TSDB_DB_FNAME_LEN];
1878
  int64_t            dbId;
1879
} SDbHbRsp;
1880

1881
typedef struct {
1882
  SArray* pArray;  // Array of SDbHbRsp
1883
} SDbHbBatchRsp;
1884

1885
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1886
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1887
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1888

1889
typedef struct {
1890
  SArray* pArray;  // Array of SGetUserAuthRsp
1891
} SUserAuthBatchRsp;
1892

1893
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1894
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1895
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1896

1897
typedef struct {
1898
  char        db[TSDB_DB_FNAME_LEN];
1899
  STimeWindow timeRange;
1900
  int32_t     sqlLen;
1901
  char*       sql;
1902
  SArray*     vgroupIds;
1903
  int8_t      metaOnly;
1904
} SCompactDbReq;
1905

1906
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1907
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1908
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1909

1910
typedef struct {
1911
  int32_t compactId;
1912
  int8_t  bAccepted;
1913
} SCompactDbRsp;
1914

1915
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1916
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1917

1918
typedef struct {
1919
  int32_t compactId;
1920
  int32_t sqlLen;
1921
  char*   sql;
1922
} SKillCompactReq;
1923

1924
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1925
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1926
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1927

1928
typedef struct {
1929
  char    name[TSDB_FUNC_NAME_LEN];
1930
  int8_t  igExists;
1931
  int8_t  funcType;
1932
  int8_t  scriptType;
1933
  int8_t  outputType;
1934
  int32_t outputLen;
1935
  int32_t bufSize;
1936
  int32_t codeLen;
1937
  int64_t signature;
1938
  char*   pComment;
1939
  char*   pCode;
1940
  int8_t  orReplace;
1941
} SCreateFuncReq;
1942

1943
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1944
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1945
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1946

1947
typedef struct {
1948
  char   name[TSDB_FUNC_NAME_LEN];
1949
  int8_t igNotExists;
1950
} SDropFuncReq;
1951

1952
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1953
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1954

1955
typedef struct {
1956
  int32_t numOfFuncs;
1957
  bool    ignoreCodeComment;
1958
  SArray* pFuncNames;
1959
} SRetrieveFuncReq;
1960

1961
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1962
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1963
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1964

1965
typedef struct {
1966
  char    name[TSDB_FUNC_NAME_LEN];
1967
  int8_t  funcType;
1968
  int8_t  scriptType;
1969
  int8_t  outputType;
1970
  int32_t outputLen;
1971
  int32_t bufSize;
1972
  int64_t signature;
1973
  int32_t commentSize;
1974
  int32_t codeSize;
1975
  char*   pComment;
1976
  char*   pCode;
1977
} SFuncInfo;
1978

1979
typedef struct {
1980
  int32_t funcVersion;
1981
  int64_t funcCreatedTime;
1982
} SFuncExtraInfo;
1983

1984
typedef struct {
1985
  int32_t numOfFuncs;
1986
  SArray* pFuncInfos;
1987
  SArray* pFuncExtraInfos;
1988
} SRetrieveFuncRsp;
1989

1990
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1991
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1992
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1993
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1994

1995
typedef struct {
1996
  int32_t       statusInterval;
1997
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1998
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1999
  char          locale[TD_LOCALE_LEN];      // tsLocale
2000
  char          charset[TD_LOCALE_LEN];     // tsCharset
2001
  int8_t        ttlChangeOnWrite;
2002
  int8_t        enableWhiteList;
2003
  int8_t        encryptionKeyStat;
2004
  uint32_t      encryptionKeyChksum;
2005
  SMonitorParas monitorParas;
2006
} SClusterCfg;
2007

2008
typedef struct {
2009
  int32_t openVnodes;
2010
  int32_t dropVnodes;
2011
  int32_t totalVnodes;
2012
  int32_t masterNum;
2013
  int64_t numOfSelectReqs;
2014
  int64_t numOfInsertReqs;
2015
  int64_t numOfInsertSuccessReqs;
2016
  int64_t numOfBatchInsertReqs;
2017
  int64_t numOfBatchInsertSuccessReqs;
2018
  int64_t errors;
2019
} SVnodesStat;
2020

2021
typedef struct {
2022
  int32_t vgId;
2023
  int8_t  syncState;
2024
  int8_t  syncRestore;
2025
  int64_t syncTerm;
2026
  int64_t roleTimeMs;
2027
  int64_t startTimeMs;
2028
  int8_t  syncCanRead;
2029
  int64_t cacheUsage;
2030
  int64_t numOfTables;
2031
  int64_t numOfTimeSeries;
2032
  int64_t totalStorage;
2033
  int64_t compStorage;
2034
  int64_t pointsWritten;
2035
  int64_t numOfSelectReqs;
2036
  int64_t numOfInsertReqs;
2037
  int64_t numOfInsertSuccessReqs;
2038
  int64_t numOfBatchInsertReqs;
2039
  int64_t numOfBatchInsertSuccessReqs;
2040
  int32_t numOfCachedTables;
2041
  int32_t learnerProgress;  // use one reservered
2042
  int64_t syncAppliedIndex;
2043
  int64_t syncCommitIndex;
2044
  int64_t bufferSegmentUsed;
2045
  int64_t bufferSegmentSize;
2046
} SVnodeLoad;
2047

2048
typedef struct {
2049
  int64_t total_requests;
2050
  int64_t total_rows;
2051
  int64_t total_bytes;
2052
  double  write_size;
2053
  double  cache_hit_ratio;
2054
  int64_t rpc_queue_wait;
2055
  int64_t preprocess_time;
2056

2057
  int64_t memory_table_size;
2058
  int64_t commit_count;
2059
  int64_t merge_count;
2060
  double  commit_time;
2061
  double  merge_time;
2062
  int64_t block_commit_time;
2063
  int64_t memtable_wait_time;
2064
} SVnodeMetrics;
2065

2066
typedef struct {
2067
  int32_t     vgId;
2068
  int64_t     numOfTables;
2069
  int64_t     memSize;
2070
  int64_t     l1Size;
2071
  int64_t     l2Size;
2072
  int64_t     l3Size;
2073
  int64_t     cacheSize;
2074
  int64_t     walSize;
2075
  int64_t     metaSize;
2076
  int64_t     rawDataSize;
2077
  int64_t     s3Size;
2078
  const char* dbname;
2079
} SDbSizeStatisInfo;
2080

2081
typedef struct {
2082
  int32_t vgId;
2083
  int64_t nTimeSeries;
2084
} SVnodeLoadLite;
2085

2086
typedef struct {
2087
  int8_t  syncState;
2088
  int64_t syncTerm;
2089
  int8_t  syncRestore;
2090
  int64_t roleTimeMs;
2091
} SMnodeLoad;
2092

2093
typedef struct {
2094
  int32_t dnodeId;
2095
  int64_t numOfProcessedQuery;
2096
  int64_t numOfProcessedCQuery;
2097
  int64_t numOfProcessedFetch;
2098
  int64_t numOfProcessedDrop;
2099
  int64_t numOfProcessedNotify;
2100
  int64_t numOfProcessedHb;
2101
  int64_t numOfProcessedDelete;
2102
  int64_t cacheDataSize;
2103
  int64_t numOfQueryInQueue;
2104
  int64_t numOfFetchInQueue;
2105
  int64_t timeInQueryQueue;
2106
  int64_t timeInFetchQueue;
2107
} SQnodeLoad;
2108

2109
typedef struct {
2110
  int32_t     sver;      // software version
2111
  int64_t     dnodeVer;  // dnode table version in sdb
2112
  int32_t     dnodeId;
2113
  int64_t     clusterId;
2114
  int64_t     rebootTime;
2115
  int64_t     updateTime;
2116
  float       numOfCores;
2117
  int32_t     numOfSupportVnodes;
2118
  int32_t     numOfDiskCfg;
2119
  int64_t     memTotal;
2120
  int64_t     memAvail;
2121
  char        dnodeEp[TSDB_EP_LEN];
2122
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2123
  SMnodeLoad  mload;
2124
  SQnodeLoad  qload;
2125
  SClusterCfg clusterCfg;
2126
  SArray*     pVloads;  // array of SVnodeLoad
2127
  int32_t     statusSeq;
2128
  int64_t     ipWhiteVer;
2129
  int64_t     analVer;
2130
  int64_t     timestamp;
2131
} SStatusReq;
2132

2133
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2134
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2135
void    tFreeSStatusReq(SStatusReq* pReq);
2136

2137
typedef struct {
2138
  int32_t forceReadConfig;
2139
  int32_t cver;
2140
  SArray* array;
2141
} SConfigReq;
2142

2143
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2144
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2145
void    tFreeSConfigReq(SConfigReq* pReq);
2146

2147
typedef struct {
2148
  int32_t dnodeId;
2149
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2150
} SDnodeInfoReq;
2151

2152
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2153
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2154

2155
typedef enum {
2156
  MONITOR_TYPE_COUNTER = 0,
2157
  MONITOR_TYPE_SLOW_LOG = 1,
2158
} MONITOR_TYPE;
2159

2160
typedef struct {
2161
  int32_t      contLen;
2162
  char*        pCont;
2163
  MONITOR_TYPE type;
2164
} SStatisReq;
2165

2166
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2167
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2168
void    tFreeSStatisReq(SStatisReq* pReq);
2169

2170
typedef struct {
2171
  char    db[TSDB_DB_FNAME_LEN];
2172
  char    table[TSDB_TABLE_NAME_LEN];
2173
  char    operation[AUDIT_OPERATION_LEN];
2174
  int32_t sqlLen;
2175
  char*   pSql;
2176
} SAuditReq;
2177
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2178
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2179
void    tFreeSAuditReq(SAuditReq* pReq);
2180

2181
typedef struct {
2182
  int32_t dnodeId;
2183
  int64_t clusterId;
2184
  SArray* pVloads;
2185
} SNotifyReq;
2186

2187
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2188
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2189
void    tFreeSNotifyReq(SNotifyReq* pReq);
2190

2191
typedef struct {
2192
  int32_t dnodeId;
2193
  int64_t clusterId;
2194
} SDnodeCfg;
2195

2196
typedef struct {
2197
  int32_t id;
2198
  int8_t  isMnode;
2199
  SEp     ep;
2200
} SDnodeEp;
2201

2202
typedef struct {
2203
  int32_t id;
2204
  int8_t  isMnode;
2205
  int8_t  offlineReason;
2206
  SEp     ep;
2207
  char    active[TSDB_ACTIVE_KEY_LEN];
2208
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2209
} SDnodeInfo;
2210

2211
typedef struct {
2212
  int64_t   dnodeVer;
2213
  SDnodeCfg dnodeCfg;
2214
  SArray*   pDnodeEps;  // Array of SDnodeEp
2215
  int32_t   statusSeq;
2216
  int64_t   ipWhiteVer;
2217
  int64_t   analVer;
2218
} SStatusRsp;
2219

2220
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2221
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2222
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2223

2224
typedef struct {
2225
  int32_t forceReadConfig;
2226
  int32_t isConifgVerified;
2227
  int32_t isVersionVerified;
2228
  int32_t cver;
2229
  SArray* array;
2230
} SConfigRsp;
2231

2232
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2233
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2234
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2235

2236
typedef struct {
2237
  int32_t reserved;
2238
} SMTimerReq;
2239

2240
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2241
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2242

2243
typedef struct SOrphanTask {
2244
  int64_t streamId;
2245
  int32_t taskId;
2246
  int32_t nodeId;
2247
} SOrphanTask;
2248

2249
typedef struct SMStreamDropOrphanMsg {
2250
  SArray* pList;  // SArray<SOrphanTask>
2251
} SMStreamDropOrphanMsg;
2252

2253
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2254
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2255
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2256

2257
typedef struct {
2258
  int32_t  id;
2259
  uint16_t port;                 // node sync Port
2260
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2261
} SReplica;
2262

2263
typedef struct {
2264
  int32_t  vgId;
2265
  char     db[TSDB_DB_FNAME_LEN];
2266
  int64_t  dbUid;
2267
  int32_t  vgVersion;
2268
  int32_t  numOfStables;
2269
  int32_t  buffer;
2270
  int32_t  pageSize;
2271
  int32_t  pages;
2272
  int32_t  cacheLastSize;
2273
  int32_t  daysPerFile;
2274
  int32_t  daysToKeep0;
2275
  int32_t  daysToKeep1;
2276
  int32_t  daysToKeep2;
2277
  int32_t  keepTimeOffset;
2278
  int32_t  minRows;
2279
  int32_t  maxRows;
2280
  int32_t  walFsyncPeriod;
2281
  uint32_t hashBegin;
2282
  uint32_t hashEnd;
2283
  int8_t   hashMethod;
2284
  int8_t   walLevel;
2285
  int8_t   precision;
2286
  int8_t   compression;
2287
  int8_t   strict;
2288
  int8_t   cacheLast;
2289
  int8_t   isTsma;
2290
  int8_t   replica;
2291
  int8_t   selfIndex;
2292
  SReplica replicas[TSDB_MAX_REPLICA];
2293
  int32_t  numOfRetensions;
2294
  SArray*  pRetensions;  // SRetention
2295
  void*    pTsma;
2296
  int32_t  walRetentionPeriod;
2297
  int64_t  walRetentionSize;
2298
  int32_t  walRollPeriod;
2299
  int64_t  walSegmentSize;
2300
  int16_t  sstTrigger;
2301
  int16_t  hashPrefix;
2302
  int16_t  hashSuffix;
2303
  int32_t  tsdbPageSize;
2304
  int32_t  s3ChunkSize;
2305
  int32_t  s3KeepLocal;
2306
  int8_t   s3Compact;
2307
  int64_t  reserved[6];
2308
  int8_t   learnerReplica;
2309
  int8_t   learnerSelfIndex;
2310
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2311
  int32_t  changeVersion;
2312
  int8_t   encryptAlgorithm;
2313
} SCreateVnodeReq;
2314

2315
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2316
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2317
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2318

2319
typedef struct {
2320
  int32_t compactId;
2321
  int32_t vgId;
2322
  int32_t dnodeId;
2323
} SQueryCompactProgressReq;
2324

2325
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2326
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2327

2328
typedef struct {
2329
  int32_t compactId;
2330
  int32_t vgId;
2331
  int32_t dnodeId;
2332
  int32_t numberFileset;
2333
  int32_t finished;
2334
  int32_t progress;
2335
  int64_t remainingTime;
2336
} SQueryCompactProgressRsp;
2337

2338
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2339
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2340

2341
typedef struct {
2342
  int32_t vgId;
2343
  int32_t dnodeId;
2344
  int64_t dbUid;
2345
  char    db[TSDB_DB_FNAME_LEN];
2346
  int64_t reserved[8];
2347
} SDropVnodeReq;
2348

2349
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2350
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2351

2352
typedef struct {
2353
  char    colName[TSDB_COL_NAME_LEN];
2354
  char    stb[TSDB_TABLE_FNAME_LEN];
2355
  int64_t stbUid;
2356
  int64_t dbUid;
2357
  int64_t reserved[8];
2358
} SDropIndexReq;
2359

2360
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2361
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2362

2363
typedef struct {
2364
  int64_t     dbUid;
2365
  char        db[TSDB_DB_FNAME_LEN];
2366
  int64_t     compactStartTime;
2367
  STimeWindow tw;
2368
  int32_t     compactId;
2369
  int8_t      metaOnly;
2370
} SCompactVnodeReq;
2371

2372
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2373
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2374

2375
typedef struct {
2376
  int32_t compactId;
2377
  int32_t vgId;
2378
  int32_t dnodeId;
2379
} SVKillCompactReq;
2380

2381
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2382
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2383

2384
typedef struct {
2385
  int32_t vgVersion;
2386
  int32_t buffer;
2387
  int32_t pageSize;
2388
  int32_t pages;
2389
  int32_t cacheLastSize;
2390
  int32_t daysPerFile;
2391
  int32_t daysToKeep0;
2392
  int32_t daysToKeep1;
2393
  int32_t daysToKeep2;
2394
  int32_t keepTimeOffset;
2395
  int32_t walFsyncPeriod;
2396
  int8_t  walLevel;
2397
  int8_t  strict;
2398
  int8_t  cacheLast;
2399
  int64_t reserved[7];
2400
  // 1st modification
2401
  int16_t sttTrigger;
2402
  int32_t minRows;
2403
  // 2nd modification
2404
  int32_t walRetentionPeriod;
2405
  int32_t walRetentionSize;
2406
  int32_t s3KeepLocal;
2407
  int8_t  s3Compact;
2408
} SAlterVnodeConfigReq;
2409

2410
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2411
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2412

2413
typedef struct {
2414
  int32_t  vgId;
2415
  int8_t   strict;
2416
  int8_t   selfIndex;
2417
  int8_t   replica;
2418
  SReplica replicas[TSDB_MAX_REPLICA];
2419
  int64_t  reserved[8];
2420
  int8_t   learnerSelfIndex;
2421
  int8_t   learnerReplica;
2422
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2423
  int32_t  changeVersion;
2424
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2425

2426
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2427
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2428

2429
typedef struct {
2430
  int32_t vgId;
2431
  int8_t  disable;
2432
} SDisableVnodeWriteReq;
2433

2434
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2435
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2436

2437
typedef struct {
2438
  int32_t  srcVgId;
2439
  int32_t  dstVgId;
2440
  uint32_t hashBegin;
2441
  uint32_t hashEnd;
2442
  int32_t  changeVersion;
2443
  int32_t  reserved;
2444
} SAlterVnodeHashRangeReq;
2445

2446
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2447
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2448

2449
#define REQ_OPT_TBNAME 0x0
2450
#define REQ_OPT_TBUID  0x01
2451
typedef struct {
2452
  SMsgHead header;
2453
  char     dbFName[TSDB_DB_FNAME_LEN];
2454
  char     tbName[TSDB_TABLE_NAME_LEN];
2455
  uint8_t  option;
2456
  uint8_t  autoCreateCtb;
2457
} STableInfoReq;
2458

2459
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2460
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2461

2462
typedef struct {
2463
  int8_t  metaClone;  // create local clone of the cached table meta
2464
  int32_t numOfVgroups;
2465
  int32_t numOfTables;
2466
  int32_t numOfUdfs;
2467
  char    tableNames[];
2468
} SMultiTableInfoReq;
2469

2470
// todo refactor
2471
typedef struct SVgroupInfo {
2472
  int32_t  vgId;
2473
  uint32_t hashBegin;
2474
  uint32_t hashEnd;
2475
  SEpSet   epSet;
2476
  union {
2477
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2478
    int32_t taskId;      // used in stream
2479
  };
2480
} SVgroupInfo;
2481

2482
typedef struct {
2483
  int32_t     numOfVgroups;
2484
  SVgroupInfo vgroups[];
2485
} SVgroupsInfo;
2486

2487
typedef struct {
2488
  STableMetaRsp* pMeta;
2489
} SMAlterStbRsp;
2490

2491
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2492
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2493
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2494

2495
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2496
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2497
void    tFreeSTableMetaRsp(void* pRsp);
2498
void    tFreeSTableIndexRsp(void* info);
2499

2500
typedef struct {
2501
  SArray* pMetaRsp;   // Array of STableMetaRsp
2502
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2503
} SSTbHbRsp;
2504

2505
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2506
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2507
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2508

2509
typedef struct {
2510
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2511
} SViewHbRsp;
2512

2513
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2514
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2515
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2516

2517
typedef struct {
2518
  int32_t numOfTables;
2519
  int32_t numOfVgroup;
2520
  int32_t numOfUdf;
2521
  int32_t contLen;
2522
  int8_t  compressed;  // denote if compressed or not
2523
  int32_t rawLen;      // size before compress
2524
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2525
  char    meta[];
2526
} SMultiTableMeta;
2527

2528
typedef struct {
2529
  int32_t dataLen;
2530
  char    name[TSDB_TABLE_FNAME_LEN];
2531
  char*   data;
2532
} STagData;
2533

2534
typedef struct {
2535
  int32_t  opType;
2536
  uint32_t valLen;
2537
  char*    val;
2538
} SShowVariablesReq;
2539

2540
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2541
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2542
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2543

2544
typedef struct {
2545
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2546
  char value[TSDB_CONFIG_PATH_LEN + 1];
2547
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2548
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2549
  char info[TSDB_CONFIG_INFO_LEN + 1];
2550
} SVariablesInfo;
2551

2552
typedef struct {
2553
  SArray* variables;  // SArray<SVariablesInfo>
2554
} SShowVariablesRsp;
2555

2556
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2557
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2558

2559
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2560

2561
/*
2562
 * sql: show tables like '%a_%'
2563
 * payload is the query condition, e.g., '%a_%'
2564
 * payloadLen is the length of payload
2565
 */
2566
typedef struct {
2567
  int32_t type;
2568
  char    db[TSDB_DB_FNAME_LEN];
2569
  int32_t payloadLen;
2570
  char*   payload;
2571
} SShowReq;
2572

2573
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2574
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2575
void tFreeSShowReq(SShowReq* pReq);
2576

2577
typedef struct {
2578
  int64_t       showId;
2579
  STableMetaRsp tableMeta;
2580
} SShowRsp, SVShowTablesRsp;
2581

2582
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2583
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2584
// void    tFreeSShowRsp(SShowRsp* pRsp);
2585

2586
typedef struct {
2587
  char    db[TSDB_DB_FNAME_LEN];
2588
  char    tb[TSDB_TABLE_NAME_LEN];
2589
  char    user[TSDB_USER_LEN];
2590
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2591
  int64_t showId;
2592
  int64_t compactId;  // for compact
2593
  bool    withFull;   // for show users full
2594
} SRetrieveTableReq;
2595

2596
typedef struct SSysTableSchema {
2597
  int8_t   type;
2598
  col_id_t colId;
2599
  int32_t  bytes;
2600
} SSysTableSchema;
2601

2602
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2603
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2604

2605
#define RETRIEVE_TABLE_RSP_VERSION         0
2606
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2607
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2608

2609
typedef struct {
2610
  int64_t useconds;
2611
  int8_t  completed;  // all results are returned to client
2612
  int8_t  precision;
2613
  int8_t  compressed;
2614
  int8_t  streamBlockType;
2615
  int32_t payloadLen;
2616
  int32_t compLen;
2617
  int32_t numOfBlocks;
2618
  int64_t numOfRows;  // from int32_t change to int64_t
2619
  int64_t numOfCols;
2620
  int64_t skey;
2621
  int64_t ekey;
2622
  int64_t version;                         // for stream
2623
  TSKEY   watermark;                       // for stream
2624
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2625
  char    data[];
2626
} SRetrieveTableRsp;
2627

2628
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2629

2630
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2631
  do {                                          \
2632
    ((int32_t*)(_p))[0] = (_compLen);           \
2633
    ((int32_t*)(_p))[1] = (_fullLen);           \
2634
  } while (0);
2635

2636
typedef struct {
2637
  int64_t version;
2638
  int64_t numOfRows;
2639
  int8_t  compressed;
2640
  int8_t  precision;
2641
  char    data[];
2642
} SRetrieveTableRspForTmq;
2643

2644
typedef struct {
2645
  int64_t handle;
2646
  int64_t useconds;
2647
  int8_t  completed;  // all results are returned to client
2648
  int8_t  precision;
2649
  int8_t  compressed;
2650
  int32_t compLen;
2651
  int32_t numOfRows;
2652
  int32_t fullLen;
2653
  char    data[];
2654
} SRetrieveMetaTableRsp;
2655

2656
typedef struct SExplainExecInfo {
2657
  double   startupCost;
2658
  double   totalCost;
2659
  uint64_t numOfRows;
2660
  uint32_t verboseLen;
2661
  void*    verboseInfo;
2662
} SExplainExecInfo;
2663

2664
typedef struct {
2665
  int32_t           numOfPlans;
2666
  SExplainExecInfo* subplanInfo;
2667
} SExplainRsp;
2668

2669
typedef struct {
2670
  SExplainRsp rsp;
2671
  uint64_t    qId;
2672
  uint64_t    cId;
2673
  uint64_t    tId;
2674
  int64_t     rId;
2675
  int32_t     eId;
2676
} SExplainLocalRsp;
2677

2678
typedef struct STableScanAnalyzeInfo {
2679
  uint64_t totalRows;
2680
  uint64_t totalCheckedRows;
2681
  uint32_t totalBlocks;
2682
  uint32_t loadBlocks;
2683
  uint32_t loadBlockStatis;
2684
  uint32_t skipBlocks;
2685
  uint32_t filterOutBlocks;
2686
  double   elapsedTime;
2687
  double   filterTime;
2688
} STableScanAnalyzeInfo;
2689

2690
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2691
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2692
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2693

2694
typedef struct {
2695
  char    config[TSDB_DNODE_CONFIG_LEN];
2696
  char    value[TSDB_CLUSTER_VALUE_LEN];
2697
  int32_t sqlLen;
2698
  char*   sql;
2699
} SMCfgClusterReq;
2700

2701
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2702
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2703
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2704

2705
typedef struct {
2706
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2707
  int32_t port;
2708
  int32_t sqlLen;
2709
  char*   sql;
2710
} SCreateDnodeReq;
2711

2712
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2713
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2714
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2715

2716
typedef struct {
2717
  int32_t dnodeId;
2718
  char    fqdn[TSDB_FQDN_LEN];
2719
  int32_t port;
2720
  int8_t  force;
2721
  int8_t  unsafe;
2722
  int32_t sqlLen;
2723
  char*   sql;
2724
} SDropDnodeReq;
2725

2726
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2727
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2728
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2729

2730
enum {
2731
  RESTORE_TYPE__ALL = 1,
2732
  RESTORE_TYPE__MNODE,
2733
  RESTORE_TYPE__VNODE,
2734
  RESTORE_TYPE__QNODE,
2735
};
2736

2737
typedef struct {
2738
  int32_t dnodeId;
2739
  int8_t  restoreType;
2740
  int32_t sqlLen;
2741
  char*   sql;
2742
} SRestoreDnodeReq;
2743

2744
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2745
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2746
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2747

2748
typedef struct {
2749
  int32_t dnodeId;
2750
  char    config[TSDB_DNODE_CONFIG_LEN];
2751
  char    value[TSDB_DNODE_VALUE_LEN];
2752
  int32_t sqlLen;
2753
  char*   sql;
2754
} SMCfgDnodeReq;
2755

2756
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2757
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2758
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2759

2760
typedef struct {
2761
  char    config[TSDB_DNODE_CONFIG_LEN];
2762
  char    value[TSDB_DNODE_VALUE_LEN];
2763
  int32_t version;
2764
} SDCfgDnodeReq;
2765

2766
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2767
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2768

2769
typedef struct {
2770
  int32_t dnodeId;
2771
  int32_t sqlLen;
2772
  char*   sql;
2773
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2774
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2775

2776
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2777
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2778
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2779
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2780
typedef struct {
2781
  int8_t   replica;
2782
  SReplica replicas[TSDB_MAX_REPLICA];
2783
  int8_t   learnerReplica;
2784
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2785
  int64_t  lastIndex;
2786
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2787

2788
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2789
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2790

2791
typedef struct {
2792
  int32_t urlLen;
2793
  int32_t sqlLen;
2794
  char*   url;
2795
  char*   sql;
2796
} SMCreateAnodeReq;
2797

2798
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2799
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2800
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2801

2802
typedef struct {
2803
  int32_t anodeId;
2804
  int32_t sqlLen;
2805
  char*   sql;
2806
} SMDropAnodeReq, SMUpdateAnodeReq;
2807

2808
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2809
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2810
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2811
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2812
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2813
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2814

2815
typedef struct {
2816
  int32_t dnodeId;
2817
  int32_t bnodeProto;
2818
  int32_t sqlLen;
2819
  char*   sql;
2820
} SMCreateBnodeReq, SDCreateBnodeReq;
2821

2822
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2823
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2824
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
2825

2826
typedef struct {
2827
  int32_t dnodeId;
2828
  int32_t sqlLen;
2829
  char*   sql;
2830
} SMDropBnodeReq, SDDropBnodeReq;
2831

2832
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2833
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2834
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
2835

2836
typedef struct {
2837
  int32_t vgId;
2838
  int32_t hbSeq;
2839
} SVArbHbReqMember;
2840

2841
typedef struct {
2842
  int32_t dnodeId;
2843
  char*   arbToken;
2844
  int64_t arbTerm;
2845
  SArray* hbMembers;  // SVArbHbReqMember
2846
} SVArbHeartBeatReq;
2847

2848
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2849
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2850
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2851

2852
typedef struct {
2853
  int32_t vgId;
2854
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2855
  int32_t hbSeq;
2856
} SVArbHbRspMember;
2857

2858
typedef struct {
2859
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2860
  int32_t dnodeId;
2861
  SArray* hbMembers;  // SVArbHbRspMember
2862
} SVArbHeartBeatRsp;
2863

2864
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2865
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2866
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2867

2868
typedef struct {
2869
  char*   arbToken;
2870
  int64_t arbTerm;
2871
  char*   member0Token;
2872
  char*   member1Token;
2873
} SVArbCheckSyncReq;
2874

2875
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2876
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2877
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2878

2879
typedef struct {
2880
  char*   arbToken;
2881
  char*   member0Token;
2882
  char*   member1Token;
2883
  int32_t vgId;
2884
  int32_t errCode;
2885
} SVArbCheckSyncRsp;
2886

2887
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2888
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2889
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2890

2891
typedef struct {
2892
  char*   arbToken;
2893
  int64_t arbTerm;
2894
  char*   memberToken;
2895
  int8_t  force;
2896
} SVArbSetAssignedLeaderReq;
2897

2898
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2899
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2900
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2901

2902
typedef struct {
2903
  char*   arbToken;
2904
  char*   memberToken;
2905
  int32_t vgId;
2906
} SVArbSetAssignedLeaderRsp;
2907

2908
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2909
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2910
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2911

2912
typedef struct {
2913
  int32_t dnodeId;
2914
  char*   token;
2915
} SMArbUpdateGroupMember;
2916

2917
typedef struct {
2918
  int32_t dnodeId;
2919
  char*   token;
2920
  int8_t  acked;
2921
} SMArbUpdateGroupAssigned;
2922

2923
typedef struct {
2924
  int32_t                  vgId;
2925
  int64_t                  dbUid;
2926
  SMArbUpdateGroupMember   members[2];
2927
  int8_t                   isSync;
2928
  int8_t                   assignedAcked;
2929
  SMArbUpdateGroupAssigned assignedLeader;
2930
  int64_t                  version;
2931
  int32_t                  code;
2932
  int64_t                  updateTimeMs;
2933
} SMArbUpdateGroup;
2934

2935
typedef struct {
2936
  SArray* updateArray;  // SMArbUpdateGroup
2937
} SMArbUpdateGroupBatchReq;
2938

2939
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2940
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2941
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2942

2943
typedef struct {
2944
  char queryStrId[TSDB_QUERY_ID_LEN];
2945
} SKillQueryReq;
2946

2947
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2948
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2949

2950
typedef struct {
2951
  uint32_t connId;
2952
} SKillConnReq;
2953

2954
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2955
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2956

2957
typedef struct {
2958
  int32_t transId;
2959
} SKillTransReq;
2960

2961
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2962
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2963

2964
typedef struct {
2965
  int32_t useless;  // useless
2966
  int32_t sqlLen;
2967
  char*   sql;
2968
} SBalanceVgroupReq;
2969

2970
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2971
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2972
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2973

2974
typedef struct {
2975
  int32_t useless;  // useless
2976
  int32_t sqlLen;
2977
  char*   sql;
2978
} SAssignLeaderReq;
2979

2980
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2981
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2982
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2983
typedef struct {
2984
  int32_t vgId1;
2985
  int32_t vgId2;
2986
} SMergeVgroupReq;
2987

2988
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2989
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2990

2991
typedef struct {
2992
  int32_t vgId;
2993
  int32_t dnodeId1;
2994
  int32_t dnodeId2;
2995
  int32_t dnodeId3;
2996
  int32_t sqlLen;
2997
  char*   sql;
2998
} SRedistributeVgroupReq;
2999

3000
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3001
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3002
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3003

3004
typedef struct {
3005
  int32_t reserved;
3006
  int32_t vgId;
3007
  int32_t sqlLen;
3008
  char*   sql;
3009
  char    db[TSDB_DB_FNAME_LEN];
3010
} SBalanceVgroupLeaderReq;
3011

3012
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3013
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3014
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3015

3016
typedef struct {
3017
  int32_t vgId;
3018
} SForceBecomeFollowerReq;
3019

3020
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3021
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3022

3023
typedef struct {
3024
  int32_t vgId;
3025
} SSplitVgroupReq;
3026

3027
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3028
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3029

3030
typedef struct {
3031
  char user[TSDB_USER_LEN];
3032
  char spi;
3033
  char encrypt;
3034
  char secret[TSDB_PASSWORD_LEN];
3035
  char ckey[TSDB_PASSWORD_LEN];
3036
} SAuthReq, SAuthRsp;
3037

3038
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3039
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3040

3041
typedef struct {
3042
  int32_t statusCode;
3043
  char    details[1024];
3044
} SServerStatusRsp;
3045

3046
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3047
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3048

3049
/**
3050
 * The layout of the query message payload is as following:
3051
 * +--------------------+---------------------------------+
3052
 * |Sql statement       | Physical plan                   |
3053
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3054
 * +--------------------+---------------------------------+
3055
 */
3056
typedef struct SSubQueryMsg {
3057
  SMsgHead header;
3058
  uint64_t sId;
3059
  uint64_t queryId;
3060
  uint64_t clientId;
3061
  uint64_t taskId;
3062
  int64_t  refId;
3063
  int32_t  execId;
3064
  int32_t  msgMask;
3065
  int8_t   taskType;
3066
  int8_t   explain;
3067
  int8_t   needFetch;
3068
  int8_t   compress;
3069
  uint32_t sqlLen;
3070
  char*    sql;
3071
  uint32_t msgLen;
3072
  char*    msg;
3073
} SSubQueryMsg;
3074

3075
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3076
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3077
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3078

3079
typedef struct {
3080
  SMsgHead header;
3081
  uint64_t sId;
3082
  uint64_t queryId;
3083
  uint64_t taskId;
3084
} SSinkDataReq;
3085

3086
typedef struct {
3087
  SMsgHead header;
3088
  uint64_t sId;
3089
  uint64_t queryId;
3090
  uint64_t clientId;
3091
  uint64_t taskId;
3092
  int32_t  execId;
3093
} SQueryContinueReq;
3094

3095
typedef struct {
3096
  SMsgHead header;
3097
  uint64_t sId;
3098
  uint64_t queryId;
3099
  uint64_t taskId;
3100
} SResReadyReq;
3101

3102
typedef struct {
3103
  int32_t code;
3104
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3105
  int32_t sversion;
3106
  int32_t tversion;
3107
} SResReadyRsp;
3108

3109
typedef struct SOperatorParam {
3110
  int32_t opType;
3111
  int32_t downstreamIdx;
3112
  void*   value;
3113
  SArray* pChildren;  // SArray<SOperatorParam*>
3114
  bool    reUse;
3115
} SOperatorParam;
3116

3117
typedef struct SColIdNameKV {
3118
  col_id_t colId;
3119
  char     colName[TSDB_COL_NAME_LEN];
3120
} SColIdNameKV;
3121

3122
typedef struct SColIdPair {
3123
  col_id_t vtbColId;
3124
  col_id_t orgColId;
3125
} SColIdPair;
3126

3127
typedef struct SOrgTbInfo {
3128
  int32_t vgId;
3129
  char    tbName[TSDB_TABLE_FNAME_LEN];
3130
  SArray* colMap;  // SArray<SColIdNameKV>
3131
} SOrgTbInfo;
3132

3133
typedef struct STableScanOperatorParam {
3134
  bool        tableSeq;
3135
  SArray*     pUidList;
3136
  SOrgTbInfo* pOrgTbInfo;
3137
  STimeWindow window;
3138
} STableScanOperatorParam;
3139

3140
typedef struct SVTableScanOperatorParam {
3141
  uint64_t uid;
3142
  SArray*  pOpParamArray;  // SArray<SOperatorParam>
3143
} SVTableScanOperatorParam;
3144

3145
typedef struct {
3146
  SMsgHead        header;
3147
  uint64_t        sId;
3148
  uint64_t        queryId;
3149
  uint64_t        clientId;
3150
  uint64_t        taskId;
3151
  int32_t         execId;
3152
  SOperatorParam* pOpParam;
3153
} SResFetchReq;
3154

3155
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3156
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3157

3158
typedef struct {
3159
  SMsgHead header;
3160
  uint64_t clientId;
3161
} SSchTasksStatusReq;
3162

3163
typedef struct {
3164
  uint64_t queryId;
3165
  uint64_t clientId;
3166
  uint64_t taskId;
3167
  int64_t  refId;
3168
  int32_t  execId;
3169
  int8_t   status;
3170
} STaskStatus;
3171

3172
typedef struct {
3173
  int64_t refId;
3174
  SArray* taskStatus;  // SArray<STaskStatus>
3175
} SSchedulerStatusRsp;
3176

3177
typedef struct {
3178
  uint64_t queryId;
3179
  uint64_t taskId;
3180
  int8_t   action;
3181
} STaskAction;
3182

3183
typedef struct SQueryNodeEpId {
3184
  int32_t nodeId;  // vgId or qnodeId
3185
  SEp     ep;
3186
} SQueryNodeEpId;
3187

3188
typedef struct {
3189
  SMsgHead       header;
3190
  uint64_t       clientId;
3191
  SQueryNodeEpId epId;
3192
  SArray*        taskAction;  // SArray<STaskAction>
3193
} SSchedulerHbReq;
3194

3195
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3196
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3197
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3198

3199
typedef struct {
3200
  SQueryNodeEpId epId;
3201
  SArray*        taskStatus;  // SArray<STaskStatus>
3202
} SSchedulerHbRsp;
3203

3204
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3205
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3206
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3207

3208
typedef struct {
3209
  SMsgHead header;
3210
  uint64_t sId;
3211
  uint64_t queryId;
3212
  uint64_t clientId;
3213
  uint64_t taskId;
3214
  int64_t  refId;
3215
  int32_t  execId;
3216
} STaskCancelReq;
3217

3218
typedef struct {
3219
  int32_t code;
3220
} STaskCancelRsp;
3221

3222
typedef struct {
3223
  SMsgHead header;
3224
  uint64_t sId;
3225
  uint64_t queryId;
3226
  uint64_t clientId;
3227
  uint64_t taskId;
3228
  int64_t  refId;
3229
  int32_t  execId;
3230
} STaskDropReq;
3231

3232
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3233
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3234

3235
typedef enum {
3236
  TASK_NOTIFY_FINISHED = 1,
3237
} ETaskNotifyType;
3238

3239
typedef struct {
3240
  SMsgHead        header;
3241
  uint64_t        sId;
3242
  uint64_t        queryId;
3243
  uint64_t        clientId;
3244
  uint64_t        taskId;
3245
  int64_t         refId;
3246
  int32_t         execId;
3247
  ETaskNotifyType type;
3248
} STaskNotifyReq;
3249

3250
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3251
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3252

3253
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3254
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3255

3256
typedef struct {
3257
  int32_t code;
3258
} STaskDropRsp;
3259

3260
#define STREAM_TRIGGER_AT_ONCE                 1
3261
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3262
#define STREAM_TRIGGER_MAX_DELAY               3
3263
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3264
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3265

3266
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3267
#define STREAM_FILL_HISTORY_ON        1
3268
#define STREAM_FILL_HISTORY_OFF       0
3269
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3270
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3271
#define STREAM_CREATE_STABLE_TRUE     1
3272
#define STREAM_CREATE_STABLE_FALSE    0
3273

3274
typedef struct SColLocation {
3275
  int16_t  slotId;
3276
  col_id_t colId;
3277
  int8_t   type;
3278
} SColLocation;
3279

3280
typedef struct SVgroupVer {
3281
  int32_t vgId;
3282
  int64_t ver;
3283
} SVgroupVer;
3284

3285
typedef struct {
3286
  char    name[TSDB_STREAM_FNAME_LEN];
3287
  char    sourceDB[TSDB_DB_FNAME_LEN];
3288
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3289
  char*   sql;
3290
  char*   ast;
3291
  int8_t  igExists;
3292
  int8_t  triggerType;
3293
  int8_t  igExpired;
3294
  int8_t  fillHistory;  // process data inserted before creating stream
3295
  int64_t maxDelay;
3296
  int64_t watermark;
3297
  int32_t numOfTags;
3298
  SArray* pTags;  // array of SField
3299
  // 3.0.20
3300
  int64_t checkpointFreq;  // ms
3301
  // 3.0.2.3
3302
  int8_t   createStb;
3303
  uint64_t targetStbUid;
3304
  SArray*  fillNullCols;  // array of SColLocation
3305
  int64_t  deleteMark;
3306
  int8_t   igUpdate;
3307
  int64_t  lastTs;
3308
  SArray*  pVgroupVerList;
3309
  // 3.3.0.0
3310
  SArray* pCols;  // array of SField
3311
  int64_t smaId;
3312
  // 3.3.6.0
3313
  SArray* pNotifyAddrUrls;
3314
  int32_t notifyEventTypes;
3315
  int32_t notifyErrorHandle;
3316
  int8_t  notifyHistory;
3317
  int64_t recalculateInterval;
3318
  char    pWstartName[TSDB_COL_NAME_LEN];
3319
  char    pWendName[TSDB_COL_NAME_LEN];
3320
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3321
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3322
  SArray* pVSubTables;  // array of SVSubTablesRsp
3323
} SCMCreateStreamReq;
3324

3325
typedef struct STaskNotifyEventStat {
3326
  int64_t notifyEventAddTimes;     // call times of add function
3327
  int64_t notifyEventAddElems;     // elements added by add function
3328
  double  notifyEventAddCostSec;   // time cost of add function
3329
  int64_t notifyEventPushTimes;    // call times of push function
3330
  int64_t notifyEventPushElems;    // elements pushed by push function
3331
  double  notifyEventPushCostSec;  // time cost of push function
3332
  int64_t notifyEventPackTimes;    // call times of pack function
3333
  int64_t notifyEventPackElems;    // elements packed by pack function
3334
  double  notifyEventPackCostSec;  // time cost of pack function
3335
  int64_t notifyEventSendTimes;    // call times of send function
3336
  int64_t notifyEventSendElems;    // elements sent by send function
3337
  double  notifyEventSendCostSec;  // time cost of send function
3338
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3339
} STaskNotifyEventStat;
3340

3341
typedef struct {
3342
  int64_t streamId;
3343
} SCMCreateStreamRsp;
3344

3345
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3346
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3347
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3348

3349
enum {
3350
  TOPIC_SUB_TYPE__DB = 1,
3351
  TOPIC_SUB_TYPE__TABLE,
3352
  TOPIC_SUB_TYPE__COLUMN,
3353
};
3354

3355
#define DEFAULT_MAX_POLL_INTERVAL  300000
3356
#define DEFAULT_SESSION_TIMEOUT    12000
3357
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3358
#define DEFAULT_MIN_POLL_ROWS      4096
3359

3360
typedef struct {
3361
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3362
  int8_t igExists;
3363
  int8_t subType;
3364
  int8_t withMeta;
3365
  char*  sql;
3366
  char   subDbName[TSDB_DB_FNAME_LEN];
3367
  char*  ast;
3368
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3369
} SCMCreateTopicReq;
3370

3371
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3372
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3373
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3374

3375
typedef struct {
3376
  int64_t consumerId;
3377
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3378

3379
typedef struct {
3380
  int64_t consumerId;
3381
  char    cgroup[TSDB_CGROUP_LEN];
3382
  char    clientId[TSDB_CLIENT_ID_LEN];
3383
  char    user[TSDB_USER_LEN];
3384
  char    fqdn[TSDB_FQDN_LEN];
3385
  SArray* topicNames;  // SArray<char**>
3386

3387
  int8_t  withTbName;
3388
  int8_t  autoCommit;
3389
  int32_t autoCommitInterval;
3390
  int8_t  resetOffsetCfg;
3391
  int8_t  enableReplay;
3392
  int8_t  enableBatchMeta;
3393
  int32_t sessionTimeoutMs;
3394
  int32_t maxPollIntervalMs;
3395
} SCMSubscribeReq;
3396

3397
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3398
  int32_t tlen = 0;
2,472✔
3399
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,472!
3400
  tlen += taosEncodeString(buf, pReq->cgroup);
2,472✔
3401
  tlen += taosEncodeString(buf, pReq->clientId);
2,472✔
3402

3403
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,472!
3404
  tlen += taosEncodeFixedI32(buf, topicNum);
2,472✔
3405

3406
  for (int32_t i = 0; i < topicNum; i++) {
3,508✔
3407
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,072✔
3408
  }
3409

3410
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,472!
3411
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,472!
3412
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,472!
3413
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,472!
3414
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,472!
3415
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,472!
3416
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,472!
3417
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,472!
3418
  tlen += taosEncodeString(buf, pReq->user);
2,472✔
3419
  tlen += taosEncodeString(buf, pReq->fqdn);
2,472✔
3420

3421
  return tlen;
2,472✔
3422
}
3423

3424
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3425
  void* start = buf;
1,337✔
3426
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,337!
3427
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,337✔
3428
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,337✔
3429

3430
  int32_t topicNum = 0;
1,337!
3431
  buf = taosDecodeFixedI32(buf, &topicNum);
1,337✔
3432

3433
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,337✔
3434
  if (pReq->topicNames == NULL) {
1,337!
3435
    return terrno;
×
3436
  }
3437
  for (int32_t i = 0; i < topicNum; i++) {
1,958✔
3438
    char* name = NULL;
621✔
3439
    buf = taosDecodeString(buf, &name);
621✔
3440
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,242!
3441
      return terrno;
×
3442
    }
3443
  }
3444

3445
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,337✔
3446
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,337✔
3447
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,337!
3448
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,337✔
3449
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,337✔
3450
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,337✔
3451
  if ((char*)buf - (char*)start < len) {
1,337!
3452
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,337!
3453
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,337!
3454
    buf = taosDecodeStringTo(buf, pReq->user);
1,337✔
3455
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,674✔
3456
  } else {
3457
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3458
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3459
  }
3460

3461
  return 0;
1,337✔
3462
}
3463

3464
typedef struct {
3465
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3466
  SArray* removedConsumers;  // SArray<int64_t>
3467
  SArray* newConsumers;      // SArray<int64_t>
3468
} SMqRebInfo;
3469

3470
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3471
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,341!
3472
  if (pRebInfo == NULL) {
1,341!
3473
    return NULL;
×
3474
  }
3475
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,341✔
3476
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,341✔
3477
  if (pRebInfo->removedConsumers == NULL) {
1,341!
3478
    goto _err;
×
3479
  }
3480
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,341✔
3481
  if (pRebInfo->newConsumers == NULL) {
1,341!
3482
    goto _err;
×
3483
  }
3484
  return pRebInfo;
1,341✔
3485
_err:
×
3486
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3487
  taosArrayDestroy(pRebInfo->newConsumers);
×
3488
  taosMemoryFreeClear(pRebInfo);
×
3489
  return NULL;
×
3490
}
3491

3492
typedef struct {
3493
  int64_t streamId;
3494
  int64_t checkpointId;
3495
  char    streamName[TSDB_STREAM_FNAME_LEN];
3496
} SMStreamDoCheckpointMsg;
3497

3498
typedef struct {
3499
  int64_t status;
3500
} SMVSubscribeRsp;
3501

3502
typedef struct {
3503
  char    name[TSDB_TOPIC_FNAME_LEN];
3504
  int8_t  igNotExists;
3505
  int32_t sqlLen;
3506
  char*   sql;
3507
  int8_t  force;
3508
} SMDropTopicReq;
3509

3510
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3511
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3512
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3513

3514
typedef struct {
3515
  char   topic[TSDB_TOPIC_FNAME_LEN];
3516
  char   cgroup[TSDB_CGROUP_LEN];
3517
  int8_t igNotExists;
3518
  int8_t force;
3519
} SMDropCgroupReq;
3520

3521
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3522
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3523

3524
typedef struct {
3525
  int8_t reserved;
3526
} SMDropCgroupRsp;
3527

3528
typedef struct {
3529
  char    name[TSDB_TABLE_FNAME_LEN];
3530
  int8_t  alterType;
3531
  SSchema schema;
3532
} SAlterTopicReq;
3533

3534
typedef struct {
3535
  SMsgHead head;
3536
  char     name[TSDB_TABLE_FNAME_LEN];
3537
  int64_t  tuid;
3538
  int32_t  sverson;
3539
  int32_t  execLen;
3540
  char*    executor;
3541
  int32_t  sqlLen;
3542
  char*    sql;
3543
} SDCreateTopicReq;
3544

3545
typedef struct {
3546
  SMsgHead head;
3547
  char     name[TSDB_TABLE_FNAME_LEN];
3548
  int64_t  tuid;
3549
} SDDropTopicReq;
3550

3551
typedef struct {
3552
  int64_t maxdelay[2];
3553
  int64_t watermark[2];
3554
  int64_t deleteMark[2];
3555
  int32_t qmsgLen[2];
3556
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3557
} SRSmaParam;
3558

3559
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3560
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3561

3562
// TDMT_VND_CREATE_STB ==============
3563
typedef struct SVCreateStbReq {
3564
  char*           name;
3565
  tb_uid_t        suid;
3566
  int8_t          rollup;
3567
  SSchemaWrapper  schemaRow;
3568
  SSchemaWrapper  schemaTag;
3569
  SRSmaParam      rsmaParam;
3570
  int32_t         alterOriDataLen;
3571
  void*           alterOriData;
3572
  int8_t          source;
3573
  int8_t          colCmpred;
3574
  SColCmprWrapper colCmpr;
3575
  int64_t         keep;
3576
  SExtSchema*     pExtSchemas;
3577
  int8_t          virtualStb;
3578
} SVCreateStbReq;
3579

3580
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3581
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3582

3583
// TDMT_VND_DROP_STB ==============
3584
typedef struct SVDropStbReq {
3585
  char*    name;
3586
  tb_uid_t suid;
3587
} SVDropStbReq;
3588

3589
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3590
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3591

3592
// TDMT_VND_CREATE_TABLE ==============
3593
#define TD_CREATE_IF_NOT_EXISTS 0x1
3594
typedef struct SVCreateTbReq {
3595
  int32_t  flags;
3596
  char*    name;
3597
  tb_uid_t uid;
3598
  int64_t  btime;
3599
  int32_t  ttl;
3600
  int32_t  commentLen;
3601
  char*    comment;
3602
  int8_t   type;
3603
  union {
3604
    struct {
3605
      char*    stbName;  // super table name
3606
      uint8_t  tagNum;
3607
      tb_uid_t suid;
3608
      SArray*  tagName;
3609
      uint8_t* pTag;
3610
    } ctb;
3611
    struct {
3612
      SSchemaWrapper schemaRow;
3613
    } ntb;
3614
  };
3615
  int32_t         sqlLen;
3616
  char*           sql;
3617
  SColCmprWrapper colCmpr;
3618
  SExtSchema*     pExtSchemas;
3619
  SColRefWrapper  colRef;  // col reference for virtual table
3620
} SVCreateTbReq;
3621

3622
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3623
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3624
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3625

3626
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
2,454✔
3627
  if (NULL == req) {
6,244,160!
3628
    return;
5,975,573✔
3629
  }
3630

3631
  taosMemoryFreeClear(req->sql);
268,587!
3632
  taosMemoryFreeClear(req->name);
268,587!
3633
  taosMemoryFreeClear(req->comment);
268,617!
3634
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
268,617!
3635
    taosMemoryFreeClear(req->ctb.pTag);
254,407!
3636
    taosMemoryFreeClear(req->ctb.stbName);
254,479!
3637
    taosArrayDestroy(req->ctb.tagName);
254,479✔
3638
    req->ctb.tagName = NULL;
254,416✔
3639
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,210!
3640
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,210!
3641
  }
3642
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
268,625!
3643
  taosMemoryFreeClear(req->pExtSchemas);
268,626!
3644
  taosMemoryFreeClear(req->colRef.pColRef);
268,626!
3645
}
3646

3647
typedef struct {
3648
  int32_t nReqs;
3649
  union {
3650
    SVCreateTbReq* pReqs;
3651
    SArray*        pArray;
3652
  };
3653
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3654
} SVCreateTbBatchReq;
3655

3656
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3657
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3658
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3659

3660
typedef struct {
3661
  int32_t        code;
3662
  STableMetaRsp* pMeta;
3663
} SVCreateTbRsp, SVUpdateTbRsp;
3664

3665
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3666
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3667
void tFreeSVCreateTbRsp(void* param);
3668

3669
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3670
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3671

3672
typedef struct {
3673
  int32_t nRsps;
3674
  union {
3675
    SVCreateTbRsp* pRsps;
3676
    SArray*        pArray;
3677
  };
3678
} SVCreateTbBatchRsp;
3679

3680
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3681
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3682

3683
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3684
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3685

3686
// TDMT_VND_DROP_TABLE =================
3687
typedef struct {
3688
  char*    name;
3689
  uint64_t suid;  // for tmq in wal format
3690
  int64_t  uid;
3691
  int8_t   igNotExists;
3692
  int8_t   isVirtual;
3693
} SVDropTbReq;
3694

3695
typedef struct {
3696
  int32_t code;
3697
} SVDropTbRsp;
3698

3699
typedef struct {
3700
  int32_t nReqs;
3701
  union {
3702
    SVDropTbReq* pReqs;
3703
    SArray*      pArray;
3704
  };
3705
} SVDropTbBatchReq;
3706

3707
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3708
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3709

3710
typedef struct {
3711
  int32_t nRsps;
3712
  union {
3713
    SVDropTbRsp* pRsps;
3714
    SArray*      pArray;
3715
  };
3716
} SVDropTbBatchRsp;
3717

3718
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3719
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3720

3721
// TDMT_VND_ALTER_TABLE =====================
3722
typedef struct SMultiTagUpateVal {
3723
  char*    tagName;
3724
  int32_t  colId;
3725
  int8_t   tagType;
3726
  int8_t   tagFree;
3727
  uint32_t nTagVal;
3728
  uint8_t* pTagVal;
3729
  int8_t   isNull;
3730
  SArray*  pTagArray;
3731
} SMultiTagUpateVal;
3732
typedef struct SVAlterTbReq {
3733
  char*   tbName;
3734
  int8_t  action;
3735
  char*   colName;
3736
  int32_t colId;
3737
  // TSDB_ALTER_TABLE_ADD_COLUMN
3738
  int8_t  type;
3739
  int8_t  flags;
3740
  int32_t bytes;
3741
  // TSDB_ALTER_TABLE_DROP_COLUMN
3742
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3743
  int8_t   colModType;
3744
  int32_t  colModBytes;
3745
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3746
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3747
  int8_t   isNull;
3748
  int8_t   tagType;
3749
  int8_t   tagFree;
3750
  uint32_t nTagVal;
3751
  uint8_t* pTagVal;
3752
  SArray*  pTagArray;
3753
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3754
  int8_t   updateTTL;
3755
  int32_t  newTTL;
3756
  int32_t  newCommentLen;
3757
  char*    newComment;
3758
  int64_t  ctimeMs;    // fill by vnode
3759
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3760
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3761
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3762
  // for Add column
3763
  STypeMod typeMod;
3764
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3765
  char* refDbName;
3766
  char* refTbName;
3767
  char* refColName;
3768
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3769
} SVAlterTbReq;
3770

3771
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3772
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3773
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3774
void    tfreeMultiTagUpateVal(void* pMultiTag);
3775

3776
typedef struct {
3777
  int32_t        code;
3778
  STableMetaRsp* pMeta;
3779
} SVAlterTbRsp;
3780

3781
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3782
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3783
// ======================
3784

3785
typedef struct {
3786
  SMsgHead head;
3787
  int64_t  uid;
3788
  int32_t  tid;
3789
  int16_t  tversion;
3790
  int16_t  colId;
3791
  int8_t   type;
3792
  int16_t  bytes;
3793
  int32_t  tagValLen;
3794
  int16_t  numOfTags;
3795
  int32_t  schemaLen;
3796
  char     data[];
3797
} SUpdateTagValReq;
3798

3799
typedef struct {
3800
  SMsgHead head;
3801
} SUpdateTagValRsp;
3802

3803
typedef struct {
3804
  SMsgHead head;
3805
} SVShowTablesReq;
3806

3807
typedef struct {
3808
  SMsgHead head;
3809
  int32_t  id;
3810
} SVShowTablesFetchReq;
3811

3812
typedef struct {
3813
  int64_t useconds;
3814
  int8_t  completed;  // all results are returned to client
3815
  int8_t  precision;
3816
  int8_t  compressed;
3817
  int32_t compLen;
3818
  int32_t numOfRows;
3819
  char    data[];
3820
} SVShowTablesFetchRsp;
3821

3822
typedef struct {
3823
  int64_t consumerId;
3824
  int32_t epoch;
3825
  char    cgroup[TSDB_CGROUP_LEN];
3826
} SMqAskEpReq;
3827

3828
typedef struct {
3829
  int32_t key;
3830
  int32_t valueLen;
3831
  void*   value;
3832
} SKv;
3833

3834
typedef struct {
3835
  int64_t tscRid;
3836
  int8_t  connType;
3837
} SClientHbKey;
3838

3839
typedef struct {
3840
  int64_t tid;
3841
  char    status[TSDB_JOB_STATUS_LEN];
3842
} SQuerySubDesc;
3843

3844
typedef struct {
3845
  char     sql[TSDB_SHOW_SQL_LEN];
3846
  uint64_t queryId;
3847
  int64_t  useconds;
3848
  int64_t  stime;  // timestamp precision ms
3849
  int64_t  reqRid;
3850
  bool     stableQuery;
3851
  bool     isSubQuery;
3852
  char     fqdn[TSDB_FQDN_LEN];
3853
  int32_t  subPlanNum;
3854
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3855
} SQueryDesc;
3856

3857
typedef struct {
3858
  uint32_t connId;
3859
  SArray*  queryDesc;  // SArray<SQueryDesc>
3860
} SQueryHbReqBasic;
3861

3862
typedef struct {
3863
  uint32_t connId;
3864
  uint64_t killRid;
3865
  int32_t  totalDnodes;
3866
  int32_t  onlineDnodes;
3867
  int8_t   killConnection;
3868
  int8_t   align[3];
3869
  SEpSet   epSet;
3870
  SArray*  pQnodeList;
3871
} SQueryHbRspBasic;
3872

3873
typedef struct SAppClusterSummary {
3874
  uint64_t numOfInsertsReq;
3875
  uint64_t numOfInsertRows;
3876
  uint64_t insertElapsedTime;
3877
  uint64_t insertBytes;  // submit to tsdb since launched.
3878

3879
  uint64_t fetchBytes;
3880
  uint64_t numOfQueryReq;
3881
  uint64_t queryElapsedTime;
3882
  uint64_t numOfSlowQueries;
3883
  uint64_t totalRequests;
3884
  uint64_t currentRequests;  // the number of SRequestObj
3885
} SAppClusterSummary;
3886

3887
typedef struct {
3888
  int64_t            appId;
3889
  int32_t            pid;
3890
  char               name[TSDB_APP_NAME_LEN];
3891
  int64_t            startTime;
3892
  SAppClusterSummary summary;
3893
} SAppHbReq;
3894

3895
typedef struct {
3896
  SClientHbKey      connKey;
3897
  int64_t           clusterId;
3898
  SAppHbReq         app;
3899
  SQueryHbReqBasic* query;
3900
  SHashObj*         info;  // hash<Skv.key, Skv>
3901
  char              userApp[TSDB_APP_NAME_LEN];
3902
  uint32_t          userIp;
3903
  SIpRange          userDualIp;
3904
} SClientHbReq;
3905

3906
typedef struct {
3907
  int64_t reqId;
3908
  SArray* reqs;  // SArray<SClientHbReq>
3909
  int64_t ipWhiteListVer;
3910
} SClientHbBatchReq;
3911

3912
typedef struct {
3913
  SClientHbKey      connKey;
3914
  int32_t           status;
3915
  SQueryHbRspBasic* query;
3916
  SArray*           info;  // Array<Skv>
3917
} SClientHbRsp;
3918

3919
typedef struct {
3920
  int64_t       reqId;
3921
  int64_t       rspId;
3922
  int32_t       svrTimestamp;
3923
  SArray*       rsps;  // SArray<SClientHbRsp>
3924
  SMonitorParas monitorParas;
3925
  int8_t        enableAuditDelete;
3926
  int8_t        enableStrongPass;
3927
} SClientHbBatchRsp;
3928

3929
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
262,029✔
3930

3931
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3932
  void* pIter = taosHashIterate(info, NULL);
120,468✔
3933
  while (pIter != NULL) {
244,206!
3934
    SKv* kv = (SKv*)pIter;
123,739✔
3935
    taosMemoryFreeClear(kv->value);
123,739!
3936
    pIter = taosHashIterate(info, pIter);
123,739✔
3937
  }
3938
}
120,467✔
3939

3940
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
65,936✔
3941
  SQueryDesc* desc = (SQueryDesc*)pDesc;
65,936✔
3942
  if (desc->subDesc) {
65,936✔
3943
    taosArrayDestroy(desc->subDesc);
57,553✔
3944
    desc->subDesc = NULL;
57,553✔
3945
  }
3946
}
65,936✔
3947

3948
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
177,610✔
3949
  SClientHbReq* req = (SClientHbReq*)pReq;
208,381✔
3950
  if (req->query) {
208,381!
3951
    if (req->query->queryDesc) {
165,072!
3952
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
47,951✔
3953
    }
3954
    taosMemoryFreeClear(req->query);
165,072!
3955
  }
3956

3957
  if (req->info) {
208,382!
3958
    tFreeReqKvHash(req->info);
120,468✔
3959
    taosHashCleanup(req->info);
120,467✔
3960
    req->info = NULL;
120,469✔
3961
  }
3962
}
108,993✔
3963

3964
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3965
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3966

3967
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3968
  if (pReq == NULL) return;
53,659!
3969
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
53,659✔
3970
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
53,659✔
3971
  taosMemoryFree(pReq);
53,659!
3972
}
3973

3974
static FORCE_INLINE void tFreeClientKv(void* pKv) {
46,938✔
3975
  SKv* kv = (SKv*)pKv;
46,938✔
3976
  if (kv) {
46,938!
3977
    taosMemoryFreeClear(kv->value);
46,938!
3978
  }
3979
}
46,939✔
3980

3981
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
173,690✔
3982
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
173,690✔
3983
  if (rsp->query) {
173,690✔
3984
    taosArrayDestroy(rsp->query->pQnodeList);
161,216✔
3985
    taosMemoryFreeClear(rsp->query);
161,218!
3986
  }
3987
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
173,691!
3988
}
95,472✔
3989

3990
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3991
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
101,582✔
3992
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
101,582✔
3993
}
101,580✔
3994

3995
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3996
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3997
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3998

3999
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4000
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
350,654!
4001
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
350,654!
4002
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
350,654!
4003
  return 0;
175,327✔
4004
}
4005

4006
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4007
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
165,869!
4008
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
165,868!
4009
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
82,934!
4010
  if (pKv->value == NULL) {
82,935!
4011
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4012
  }
4013
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
82,935!
4014
  return 0;
82,935✔
4015
}
4016

4017
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4018
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
709,532!
4019
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
709,532!
4020
  return 0;
354,766✔
4021
}
4022

4023
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4024
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
346,928!
4025
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
346,928!
4026
  return 0;
173,464✔
4027
}
4028

4029
typedef struct {
4030
  int32_t vgId;
4031
  // TODO stas
4032
} SMqReportVgInfo;
4033

4034
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4035
  int32_t tlen = 0;
4036
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4037
  return tlen;
4038
}
4039

4040
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4041
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4042
  return buf;
4043
}
4044

4045
typedef struct {
4046
  int32_t epoch;
4047
  int64_t topicUid;
4048
  char    name[TSDB_TOPIC_FNAME_LEN];
4049
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4050
} SMqTopicInfo;
4051

4052
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4053
  int32_t tlen = 0;
4054
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4055
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4056
  tlen += taosEncodeString(buf, pTopicInfo->name);
4057
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4058
  tlen += taosEncodeFixedI32(buf, sz);
4059
  for (int32_t i = 0; i < sz; i++) {
4060
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4061
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4062
  }
4063
  return tlen;
4064
}
4065

4066
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4067
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4068
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4069
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4070
  int32_t sz;
4071
  buf = taosDecodeFixedI32(buf, &sz);
4072
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4073
    return NULL;
4074
  }
4075
  for (int32_t i = 0; i < sz; i++) {
4076
    SMqReportVgInfo vgInfo;
4077
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4078
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4079
      return NULL;
4080
    }
4081
  }
4082
  return buf;
4083
}
4084

4085
typedef struct {
4086
  int32_t status;  // ask hb endpoint
4087
  int32_t epoch;
4088
  int64_t consumerId;
4089
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4090
} SMqReportReq;
4091

4092
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4093
  int32_t tlen = 0;
4094
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4095
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4096
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4097
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4098
  tlen += taosEncodeFixedI32(buf, sz);
4099
  for (int32_t i = 0; i < sz; i++) {
4100
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4101
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4102
  }
4103
  return tlen;
4104
}
4105

4106
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4107
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4108
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4109
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4110
  int32_t sz;
4111
  buf = taosDecodeFixedI32(buf, &sz);
4112
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4113
    return NULL;
4114
  }
4115
  for (int32_t i = 0; i < sz; i++) {
4116
    SMqTopicInfo topicInfo;
4117
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4118
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4119
      return NULL;
4120
    }
4121
  }
4122
  return buf;
4123
}
4124

4125
typedef struct {
4126
  SMsgHead head;
4127
  int64_t  leftForVer;
4128
  int32_t  vgId;
4129
  int64_t  consumerId;
4130
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4131
} SMqVDeleteReq;
4132

4133
typedef struct {
4134
  int8_t reserved;
4135
} SMqVDeleteRsp;
4136

4137
typedef struct {
4138
  char    name[TSDB_STREAM_FNAME_LEN];
4139
  int8_t  igNotExists;
4140
  int32_t sqlLen;
4141
  char*   sql;
4142
} SMDropStreamReq;
4143

4144
typedef struct {
4145
  int8_t reserved;
4146
} SMDropStreamRsp;
4147

4148
typedef struct {
4149
  SMsgHead head;
4150
  int64_t  resetRelHalt;  // reset related stream task halt status
4151
  int64_t  streamId;
4152
  int32_t  taskId;
4153
} SVDropStreamTaskReq;
4154

4155
typedef struct {
4156
  int8_t reserved;
4157
} SVDropStreamTaskRsp;
4158

4159
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4160
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4161
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4162

4163
typedef struct SVUpdateCheckpointInfoReq {
4164
  SMsgHead head;
4165
  int64_t  streamId;
4166
  int32_t  taskId;
4167
  int64_t  checkpointId;
4168
  int64_t  checkpointVer;
4169
  int64_t  checkpointTs;
4170
  int32_t  transId;
4171
  int64_t  hStreamId;  // add encode/decode
4172
  int64_t  hTaskId;
4173
  int8_t   dropRelHTask;
4174
} SVUpdateCheckpointInfoReq;
4175

4176
typedef struct {
4177
  int64_t leftForVer;
4178
  int32_t vgId;
4179
  int64_t oldConsumerId;
4180
  int64_t newConsumerId;
4181
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4182
  int8_t  subType;
4183
  int8_t  withMeta;
4184
  char*   qmsg;  // SubPlanToString
4185
  int64_t suid;
4186
} SMqRebVgReq;
4187

4188
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4189
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4190

4191
typedef struct {
4192
  char    topic[TSDB_TOPIC_FNAME_LEN];
4193
  int64_t ntbUid;
4194
  SArray* colIdList;  // SArray<int16_t>
4195
} STqCheckInfo;
4196

4197
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4198
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4199
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4200

4201
// tqOffset
4202
enum {
4203
  TMQ_OFFSET__RESET_NONE = -3,
4204
  TMQ_OFFSET__RESET_EARLIEST = -2,
4205
  TMQ_OFFSET__RESET_LATEST = -1,
4206
  TMQ_OFFSET__LOG = 1,
4207
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4208
  TMQ_OFFSET__SNAPSHOT_META = 3,
4209
};
4210

4211
enum {
4212
  WITH_DATA = 0,
4213
  WITH_META = 1,
4214
  ONLY_META = 2,
4215
};
4216

4217
#define TQ_OFFSET_VERSION 1
4218

4219
typedef struct {
4220
  int8_t type;
4221
  union {
4222
    // snapshot
4223
    struct {
4224
      int64_t uid;
4225
      int64_t ts;
4226
      SValue  primaryKey;
4227
    };
4228
    // log
4229
    struct {
4230
      int64_t version;
4231
    };
4232
  };
4233
} STqOffsetVal;
4234

4235
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4236
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,129✔
4237
  pOffsetVal->uid = uid;
26,129✔
4238
  pOffsetVal->ts = ts;
26,129✔
4239
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,129!
4240
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4241
  }
4242
  pOffsetVal->primaryKey = primaryKey;
26,137✔
4243
}
26,137✔
4244

4245
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4246
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
4247
  pOffsetVal->uid = uid;
148✔
4248
}
148✔
4249

4250
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4251
  pOffsetVal->type = TMQ_OFFSET__LOG;
532,028✔
4252
  pOffsetVal->version = ver;
532,028✔
4253
}
532,028✔
4254

4255
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4256
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4257
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4258
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4259
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4260
void    tOffsetDestroy(void* pVal);
4261

4262
typedef struct {
4263
  STqOffsetVal val;
4264
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4265
} STqOffset;
4266

4267
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4268
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4269
void    tDeleteSTqOffset(void* val);
4270

4271
typedef struct SMqVgOffset {
4272
  int64_t   consumerId;
4273
  STqOffset offset;
4274
} SMqVgOffset;
4275

4276
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4277
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4278

4279
typedef struct {
4280
  SMsgHead head;
4281
  int64_t  streamId;
4282
  int32_t  taskId;
4283
} SVPauseStreamTaskReq;
4284

4285
typedef struct {
4286
  SMsgHead head;
4287
  int64_t  streamId;
4288
  int32_t  taskId;
4289
  int64_t  chkptId;
4290
} SVResetStreamTaskReq;
4291

4292
typedef struct {
4293
  char   name[TSDB_STREAM_FNAME_LEN];
4294
  int8_t igNotExists;
4295
} SMPauseStreamReq;
4296

4297
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4298
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4299

4300
typedef struct {
4301
  SMsgHead head;
4302
  int32_t  taskId;
4303
  int64_t  streamId;
4304
  int8_t   igUntreated;
4305
} SVResumeStreamTaskReq;
4306

4307
typedef struct {
4308
  int8_t reserved;
4309
} SVResumeStreamTaskRsp;
4310

4311
typedef struct {
4312
  char   name[TSDB_STREAM_FNAME_LEN];
4313
  int8_t igNotExists;
4314
  int8_t igUntreated;
4315
} SMResumeStreamReq;
4316

4317
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4318
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4319

4320
typedef struct {
4321
  char   name[TSDB_STREAM_FNAME_LEN];
4322
  int8_t igNotExists;
4323
  int8_t igUntreated;
4324
} SMResetStreamReq;
4325

4326
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4327
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4328

4329
typedef struct {
4330
  char    name[TSDB_TABLE_FNAME_LEN];
4331
  char    stb[TSDB_TABLE_FNAME_LEN];
4332
  int8_t  igExists;
4333
  int8_t  intervalUnit;
4334
  int8_t  slidingUnit;
4335
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4336
  int32_t dstVgId;   // for stream
4337
  int64_t interval;
4338
  int64_t offset;
4339
  int64_t sliding;
4340
  int64_t maxDelay;
4341
  int64_t watermark;
4342
  int32_t exprLen;        // strlen + 1
4343
  int32_t tagsFilterLen;  // strlen + 1
4344
  int32_t sqlLen;         // strlen + 1
4345
  int32_t astLen;         // strlen + 1
4346
  char*   expr;
4347
  char*   tagsFilter;
4348
  char*   sql;
4349
  char*   ast;
4350
  int64_t deleteMark;
4351
  int64_t lastTs;
4352
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4353
  SArray* pVgroupVerList;
4354
  int8_t  recursiveTsma;
4355
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4356
} SMCreateSmaReq;
4357

4358
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4359
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4360
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4361

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

4367
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4368
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4369

4370
typedef struct {
4371
  char   dbFName[TSDB_DB_FNAME_LEN];
4372
  char   stbName[TSDB_TABLE_NAME_LEN];
4373
  char   colName[TSDB_COL_NAME_LEN];
4374
  char   idxName[TSDB_INDEX_FNAME_LEN];
4375
  int8_t idxType;
4376
} SCreateTagIndexReq;
4377

4378
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4379
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4380

4381
typedef SMDropSmaReq SDropTagIndexReq;
4382

4383
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4384
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4385

4386
typedef struct {
4387
  int8_t         version;       // for compatibility(default 0)
4388
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4389
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4390
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4391
  int32_t        dstVgId;
4392
  char           indexName[TSDB_INDEX_NAME_LEN];
4393
  int32_t        exprLen;
4394
  int32_t        tagsFilterLen;
4395
  int64_t        indexUid;
4396
  tb_uid_t       tableUid;  // super/child/common table uid
4397
  tb_uid_t       dstTbUid;  // for dstVgroup
4398
  int64_t        interval;
4399
  int64_t        offset;  // use unit by precision of DB
4400
  int64_t        sliding;
4401
  char*          dstTbName;  // for dstVgroup
4402
  char*          expr;       // sma expression
4403
  char*          tagsFilter;
4404
  SSchemaWrapper schemaRow;  // for dstVgroup
4405
  SSchemaWrapper schemaTag;  // for dstVgroup
4406
} STSma;                     // Time-range-wise SMA
4407

4408
typedef STSma SVCreateTSmaReq;
4409

4410
typedef struct {
4411
  int8_t  type;  // 0 status report, 1 update data
4412
  int64_t indexUid;
4413
  int64_t skey;  // start TS key of interval/sliding window
4414
} STSmaMsg;
4415

4416
typedef struct {
4417
  int64_t indexUid;
4418
  char    indexName[TSDB_INDEX_NAME_LEN];
4419
} SVDropTSmaReq;
4420

4421
typedef struct {
4422
  int tmp;  // TODO: to avoid compile error
4423
} SVCreateTSmaRsp, SVDropTSmaRsp;
4424

4425
#if 0
4426
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4427
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4428
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4429
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4430
#endif
4431

4432
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4433
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4434
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4435
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4436

4437
typedef struct {
4438
  int32_t number;
4439
  STSma*  tSma;
4440
} STSmaWrapper;
4441

4442
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4443
  if (pSma) {
×
4444
    taosMemoryFreeClear(pSma->dstTbName);
×
4445
    taosMemoryFreeClear(pSma->expr);
×
4446
    taosMemoryFreeClear(pSma->tagsFilter);
×
4447
  }
4448
}
×
4449

4450
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4451
  if (pSW) {
×
4452
    if (pSW->tSma) {
×
4453
      if (deepCopy) {
×
4454
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4455
          tDestroyTSma(pSW->tSma + i);
×
4456
        }
4457
      }
4458
      taosMemoryFreeClear(pSW->tSma);
×
4459
    }
4460
  }
4461
}
×
4462

4463
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4464
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4465
  taosMemoryFreeClear(pSW);
×
4466
  return NULL;
×
4467
}
4468

4469
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4470
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4471

4472
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4473
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4474

4475
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4476
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4477
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4478
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4479
  }
4480
  return 0;
×
4481
}
4482

4483
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4484
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4485
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4486
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4487
  }
4488
  return 0;
×
4489
}
4490

4491
typedef struct {
4492
  int idx;
4493
} SMCreateFullTextReq;
4494

4495
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4496
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4497
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4498

4499
typedef struct {
4500
  char   name[TSDB_TABLE_FNAME_LEN];
4501
  int8_t igNotExists;
4502
} SMDropFullTextReq;
4503

4504
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4505
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4506

4507
typedef struct {
4508
  char indexFName[TSDB_INDEX_FNAME_LEN];
4509
} SUserIndexReq;
4510

4511
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4512
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4513

4514
typedef struct {
4515
  char dbFName[TSDB_DB_FNAME_LEN];
4516
  char tblFName[TSDB_TABLE_FNAME_LEN];
4517
  char colName[TSDB_COL_NAME_LEN];
4518
  char indexType[TSDB_INDEX_TYPE_LEN];
4519
  char indexExts[TSDB_INDEX_EXTS_LEN];
4520
} SUserIndexRsp;
4521

4522
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4523
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4524

4525
typedef struct {
4526
  char tbFName[TSDB_TABLE_FNAME_LEN];
4527
} STableIndexReq;
4528

4529
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4530
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4531

4532
typedef struct {
4533
  int8_t  intervalUnit;
4534
  int8_t  slidingUnit;
4535
  int64_t interval;
4536
  int64_t offset;
4537
  int64_t sliding;
4538
  int64_t dstTbUid;
4539
  int32_t dstVgId;
4540
  SEpSet  epSet;
4541
  char*   expr;
4542
} STableIndexInfo;
4543

4544
typedef struct {
4545
  char     tbName[TSDB_TABLE_NAME_LEN];
4546
  char     dbFName[TSDB_DB_FNAME_LEN];
4547
  uint64_t suid;
4548
  int32_t  version;
4549
  int32_t  indexSize;
4550
  SArray*  pIndex;  // STableIndexInfo
4551
} STableIndexRsp;
4552

4553
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4554
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4555
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4556

4557
void tFreeSTableIndexInfo(void* pInfo);
4558

4559
typedef struct {
4560
  int8_t  mqMsgType;
4561
  int32_t code;
4562
  int32_t epoch;
4563
  int64_t consumerId;
4564
  int64_t walsver;
4565
  int64_t walever;
4566
} SMqRspHead;
4567

4568
typedef struct {
4569
  SMsgHead     head;
4570
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4571
  int8_t       withTbName;
4572
  int8_t       useSnapshot;
4573
  int32_t      epoch;
4574
  uint64_t     reqId;
4575
  int64_t      consumerId;
4576
  int64_t      timeout;
4577
  STqOffsetVal reqOffset;
4578
  int8_t       enableReplay;
4579
  int8_t       sourceExcluded;
4580
  int8_t       rawData;
4581
  int32_t      minPollRows;
4582
  int8_t       enableBatchMeta;
4583
  SHashObj*    uidHash;  // to find if uid is duplicated
4584
} SMqPollReq;
4585

4586
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4587
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4588
void    tDestroySMqPollReq(SMqPollReq* pReq);
4589

4590
typedef struct {
4591
  int32_t vgId;
4592
  int64_t offset;
4593
  SEpSet  epSet;
4594
} SMqSubVgEp;
4595

4596
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4597
  int32_t tlen = 0;
9,326✔
4598
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
9,326✔
4599
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
9,326✔
4600
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
9,326✔
4601
  return tlen;
9,326✔
4602
}
4603

4604
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4605
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,517!
4606
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,517!
4607
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,517✔
4608
  return buf;
4,517✔
4609
}
4610

4611
typedef struct {
4612
  char           topic[TSDB_TOPIC_FNAME_LEN];
4613
  char           db[TSDB_DB_FNAME_LEN];
4614
  SArray*        vgs;  // SArray<SMqSubVgEp>
4615
  SSchemaWrapper schema;
4616
} SMqSubTopicEp;
4617

4618
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4619
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4620
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4621

4622
typedef struct {
4623
  SMqRspHead   head;
4624
  STqOffsetVal rspOffset;
4625
  int16_t      resMsgType;
4626
  int32_t      metaRspLen;
4627
  void*        metaRsp;
4628
} SMqMetaRsp;
4629

4630
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4631
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4632
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4633

4634
#define MQ_DATA_RSP_VERSION 100
4635

4636
typedef struct {
4637
  SMqRspHead   head;
4638
  STqOffsetVal rspOffset;
4639
  STqOffsetVal reqOffset;
4640
  int32_t      blockNum;
4641
  int8_t       withTbName;
4642
  int8_t       withSchema;
4643
  SArray*      blockDataLen;
4644
  SArray*      blockData;
4645
  SArray*      blockTbName;
4646
  SArray*      blockSchema;
4647

4648
  union {
4649
    struct {
4650
      int64_t sleepTime;
4651
    };
4652
    struct {
4653
      int32_t createTableNum;
4654
      SArray* createTableLen;
4655
      SArray* createTableReq;
4656
    };
4657
    struct {
4658
      int32_t len;
4659
      void*   rawData;
4660
    };
4661
  };
4662
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4663
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4664
} SMqDataRsp;
4665

4666
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4667
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4668
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4669
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4670
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4671

4672
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4673
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4674
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4675

4676
typedef struct SMqBatchMetaRsp {
4677
  SMqRspHead   head;  // not serialize
4678
  STqOffsetVal rspOffset;
4679
  SArray*      batchMetaLen;
4680
  SArray*      batchMetaReq;
4681
  void*        pMetaBuff;    // not serialize
4682
  uint32_t     metaBuffLen;  // not serialize
4683
} SMqBatchMetaRsp;
4684

4685
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4686
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4687
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4688
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4689

4690
typedef struct {
4691
  SMqRspHead head;
4692
  char       cgroup[TSDB_CGROUP_LEN];
4693
  SArray*    topics;  // SArray<SMqSubTopicEp>
4694
} SMqAskEpRsp;
4695

4696
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4697
  int32_t tlen = 0;
18,281✔
4698
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4699
  int32_t sz = taosArrayGetSize(pRsp->topics);
18,281!
4700
  tlen += taosEncodeFixedI32(buf, sz);
18,282✔
4701
  for (int32_t i = 0; i < sz; i++) {
25,742✔
4702
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,460✔
4703
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,460✔
4704
  }
4705
  return tlen;
18,282✔
4706
}
4707

4708
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4709
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4710
  int32_t sz;
4711
  buf = taosDecodeFixedI32(buf, &sz);
8,617✔
4712
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,617✔
4713
  if (pRsp->topics == NULL) {
8,617!
4714
    return NULL;
×
4715
  }
4716
  for (int32_t i = 0; i < sz; i++) {
12,251✔
4717
    SMqSubTopicEp topicEp;
4718
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,634✔
4719
    if (buf == NULL) {
3,634!
4720
      return NULL;
×
4721
    }
4722
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
7,268!
4723
      return NULL;
×
4724
    }
4725
  }
4726
  return buf;
8,617✔
4727
}
4728

4729
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4730
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,708✔
4731
}
20,708✔
4732

4733
typedef struct {
4734
  int32_t      vgId;
4735
  STqOffsetVal offset;
4736
  int64_t      rows;
4737
  int64_t      ever;
4738
} OffsetRows;
4739

4740
typedef struct {
4741
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4742
  SArray* offsetRows;
4743
} TopicOffsetRows;
4744

4745
typedef struct {
4746
  int64_t consumerId;
4747
  int32_t epoch;
4748
  SArray* topics;
4749
  int8_t  pollFlag;
4750
} SMqHbReq;
4751

4752
typedef struct {
4753
  char   topic[TSDB_TOPIC_FNAME_LEN];
4754
  int8_t noPrivilege;
4755
} STopicPrivilege;
4756

4757
typedef struct {
4758
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4759
  int32_t debugFlag;
4760
} SMqHbRsp;
4761

4762
typedef struct {
4763
  SMsgHead head;
4764
  int64_t  consumerId;
4765
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4766
} SMqSeekReq;
4767

4768
#define TD_AUTO_CREATE_TABLE 0x1
4769
typedef struct {
4770
  int64_t       suid;
4771
  int64_t       uid;
4772
  int32_t       sver;
4773
  uint32_t      nData;
4774
  uint8_t*      pData;
4775
  SVCreateTbReq cTbReq;
4776
} SVSubmitBlk;
4777

4778
typedef struct {
4779
  SMsgHead header;
4780
  uint64_t sId;
4781
  uint64_t queryId;
4782
  uint64_t clientId;
4783
  uint64_t taskId;
4784
  uint32_t sqlLen;
4785
  uint32_t phyLen;
4786
  char*    sql;
4787
  char*    msg;
4788
  int8_t   source;
4789
} SVDeleteReq;
4790

4791
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4792
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4793

4794
typedef struct {
4795
  int64_t affectedRows;
4796
} SVDeleteRsp;
4797

4798
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4799
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4800

4801
typedef struct SDeleteRes {
4802
  uint64_t suid;
4803
  SArray*  uidList;
4804
  int64_t  skey;
4805
  int64_t  ekey;
4806
  int64_t  affectedRows;
4807
  char     tableFName[TSDB_TABLE_NAME_LEN];
4808
  char     tsColName[TSDB_COL_NAME_LEN];
4809
  int64_t  ctimeMs;  // fill by vnode
4810
  int8_t   source;
4811
} SDeleteRes;
4812

4813
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4814
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4815

4816
typedef struct {
4817
  // int64_t uid;
4818
  char    tbname[TSDB_TABLE_NAME_LEN];
4819
  int64_t startTs;
4820
  int64_t endTs;
4821
} SSingleDeleteReq;
4822

4823
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4824
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4825

4826
typedef struct {
4827
  int64_t suid;
4828
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4829
  int64_t ctimeMs;     // fill by vnode
4830
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4831
} SBatchDeleteReq;
4832

4833
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4834
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4835
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4836

4837
typedef struct {
4838
  int32_t msgIdx;
4839
  int32_t msgType;
4840
  int32_t msgLen;
4841
  void*   msg;
4842
} SBatchMsg;
4843

4844
typedef struct {
4845
  SMsgHead header;
4846
  SArray*  pMsgs;  // SArray<SBatchMsg>
4847
} SBatchReq;
4848

4849
typedef struct {
4850
  int32_t reqType;
4851
  int32_t msgIdx;
4852
  int32_t msgLen;
4853
  int32_t rspCode;
4854
  void*   msg;
4855
} SBatchRspMsg;
4856

4857
typedef struct {
4858
  SArray* pRsps;  // SArray<SBatchRspMsg>
4859
} SBatchRsp;
4860

4861
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4862
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4863
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
467,522✔
4864
  if (NULL == msg) {
467,522!
4865
    return;
×
4866
  }
4867
  SBatchMsg* pMsg = (SBatchMsg*)msg;
467,522✔
4868
  taosMemoryFree(pMsg->msg);
467,522!
4869
}
4870

4871
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4872
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4873

4874
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
560,823✔
4875
  if (NULL == p) {
560,823!
4876
    return;
×
4877
  }
4878

4879
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
560,823✔
4880
  taosMemoryFree(pRsp->msg);
560,823!
4881
}
4882

4883
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4884
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4885
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4886
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4887
void    tDestroySMqHbReq(SMqHbReq* pReq);
4888

4889
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4890
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4891
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4892

4893
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4894
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4895

4896
#define TD_REQ_FROM_APP               0x0
4897
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4898
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4899
#define SUBMIT_REQ_FROM_FILE          0x4
4900
#define TD_REQ_FROM_TAOX              0x8
4901
#define TD_REQ_FROM_SML               0x10
4902
#define SUBMIT_REQUEST_VERSION        (1)
4903

4904
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4905

4906
typedef struct {
4907
  int32_t        flags;
4908
  SVCreateTbReq* pCreateTbReq;
4909
  int64_t        suid;
4910
  int64_t        uid;
4911
  int32_t        sver;
4912
  union {
4913
    SArray* aRowP;
4914
    SArray* aCol;
4915
  };
4916
  int64_t ctimeMs;
4917
} SSubmitTbData;
4918

4919
typedef struct {
4920
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4921
  bool    raw;
4922
} SSubmitReq2;
4923

4924
typedef struct {
4925
  SMsgHead header;
4926
  int64_t  version;
4927
  char     data[];  // SSubmitReq2
4928
} SSubmitReq2Msg;
4929

4930
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4931
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4932
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4933
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4934
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4935

4936
typedef struct {
4937
  int32_t affectedRows;
4938
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4939
} SSubmitRsp2;
4940

4941
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4942
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4943
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4944

4945
#define TSDB_MSG_FLG_ENCODE 0x1
4946
#define TSDB_MSG_FLG_DECODE 0x2
4947
#define TSDB_MSG_FLG_CMPT   0x3
4948

4949
typedef struct {
4950
  union {
4951
    struct {
4952
      void*   msgStr;
4953
      int32_t msgLen;
4954
      int64_t ver;
4955
    };
4956
    void* pDataBlock;
4957
  };
4958
} SPackedData;
4959

4960
typedef struct {
4961
  char     fullname[TSDB_VIEW_FNAME_LEN];
4962
  char     name[TSDB_VIEW_NAME_LEN];
4963
  char     dbFName[TSDB_DB_FNAME_LEN];
4964
  char*    querySql;
4965
  char*    sql;
4966
  int8_t   orReplace;
4967
  int8_t   precision;
4968
  int32_t  numOfCols;
4969
  SSchema* pSchema;
4970
} SCMCreateViewReq;
4971

4972
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4973
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4974
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4975

4976
typedef struct {
4977
  char   fullname[TSDB_VIEW_FNAME_LEN];
4978
  char   name[TSDB_VIEW_NAME_LEN];
4979
  char   dbFName[TSDB_DB_FNAME_LEN];
4980
  char*  sql;
4981
  int8_t igNotExists;
4982
} SCMDropViewReq;
4983

4984
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4985
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4986
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4987

4988
typedef struct {
4989
  char fullname[TSDB_VIEW_FNAME_LEN];
4990
} SViewMetaReq;
4991
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4992
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4993

4994
typedef struct {
4995
  char     name[TSDB_VIEW_NAME_LEN];
4996
  char     dbFName[TSDB_DB_FNAME_LEN];
4997
  char*    user;
4998
  uint64_t dbId;
4999
  uint64_t viewId;
5000
  char*    querySql;
5001
  int8_t   precision;
5002
  int8_t   type;
5003
  int32_t  version;
5004
  int32_t  numOfCols;
5005
  SSchema* pSchema;
5006
} SViewMetaRsp;
5007
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5008
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5009
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5010
typedef struct {
5011
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5012
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5013
} STableTSMAInfoReq;
5014

5015
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5016
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5017

5018
typedef struct {
5019
  int32_t  funcId;
5020
  col_id_t colId;
5021
} STableTSMAFuncInfo;
5022

5023
typedef struct {
5024
  char     name[TSDB_TABLE_NAME_LEN];
5025
  uint64_t tsmaId;
5026
  char     targetTb[TSDB_TABLE_NAME_LEN];
5027
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5028
  char     tb[TSDB_TABLE_NAME_LEN];
5029
  char     dbFName[TSDB_DB_FNAME_LEN];
5030
  uint64_t suid;
5031
  uint64_t destTbUid;
5032
  uint64_t dbId;
5033
  int32_t  version;
5034
  int64_t  interval;
5035
  int8_t   unit;
5036
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5037
  SArray*  pTags;      // SArray<SSchema>
5038
  SArray*  pUsedCols;  // SArray<SSchema>
5039
  char*    ast;
5040

5041
  int64_t streamUid;
5042
  int64_t reqTs;
5043
  int64_t rspTs;
5044
  int64_t delayDuration;  // ms
5045
  bool    fillHistoryFinished;
5046
} STableTSMAInfo;
5047

5048
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5049
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5050
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5051
void    tFreeTableTSMAInfo(void* p);
5052
void    tFreeAndClearTableTSMAInfo(void* p);
5053
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5054

5055
#define STSMAHbRsp            STableTSMAInfoRsp
5056
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5057
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5058
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5059

5060
typedef struct SStreamProgressReq {
5061
  int64_t streamId;
5062
  int32_t vgId;
5063
  int32_t fetchIdx;
5064
  int32_t subFetchIdx;
5065
} SStreamProgressReq;
5066

5067
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
5068
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
5069

5070
typedef struct SStreamProgressRsp {
5071
  int64_t streamId;
5072
  int32_t vgId;
5073
  bool    fillHisFinished;
5074
  int64_t progressDelay;
5075
  int32_t fetchIdx;
5076
  int32_t subFetchIdx;
5077
} SStreamProgressRsp;
5078

5079
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
5080
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
5081

5082
typedef struct SDropCtbWithTsmaSingleVgReq {
5083
  SVgroupInfo vgInfo;
5084
  SArray*     pTbs;  // SVDropTbReq
5085
} SMDropTbReqsOnSingleVg;
5086

5087
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5088
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5089
void    tFreeSMDropTbReqOnSingleVg(void* p);
5090

5091
typedef struct SDropTbsReq {
5092
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5093
} SMDropTbsReq;
5094

5095
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5096
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5097
void    tFreeSMDropTbsReq(void*);
5098

5099
typedef struct SVFetchTtlExpiredTbsRsp {
5100
  SArray* pExpiredTbs;  // SVDropTbReq
5101
  int32_t vgId;
5102
} SVFetchTtlExpiredTbsRsp;
5103

5104
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5105
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5106

5107
void tFreeFetchTtlExpiredTbsRsp(void* p);
5108

5109
void setDefaultOptionsForField(SFieldWithOptions* field);
5110
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5111

5112
#ifdef USE_MOUNT
5113
typedef struct {
5114
  char     mountName[TSDB_MOUNT_NAME_LEN];
5115
  int8_t   ignoreExist;
5116
  int16_t  nMounts;
5117
  int32_t* dnodeIds;
5118
  char**   mountPaths;
5119
  int32_t  sqlLen;
5120
  char*    sql;
5121
} SCreateMountReq;
5122

5123
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5124
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5125
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5126

5127
typedef struct {
5128
  char    mountName[TSDB_MOUNT_NAME_LEN];
5129
  int8_t  ignoreNotExists;
5130
  int32_t sqlLen;
5131
  char*   sql;
5132
} SDropMountReq;
5133

5134
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5135
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5136
void    tFreeSDropMountReq(SDropMountReq* pReq);
5137

5138
typedef struct {
5139
  char     mountName[TSDB_MOUNT_NAME_LEN];
5140
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5141
  int64_t  mountUid;
5142
  int32_t  dnodeId;
5143
  uint32_t valLen;
5144
  int8_t   ignoreExist;
5145
  void*    pVal;
5146
} SRetrieveMountPathReq;
5147

5148
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5149
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5150

5151
typedef struct {
5152
  // path
5153
  int32_t diskPrimary;
5154
  // vgInfo
5155
  int32_t  vgId;
5156
  int32_t  cacheLastSize;
5157
  int32_t  szPage;
5158
  int32_t  szCache;
5159
  uint64_t szBuf;
5160
  int8_t   cacheLast;
5161
  int8_t   standby;
5162
  int8_t   hashMethod;
5163
  uint32_t hashBegin;
5164
  uint32_t hashEnd;
5165
  int16_t  hashPrefix;
5166
  int16_t  hashSuffix;
5167
  int16_t  sttTrigger;
5168
  // syncInfo
5169
  int32_t replications;
5170
  // tsdbInfo
5171
  int8_t  precision;
5172
  int8_t  compression;
5173
  int8_t  slLevel;
5174
  int32_t daysPerFile;
5175
  int32_t keep0;
5176
  int32_t keep1;
5177
  int32_t keep2;
5178
  int32_t keepTimeOffset;
5179
  int32_t minRows;
5180
  int32_t maxRows;
5181
  int32_t tsdbPageSize;
5182
  int32_t s3ChunkSize;
5183
  int32_t s3KeepLocal;
5184
  int8_t  s3Compact;
5185
  // walInfo
5186
  int32_t walFsyncPeriod;      // millisecond
5187
  int32_t walRetentionPeriod;  // secs
5188
  int32_t walRollPeriod;       // secs
5189
  int64_t walRetentionSize;
5190
  int64_t walSegSize;
5191
  int32_t walLevel;
5192
  // encryptInfo
5193
  int32_t encryptAlgorithm;
5194
  // SVState
5195
  int64_t committed;
5196
  int64_t commitID;
5197
  int64_t commitTerm;
5198
  // stats
5199
  int64_t numOfSTables;
5200
  int64_t numOfCTables;
5201
  int64_t numOfNTables;
5202
  // dbInfo
5203
  uint64_t dbId;
5204
} SMountVgInfo;
5205

5206
typedef struct {
5207
  SMCreateStbReq req;
5208
  SArray*        pColExts;  // element: column id
5209
  SArray*        pTagExts;  // element: tag id
5210
} SMountStbInfo;
5211

5212
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5213
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5214

5215
typedef struct {
5216
  char     dbName[TSDB_DB_FNAME_LEN];
5217
  uint64_t dbId;
5218
  SArray*  pVgs;      // SMountVgInfo
5219
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5220
} SMountDbInfo;
5221

5222
typedef struct {
5223
  // common fields
5224
  char     mountName[TSDB_MOUNT_NAME_LEN];
5225
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5226
  int8_t   ignoreExist;
5227
  int64_t  mountUid;
5228
  int64_t  clusterId;
5229
  int32_t  dnodeId;
5230
  uint32_t valLen;
5231
  void*    pVal;
5232

5233
  // response fields
5234
  SArray* pDbs;  // SMountDbInfo
5235

5236
  // memory fields, no serialized
5237
  SArray*   pDisks[TFS_MAX_TIERS];
5238
  TdFilePtr pFile;
5239
} SMountInfo;
5240

5241
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5242
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5243
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5244

5245
typedef struct {
5246
  SCreateVnodeReq createReq;
5247
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5248
  char            mountName[TSDB_MOUNT_NAME_LEN];
5249
  int64_t         mountId;
5250
  int32_t         diskPrimary;
5251
  int32_t         mountVgId;
5252
  int64_t         committed;
5253
  int64_t         commitID;
5254
  int64_t         commitTerm;
5255
  int64_t         numOfSTables;
5256
  int64_t         numOfCTables;
5257
  int64_t         numOfNTables;
5258
} SMountVnodeReq;
5259

5260
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5261
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5262
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5263

5264
#endif  // USE_MOUNT
5265

5266
#pragma pack(pop)
5267

5268
#ifdef __cplusplus
5269
}
5270
#endif
5271

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