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

taosdata / TDengine / #3546

03 Dec 2024 10:02AM UTC coverage: 60.691% (-0.1%) from 60.839%
#3546

push

travis-ci

web-flow
Merge pull request #29015 from taosdata/fix/TS-5668

[TS-5668] fix(keeper): fix endpoint value too long for column/tag and eliminate warnings

120577 of 253823 branches covered (47.5%)

Branch coverage included in aggregate %.

201666 of 277134 relevant lines covered (72.77%)

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

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
7,654,706✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
7,621,471!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
15,276,177!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
38,530,089✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
38,530,089✔
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,092!
707
    terrno = TSDB_CODE_INVALID_PARA;
×
708
    return NULL;
×
709
  }
710

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

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

726
  return pDstWrapper;
2,092✔
727
}
728

729
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
730
  if (!(!pCmpr->pColCmpr)) {
13,524!
731
    return TSDB_CODE_INVALID_PARA;
×
732
  }
733
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
13,524✔
734
  if (pCmpr->pColCmpr == NULL) {
13,524!
735
    return terrno;
×
736
  }
737
  pCmpr->nCols = nCols;
13,524✔
738
  return 0;
13,524✔
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,092!
761

762
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,092!
763
  taosMemoryFreeClear(pWrapper);
2,092!
764
}
765
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
766
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,478,729!
767

768
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,478,729✔
769
  if (pSW == NULL) {
11,486,405!
770
    return NULL;
×
771
  }
772
  pSW->nCols = pSchemaWrapper->nCols;
11,486,405✔
773
  pSW->version = pSchemaWrapper->version;
11,486,405✔
774
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,486,405✔
775
  if (pSW->pSchema == NULL) {
11,477,018!
776
    taosMemoryFree(pSW);
2✔
777
    return NULL;
×
778
  }
779

780
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
11,494,914✔
781
  return pSW;
11,494,914✔
782
}
783

784
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
493,906✔
785
  if (pSchemaWrapper) {
18,953,572!
786
    taosMemoryFree(pSchemaWrapper->pSchema);
10,559,291✔
787
    taosMemoryFree(pSchemaWrapper);
10,559,295✔
788
  }
789
}
18,954,281✔
790

791
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,319,508✔
792
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,319,508!
793
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,319,884✔
794
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,323,529✔
795
  }
796
}
1,322,322✔
797

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

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

817
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
818
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
340,784,332!
819
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
354,229,682!
820
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
354,229,682!
821
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
354,229,682!
822
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
354,229,682!
823
  return 0;
177,114,841✔
824
}
825

826
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
827
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
699,204,053!
828
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,370,325,083!
829
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,354,645,359!
830
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,367,001,123!
831
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
685,527,587!
832
  return 0;
733,186,692✔
833
}
834

835
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
836
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
203,378,878!
837
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
203,378,878!
838
  return 0;
101,689,439✔
839
}
840

841
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
842
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,103,214!
843
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,103,210!
844
  return 0;
1,551,604✔
845
}
846

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

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

866
    for (int32_t i = 0; i < pSW->nCols; i++) {
28,990✔
867
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
52,222✔
868
    }
869
  } else {
870
    pSW->pSchema = NULL;
1,147✔
871
  }
872
  return (void*)buf;
4,026✔
873
}
874

875
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
876
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,533,814!
877
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,533,814!
878
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,212,257✔
879
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
26,890,700!
880
  }
881
  return 0;
766,907✔
882
}
883

884
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
885
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,608,117!
886
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,607,994!
887

888
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
803,921✔
889
  if (pSW->pSchema == NULL) {
804,043✔
890
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
22✔
891
  }
892
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,318,752✔
893
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
27,033,354!
894
  }
895

896
  return 0;
800,119✔
897
}
898

899
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
900
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
78,700,238!
901
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
82,524,182!
902

903
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
41,221,753✔
904
  if (pSW->pSchema == NULL) {
41,483,397!
905
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
906
  }
907
  for (int32_t i = 0; i < pSW->nCols; i++) {
759,104,570✔
908
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,440,529,040!
909
  }
910

911
  return 0;
36,196,703✔
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
} SInterval;
1254

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

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

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

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

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

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

1298
typedef STableCfg STableCfgRsp;
1299

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1524
typedef SDbCfgRsp SDbCfgInfo;
1525

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2221
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2222

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2927
#define DEFAULT_MAX_POLL_INTERVAL 300000
2928
#define DEFAULT_SESSION_TIMEOUT   12000
2929

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

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

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

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

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

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

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

2976
  for (int32_t i = 0; i < topicNum; i++) {
3,658✔
2977
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,100✔
2978
  }
2979

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

2991
  return tlen;
2,608✔
2992
}
2993

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

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

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

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

3031
  return 0;
1,414✔
3032
}
3033

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3189
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,749✔
3190
  if (NULL == req) {
21,679,140!
3191
    return;
21,504,630✔
3192
  }
3193

3194
  taosMemoryFreeClear(req->sql);
174,510!
3195
  taosMemoryFreeClear(req->name);
174,510!
3196
  taosMemoryFreeClear(req->comment);
174,524!
3197
  if (req->type == TSDB_CHILD_TABLE) {
174,524!
3198
    taosMemoryFreeClear(req->ctb.pTag);
160,998!
3199
    taosMemoryFreeClear(req->ctb.stbName);
160,995!
3200
    taosArrayDestroy(req->ctb.tagName);
160,996✔
3201
    req->ctb.tagName = NULL;
160,990✔
3202
  } else if (req->type == TSDB_NORMAL_TABLE) {
13,527!
3203
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,524!
3204
  }
3205
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
174,516!
3206
}
3207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3478
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
196,899✔
3479

3480
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3481
  void* pIter = taosHashIterate(info, NULL);
462,286✔
3482
  while (pIter != NULL) {
815,988!
3483
    SKv* kv = (SKv*)pIter;
353,657✔
3484
    taosMemoryFreeClear(kv->value);
353,657!
3485
    pIter = taosHashIterate(info, pIter);
353,658✔
3486
  }
3487
}
462,331✔
3488

3489
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
300,790✔
3490
  SQueryDesc* desc = (SQueryDesc*)pDesc;
300,790✔
3491
  if (desc->subDesc) {
300,790✔
3492
    taosArrayDestroy(desc->subDesc);
294,472✔
3493
    desc->subDesc = NULL;
294,471✔
3494
  }
3495
}
300,789✔
3496

3497
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
535,205✔
3498
  SClientHbReq* req = (SClientHbReq*)pReq;
547,599✔
3499
  if (req->query) {
547,599!
3500
    if (req->query->queryDesc) {
526,067!
3501
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
43,115✔
3502
    }
3503
    taosMemoryFreeClear(req->query);
526,067!
3504
  }
3505

3506
  if (req->info) {
547,592!
3507
    tFreeReqKvHash(req->info);
462,286✔
3508
    taosHashCleanup(req->info);
462,331✔
3509
    req->info = NULL;
462,284✔
3510
  }
3511
}
442,690✔
3512

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

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

3523
static FORCE_INLINE void tFreeClientKv(void* pKv) {
140,178✔
3524
  SKv* kv = (SKv*)pKv;
140,178✔
3525
  if (kv) {
140,178✔
3526
    taosMemoryFreeClear(kv->value);
140,177!
3527
  }
3528
}
140,175✔
3529

3530
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
532,748✔
3531
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
532,748✔
3532
  if (rsp->query) {
532,748✔
3533
    taosArrayDestroy(rsp->query->pQnodeList);
523,650✔
3534
    taosMemoryFreeClear(rsp->query);
523,914!
3535
  }
3536
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
533,085!
3537
}
102,809✔
3538

3539
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3540
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
376,856✔
3541
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
376,856✔
3542
}
377,038✔
3543

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

3548
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3549
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
682,374!
3550
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
682,374!
3551
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
682,374!
3552
  return 0;
341,187✔
3553
}
3554

3555
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3556
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
646,389!
3557
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
646,403!
3558
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
323,207✔
3559
  if (pKv->value == NULL) {
323,211!
3560
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3561
  }
3562
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
323,211!
3563
  return 0;
323,212✔
3564
}
3565

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

3572
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3573
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,065,851!
3574
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,065,966!
3575
  return 0;
533,018✔
3576
}
3577

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3766
#define TQ_OFFSET_VERSION 1
3767

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3921
typedef SMDropSmaReq SDropTagIndexReq;
3922

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

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

3948
typedef STSma SVCreateTSmaReq;
3949

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4097
void tFreeSTableIndexInfo(void* pInfo);
4098

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

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

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

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

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

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

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

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

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

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

4171
#define MQ_DATA_RSP_VERSION 100
4172

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

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

4196
} SMqDataRsp;
4197

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

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

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

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

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

4226
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4227
  int32_t tlen = 0;
17,384✔
4228
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4229
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,384!
4230
  tlen += taosEncodeFixedI32(buf, sz);
17,384✔
4231
  for (int32_t i = 0; i < sz; i++) {
24,142✔
4232
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,758✔
4233
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,758✔
4234
  }
4235
  return tlen;
17,384✔
4236
}
4237

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4409
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,451,250✔
4410
  taosMemoryFree(pRsp->msg);
1,451,250✔
4411
}
4412

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

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

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

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

4433
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4434

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4634
void tFreeFetchTtlExpiredTbsRsp(void* p);
4635

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

4639
#pragma pack(pop)
4640

4641
#ifdef __cplusplus
4642
}
4643
#endif
4644

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