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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

58.26
/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) {
59,939,846✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
59,939,846✔
74
  int    segIdx = TMSG_SEG_CODE(type);
59,939,846✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
59,939,846!
76
    return type < tMsgRangeDict[segIdx];
59,941,205✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,639,697✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,615,130!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,254,827!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
37,101,911✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
37,101,911✔
91
}
92

93
/* ------------------------ OTHER DEFINITIONS ------------------------ */
94
// IE type
95
#define TSDB_IE_TYPE_SEC         1
96
#define TSDB_IE_TYPE_META        2
97
#define TSDB_IE_TYPE_MGMT_IP     3
98
#define TSDB_IE_TYPE_DNODE_CFG   4
99
#define TSDB_IE_TYPE_NEW_VERSION 5
100
#define TSDB_IE_TYPE_DNODE_EXT   6
101
#define TSDB_IE_TYPE_DNODE_STATE 7
102

103
enum {
104
  CONN_TYPE__QUERY = 1,
105
  CONN_TYPE__TMQ,
106
  CONN_TYPE__UDFD,
107
  CONN_TYPE__MAX,
108
};
109

110
enum {
111
  HEARTBEAT_KEY_USER_AUTHINFO = 1,
112
  HEARTBEAT_KEY_DBINFO,
113
  HEARTBEAT_KEY_STBINFO,
114
  HEARTBEAT_KEY_TMQ,
115
  HEARTBEAT_KEY_DYN_VIEW,
116
  HEARTBEAT_KEY_VIEWINFO,
117
  HEARTBEAT_KEY_TSMA,
118
};
119

120
typedef enum _mgmt_table {
121
  TSDB_MGMT_TABLE_START,
122
  TSDB_MGMT_TABLE_DNODE,
123
  TSDB_MGMT_TABLE_MNODE,
124
  TSDB_MGMT_TABLE_MODULE,
125
  TSDB_MGMT_TABLE_QNODE,
126
  TSDB_MGMT_TABLE_SNODE,
127
  TSDB_MGMT_TABLE_BNODE,  // no longer used
128
  TSDB_MGMT_TABLE_CLUSTER,
129
  TSDB_MGMT_TABLE_DB,
130
  TSDB_MGMT_TABLE_FUNC,
131
  TSDB_MGMT_TABLE_INDEX,
132
  TSDB_MGMT_TABLE_STB,
133
  TSDB_MGMT_TABLE_STREAMS,
134
  TSDB_MGMT_TABLE_TABLE,
135
  TSDB_MGMT_TABLE_TAG,
136
  TSDB_MGMT_TABLE_COL,
137
  TSDB_MGMT_TABLE_USER,
138
  TSDB_MGMT_TABLE_GRANTS,
139
  TSDB_MGMT_TABLE_VGROUP,
140
  TSDB_MGMT_TABLE_TOPICS,
141
  TSDB_MGMT_TABLE_CONSUMERS,
142
  TSDB_MGMT_TABLE_SUBSCRIPTIONS,
143
  TSDB_MGMT_TABLE_TRANS,
144
  TSDB_MGMT_TABLE_SMAS,
145
  TSDB_MGMT_TABLE_CONFIGS,
146
  TSDB_MGMT_TABLE_CONNS,
147
  TSDB_MGMT_TABLE_QUERIES,
148
  TSDB_MGMT_TABLE_VNODES,
149
  TSDB_MGMT_TABLE_APPS,
150
  TSDB_MGMT_TABLE_STREAM_TASKS,
151
  TSDB_MGMT_TABLE_PRIVILEGES,
152
  TSDB_MGMT_TABLE_VIEWS,
153
  TSDB_MGMT_TABLE_TSMAS,
154
  TSDB_MGMT_TABLE_COMPACT,
155
  TSDB_MGMT_TABLE_COMPACT_DETAIL,
156
  TSDB_MGMT_TABLE_GRANTS_FULL,
157
  TSDB_MGMT_TABLE_GRANTS_LOGS,
158
  TSDB_MGMT_TABLE_MACHINES,
159
  TSDB_MGMT_TABLE_ARBGROUP,
160
  TSDB_MGMT_TABLE_ENCRYPTIONS,
161
  TSDB_MGMT_TABLE_USER_FULL,
162
  TSDB_MGMT_TABLE_ANODE,
163
  TSDB_MGMT_TABLE_ANODE_FULL,
164
  TSDB_MGMT_TABLE_USAGE,
165
  TSDB_MGMT_TABLE_MAX,
166
} EShowType;
167

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

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

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

204
#define TSDB_KILL_MSG_LEN 30
205

206
#define TSDB_TABLE_NUM_UNIT 100000
207

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

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

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

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

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

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

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

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

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

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

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

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

511
typedef struct SRetention {
512
  int64_t freq;
513
  int64_t keep;
514
  int8_t  freqUnit;
515
  int8_t  keepUnit;
516
} SRetention;
517

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

520
#pragma pack(push, 1)
521

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

528
typedef struct {
529
  int32_t contLen;
530
  int32_t vgId;
531
} SMsgHead;
532

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

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

553
typedef struct {
554
  int32_t totalLen;
555
  int32_t len;
556
  STSRow* row;
557
} SSubmitBlkIter;
558

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

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

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

593
//
594

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

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

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

633
typedef struct {
634
  int32_t numOfRows;
635
  int32_t affectedRows;
636
  int32_t nBlocks;
637
  union {
638
    SArray*        pArray;
639
    SSubmitBlkRsp* pBlocks;
640
  };
641
} SSubmitRsp;
642

643
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
644
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
645
// void    tFreeSSubmitBlkRsp(void* param);
646
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
647

648
#define COL_SMA_ON     ((int8_t)0x1)
649
#define COL_IDX_ON     ((int8_t)0x2)
650
#define COL_IS_KEY     ((int8_t)0x4)
651
#define COL_SET_NULL   ((int8_t)0x10)
652
#define COL_SET_VAL    ((int8_t)0x20)
653
#define COL_IS_SYSINFO ((int8_t)0x40)
654

655
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
656
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
657

658
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
659
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
660
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
661

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

667
#define SSCHMEA_SET_IDX_OFF(s)   \
668
  do {                           \
669
    (s)->flags &= (~COL_IDX_ON); \
670
  } while (0)
671

672
#define SSCHMEA_TYPE(s)  ((s)->type)
673
#define SSCHMEA_FLAGS(s) ((s)->flags)
674
#define SSCHMEA_COLID(s) ((s)->colId)
675
#define SSCHMEA_BYTES(s) ((s)->bytes)
676
#define SSCHMEA_NAME(s)  ((s)->name)
677

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

688
typedef struct {
689
  int32_t  nCols;
690
  int32_t  version;
691
  SSchema* pSchema;
692
} SSchemaWrapper;
693

694
typedef struct {
695
  col_id_t id;
696
  uint32_t alg;
697
} SColCmpr;
698

699
typedef struct {
700
  int32_t   nCols;
701
  int32_t   version;
702
  SColCmpr* pColCmpr;
703
} SColCmprWrapper;
704

705
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
706
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
2,098!
707
    terrno = TSDB_CODE_INVALID_PARA;
×
708
    return NULL;
×
709
  }
710

711
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
2,098✔
712
  if (pDstWrapper == NULL) {
2,098!
713
    return NULL;
×
714
  }
715
  pDstWrapper->nCols = pSrcWrapper->nCols;
2,098✔
716
  pDstWrapper->version = pSrcWrapper->version;
2,098✔
717

718
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
2,098✔
719
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
2,098✔
720
  if (pDstWrapper->pColCmpr == NULL) {
2,098!
721
    taosMemoryFree(pDstWrapper);
×
722
    return NULL;
×
723
  }
724
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
2,098✔
725

726
  return pDstWrapper;
2,098✔
727
}
728

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

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

759
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
760
  if (pWrapper == NULL) return;
2,098!
761

762
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,098!
763
  taosMemoryFreeClear(pWrapper);
2,098!
764
}
765
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
766
  if (pSchemaWrapper->pSchema == NULL) return NULL;
10,896,147!
767

768
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
10,896,147✔
769
  if (pSW == NULL) {
10,897,347!
770
    return NULL;
×
771
  }
772
  pSW->nCols = pSchemaWrapper->nCols;
10,897,347✔
773
  pSW->version = pSchemaWrapper->version;
10,897,347✔
774
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
10,897,347✔
775
  if (pSW->pSchema == NULL) {
10,889,517!
776
    taosMemoryFree(pSW);
1✔
777
    return NULL;
×
778
  }
779

780
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
10,906,266✔
781
  return pSW;
10,906,266✔
782
}
783

784
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
471,880✔
785
  if (pSchemaWrapper) {
17,975,782!
786
    taosMemoryFree(pSchemaWrapper->pSchema);
9,942,416✔
787
    taosMemoryFree(pSchemaWrapper);
9,942,420✔
788
  }
789
}
17,976,213✔
790

791
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,311,736✔
792
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,311,736!
793
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,312,118✔
794
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,320,195✔
795
  }
796
}
1,319,340✔
797

798
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
799
  int32_t tlen = 0;
57,496✔
800
  tlen += taosEncodeFixedI8(buf, pSchema->type);
114,992✔
801
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
57,496!
802
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
57,496!
803
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
57,496!
804
  tlen += taosEncodeString(buf, pSchema->name);
57,496✔
805
  return tlen;
57,496✔
806
}
807

808
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
809
  buf = taosDecodeFixedI8(buf, &pSchema->type);
53,534✔
810
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
26,767✔
811
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
26,767!
812
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
26,767!
813
  buf = taosDecodeStringTo(buf, pSchema->name);
26,767✔
814
  return (void*)buf;
26,767✔
815
}
816

817
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
818
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
334,880,217!
819
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
342,438,668!
820
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
342,438,668!
821
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
342,438,668!
822
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
342,438,668!
823
  return 0;
171,219,334✔
824
}
825

826
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
827
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
670,348,241!
828
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,314,582,074!
829
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,299,862,560!
830
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,317,091,772!
831
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
662,803,526!
832
  return 0;
712,471,762✔
833
}
834

835
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
836
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
201,614,150!
837
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
201,614,150!
838
  return 0;
100,807,075✔
839
}
840

841
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
842
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
1,562,720!
843
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
1,562,719!
844
  return 0;
781,360✔
845
}
846

847
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
848
  int32_t tlen = 0;
8,544✔
849
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,544✔
850
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,544✔
851
  for (int32_t i = 0; i < pSW->nCols; i++) {
66,040✔
852
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
114,992!
853
  }
854
  return tlen;
8,544✔
855
}
856

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

866
    for (int32_t i = 0; i < pSW->nCols; i++) {
29,675✔
867
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
53,534✔
868
    }
869
  } else {
870
    pSW->pSchema = NULL;
1,074✔
871
  }
872
  return (void*)buf;
3,982✔
873
}
874

875
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
876
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,346,680!
877
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,346,680!
878
  for (int32_t i = 0; i < pSW->nCols; i++) {
8,231,791✔
879
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
15,116,902!
880
  }
881
  return 0;
673,340✔
882
}
883

884
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
885
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,517,674!
886
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,517,435!
887

888
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
758,647✔
889
  if (pSW->pSchema == NULL) {
758,785✔
890
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
28✔
891
  }
892
  for (int32_t i = 0; i < pSW->nCols; i++) {
13,054,061✔
893
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
24,591,567!
894
  }
895

896
  return 0;
757,770✔
897
}
898

899
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
900
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
77,799,453!
901
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
80,201,080!
902

903
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
40,069,671✔
904
  if (pSW->pSchema == NULL) {
40,369,452!
905
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
906
  }
907
  for (int32_t i = 0; i < pSW->nCols; i++) {
739,205,457✔
908
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,400,452,913!
909
  }
910

911
  return 0;
37,588,549✔
912
}
913

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

945
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
946
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
947
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
948

949
typedef struct {
950
  STableMetaRsp* pMeta;
951
} SMCreateStbRsp;
952

953
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
954
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
955
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
956

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

967
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
968
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
969
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
970

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

983
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
984
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
985
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
986

987
typedef struct SEpSet {
988
  int8_t inUse;
989
  int8_t numOfEps;
990
  SEp    eps[TSDB_MAX_REPLICA];
991
} SEpSet;
992

993
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
994
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
995
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
996
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
997

998
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
999
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1000

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

1012
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1013
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1014

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

1034
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1035
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1036

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

1048
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1049
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1050

1051
typedef struct {
1052
  char    user[TSDB_USER_LEN];
1053
  int32_t sqlLen;
1054
  char*   sql;
1055
} SDropUserReq, SDropAcctReq;
1056

1057
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1058
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1059
void    tFreeSDropUserReq(SDropUserReq* pReq);
1060

1061
typedef struct SIpV4Range {
1062
  uint32_t ip;
1063
  uint32_t mask;
1064
} SIpV4Range;
1065

1066
typedef struct {
1067
  int32_t    num;
1068
  SIpV4Range pIpRange[];
1069
} SIpWhiteList;
1070

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

1087
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1088
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1089
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1090

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

1103
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1104
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1105
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1106
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1107

1108
typedef struct {
1109
  int64_t ipWhiteVer;
1110
} SRetrieveIpWhiteReq;
1111

1112
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1113
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1114

1115
typedef struct {
1116
  int32_t dnodeId;
1117
  int64_t analVer;
1118
} SRetrieveAnalAlgoReq;
1119

1120
typedef struct {
1121
  int64_t   ver;
1122
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1123
} SRetrieveAnalAlgoRsp;
1124

1125
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1126
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1127
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1128
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1129
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1130

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

1157
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1158
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1159
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1160

1161
typedef struct {
1162
  char user[TSDB_USER_LEN];
1163
} SGetUserAuthReq;
1164

1165
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1166
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1167

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

1189
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1190
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1191
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1192

1193
typedef struct {
1194
  char user[TSDB_USER_LEN];
1195
} SGetUserWhiteListReq;
1196

1197
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1198
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1199

1200
typedef struct {
1201
  char        user[TSDB_USER_LEN];
1202
  int32_t     numWhiteLists;
1203
  SIpV4Range* pWhiteLists;
1204
} SGetUserWhiteListRsp;
1205

1206
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1207
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1208
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1209

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

1220
  uint8_t precision;
1221
  uint8_t scale;
1222
  int32_t bytes;
1223
  int8_t  type;
1224
  uint8_t pk;
1225
  bool    noData;
1226
} SColumnInfo;
1227

1228
typedef struct STimeWindow {
1229
  TSKEY skey;
1230
  TSKEY ekey;
1231
} STimeWindow;
1232

1233
typedef struct SQueryHint {
1234
  bool batchScan;
1235
} SQueryHint;
1236

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

1244
typedef struct {
1245
  int32_t     tz;  // query client timezone
1246
  char        intervalUnit;
1247
  char        slidingUnit;
1248
  char        offsetUnit;
1249
  int8_t      precision;
1250
  int64_t     interval;
1251
  int64_t     sliding;
1252
  int64_t     offset;
1253
  STimeWindow timeRange;
1254
} SInterval;
1255

1256
typedef struct STbVerInfo {
1257
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1258
  int32_t sversion;
1259
  int32_t tversion;
1260
} STbVerInfo;
1261

1262
typedef struct {
1263
  int32_t code;
1264
  int64_t affectedRows;
1265
  SArray* tbVerInfo;  // STbVerInfo
1266
} SQueryTableRsp;
1267

1268
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1269

1270
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1271

1272
typedef struct {
1273
  SMsgHead header;
1274
  char     dbFName[TSDB_DB_FNAME_LEN];
1275
  char     tbName[TSDB_TABLE_NAME_LEN];
1276
} STableCfgReq;
1277

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

1299
typedef STableCfg STableCfgRsp;
1300

1301
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1302
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1303

1304
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1305
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1306
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1307

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

1352
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1353
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1354
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1355

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

1383
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1384
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1385
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1386

1387
typedef struct {
1388
  char    db[TSDB_DB_FNAME_LEN];
1389
  int8_t  ignoreNotExists;
1390
  int32_t sqlLen;
1391
  char*   sql;
1392
} SDropDbReq;
1393

1394
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1395
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1396
void    tFreeSDropDbReq(SDropDbReq* pReq);
1397

1398
typedef struct {
1399
  char    db[TSDB_DB_FNAME_LEN];
1400
  int64_t uid;
1401
} SDropDbRsp;
1402

1403
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1404
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1405

1406
typedef struct {
1407
  char    db[TSDB_DB_FNAME_LEN];
1408
  int64_t dbId;
1409
  int32_t vgVersion;
1410
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1411
  int64_t stateTs;     // ms
1412
} SUseDbReq;
1413

1414
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1415
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1416

1417
typedef struct {
1418
  char    db[TSDB_DB_FNAME_LEN];
1419
  int64_t uid;
1420
  int32_t vgVersion;
1421
  int32_t vgNum;
1422
  int16_t hashPrefix;
1423
  int16_t hashSuffix;
1424
  int8_t  hashMethod;
1425
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1426
  int32_t errCode;
1427
  int64_t stateTs;  // ms
1428
} SUseDbRsp;
1429

1430
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1431
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1432
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1433
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1434
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1435

1436
typedef struct {
1437
  char db[TSDB_DB_FNAME_LEN];
1438
} SDbCfgReq;
1439

1440
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1441
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1442

1443
typedef struct {
1444
  char    db[TSDB_DB_FNAME_LEN];
1445
  int32_t maxSpeed;
1446
} STrimDbReq;
1447

1448
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1449
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1450

1451
typedef struct {
1452
  int32_t timestamp;
1453
} SVTrimDbReq;
1454

1455
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1456
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1457

1458
typedef struct {
1459
  char db[TSDB_DB_FNAME_LEN];
1460
} SS3MigrateDbReq;
1461

1462
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1463
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1464

1465
typedef struct {
1466
  int32_t timestamp;
1467
} SVS3MigrateDbReq;
1468

1469
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1470
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1471

1472
typedef struct {
1473
  int32_t timestampSec;
1474
  int32_t ttlDropMaxCount;
1475
  int32_t nUids;
1476
  SArray* pTbUids;
1477
} SVDropTtlTableReq;
1478

1479
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1480
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1481

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

1525
typedef SDbCfgRsp SDbCfgInfo;
1526

1527
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1528
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1529
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1530
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1531
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1532

1533
typedef struct {
1534
  int32_t rowNum;
1535
} SQnodeListReq;
1536

1537
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1538
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1539

1540
typedef struct {
1541
  int32_t rowNum;
1542
} SDnodeListReq;
1543

1544
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1545

1546
typedef struct {
1547
  int32_t useless;  // useless
1548
} SServerVerReq;
1549

1550
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1551
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1552

1553
typedef struct {
1554
  char ver[TSDB_VERSION_LEN];
1555
} SServerVerRsp;
1556

1557
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1558
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1559

1560
typedef struct SQueryNodeAddr {
1561
  int32_t nodeId;  // vgId or qnodeId
1562
  SEpSet  epSet;
1563
} SQueryNodeAddr;
1564

1565
typedef struct {
1566
  SQueryNodeAddr addr;
1567
  uint64_t       load;
1568
} SQueryNodeLoad;
1569

1570
typedef struct {
1571
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1572
} SQnodeListRsp;
1573

1574
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1575
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1576
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1577

1578
typedef struct {
1579
  SArray* dnodeList;  // SArray<SEpSet>
1580
} SDnodeListRsp;
1581

1582
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1583
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1584
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1585

1586
typedef struct {
1587
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1588
} STableTSMAInfoRsp;
1589

1590
typedef struct {
1591
  SUseDbRsp*         useDbRsp;
1592
  SDbCfgRsp*         cfgRsp;
1593
  STableTSMAInfoRsp* pTsmaRsp;
1594
  int32_t            dbTsmaVersion;
1595
  char               db[TSDB_DB_FNAME_LEN];
1596
  int64_t            dbId;
1597
} SDbHbRsp;
1598

1599
typedef struct {
1600
  SArray* pArray;  // Array of SDbHbRsp
1601
} SDbHbBatchRsp;
1602

1603
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1604
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1605
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1606

1607
typedef struct {
1608
  SArray* pArray;  // Array of SGetUserAuthRsp
1609
} SUserAuthBatchRsp;
1610

1611
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1612
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1613
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1614

1615
typedef struct {
1616
  char        db[TSDB_DB_FNAME_LEN];
1617
  STimeWindow timeRange;
1618
  int32_t     sqlLen;
1619
  char*       sql;
1620
} SCompactDbReq;
1621

1622
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1623
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1624
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1625

1626
typedef struct {
1627
  int32_t compactId;
1628
  int8_t  bAccepted;
1629
} SCompactDbRsp;
1630

1631
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1632
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1633

1634
typedef struct {
1635
  int32_t compactId;
1636
  int32_t sqlLen;
1637
  char*   sql;
1638
} SKillCompactReq;
1639

1640
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1641
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1642
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1643

1644
typedef struct {
1645
  char    name[TSDB_FUNC_NAME_LEN];
1646
  int8_t  igExists;
1647
  int8_t  funcType;
1648
  int8_t  scriptType;
1649
  int8_t  outputType;
1650
  int32_t outputLen;
1651
  int32_t bufSize;
1652
  int32_t codeLen;
1653
  int64_t signature;
1654
  char*   pComment;
1655
  char*   pCode;
1656
  int8_t  orReplace;
1657
} SCreateFuncReq;
1658

1659
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1660
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1661
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1662

1663
typedef struct {
1664
  char   name[TSDB_FUNC_NAME_LEN];
1665
  int8_t igNotExists;
1666
} SDropFuncReq;
1667

1668
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1669
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1670

1671
typedef struct {
1672
  int32_t numOfFuncs;
1673
  bool    ignoreCodeComment;
1674
  SArray* pFuncNames;
1675
} SRetrieveFuncReq;
1676

1677
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1678
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1679
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1680

1681
typedef struct {
1682
  char    name[TSDB_FUNC_NAME_LEN];
1683
  int8_t  funcType;
1684
  int8_t  scriptType;
1685
  int8_t  outputType;
1686
  int32_t outputLen;
1687
  int32_t bufSize;
1688
  int64_t signature;
1689
  int32_t commentSize;
1690
  int32_t codeSize;
1691
  char*   pComment;
1692
  char*   pCode;
1693
} SFuncInfo;
1694

1695
typedef struct {
1696
  int32_t funcVersion;
1697
  int64_t funcCreatedTime;
1698
} SFuncExtraInfo;
1699

1700
typedef struct {
1701
  int32_t numOfFuncs;
1702
  SArray* pFuncInfos;
1703
  SArray* pFuncExtraInfos;
1704
} SRetrieveFuncRsp;
1705

1706
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1707
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1708
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1709
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1710

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

1724
typedef struct {
1725
  int32_t openVnodes;
1726
  int32_t dropVnodes;
1727
  int32_t totalVnodes;
1728
  int32_t masterNum;
1729
  int64_t numOfSelectReqs;
1730
  int64_t numOfInsertReqs;
1731
  int64_t numOfInsertSuccessReqs;
1732
  int64_t numOfBatchInsertReqs;
1733
  int64_t numOfBatchInsertSuccessReqs;
1734
  int64_t errors;
1735
} SVnodesStat;
1736

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

1760
typedef struct {
1761
  int32_t     vgId;
1762
  int64_t     numOfTables;
1763
  int64_t     memSize;
1764
  int64_t     l1Size;
1765
  int64_t     l2Size;
1766
  int64_t     l3Size;
1767
  int64_t     cacheSize;
1768
  int64_t     walSize;
1769
  int64_t     metaSize;
1770
  int64_t     rawDataSize;
1771
  int64_t     s3Size;
1772
  const char* dbname;
1773
} SDbSizeStatisInfo;
1774

1775
typedef struct {
1776
  int32_t vgId;
1777
  int64_t nTimeSeries;
1778
} SVnodeLoadLite;
1779

1780
typedef struct {
1781
  int8_t  syncState;
1782
  int64_t syncTerm;
1783
  int8_t  syncRestore;
1784
  int64_t roleTimeMs;
1785
} SMnodeLoad;
1786

1787
typedef struct {
1788
  int32_t dnodeId;
1789
  int64_t numOfProcessedQuery;
1790
  int64_t numOfProcessedCQuery;
1791
  int64_t numOfProcessedFetch;
1792
  int64_t numOfProcessedDrop;
1793
  int64_t numOfProcessedNotify;
1794
  int64_t numOfProcessedHb;
1795
  int64_t numOfProcessedDelete;
1796
  int64_t cacheDataSize;
1797
  int64_t numOfQueryInQueue;
1798
  int64_t numOfFetchInQueue;
1799
  int64_t timeInQueryQueue;
1800
  int64_t timeInFetchQueue;
1801
} SQnodeLoad;
1802

1803
typedef struct {
1804
  int32_t     sver;      // software version
1805
  int64_t     dnodeVer;  // dnode table version in sdb
1806
  int32_t     dnodeId;
1807
  int64_t     clusterId;
1808
  int64_t     rebootTime;
1809
  int64_t     updateTime;
1810
  float       numOfCores;
1811
  int32_t     numOfSupportVnodes;
1812
  int32_t     numOfDiskCfg;
1813
  int64_t     memTotal;
1814
  int64_t     memAvail;
1815
  char        dnodeEp[TSDB_EP_LEN];
1816
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1817
  SMnodeLoad  mload;
1818
  SQnodeLoad  qload;
1819
  SClusterCfg clusterCfg;
1820
  SArray*     pVloads;  // array of SVnodeLoad
1821
  int32_t     statusSeq;
1822
  int64_t     ipWhiteVer;
1823
  int64_t     analVer;
1824
} SStatusReq;
1825

1826
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1827
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1828
void    tFreeSStatusReq(SStatusReq* pReq);
1829

1830
typedef struct {
1831
  int32_t dnodeId;
1832
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1833
} SDnodeInfoReq;
1834

1835
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1836
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1837

1838
typedef enum {
1839
  MONITOR_TYPE_COUNTER = 0,
1840
  MONITOR_TYPE_SLOW_LOG = 1,
1841
} MONITOR_TYPE;
1842

1843
typedef struct {
1844
  int32_t      contLen;
1845
  char*        pCont;
1846
  MONITOR_TYPE type;
1847
} SStatisReq;
1848

1849
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1850
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1851
void    tFreeSStatisReq(SStatisReq* pReq);
1852

1853
typedef struct {
1854
  char    db[TSDB_DB_FNAME_LEN];
1855
  char    table[TSDB_TABLE_NAME_LEN];
1856
  char    operation[AUDIT_OPERATION_LEN];
1857
  int32_t sqlLen;
1858
  char*   pSql;
1859
} SAuditReq;
1860
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1861
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1862
void    tFreeSAuditReq(SAuditReq* pReq);
1863

1864
typedef struct {
1865
  int32_t dnodeId;
1866
  int64_t clusterId;
1867
  SArray* pVloads;
1868
} SNotifyReq;
1869

1870
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1871
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1872
void    tFreeSNotifyReq(SNotifyReq* pReq);
1873

1874
typedef struct {
1875
  int32_t dnodeId;
1876
  int64_t clusterId;
1877
} SDnodeCfg;
1878

1879
typedef struct {
1880
  int32_t id;
1881
  int8_t  isMnode;
1882
  SEp     ep;
1883
} SDnodeEp;
1884

1885
typedef struct {
1886
  int32_t id;
1887
  int8_t  isMnode;
1888
  int8_t  offlineReason;
1889
  SEp     ep;
1890
  char    active[TSDB_ACTIVE_KEY_LEN];
1891
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1892
} SDnodeInfo;
1893

1894
typedef struct {
1895
  int64_t   dnodeVer;
1896
  SDnodeCfg dnodeCfg;
1897
  SArray*   pDnodeEps;  // Array of SDnodeEp
1898
  int32_t   statusSeq;
1899
  int64_t   ipWhiteVer;
1900
  int64_t   analVer;
1901
} SStatusRsp;
1902

1903
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1904
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1905
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1906

1907
typedef struct {
1908
  int32_t reserved;
1909
} SMTimerReq;
1910

1911
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1912
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1913

1914
typedef struct SOrphanTask {
1915
  int64_t streamId;
1916
  int32_t taskId;
1917
  int32_t nodeId;
1918
} SOrphanTask;
1919

1920
typedef struct SMStreamDropOrphanMsg {
1921
  SArray* pList;  // SArray<SOrphanTask>
1922
} SMStreamDropOrphanMsg;
1923

1924
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1925
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1926
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1927

1928
typedef struct {
1929
  int32_t  id;
1930
  uint16_t port;                 // node sync Port
1931
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1932
} SReplica;
1933

1934
typedef struct {
1935
  int32_t  vgId;
1936
  char     db[TSDB_DB_FNAME_LEN];
1937
  int64_t  dbUid;
1938
  int32_t  vgVersion;
1939
  int32_t  numOfStables;
1940
  int32_t  buffer;
1941
  int32_t  pageSize;
1942
  int32_t  pages;
1943
  int32_t  cacheLastSize;
1944
  int32_t  daysPerFile;
1945
  int32_t  daysToKeep0;
1946
  int32_t  daysToKeep1;
1947
  int32_t  daysToKeep2;
1948
  int32_t  keepTimeOffset;
1949
  int32_t  minRows;
1950
  int32_t  maxRows;
1951
  int32_t  walFsyncPeriod;
1952
  uint32_t hashBegin;
1953
  uint32_t hashEnd;
1954
  int8_t   hashMethod;
1955
  int8_t   walLevel;
1956
  int8_t   precision;
1957
  int8_t   compression;
1958
  int8_t   strict;
1959
  int8_t   cacheLast;
1960
  int8_t   isTsma;
1961
  int8_t   replica;
1962
  int8_t   selfIndex;
1963
  SReplica replicas[TSDB_MAX_REPLICA];
1964
  int32_t  numOfRetensions;
1965
  SArray*  pRetensions;  // SRetention
1966
  void*    pTsma;
1967
  int32_t  walRetentionPeriod;
1968
  int64_t  walRetentionSize;
1969
  int32_t  walRollPeriod;
1970
  int64_t  walSegmentSize;
1971
  int16_t  sstTrigger;
1972
  int16_t  hashPrefix;
1973
  int16_t  hashSuffix;
1974
  int32_t  tsdbPageSize;
1975
  int32_t  s3ChunkSize;
1976
  int32_t  s3KeepLocal;
1977
  int8_t   s3Compact;
1978
  int64_t  reserved[6];
1979
  int8_t   learnerReplica;
1980
  int8_t   learnerSelfIndex;
1981
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
1982
  int32_t  changeVersion;
1983
  int8_t   encryptAlgorithm;
1984
} SCreateVnodeReq;
1985

1986
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1987
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1988
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
1989

1990
typedef struct {
1991
  int32_t compactId;
1992
  int32_t vgId;
1993
  int32_t dnodeId;
1994
} SQueryCompactProgressReq;
1995

1996
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1997
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1998

1999
typedef struct {
2000
  int32_t compactId;
2001
  int32_t vgId;
2002
  int32_t dnodeId;
2003
  int32_t numberFileset;
2004
  int32_t finished;
2005
} SQueryCompactProgressRsp;
2006

2007
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2008
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2009

2010
typedef struct {
2011
  int32_t vgId;
2012
  int32_t dnodeId;
2013
  int64_t dbUid;
2014
  char    db[TSDB_DB_FNAME_LEN];
2015
  int64_t reserved[8];
2016
} SDropVnodeReq;
2017

2018
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2019
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2020

2021
typedef struct {
2022
  char    colName[TSDB_COL_NAME_LEN];
2023
  char    stb[TSDB_TABLE_FNAME_LEN];
2024
  int64_t stbUid;
2025
  int64_t dbUid;
2026
  int64_t reserved[8];
2027
} SDropIndexReq;
2028

2029
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2030
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2031

2032
typedef struct {
2033
  int64_t     dbUid;
2034
  char        db[TSDB_DB_FNAME_LEN];
2035
  int64_t     compactStartTime;
2036
  STimeWindow tw;
2037
  int32_t     compactId;
2038
} SCompactVnodeReq;
2039

2040
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2041
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2042

2043
typedef struct {
2044
  int32_t compactId;
2045
  int32_t vgId;
2046
  int32_t dnodeId;
2047
} SVKillCompactReq;
2048

2049
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2050
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2051

2052
typedef struct {
2053
  int32_t vgVersion;
2054
  int32_t buffer;
2055
  int32_t pageSize;
2056
  int32_t pages;
2057
  int32_t cacheLastSize;
2058
  int32_t daysPerFile;
2059
  int32_t daysToKeep0;
2060
  int32_t daysToKeep1;
2061
  int32_t daysToKeep2;
2062
  int32_t keepTimeOffset;
2063
  int32_t walFsyncPeriod;
2064
  int8_t  walLevel;
2065
  int8_t  strict;
2066
  int8_t  cacheLast;
2067
  int64_t reserved[7];
2068
  // 1st modification
2069
  int16_t sttTrigger;
2070
  int32_t minRows;
2071
  // 2nd modification
2072
  int32_t walRetentionPeriod;
2073
  int32_t walRetentionSize;
2074
  int32_t s3KeepLocal;
2075
  int8_t  s3Compact;
2076
} SAlterVnodeConfigReq;
2077

2078
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2079
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2080

2081
typedef struct {
2082
  int32_t  vgId;
2083
  int8_t   strict;
2084
  int8_t   selfIndex;
2085
  int8_t   replica;
2086
  SReplica replicas[TSDB_MAX_REPLICA];
2087
  int64_t  reserved[8];
2088
  int8_t   learnerSelfIndex;
2089
  int8_t   learnerReplica;
2090
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2091
  int32_t  changeVersion;
2092
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2093

2094
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2095
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2096

2097
typedef struct {
2098
  int32_t vgId;
2099
  int8_t  disable;
2100
} SDisableVnodeWriteReq;
2101

2102
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2103
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2104

2105
typedef struct {
2106
  int32_t  srcVgId;
2107
  int32_t  dstVgId;
2108
  uint32_t hashBegin;
2109
  uint32_t hashEnd;
2110
  int32_t  changeVersion;
2111
  int32_t  reserved;
2112
} SAlterVnodeHashRangeReq;
2113

2114
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2115
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2116

2117
#define REQ_OPT_TBNAME 0x0
2118
#define REQ_OPT_TBUID  0x01
2119
typedef struct {
2120
  SMsgHead header;
2121
  char     dbFName[TSDB_DB_FNAME_LEN];
2122
  char     tbName[TSDB_TABLE_NAME_LEN];
2123
  uint8_t  option;
2124
} STableInfoReq;
2125

2126
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2127
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2128

2129
typedef struct {
2130
  int8_t  metaClone;  // create local clone of the cached table meta
2131
  int32_t numOfVgroups;
2132
  int32_t numOfTables;
2133
  int32_t numOfUdfs;
2134
  char    tableNames[];
2135
} SMultiTableInfoReq;
2136

2137
// todo refactor
2138
typedef struct SVgroupInfo {
2139
  int32_t  vgId;
2140
  uint32_t hashBegin;
2141
  uint32_t hashEnd;
2142
  SEpSet   epSet;
2143
  union {
2144
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2145
    int32_t taskId;      // used in stream
2146
  };
2147
} SVgroupInfo;
2148

2149
typedef struct {
2150
  int32_t     numOfVgroups;
2151
  SVgroupInfo vgroups[];
2152
} SVgroupsInfo;
2153

2154
typedef struct {
2155
  STableMetaRsp* pMeta;
2156
} SMAlterStbRsp;
2157

2158
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2159
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2160
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2161

2162
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2163
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2164
void    tFreeSTableMetaRsp(void* pRsp);
2165
void    tFreeSTableIndexRsp(void* info);
2166

2167
typedef struct {
2168
  SArray* pMetaRsp;   // Array of STableMetaRsp
2169
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2170
} SSTbHbRsp;
2171

2172
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2173
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2174
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2175

2176
typedef struct {
2177
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2178
} SViewHbRsp;
2179

2180
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2181
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2182
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2183

2184
typedef struct {
2185
  int32_t numOfTables;
2186
  int32_t numOfVgroup;
2187
  int32_t numOfUdf;
2188
  int32_t contLen;
2189
  int8_t  compressed;  // denote if compressed or not
2190
  int32_t rawLen;      // size before compress
2191
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2192
  char    meta[];
2193
} SMultiTableMeta;
2194

2195
typedef struct {
2196
  int32_t dataLen;
2197
  char    name[TSDB_TABLE_FNAME_LEN];
2198
  char*   data;
2199
} STagData;
2200

2201
typedef struct {
2202
  int32_t useless;  // useless
2203
} SShowVariablesReq;
2204

2205
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2206
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2207

2208
typedef struct {
2209
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2210
  char value[TSDB_CONFIG_PATH_LEN + 1];
2211
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2212
  char info[TSDB_CONFIG_INFO_LEN + 1];
2213
} SVariablesInfo;
2214

2215
typedef struct {
2216
  SArray* variables;  // SArray<SVariablesInfo>
2217
} SShowVariablesRsp;
2218

2219
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2220
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2221

2222
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2223

2224
/*
2225
 * sql: show tables like '%a_%'
2226
 * payload is the query condition, e.g., '%a_%'
2227
 * payloadLen is the length of payload
2228
 */
2229
typedef struct {
2230
  int32_t type;
2231
  char    db[TSDB_DB_FNAME_LEN];
2232
  int32_t payloadLen;
2233
  char*   payload;
2234
} SShowReq;
2235

2236
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2237
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2238
void tFreeSShowReq(SShowReq* pReq);
2239

2240
typedef struct {
2241
  int64_t       showId;
2242
  STableMetaRsp tableMeta;
2243
} SShowRsp, SVShowTablesRsp;
2244

2245
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2246
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2247
// void    tFreeSShowRsp(SShowRsp* pRsp);
2248

2249
typedef struct {
2250
  char    db[TSDB_DB_FNAME_LEN];
2251
  char    tb[TSDB_TABLE_NAME_LEN];
2252
  char    user[TSDB_USER_LEN];
2253
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2254
  int64_t showId;
2255
  int64_t compactId;  // for compact
2256
  bool    withFull;   // for show users full
2257
} SRetrieveTableReq;
2258

2259
typedef struct SSysTableSchema {
2260
  int8_t   type;
2261
  col_id_t colId;
2262
  int32_t  bytes;
2263
} SSysTableSchema;
2264

2265
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2266
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2267

2268
typedef struct {
2269
  int64_t useconds;
2270
  int8_t  completed;  // all results are returned to client
2271
  int8_t  precision;
2272
  int8_t  compressed;
2273
  int8_t  streamBlockType;
2274
  int32_t payloadLen;
2275
  int32_t compLen;
2276
  int32_t numOfBlocks;
2277
  int64_t numOfRows;  // from int32_t change to int64_t
2278
  int64_t numOfCols;
2279
  int64_t skey;
2280
  int64_t ekey;
2281
  int64_t version;                         // for stream
2282
  TSKEY   watermark;                       // for stream
2283
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2284
  char    data[];
2285
} SRetrieveTableRsp;
2286

2287
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2288

2289
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2290
  do {                                          \
2291
    ((int32_t*)(_p))[0] = (_compLen);           \
2292
    ((int32_t*)(_p))[1] = (_fullLen);           \
2293
  } while (0);
2294

2295
typedef struct {
2296
  int64_t version;
2297
  int64_t numOfRows;
2298
  int8_t  compressed;
2299
  int8_t  precision;
2300
  char    data[];
2301
} SRetrieveTableRspForTmq;
2302

2303
typedef struct {
2304
  int64_t handle;
2305
  int64_t useconds;
2306
  int8_t  completed;  // all results are returned to client
2307
  int8_t  precision;
2308
  int8_t  compressed;
2309
  int32_t compLen;
2310
  int32_t numOfRows;
2311
  int32_t fullLen;
2312
  char    data[];
2313
} SRetrieveMetaTableRsp;
2314

2315
typedef struct SExplainExecInfo {
2316
  double   startupCost;
2317
  double   totalCost;
2318
  uint64_t numOfRows;
2319
  uint32_t verboseLen;
2320
  void*    verboseInfo;
2321
} SExplainExecInfo;
2322

2323
typedef struct {
2324
  int32_t           numOfPlans;
2325
  SExplainExecInfo* subplanInfo;
2326
} SExplainRsp;
2327

2328
typedef struct {
2329
  SExplainRsp rsp;
2330
  uint64_t    qId;
2331
  uint64_t    cId;
2332
  uint64_t    tId;
2333
  int64_t     rId;
2334
  int32_t     eId;
2335
} SExplainLocalRsp;
2336

2337
typedef struct STableScanAnalyzeInfo {
2338
  uint64_t totalRows;
2339
  uint64_t totalCheckedRows;
2340
  uint32_t totalBlocks;
2341
  uint32_t loadBlocks;
2342
  uint32_t loadBlockStatis;
2343
  uint32_t skipBlocks;
2344
  uint32_t filterOutBlocks;
2345
  double   elapsedTime;
2346
  double   filterTime;
2347
} STableScanAnalyzeInfo;
2348

2349
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2350
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2351
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2352

2353
typedef struct {
2354
  char    config[TSDB_DNODE_CONFIG_LEN];
2355
  char    value[TSDB_CLUSTER_VALUE_LEN];
2356
  int32_t sqlLen;
2357
  char*   sql;
2358
} SMCfgClusterReq;
2359

2360
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2361
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2362
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2363

2364
typedef struct {
2365
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2366
  int32_t port;
2367
  int32_t sqlLen;
2368
  char*   sql;
2369
} SCreateDnodeReq;
2370

2371
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2372
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2373
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2374

2375
typedef struct {
2376
  int32_t dnodeId;
2377
  char    fqdn[TSDB_FQDN_LEN];
2378
  int32_t port;
2379
  int8_t  force;
2380
  int8_t  unsafe;
2381
  int32_t sqlLen;
2382
  char*   sql;
2383
} SDropDnodeReq;
2384

2385
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2386
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2387
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2388

2389
enum {
2390
  RESTORE_TYPE__ALL = 1,
2391
  RESTORE_TYPE__MNODE,
2392
  RESTORE_TYPE__VNODE,
2393
  RESTORE_TYPE__QNODE,
2394
};
2395

2396
typedef struct {
2397
  int32_t dnodeId;
2398
  int8_t  restoreType;
2399
  int32_t sqlLen;
2400
  char*   sql;
2401
} SRestoreDnodeReq;
2402

2403
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2404
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2405
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2406

2407
typedef struct {
2408
  int32_t dnodeId;
2409
  char    config[TSDB_DNODE_CONFIG_LEN];
2410
  char    value[TSDB_DNODE_VALUE_LEN];
2411
  int32_t sqlLen;
2412
  char*   sql;
2413
} SMCfgDnodeReq;
2414

2415
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2416
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2417
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2418

2419
typedef struct {
2420
  char config[TSDB_DNODE_CONFIG_LEN];
2421
  char value[TSDB_DNODE_VALUE_LEN];
2422
} SDCfgDnodeReq;
2423

2424
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2425
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2426

2427
typedef struct {
2428
  int32_t dnodeId;
2429
  int32_t sqlLen;
2430
  char*   sql;
2431
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2432
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2433

2434
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2435
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2436
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2437
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2438
typedef struct {
2439
  int8_t   replica;
2440
  SReplica replicas[TSDB_MAX_REPLICA];
2441
  int8_t   learnerReplica;
2442
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2443
  int64_t  lastIndex;
2444
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2445

2446
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2447
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2448

2449
typedef struct {
2450
  int32_t urlLen;
2451
  int32_t sqlLen;
2452
  char*   url;
2453
  char*   sql;
2454
} SMCreateAnodeReq;
2455

2456
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2457
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2458
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2459

2460
typedef struct {
2461
  int32_t anodeId;
2462
  int32_t sqlLen;
2463
  char*   sql;
2464
} SMDropAnodeReq, SMUpdateAnodeReq;
2465

2466
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2467
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2468
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2469
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2470
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2471
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2472

2473
typedef struct {
2474
  int32_t vgId;
2475
  int32_t hbSeq;
2476
} SVArbHbReqMember;
2477

2478
typedef struct {
2479
  int32_t dnodeId;
2480
  char*   arbToken;
2481
  int64_t arbTerm;
2482
  SArray* hbMembers;  // SVArbHbReqMember
2483
} SVArbHeartBeatReq;
2484

2485
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2486
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2487
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2488

2489
typedef struct {
2490
  int32_t vgId;
2491
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2492
  int32_t hbSeq;
2493
} SVArbHbRspMember;
2494

2495
typedef struct {
2496
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2497
  int32_t dnodeId;
2498
  SArray* hbMembers;  // SVArbHbRspMember
2499
} SVArbHeartBeatRsp;
2500

2501
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2502
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2503
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2504

2505
typedef struct {
2506
  char*   arbToken;
2507
  int64_t arbTerm;
2508
  char*   member0Token;
2509
  char*   member1Token;
2510
} SVArbCheckSyncReq;
2511

2512
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2513
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2514
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2515

2516
typedef struct {
2517
  char*   arbToken;
2518
  char*   member0Token;
2519
  char*   member1Token;
2520
  int32_t vgId;
2521
  int32_t errCode;
2522
} SVArbCheckSyncRsp;
2523

2524
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2525
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2526
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2527

2528
typedef struct {
2529
  char*   arbToken;
2530
  int64_t arbTerm;
2531
  char*   memberToken;
2532
} SVArbSetAssignedLeaderReq;
2533

2534
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2535
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2536
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2537

2538
typedef struct {
2539
  char*   arbToken;
2540
  char*   memberToken;
2541
  int32_t vgId;
2542
} SVArbSetAssignedLeaderRsp;
2543

2544
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2545
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2546
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2547

2548
typedef struct {
2549
  int32_t dnodeId;
2550
  char*   token;
2551
} SMArbUpdateGroupMember;
2552

2553
typedef struct {
2554
  int32_t dnodeId;
2555
  char*   token;
2556
  int8_t  acked;
2557
} SMArbUpdateGroupAssigned;
2558

2559
typedef struct {
2560
  int32_t                  vgId;
2561
  int64_t                  dbUid;
2562
  SMArbUpdateGroupMember   members[2];
2563
  int8_t                   isSync;
2564
  int8_t                   assignedAcked;
2565
  SMArbUpdateGroupAssigned assignedLeader;
2566
  int64_t                  version;
2567
} SMArbUpdateGroup;
2568

2569
typedef struct {
2570
  SArray* updateArray;  // SMArbUpdateGroup
2571
} SMArbUpdateGroupBatchReq;
2572

2573
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2574
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2575
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2576

2577
typedef struct {
2578
  char queryStrId[TSDB_QUERY_ID_LEN];
2579
} SKillQueryReq;
2580

2581
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2582
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2583

2584
typedef struct {
2585
  uint32_t connId;
2586
} SKillConnReq;
2587

2588
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2589
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2590

2591
typedef struct {
2592
  int32_t transId;
2593
} SKillTransReq;
2594

2595
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2596
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2597

2598
typedef struct {
2599
  int32_t useless;  // useless
2600
  int32_t sqlLen;
2601
  char*   sql;
2602
} SBalanceVgroupReq;
2603

2604
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2605
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2606
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2607

2608
typedef struct {
2609
  int32_t vgId1;
2610
  int32_t vgId2;
2611
} SMergeVgroupReq;
2612

2613
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2614
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2615

2616
typedef struct {
2617
  int32_t vgId;
2618
  int32_t dnodeId1;
2619
  int32_t dnodeId2;
2620
  int32_t dnodeId3;
2621
  int32_t sqlLen;
2622
  char*   sql;
2623
} SRedistributeVgroupReq;
2624

2625
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2626
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2627
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2628

2629
typedef struct {
2630
  int32_t reserved;
2631
  int32_t vgId;
2632
  int32_t sqlLen;
2633
  char*   sql;
2634
  char    db[TSDB_DB_FNAME_LEN];
2635
} SBalanceVgroupLeaderReq;
2636

2637
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2638
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2639
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2640

2641
typedef struct {
2642
  int32_t vgId;
2643
} SForceBecomeFollowerReq;
2644

2645
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2646
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2647

2648
typedef struct {
2649
  int32_t vgId;
2650
} SSplitVgroupReq;
2651

2652
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2653
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2654

2655
typedef struct {
2656
  char user[TSDB_USER_LEN];
2657
  char spi;
2658
  char encrypt;
2659
  char secret[TSDB_PASSWORD_LEN];
2660
  char ckey[TSDB_PASSWORD_LEN];
2661
} SAuthReq, SAuthRsp;
2662

2663
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2664
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2665

2666
typedef struct {
2667
  int32_t statusCode;
2668
  char    details[1024];
2669
} SServerStatusRsp;
2670

2671
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2672
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2673

2674
/**
2675
 * The layout of the query message payload is as following:
2676
 * +--------------------+---------------------------------+
2677
 * |Sql statement       | Physical plan                   |
2678
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2679
 * +--------------------+---------------------------------+
2680
 */
2681
typedef struct SSubQueryMsg {
2682
  SMsgHead header;
2683
  uint64_t sId;
2684
  uint64_t queryId;
2685
  uint64_t clientId;
2686
  uint64_t taskId;
2687
  int64_t  refId;
2688
  int32_t  execId;
2689
  int32_t  msgMask;
2690
  int8_t   taskType;
2691
  int8_t   explain;
2692
  int8_t   needFetch;
2693
  int8_t   compress;
2694
  uint32_t sqlLen;
2695
  char*    sql;
2696
  uint32_t msgLen;
2697
  char*    msg;
2698
} SSubQueryMsg;
2699

2700
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2701
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2702
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2703

2704
typedef struct {
2705
  SMsgHead header;
2706
  uint64_t sId;
2707
  uint64_t queryId;
2708
  uint64_t taskId;
2709
} SSinkDataReq;
2710

2711
typedef struct {
2712
  SMsgHead header;
2713
  uint64_t sId;
2714
  uint64_t queryId;
2715
  uint64_t clientId;
2716
  uint64_t taskId;
2717
  int32_t  execId;
2718
} SQueryContinueReq;
2719

2720
typedef struct {
2721
  SMsgHead header;
2722
  uint64_t sId;
2723
  uint64_t queryId;
2724
  uint64_t taskId;
2725
} SResReadyReq;
2726

2727
typedef struct {
2728
  int32_t code;
2729
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2730
  int32_t sversion;
2731
  int32_t tversion;
2732
} SResReadyRsp;
2733

2734
typedef struct SOperatorParam {
2735
  int32_t opType;
2736
  int32_t downstreamIdx;
2737
  void*   value;
2738
  SArray* pChildren;  // SArray<SOperatorParam*>
2739
} SOperatorParam;
2740

2741
typedef struct STableScanOperatorParam {
2742
  bool    tableSeq;
2743
  SArray* pUidList;
2744
} STableScanOperatorParam;
2745

2746
typedef struct {
2747
  SMsgHead        header;
2748
  uint64_t        sId;
2749
  uint64_t        queryId;
2750
  uint64_t        clientId;
2751
  uint64_t        taskId;
2752
  int32_t         execId;
2753
  SOperatorParam* pOpParam;
2754
} SResFetchReq;
2755

2756
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2757
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2758

2759
typedef struct {
2760
  SMsgHead header;
2761
  uint64_t sId;
2762
} SSchTasksStatusReq;
2763

2764
typedef struct {
2765
  uint64_t queryId;
2766
  uint64_t clientId;
2767
  uint64_t taskId;
2768
  int64_t  refId;
2769
  int32_t  execId;
2770
  int8_t   status;
2771
} STaskStatus;
2772

2773
typedef struct {
2774
  int64_t refId;
2775
  SArray* taskStatus;  // SArray<STaskStatus>
2776
} SSchedulerStatusRsp;
2777

2778
typedef struct {
2779
  uint64_t queryId;
2780
  uint64_t taskId;
2781
  int8_t   action;
2782
} STaskAction;
2783

2784
typedef struct SQueryNodeEpId {
2785
  int32_t nodeId;  // vgId or qnodeId
2786
  SEp     ep;
2787
} SQueryNodeEpId;
2788

2789
typedef struct {
2790
  SMsgHead       header;
2791
  uint64_t       sId;
2792
  SQueryNodeEpId epId;
2793
  SArray*        taskAction;  // SArray<STaskAction>
2794
} SSchedulerHbReq;
2795

2796
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2797
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2798
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2799

2800
typedef struct {
2801
  SQueryNodeEpId epId;
2802
  SArray*        taskStatus;  // SArray<STaskStatus>
2803
} SSchedulerHbRsp;
2804

2805
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2806
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2807
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2808

2809
typedef struct {
2810
  SMsgHead header;
2811
  uint64_t sId;
2812
  uint64_t queryId;
2813
  uint64_t clientId;
2814
  uint64_t taskId;
2815
  int64_t  refId;
2816
  int32_t  execId;
2817
} STaskCancelReq;
2818

2819
typedef struct {
2820
  int32_t code;
2821
} STaskCancelRsp;
2822

2823
typedef struct {
2824
  SMsgHead header;
2825
  uint64_t sId;
2826
  uint64_t queryId;
2827
  uint64_t clientId;
2828
  uint64_t taskId;
2829
  int64_t  refId;
2830
  int32_t  execId;
2831
} STaskDropReq;
2832

2833
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2834
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2835

2836
typedef enum {
2837
  TASK_NOTIFY_FINISHED = 1,
2838
} ETaskNotifyType;
2839

2840
typedef struct {
2841
  SMsgHead        header;
2842
  uint64_t        sId;
2843
  uint64_t        queryId;
2844
  uint64_t        clientId;
2845
  uint64_t        taskId;
2846
  int64_t         refId;
2847
  int32_t         execId;
2848
  ETaskNotifyType type;
2849
} STaskNotifyReq;
2850

2851
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2852
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2853

2854
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2855
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2856

2857
typedef struct {
2858
  int32_t code;
2859
} STaskDropRsp;
2860

2861
#define STREAM_TRIGGER_AT_ONCE            1
2862
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2863
#define STREAM_TRIGGER_MAX_DELAY          3
2864
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2865

2866
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2867
#define STREAM_FILL_HISTORY_ON        1
2868
#define STREAM_FILL_HISTORY_OFF       0
2869
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2870
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2871
#define STREAM_CREATE_STABLE_TRUE     1
2872
#define STREAM_CREATE_STABLE_FALSE    0
2873

2874
typedef struct SColLocation {
2875
  int16_t  slotId;
2876
  col_id_t colId;
2877
  int8_t   type;
2878
} SColLocation;
2879

2880
typedef struct SVgroupVer {
2881
  int32_t vgId;
2882
  int64_t ver;
2883
} SVgroupVer;
2884

2885
typedef struct {
2886
  char    name[TSDB_STREAM_FNAME_LEN];
2887
  char    sourceDB[TSDB_DB_FNAME_LEN];
2888
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2889
  char*   sql;
2890
  char*   ast;
2891
  int8_t  igExists;
2892
  int8_t  triggerType;
2893
  int8_t  igExpired;
2894
  int8_t  fillHistory;  // process data inserted before creating stream
2895
  int64_t maxDelay;
2896
  int64_t watermark;
2897
  int32_t numOfTags;
2898
  SArray* pTags;  // array of SField
2899
  // 3.0.20
2900
  int64_t checkpointFreq;  // ms
2901
  // 3.0.2.3
2902
  int8_t   createStb;
2903
  uint64_t targetStbUid;
2904
  SArray*  fillNullCols;  // array of SColLocation
2905
  int64_t  deleteMark;
2906
  int8_t   igUpdate;
2907
  int64_t  lastTs;
2908
  SArray*  pVgroupVerList;
2909
  // 3.3.0.0
2910
  SArray* pCols;  // array of SField
2911
  int64_t smaId;
2912
} SCMCreateStreamReq;
2913

2914
typedef struct {
2915
  int64_t streamId;
2916
} SCMCreateStreamRsp;
2917

2918
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2919
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2920
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2921

2922
enum {
2923
  TOPIC_SUB_TYPE__DB = 1,
2924
  TOPIC_SUB_TYPE__TABLE,
2925
  TOPIC_SUB_TYPE__COLUMN,
2926
};
2927

2928
#define DEFAULT_MAX_POLL_INTERVAL 300000
2929
#define DEFAULT_SESSION_TIMEOUT   12000
2930

2931
typedef struct {
2932
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2933
  int8_t igExists;
2934
  int8_t subType;
2935
  int8_t withMeta;
2936
  char*  sql;
2937
  char   subDbName[TSDB_DB_FNAME_LEN];
2938
  char*  ast;
2939
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2940
} SCMCreateTopicReq;
2941

2942
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2943
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2944
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2945

2946
typedef struct {
2947
  int64_t consumerId;
2948
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2949

2950
typedef struct {
2951
  int64_t consumerId;
2952
  char    cgroup[TSDB_CGROUP_LEN];
2953
  char    clientId[TSDB_CLIENT_ID_LEN];
2954
  char    user[TSDB_USER_LEN];
2955
  char    fqdn[TSDB_FQDN_LEN];
2956
  SArray* topicNames;  // SArray<char**>
2957

2958
  int8_t  withTbName;
2959
  int8_t  autoCommit;
2960
  int32_t autoCommitInterval;
2961
  int8_t  resetOffsetCfg;
2962
  int8_t  enableReplay;
2963
  int8_t  enableBatchMeta;
2964
  int32_t sessionTimeoutMs;
2965
  int32_t maxPollIntervalMs;
2966
} SCMSubscribeReq;
2967

2968
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
2969
  int32_t tlen = 0;
2,398✔
2970
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,398!
2971
  tlen += taosEncodeString(buf, pReq->cgroup);
2,398✔
2972
  tlen += taosEncodeString(buf, pReq->clientId);
2,398✔
2973

2974
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,398!
2975
  tlen += taosEncodeFixedI32(buf, topicNum);
2,398✔
2976

2977
  for (int32_t i = 0; i < topicNum; i++) {
3,372✔
2978
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,948✔
2979
  }
2980

2981
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,398!
2982
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,398!
2983
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,398!
2984
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,398!
2985
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,398!
2986
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,398!
2987
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,398!
2988
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,398!
2989
  tlen += taosEncodeString(buf, pReq->user);
2,398✔
2990
  tlen += taosEncodeString(buf, pReq->fqdn);
2,398✔
2991

2992
  return tlen;
2,398✔
2993
}
2994

2995
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
2996
  void* start = buf;
1,314✔
2997
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,314!
2998
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,314✔
2999
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,314✔
3000

3001
  int32_t topicNum = 0;
1,314!
3002
  buf = taosDecodeFixedI32(buf, &topicNum);
1,314✔
3003

3004
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,314✔
3005
  if (pReq->topicNames == NULL) {
1,314!
3006
    return terrno;
×
3007
  }
3008
  for (int32_t i = 0; i < topicNum; i++) {
1,914✔
3009
    char* name = NULL;
600✔
3010
    buf = taosDecodeString(buf, &name);
600✔
3011
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,200!
3012
      return terrno;
×
3013
    }
3014
  }
3015

3016
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,314✔
3017
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,314✔
3018
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,314!
3019
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,314✔
3020
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,314✔
3021
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,314✔
3022
  if ((char*)buf - (char*)start < len) {
1,314!
3023
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,314!
3024
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,314!
3025
    buf = taosDecodeStringTo(buf, pReq->user);
1,314✔
3026
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,628✔
3027
  } else {
3028
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3029
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3030
  }
3031

3032
  return 0;
1,314✔
3033
}
3034

3035
typedef struct {
3036
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3037
  SArray* removedConsumers;  // SArray<int64_t>
3038
  SArray* newConsumers;      // SArray<int64_t>
3039
} SMqRebInfo;
3040

3041
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3042
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,266✔
3043
  if (pRebInfo == NULL) {
1,266!
3044
    return NULL;
×
3045
  }
3046
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,266✔
3047
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,266✔
3048
  if (pRebInfo->removedConsumers == NULL) {
1,266!
3049
    goto _err;
×
3050
  }
3051
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,266✔
3052
  if (pRebInfo->newConsumers == NULL) {
1,266!
3053
    goto _err;
×
3054
  }
3055
  return pRebInfo;
1,266✔
3056
_err:
×
3057
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3058
  taosArrayDestroy(pRebInfo->newConsumers);
×
3059
  taosMemoryFreeClear(pRebInfo);
×
3060
  return NULL;
×
3061
}
3062

3063
typedef struct {
3064
  int64_t streamId;
3065
  int64_t checkpointId;
3066
  char    streamName[TSDB_STREAM_FNAME_LEN];
3067
} SMStreamDoCheckpointMsg;
3068

3069
typedef struct {
3070
  int64_t status;
3071
} SMVSubscribeRsp;
3072

3073
typedef struct {
3074
  char    name[TSDB_TOPIC_FNAME_LEN];
3075
  int8_t  igNotExists;
3076
  int32_t sqlLen;
3077
  char*   sql;
3078
} SMDropTopicReq;
3079

3080
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3081
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3082
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3083

3084
typedef struct {
3085
  char   topic[TSDB_TOPIC_FNAME_LEN];
3086
  char   cgroup[TSDB_CGROUP_LEN];
3087
  int8_t igNotExists;
3088
} SMDropCgroupReq;
3089

3090
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3091
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3092

3093
typedef struct {
3094
  int8_t reserved;
3095
} SMDropCgroupRsp;
3096

3097
typedef struct {
3098
  char    name[TSDB_TABLE_FNAME_LEN];
3099
  int8_t  alterType;
3100
  SSchema schema;
3101
} SAlterTopicReq;
3102

3103
typedef struct {
3104
  SMsgHead head;
3105
  char     name[TSDB_TABLE_FNAME_LEN];
3106
  int64_t  tuid;
3107
  int32_t  sverson;
3108
  int32_t  execLen;
3109
  char*    executor;
3110
  int32_t  sqlLen;
3111
  char*    sql;
3112
} SDCreateTopicReq;
3113

3114
typedef struct {
3115
  SMsgHead head;
3116
  char     name[TSDB_TABLE_FNAME_LEN];
3117
  int64_t  tuid;
3118
} SDDropTopicReq;
3119

3120
typedef struct {
3121
  int64_t maxdelay[2];
3122
  int64_t watermark[2];
3123
  int64_t deleteMark[2];
3124
  int32_t qmsgLen[2];
3125
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3126
} SRSmaParam;
3127

3128
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3129
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3130

3131
// TDMT_VND_CREATE_STB ==============
3132
typedef struct SVCreateStbReq {
3133
  char*           name;
3134
  tb_uid_t        suid;
3135
  int8_t          rollup;
3136
  SSchemaWrapper  schemaRow;
3137
  SSchemaWrapper  schemaTag;
3138
  SRSmaParam      rsmaParam;
3139
  int32_t         alterOriDataLen;
3140
  void*           alterOriData;
3141
  int8_t          source;
3142
  int8_t          colCmpred;
3143
  SColCmprWrapper colCmpr;
3144
} SVCreateStbReq;
3145

3146
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3147
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3148

3149
// TDMT_VND_DROP_STB ==============
3150
typedef struct SVDropStbReq {
3151
  char*    name;
3152
  tb_uid_t suid;
3153
} SVDropStbReq;
3154

3155
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3156
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3157

3158
// TDMT_VND_CREATE_TABLE ==============
3159
#define TD_CREATE_IF_NOT_EXISTS 0x1
3160
typedef struct SVCreateTbReq {
3161
  int32_t  flags;
3162
  char*    name;
3163
  tb_uid_t uid;
3164
  int64_t  btime;
3165
  int32_t  ttl;
3166
  int32_t  commentLen;
3167
  char*    comment;
3168
  int8_t   type;
3169
  union {
3170
    struct {
3171
      char*    stbName;  // super table name
3172
      uint8_t  tagNum;
3173
      tb_uid_t suid;
3174
      SArray*  tagName;
3175
      uint8_t* pTag;
3176
    } ctb;
3177
    struct {
3178
      SSchemaWrapper schemaRow;
3179
    } ntb;
3180
  };
3181
  int32_t         sqlLen;
3182
  char*           sql;
3183
  SColCmprWrapper colCmpr;
3184
} SVCreateTbReq;
3185

3186
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3187
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3188
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3189

3190
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,519✔
3191
  if (NULL == req) {
19,331,880!
3192
    return;
19,182,125✔
3193
  }
3194

3195
  taosMemoryFreeClear(req->sql);
149,755!
3196
  taosMemoryFreeClear(req->name);
149,755!
3197
  taosMemoryFreeClear(req->comment);
149,768!
3198
  if (req->type == TSDB_CHILD_TABLE) {
149,768!
3199
    taosMemoryFreeClear(req->ctb.pTag);
137,235!
3200
    taosMemoryFreeClear(req->ctb.stbName);
137,237!
3201
    taosArrayDestroy(req->ctb.tagName);
137,243✔
3202
    req->ctb.tagName = NULL;
137,243✔
3203
  } else if (req->type == TSDB_NORMAL_TABLE) {
12,533!
3204
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
12,533!
3205
  }
3206
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
149,776!
3207
}
3208

3209
typedef struct {
3210
  int32_t nReqs;
3211
  union {
3212
    SVCreateTbReq* pReqs;
3213
    SArray*        pArray;
3214
  };
3215
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3216
} SVCreateTbBatchReq;
3217

3218
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3219
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3220
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3221

3222
typedef struct {
3223
  int32_t        code;
3224
  STableMetaRsp* pMeta;
3225
} SVCreateTbRsp, SVUpdateTbRsp;
3226

3227
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3228
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3229
void tFreeSVCreateTbRsp(void* param);
3230

3231
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3232
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3233

3234
typedef struct {
3235
  int32_t nRsps;
3236
  union {
3237
    SVCreateTbRsp* pRsps;
3238
    SArray*        pArray;
3239
  };
3240
} SVCreateTbBatchRsp;
3241

3242
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3243
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3244

3245
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3246
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3247

3248
// TDMT_VND_DROP_TABLE =================
3249
typedef struct {
3250
  char*    name;
3251
  uint64_t suid;  // for tmq in wal format
3252
  int64_t  uid;
3253
  int8_t   igNotExists;
3254
} SVDropTbReq;
3255

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

3260
typedef struct {
3261
  int32_t nReqs;
3262
  union {
3263
    SVDropTbReq* pReqs;
3264
    SArray*      pArray;
3265
  };
3266
} SVDropTbBatchReq;
3267

3268
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3269
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3270

3271
typedef struct {
3272
  int32_t nRsps;
3273
  union {
3274
    SVDropTbRsp* pRsps;
3275
    SArray*      pArray;
3276
  };
3277
} SVDropTbBatchRsp;
3278

3279
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3280
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3281

3282
// TDMT_VND_ALTER_TABLE =====================
3283
typedef struct SMultiTagUpateVal {
3284
  char*    tagName;
3285
  int32_t  colId;
3286
  int8_t   tagType;
3287
  int8_t   tagFree;
3288
  uint32_t nTagVal;
3289
  uint8_t* pTagVal;
3290
  int8_t   isNull;
3291
  SArray*  pTagArray;
3292
} SMultiTagUpateVal;
3293
typedef struct {
3294
  char*   tbName;
3295
  int8_t  action;
3296
  char*   colName;
3297
  int32_t colId;
3298
  // TSDB_ALTER_TABLE_ADD_COLUMN
3299
  int8_t  type;
3300
  int8_t  flags;
3301
  int32_t bytes;
3302
  // TSDB_ALTER_TABLE_DROP_COLUMN
3303
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3304
  int8_t   colModType;
3305
  int32_t  colModBytes;
3306
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3307
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3308
  int8_t   isNull;
3309
  int8_t   tagType;
3310
  int8_t   tagFree;
3311
  uint32_t nTagVal;
3312
  uint8_t* pTagVal;
3313
  SArray*  pTagArray;
3314
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3315
  int8_t   updateTTL;
3316
  int32_t  newTTL;
3317
  int32_t  newCommentLen;
3318
  char*    newComment;
3319
  int64_t  ctimeMs;    // fill by vnode
3320
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3321
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3322
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3323
} SVAlterTbReq;
3324

3325
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3326
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3327
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3328
void    tfreeMultiTagUpateVal(void* pMultiTag);
3329

3330
typedef struct {
3331
  int32_t        code;
3332
  STableMetaRsp* pMeta;
3333
} SVAlterTbRsp;
3334

3335
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3336
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3337
// ======================
3338

3339
typedef struct {
3340
  SMsgHead head;
3341
  int64_t  uid;
3342
  int32_t  tid;
3343
  int16_t  tversion;
3344
  int16_t  colId;
3345
  int8_t   type;
3346
  int16_t  bytes;
3347
  int32_t  tagValLen;
3348
  int16_t  numOfTags;
3349
  int32_t  schemaLen;
3350
  char     data[];
3351
} SUpdateTagValReq;
3352

3353
typedef struct {
3354
  SMsgHead head;
3355
} SUpdateTagValRsp;
3356

3357
typedef struct {
3358
  SMsgHead head;
3359
} SVShowTablesReq;
3360

3361
typedef struct {
3362
  SMsgHead head;
3363
  int32_t  id;
3364
} SVShowTablesFetchReq;
3365

3366
typedef struct {
3367
  int64_t useconds;
3368
  int8_t  completed;  // all results are returned to client
3369
  int8_t  precision;
3370
  int8_t  compressed;
3371
  int32_t compLen;
3372
  int32_t numOfRows;
3373
  char    data[];
3374
} SVShowTablesFetchRsp;
3375

3376
typedef struct {
3377
  int64_t consumerId;
3378
  int32_t epoch;
3379
  char    cgroup[TSDB_CGROUP_LEN];
3380
} SMqAskEpReq;
3381

3382
typedef struct {
3383
  int32_t key;
3384
  int32_t valueLen;
3385
  void*   value;
3386
} SKv;
3387

3388
typedef struct {
3389
  int64_t tscRid;
3390
  int8_t  connType;
3391
} SClientHbKey;
3392

3393
typedef struct {
3394
  int64_t tid;
3395
  char    status[TSDB_JOB_STATUS_LEN];
3396
} SQuerySubDesc;
3397

3398
typedef struct {
3399
  char     sql[TSDB_SHOW_SQL_LEN];
3400
  uint64_t queryId;
3401
  int64_t  useconds;
3402
  int64_t  stime;  // timestamp precision ms
3403
  int64_t  reqRid;
3404
  bool     stableQuery;
3405
  bool     isSubQuery;
3406
  char     fqdn[TSDB_FQDN_LEN];
3407
  int32_t  subPlanNum;
3408
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3409
} SQueryDesc;
3410

3411
typedef struct {
3412
  uint32_t connId;
3413
  SArray*  queryDesc;  // SArray<SQueryDesc>
3414
} SQueryHbReqBasic;
3415

3416
typedef struct {
3417
  uint32_t connId;
3418
  uint64_t killRid;
3419
  int32_t  totalDnodes;
3420
  int32_t  onlineDnodes;
3421
  int8_t   killConnection;
3422
  int8_t   align[3];
3423
  SEpSet   epSet;
3424
  SArray*  pQnodeList;
3425
} SQueryHbRspBasic;
3426

3427
typedef struct SAppClusterSummary {
3428
  uint64_t numOfInsertsReq;
3429
  uint64_t numOfInsertRows;
3430
  uint64_t insertElapsedTime;
3431
  uint64_t insertBytes;  // submit to tsdb since launched.
3432

3433
  uint64_t fetchBytes;
3434
  uint64_t numOfQueryReq;
3435
  uint64_t queryElapsedTime;
3436
  uint64_t numOfSlowQueries;
3437
  uint64_t totalRequests;
3438
  uint64_t currentRequests;  // the number of SRequestObj
3439
} SAppClusterSummary;
3440

3441
typedef struct {
3442
  int64_t            appId;
3443
  int32_t            pid;
3444
  char               name[TSDB_APP_NAME_LEN];
3445
  int64_t            startTime;
3446
  SAppClusterSummary summary;
3447
} SAppHbReq;
3448

3449
typedef struct {
3450
  SClientHbKey      connKey;
3451
  int64_t           clusterId;
3452
  SAppHbReq         app;
3453
  SQueryHbReqBasic* query;
3454
  SHashObj*         info;  // hash<Skv.key, Skv>
3455
} SClientHbReq;
3456

3457
typedef struct {
3458
  int64_t reqId;
3459
  SArray* reqs;  // SArray<SClientHbReq>
3460
  int64_t ipWhiteList;
3461
} SClientHbBatchReq;
3462

3463
typedef struct {
3464
  SClientHbKey      connKey;
3465
  int32_t           status;
3466
  SQueryHbRspBasic* query;
3467
  SArray*           info;  // Array<Skv>
3468
} SClientHbRsp;
3469

3470
typedef struct {
3471
  int64_t       reqId;
3472
  int64_t       rspId;
3473
  int32_t       svrTimestamp;
3474
  SArray*       rsps;  // SArray<SClientHbRsp>
3475
  SMonitorParas monitorParas;
3476
  int8_t        enableAuditDelete;
3477
} SClientHbBatchRsp;
3478

3479
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
197,081✔
3480

3481
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3482
  void* pIter = taosHashIterate(info, NULL);
502,843✔
3483
  while (pIter != NULL) {
867,784!
3484
    SKv* kv = (SKv*)pIter;
364,898✔
3485
    taosMemoryFreeClear(kv->value);
364,898!
3486
    pIter = taosHashIterate(info, pIter);
364,899✔
3487
  }
3488
}
502,886✔
3489

3490
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
326,330✔
3491
  SQueryDesc* desc = (SQueryDesc*)pDesc;
326,330✔
3492
  if (desc->subDesc) {
326,330✔
3493
    taosArrayDestroy(desc->subDesc);
320,256✔
3494
    desc->subDesc = NULL;
320,252✔
3495
  }
3496
}
326,326✔
3497

3498
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
588,527✔
3499
  SClientHbReq* req = (SClientHbReq*)pReq;
599,013✔
3500
  if (req->query) {
599,013!
3501
    if (req->query->queryDesc) {
579,908!
3502
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
41,104✔
3503
    }
3504
    taosMemoryFreeClear(req->query);
579,908!
3505
  }
3506

3507
  if (req->info) {
599,056!
3508
    tFreeReqKvHash(req->info);
502,843✔
3509
    taosHashCleanup(req->info);
502,886✔
3510
    req->info = NULL;
502,858✔
3511
  }
3512
}
483,881✔
3513

3514
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3515
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3516

3517
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3518
  if (pReq == NULL) return;
36,735!
3519
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
36,735✔
3520
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
36,735✔
3521
  taosMemoryFree(pReq);
36,735✔
3522
}
3523

3524
static FORCE_INLINE void tFreeClientKv(void* pKv) {
139,240✔
3525
  SKv* kv = (SKv*)pKv;
139,240✔
3526
  if (kv) {
139,240!
3527
    taosMemoryFreeClear(kv->value);
139,240!
3528
  }
3529
}
139,240✔
3530

3531
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
586,273✔
3532
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
586,273✔
3533
  if (rsp->query) {
586,273✔
3534
    taosArrayDestroy(rsp->query->pQnodeList);
577,753✔
3535
    taosMemoryFreeClear(rsp->query);
577,878!
3536
  }
3537
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
586,504!
3538
}
113,199✔
3539

3540
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3541
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
403,020✔
3542
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
403,020✔
3543
}
403,081✔
3544

3545
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3546
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3547
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3548

3549
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3550
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
670,114!
3551
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
670,114!
3552
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
670,114!
3553
  return 0;
335,057✔
3554
}
3555

3556
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3557
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
673,179!
3558
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
673,185!
3559
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
336,594✔
3560
  if (pKv->value == NULL) {
336,593!
3561
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3562
  }
3563
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
336,593!
3564
  return 0;
336,589✔
3565
}
3566

3567
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3568
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,352,714!
3569
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,352,714!
3570
  return 0;
1,176,357✔
3571
}
3572

3573
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3574
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,172,852!
3575
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,172,958!
3576
  return 0;
586,518✔
3577
}
3578

3579
typedef struct {
3580
  int32_t vgId;
3581
  // TODO stas
3582
} SMqReportVgInfo;
3583

3584
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3585
  int32_t tlen = 0;
3586
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3587
  return tlen;
3588
}
3589

3590
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3591
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3592
  return buf;
3593
}
3594

3595
typedef struct {
3596
  int32_t epoch;
3597
  int64_t topicUid;
3598
  char    name[TSDB_TOPIC_FNAME_LEN];
3599
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3600
} SMqTopicInfo;
3601

3602
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3603
  int32_t tlen = 0;
3604
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3605
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3606
  tlen += taosEncodeString(buf, pTopicInfo->name);
3607
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3608
  tlen += taosEncodeFixedI32(buf, sz);
3609
  for (int32_t i = 0; i < sz; i++) {
3610
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3611
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3612
  }
3613
  return tlen;
3614
}
3615

3616
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3617
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3618
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3619
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3620
  int32_t sz;
3621
  buf = taosDecodeFixedI32(buf, &sz);
3622
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3623
    return NULL;
3624
  }
3625
  for (int32_t i = 0; i < sz; i++) {
3626
    SMqReportVgInfo vgInfo;
3627
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3628
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3629
      return NULL;
3630
    }
3631
  }
3632
  return buf;
3633
}
3634

3635
typedef struct {
3636
  int32_t status;  // ask hb endpoint
3637
  int32_t epoch;
3638
  int64_t consumerId;
3639
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3640
} SMqReportReq;
3641

3642
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3643
  int32_t tlen = 0;
3644
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3645
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3646
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3647
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3648
  tlen += taosEncodeFixedI32(buf, sz);
3649
  for (int32_t i = 0; i < sz; i++) {
3650
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3651
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3652
  }
3653
  return tlen;
3654
}
3655

3656
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3657
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3658
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3659
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3660
  int32_t sz;
3661
  buf = taosDecodeFixedI32(buf, &sz);
3662
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3663
    return NULL;
3664
  }
3665
  for (int32_t i = 0; i < sz; i++) {
3666
    SMqTopicInfo topicInfo;
3667
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3668
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3669
      return NULL;
3670
    }
3671
  }
3672
  return buf;
3673
}
3674

3675
typedef struct {
3676
  SMsgHead head;
3677
  int64_t  leftForVer;
3678
  int32_t  vgId;
3679
  int64_t  consumerId;
3680
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3681
} SMqVDeleteReq;
3682

3683
typedef struct {
3684
  int8_t reserved;
3685
} SMqVDeleteRsp;
3686

3687
typedef struct {
3688
  char    name[TSDB_STREAM_FNAME_LEN];
3689
  int8_t  igNotExists;
3690
  int32_t sqlLen;
3691
  char*   sql;
3692
} SMDropStreamReq;
3693

3694
typedef struct {
3695
  int8_t reserved;
3696
} SMDropStreamRsp;
3697

3698
typedef struct {
3699
  SMsgHead head;
3700
  int64_t  resetRelHalt;  // reset related stream task halt status
3701
  int64_t  streamId;
3702
  int32_t  taskId;
3703
} SVDropStreamTaskReq;
3704

3705
typedef struct {
3706
  int8_t reserved;
3707
} SVDropStreamTaskRsp;
3708

3709
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3710
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3711
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3712

3713
typedef struct SVUpdateCheckpointInfoReq {
3714
  SMsgHead head;
3715
  int64_t  streamId;
3716
  int32_t  taskId;
3717
  int64_t  checkpointId;
3718
  int64_t  checkpointVer;
3719
  int64_t  checkpointTs;
3720
  int32_t  transId;
3721
  int64_t  hStreamId;  // add encode/decode
3722
  int64_t  hTaskId;
3723
  int8_t   dropRelHTask;
3724
} SVUpdateCheckpointInfoReq;
3725

3726
typedef struct {
3727
  int64_t leftForVer;
3728
  int32_t vgId;
3729
  int64_t oldConsumerId;
3730
  int64_t newConsumerId;
3731
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3732
  int8_t  subType;
3733
  int8_t  withMeta;
3734
  char*   qmsg;  // SubPlanToString
3735
  int64_t suid;
3736
} SMqRebVgReq;
3737

3738
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3739
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3740

3741
typedef struct {
3742
  char    topic[TSDB_TOPIC_FNAME_LEN];
3743
  int64_t ntbUid;
3744
  SArray* colIdList;  // SArray<int16_t>
3745
} STqCheckInfo;
3746

3747
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3748
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3749
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3750

3751
// tqOffset
3752
enum {
3753
  TMQ_OFFSET__RESET_NONE = -3,
3754
  TMQ_OFFSET__RESET_EARLIEST = -2,
3755
  TMQ_OFFSET__RESET_LATEST = -1,
3756
  TMQ_OFFSET__LOG = 1,
3757
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3758
  TMQ_OFFSET__SNAPSHOT_META = 3,
3759
};
3760

3761
enum {
3762
  WITH_DATA = 0,
3763
  WITH_META = 1,
3764
  ONLY_META = 2,
3765
};
3766

3767
#define TQ_OFFSET_VERSION 1
3768

3769
typedef struct {
3770
  int8_t type;
3771
  union {
3772
    // snapshot
3773
    struct {
3774
      int64_t uid;
3775
      int64_t ts;
3776
      SValue  primaryKey;
3777
    };
3778
    // log
3779
    struct {
3780
      int64_t version;
3781
    };
3782
  };
3783
} STqOffsetVal;
3784

3785
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3786
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,001✔
3787
  pOffsetVal->uid = uid;
26,001✔
3788
  pOffsetVal->ts = ts;
26,001✔
3789
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,001!
3790
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3791
  }
3792
  pOffsetVal->primaryKey = primaryKey;
26,001✔
3793
}
26,001✔
3794

3795
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3796
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3797
  pOffsetVal->uid = uid;
149✔
3798
}
149✔
3799

3800
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3801
  pOffsetVal->type = TMQ_OFFSET__LOG;
566,704✔
3802
  pOffsetVal->version = ver;
566,704✔
3803
}
566,704✔
3804

3805
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3806
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3807
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3808
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3809
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3810
void    tOffsetDestroy(void* pVal);
3811

3812
typedef struct {
3813
  STqOffsetVal val;
3814
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3815
} STqOffset;
3816

3817
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3818
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3819
void    tDeleteSTqOffset(void* val);
3820

3821
typedef struct SMqVgOffset {
3822
  int64_t   consumerId;
3823
  STqOffset offset;
3824
} SMqVgOffset;
3825

3826
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3827
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3828

3829
typedef struct {
3830
  SMsgHead head;
3831
  int64_t  streamId;
3832
  int32_t  taskId;
3833
} SVPauseStreamTaskReq;
3834

3835
typedef struct {
3836
  SMsgHead head;
3837
  int64_t  streamId;
3838
  int32_t  taskId;
3839
  int64_t  chkptId;
3840
} SVResetStreamTaskReq;
3841

3842
typedef struct {
3843
  char   name[TSDB_STREAM_FNAME_LEN];
3844
  int8_t igNotExists;
3845
} SMPauseStreamReq;
3846

3847
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3848
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3849

3850
typedef struct {
3851
  SMsgHead head;
3852
  int32_t  taskId;
3853
  int64_t  streamId;
3854
  int8_t   igUntreated;
3855
} SVResumeStreamTaskReq;
3856

3857
typedef struct {
3858
  int8_t reserved;
3859
} SVResumeStreamTaskRsp;
3860

3861
typedef struct {
3862
  char   name[TSDB_STREAM_FNAME_LEN];
3863
  int8_t igNotExists;
3864
  int8_t igUntreated;
3865
} SMResumeStreamReq;
3866

3867
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3868
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3869

3870
typedef struct {
3871
  char    name[TSDB_TABLE_FNAME_LEN];
3872
  char    stb[TSDB_TABLE_FNAME_LEN];
3873
  int8_t  igExists;
3874
  int8_t  intervalUnit;
3875
  int8_t  slidingUnit;
3876
  int8_t  timezone;
3877
  int32_t dstVgId;  // for stream
3878
  int64_t interval;
3879
  int64_t offset;
3880
  int64_t sliding;
3881
  int64_t maxDelay;
3882
  int64_t watermark;
3883
  int32_t exprLen;        // strlen + 1
3884
  int32_t tagsFilterLen;  // strlen + 1
3885
  int32_t sqlLen;         // strlen + 1
3886
  int32_t astLen;         // strlen + 1
3887
  char*   expr;
3888
  char*   tagsFilter;
3889
  char*   sql;
3890
  char*   ast;
3891
  int64_t deleteMark;
3892
  int64_t lastTs;
3893
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3894
  SArray* pVgroupVerList;
3895
  int8_t  recursiveTsma;
3896
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3897
} SMCreateSmaReq;
3898

3899
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3900
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3901
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3902

3903
typedef struct {
3904
  char   name[TSDB_TABLE_FNAME_LEN];
3905
  int8_t igNotExists;
3906
} SMDropSmaReq;
3907

3908
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3909
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3910

3911
typedef struct {
3912
  char   dbFName[TSDB_DB_FNAME_LEN];
3913
  char   stbName[TSDB_TABLE_NAME_LEN];
3914
  char   colName[TSDB_COL_NAME_LEN];
3915
  char   idxName[TSDB_INDEX_FNAME_LEN];
3916
  int8_t idxType;
3917
} SCreateTagIndexReq;
3918

3919
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3920
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3921

3922
typedef SMDropSmaReq SDropTagIndexReq;
3923

3924
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3925
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3926

3927
typedef struct {
3928
  int8_t         version;       // for compatibility(default 0)
3929
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3930
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3931
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3932
  int32_t        dstVgId;
3933
  char           indexName[TSDB_INDEX_NAME_LEN];
3934
  int32_t        exprLen;
3935
  int32_t        tagsFilterLen;
3936
  int64_t        indexUid;
3937
  tb_uid_t       tableUid;  // super/child/common table uid
3938
  tb_uid_t       dstTbUid;  // for dstVgroup
3939
  int64_t        interval;
3940
  int64_t        offset;  // use unit by precision of DB
3941
  int64_t        sliding;
3942
  char*          dstTbName;  // for dstVgroup
3943
  char*          expr;       // sma expression
3944
  char*          tagsFilter;
3945
  SSchemaWrapper schemaRow;  // for dstVgroup
3946
  SSchemaWrapper schemaTag;  // for dstVgroup
3947
} STSma;                     // Time-range-wise SMA
3948

3949
typedef STSma SVCreateTSmaReq;
3950

3951
typedef struct {
3952
  int8_t  type;  // 0 status report, 1 update data
3953
  int64_t indexUid;
3954
  int64_t skey;  // start TS key of interval/sliding window
3955
} STSmaMsg;
3956

3957
typedef struct {
3958
  int64_t indexUid;
3959
  char    indexName[TSDB_INDEX_NAME_LEN];
3960
} SVDropTSmaReq;
3961

3962
typedef struct {
3963
  int tmp;  // TODO: to avoid compile error
3964
} SVCreateTSmaRsp, SVDropTSmaRsp;
3965

3966
#if 0
3967
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3968
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3969
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3970
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3971
#endif
3972

3973
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3974
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3975
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3976
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3977

3978
typedef struct {
3979
  int32_t number;
3980
  STSma*  tSma;
3981
} STSmaWrapper;
3982

3983
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3984
  if (pSma) {
1!
3985
    taosMemoryFreeClear(pSma->dstTbName);
1!
3986
    taosMemoryFreeClear(pSma->expr);
1!
3987
    taosMemoryFreeClear(pSma->tagsFilter);
1!
3988
  }
3989
}
1✔
3990

3991
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3992
  if (pSW) {
×
3993
    if (pSW->tSma) {
×
3994
      if (deepCopy) {
×
3995
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3996
          tDestroyTSma(pSW->tSma + i);
×
3997
        }
3998
      }
3999
      taosMemoryFreeClear(pSW->tSma);
×
4000
    }
4001
  }
4002
}
×
4003

4004
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4005
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4006
  taosMemoryFreeClear(pSW);
×
4007
  return NULL;
×
4008
}
4009

4010
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4011
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4012

4013
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4014
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4015

4016
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4017
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4018
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4019
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4020
  }
4021
  return 0;
×
4022
}
4023

4024
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4025
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4026
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4027
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4028
  }
4029
  return 0;
×
4030
}
4031

4032
typedef struct {
4033
  int idx;
4034
} SMCreateFullTextReq;
4035

4036
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4037
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4038
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4039

4040
typedef struct {
4041
  char   name[TSDB_TABLE_FNAME_LEN];
4042
  int8_t igNotExists;
4043
} SMDropFullTextReq;
4044

4045
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4046
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4047

4048
typedef struct {
4049
  char indexFName[TSDB_INDEX_FNAME_LEN];
4050
} SUserIndexReq;
4051

4052
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4053
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4054

4055
typedef struct {
4056
  char dbFName[TSDB_DB_FNAME_LEN];
4057
  char tblFName[TSDB_TABLE_FNAME_LEN];
4058
  char colName[TSDB_COL_NAME_LEN];
4059
  char indexType[TSDB_INDEX_TYPE_LEN];
4060
  char indexExts[TSDB_INDEX_EXTS_LEN];
4061
} SUserIndexRsp;
4062

4063
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4064
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4065

4066
typedef struct {
4067
  char tbFName[TSDB_TABLE_FNAME_LEN];
4068
} STableIndexReq;
4069

4070
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4071
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4072

4073
typedef struct {
4074
  int8_t  intervalUnit;
4075
  int8_t  slidingUnit;
4076
  int64_t interval;
4077
  int64_t offset;
4078
  int64_t sliding;
4079
  int64_t dstTbUid;
4080
  int32_t dstVgId;
4081
  SEpSet  epSet;
4082
  char*   expr;
4083
} STableIndexInfo;
4084

4085
typedef struct {
4086
  char     tbName[TSDB_TABLE_NAME_LEN];
4087
  char     dbFName[TSDB_DB_FNAME_LEN];
4088
  uint64_t suid;
4089
  int32_t  version;
4090
  int32_t  indexSize;
4091
  SArray*  pIndex;  // STableIndexInfo
4092
} STableIndexRsp;
4093

4094
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4095
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4096
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4097

4098
void tFreeSTableIndexInfo(void* pInfo);
4099

4100
typedef struct {
4101
  int8_t  mqMsgType;
4102
  int32_t code;
4103
  int32_t epoch;
4104
  int64_t consumerId;
4105
  int64_t walsver;
4106
  int64_t walever;
4107
} SMqRspHead;
4108

4109
typedef struct {
4110
  SMsgHead     head;
4111
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4112
  int8_t       withTbName;
4113
  int8_t       useSnapshot;
4114
  int32_t      epoch;
4115
  uint64_t     reqId;
4116
  int64_t      consumerId;
4117
  int64_t      timeout;
4118
  STqOffsetVal reqOffset;
4119
  int8_t       enableReplay;
4120
  int8_t       sourceExcluded;
4121
  int8_t       enableBatchMeta;
4122
} SMqPollReq;
4123

4124
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4125
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4126
void    tDestroySMqPollReq(SMqPollReq* pReq);
4127

4128
typedef struct {
4129
  int32_t vgId;
4130
  int64_t offset;
4131
  SEpSet  epSet;
4132
} SMqSubVgEp;
4133

4134
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4135
  int32_t tlen = 0;
8,460✔
4136
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,460✔
4137
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,460✔
4138
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,460✔
4139
  return tlen;
8,460✔
4140
}
4141

4142
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4143
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,093!
4144
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,093!
4145
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,093✔
4146
  return buf;
4,093✔
4147
}
4148

4149
typedef struct {
4150
  char           topic[TSDB_TOPIC_FNAME_LEN];
4151
  char           db[TSDB_DB_FNAME_LEN];
4152
  SArray*        vgs;  // SArray<SMqSubVgEp>
4153
  SSchemaWrapper schema;
4154
} SMqSubTopicEp;
4155

4156
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4157
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4158
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4159

4160
typedef struct {
4161
  SMqRspHead   head;
4162
  STqOffsetVal rspOffset;
4163
  int16_t      resMsgType;
4164
  int32_t      metaRspLen;
4165
  void*        metaRsp;
4166
} SMqMetaRsp;
4167

4168
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4169
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4170
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4171

4172
#define MQ_DATA_RSP_VERSION 100
4173

4174
typedef struct {
4175
  SMqRspHead   head;
4176
  STqOffsetVal rspOffset;
4177
  STqOffsetVal reqOffset;
4178
  int32_t      blockNum;
4179
  int8_t       withTbName;
4180
  int8_t       withSchema;
4181
  SArray*      blockDataLen;
4182
  SArray*      blockData;
4183
  SArray*      blockTbName;
4184
  SArray*      blockSchema;
4185

4186
  union {
4187
    struct {
4188
      int64_t sleepTime;
4189
    };
4190
    struct {
4191
      int32_t createTableNum;
4192
      SArray* createTableLen;
4193
      SArray* createTableReq;
4194
    };
4195
  };
4196

4197
} SMqDataRsp;
4198

4199
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4200
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4201
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4202

4203
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4204
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4205
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4206

4207
typedef struct SMqBatchMetaRsp {
4208
  SMqRspHead   head;  // not serialize
4209
  STqOffsetVal rspOffset;
4210
  SArray*      batchMetaLen;
4211
  SArray*      batchMetaReq;
4212
  void*        pMetaBuff;    // not serialize
4213
  uint32_t     metaBuffLen;  // not serialize
4214
} SMqBatchMetaRsp;
4215

4216
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4217
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4218
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4219
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4220

4221
typedef struct {
4222
  SMqRspHead head;
4223
  char       cgroup[TSDB_CGROUP_LEN];
4224
  SArray*    topics;  // SArray<SMqSubTopicEp>
4225
} SMqAskEpRsp;
4226

4227
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4228
  int32_t tlen = 0;
18,308✔
4229
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4230
  int32_t sz = taosArrayGetSize(pRsp->topics);
18,308!
4231
  tlen += taosEncodeFixedI32(buf, sz);
18,310✔
4232
  for (int32_t i = 0; i < sz; i++) {
25,039✔
4233
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,732✔
4234
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,732✔
4235
  }
4236
  return tlen;
18,307✔
4237
}
4238

4239
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4240
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4241
  int32_t sz;
4242
  buf = taosDecodeFixedI32(buf, &sz);
8,214✔
4243
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,214✔
4244
  if (pRsp->topics == NULL) {
8,214!
4245
    return NULL;
×
4246
  }
4247
  for (int32_t i = 0; i < sz; i++) {
11,467✔
4248
    SMqSubTopicEp topicEp;
4249
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,253✔
4250
    if (buf == NULL) {
3,253!
4251
      return NULL;
×
4252
    }
4253
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,506!
4254
      return NULL;
×
4255
    }
4256
  }
4257
  return buf;
8,214✔
4258
}
4259

4260
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4261
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,280✔
4262
}
20,281✔
4263

4264
typedef struct {
4265
  int32_t      vgId;
4266
  STqOffsetVal offset;
4267
  int64_t      rows;
4268
  int64_t      ever;
4269
} OffsetRows;
4270

4271
typedef struct {
4272
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4273
  SArray* offsetRows;
4274
} TopicOffsetRows;
4275

4276
typedef struct {
4277
  int64_t consumerId;
4278
  int32_t epoch;
4279
  SArray* topics;
4280
  int8_t  pollFlag;
4281
} SMqHbReq;
4282

4283
typedef struct {
4284
  char   topic[TSDB_TOPIC_FNAME_LEN];
4285
  int8_t noPrivilege;
4286
} STopicPrivilege;
4287

4288
typedef struct {
4289
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4290
  int32_t debugFlag;
4291
} SMqHbRsp;
4292

4293
typedef struct {
4294
  SMsgHead head;
4295
  int64_t  consumerId;
4296
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4297
} SMqSeekReq;
4298

4299
#define TD_AUTO_CREATE_TABLE 0x1
4300
typedef struct {
4301
  int64_t       suid;
4302
  int64_t       uid;
4303
  int32_t       sver;
4304
  uint32_t      nData;
4305
  uint8_t*      pData;
4306
  SVCreateTbReq cTbReq;
4307
} SVSubmitBlk;
4308

4309
typedef struct {
4310
  SMsgHead header;
4311
  uint64_t sId;
4312
  uint64_t queryId;
4313
  uint64_t clientId;
4314
  uint64_t taskId;
4315
  uint32_t sqlLen;
4316
  uint32_t phyLen;
4317
  char*    sql;
4318
  char*    msg;
4319
  int8_t   source;
4320
} SVDeleteReq;
4321

4322
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4323
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4324

4325
typedef struct {
4326
  int64_t affectedRows;
4327
} SVDeleteRsp;
4328

4329
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4330
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4331

4332
typedef struct SDeleteRes {
4333
  uint64_t suid;
4334
  SArray*  uidList;
4335
  int64_t  skey;
4336
  int64_t  ekey;
4337
  int64_t  affectedRows;
4338
  char     tableFName[TSDB_TABLE_NAME_LEN];
4339
  char     tsColName[TSDB_COL_NAME_LEN];
4340
  int64_t  ctimeMs;  // fill by vnode
4341
  int8_t   source;
4342
} SDeleteRes;
4343

4344
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4345
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4346

4347
typedef struct {
4348
  // int64_t uid;
4349
  char    tbname[TSDB_TABLE_NAME_LEN];
4350
  int64_t startTs;
4351
  int64_t endTs;
4352
} SSingleDeleteReq;
4353

4354
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4355
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4356

4357
typedef struct {
4358
  int64_t suid;
4359
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4360
  int64_t ctimeMs;     // fill by vnode
4361
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4362
} SBatchDeleteReq;
4363

4364
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4365
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4366
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4367

4368
typedef struct {
4369
  int32_t msgIdx;
4370
  int32_t msgType;
4371
  int32_t msgLen;
4372
  void*   msg;
4373
} SBatchMsg;
4374

4375
typedef struct {
4376
  SMsgHead header;
4377
  SArray*  pMsgs;  // SArray<SBatchMsg>
4378
} SBatchReq;
4379

4380
typedef struct {
4381
  int32_t reqType;
4382
  int32_t msgIdx;
4383
  int32_t msgLen;
4384
  int32_t rspCode;
4385
  void*   msg;
4386
} SBatchRspMsg;
4387

4388
typedef struct {
4389
  SArray* pRsps;  // SArray<SBatchRspMsg>
4390
} SBatchRsp;
4391

4392
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4393
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4394
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6,749,470✔
4395
  if (NULL == msg) {
6,749,470!
4396
    return;
×
4397
  }
4398
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6,749,470✔
4399
  taosMemoryFree(pMsg->msg);
6,749,470✔
4400
}
4401

4402
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4403
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4404

4405
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,429,861✔
4406
  if (NULL == p) {
1,429,861!
4407
    return;
×
4408
  }
4409

4410
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,429,861✔
4411
  taosMemoryFree(pRsp->msg);
1,429,861✔
4412
}
4413

4414
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4415
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4416
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4417
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4418
void    tDestroySMqHbReq(SMqHbReq* pReq);
4419

4420
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4421
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4422
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4423

4424
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4425
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4426

4427
#define TD_REQ_FROM_APP               0x0
4428
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4429
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4430
#define SUBMIT_REQ_FROM_FILE          0x4
4431
#define TD_REQ_FROM_TAOX              0x8
4432
#define SUBMIT_REQUEST_VERSION        (1)
4433

4434
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4435

4436
typedef struct {
4437
  int32_t        flags;
4438
  SVCreateTbReq* pCreateTbReq;
4439
  int64_t        suid;
4440
  int64_t        uid;
4441
  int32_t        sver;
4442
  union {
4443
    SArray* aRowP;
4444
    SArray* aCol;
4445
  };
4446
  int64_t ctimeMs;
4447
} SSubmitTbData;
4448

4449
typedef struct {
4450
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4451
} SSubmitReq2;
4452

4453
typedef struct {
4454
  SMsgHead header;
4455
  int64_t  version;
4456
  char     data[];  // SSubmitReq2
4457
} SSubmitReq2Msg;
4458

4459
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4460
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4461
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4462
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4463

4464
typedef struct {
4465
  int32_t affectedRows;
4466
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4467
} SSubmitRsp2;
4468

4469
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4470
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4471
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4472

4473
#define TSDB_MSG_FLG_ENCODE 0x1
4474
#define TSDB_MSG_FLG_DECODE 0x2
4475
#define TSDB_MSG_FLG_CMPT   0x3
4476

4477
typedef struct {
4478
  union {
4479
    struct {
4480
      void*   msgStr;
4481
      int32_t msgLen;
4482
      int64_t ver;
4483
    };
4484
    void* pDataBlock;
4485
  };
4486
} SPackedData;
4487

4488
typedef struct {
4489
  char     fullname[TSDB_VIEW_FNAME_LEN];
4490
  char     name[TSDB_VIEW_NAME_LEN];
4491
  char     dbFName[TSDB_DB_FNAME_LEN];
4492
  char*    querySql;
4493
  char*    sql;
4494
  int8_t   orReplace;
4495
  int8_t   precision;
4496
  int32_t  numOfCols;
4497
  SSchema* pSchema;
4498
} SCMCreateViewReq;
4499

4500
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4501
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4502
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4503

4504
typedef struct {
4505
  char   fullname[TSDB_VIEW_FNAME_LEN];
4506
  char   name[TSDB_VIEW_NAME_LEN];
4507
  char   dbFName[TSDB_DB_FNAME_LEN];
4508
  char*  sql;
4509
  int8_t igNotExists;
4510
} SCMDropViewReq;
4511

4512
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4513
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4514
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4515

4516
typedef struct {
4517
  char fullname[TSDB_VIEW_FNAME_LEN];
4518
} SViewMetaReq;
4519
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4520
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4521

4522
typedef struct {
4523
  char     name[TSDB_VIEW_NAME_LEN];
4524
  char     dbFName[TSDB_DB_FNAME_LEN];
4525
  char*    user;
4526
  uint64_t dbId;
4527
  uint64_t viewId;
4528
  char*    querySql;
4529
  int8_t   precision;
4530
  int8_t   type;
4531
  int32_t  version;
4532
  int32_t  numOfCols;
4533
  SSchema* pSchema;
4534
} SViewMetaRsp;
4535
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4536
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4537
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4538
typedef struct {
4539
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4540
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4541
} STableTSMAInfoReq;
4542

4543
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4544
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4545

4546
typedef struct {
4547
  int32_t  funcId;
4548
  col_id_t colId;
4549
} STableTSMAFuncInfo;
4550

4551
typedef struct {
4552
  char     name[TSDB_TABLE_NAME_LEN];
4553
  uint64_t tsmaId;
4554
  char     targetTb[TSDB_TABLE_NAME_LEN];
4555
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4556
  char     tb[TSDB_TABLE_NAME_LEN];
4557
  char     dbFName[TSDB_DB_FNAME_LEN];
4558
  uint64_t suid;
4559
  uint64_t destTbUid;
4560
  uint64_t dbId;
4561
  int32_t  version;
4562
  int64_t  interval;
4563
  int8_t   unit;
4564
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4565
  SArray*  pTags;      // SArray<SSchema>
4566
  SArray*  pUsedCols;  // SArray<SSchema>
4567
  char*    ast;
4568

4569
  int64_t streamUid;
4570
  int64_t reqTs;
4571
  int64_t rspTs;
4572
  int64_t delayDuration;  // ms
4573
  bool    fillHistoryFinished;
4574
} STableTSMAInfo;
4575

4576
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4577
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4578
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4579
void    tFreeTableTSMAInfo(void* p);
4580
void    tFreeAndClearTableTSMAInfo(void* p);
4581
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4582

4583
#define STSMAHbRsp            STableTSMAInfoRsp
4584
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4585
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4586
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4587

4588
typedef struct SStreamProgressReq {
4589
  int64_t streamId;
4590
  int32_t vgId;
4591
  int32_t fetchIdx;
4592
  int32_t subFetchIdx;
4593
} SStreamProgressReq;
4594

4595
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4596
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4597

4598
typedef struct SStreamProgressRsp {
4599
  int64_t streamId;
4600
  int32_t vgId;
4601
  bool    fillHisFinished;
4602
  int64_t progressDelay;
4603
  int32_t fetchIdx;
4604
  int32_t subFetchIdx;
4605
} SStreamProgressRsp;
4606

4607
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4608
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4609

4610
typedef struct SDropCtbWithTsmaSingleVgReq {
4611
  SVgroupInfo vgInfo;
4612
  SArray*     pTbs;  // SVDropTbReq
4613
} SMDropTbReqsOnSingleVg;
4614

4615
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4616
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4617
void    tFreeSMDropTbReqOnSingleVg(void* p);
4618

4619
typedef struct SDropTbsReq {
4620
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4621
} SMDropTbsReq;
4622

4623
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4624
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4625
void    tFreeSMDropTbsReq(void*);
4626

4627
typedef struct SVFetchTtlExpiredTbsRsp {
4628
  SArray* pExpiredTbs;  // SVDropTbReq
4629
  int32_t vgId;
4630
} SVFetchTtlExpiredTbsRsp;
4631

4632
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4633
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4634

4635
void tFreeFetchTtlExpiredTbsRsp(void* p);
4636

4637
void setDefaultOptionsForField(SFieldWithOptions* field);
4638
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4639

4640
#pragma pack(pop)
4641

4642
#ifdef __cplusplus
4643
}
4644
#endif
4645

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

© 2025 Coveralls, Inc