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

taosdata / TDengine / #3523

06 Nov 2024 02:29AM UTC coverage: 55.861% (-2.4%) from 58.216%
#3523

push

travis-ci

web-flow
Merge pull request #28551 from taosdata/feat/TS-5215-2

test(blob): testing & fixes for blob

106075 of 245834 branches covered (43.15%)

Branch coverage included in aggregate %.

0 of 15 new or added lines in 2 files covered. (0.0%)

17003 existing lines in 254 files now uncovered.

181910 of 269703 relevant lines covered (67.45%)

1527639.59 hits per line

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

57.75
/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) {
21,687,250✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
21,687,250✔
74
  int    segIdx = TMSG_SEG_CODE(type);
21,687,250✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
21,687,250!
76
    return type < tMsgRangeDict[segIdx];
21,687,614✔
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) {
139,971✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
136,578!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
276,549✔
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
12,955,080✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
12,955,080✔
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_MAX,
165
} EShowType;
166

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

182
#define TSDB_FILL_NONE        0
183
#define TSDB_FILL_NULL        1
184
#define TSDB_FILL_NULL_F      2
185
#define TSDB_FILL_SET_VALUE   3
186
#define TSDB_FILL_SET_VALUE_F 4
187
#define TSDB_FILL_LINEAR      5
188
#define TSDB_FILL_PREV        6
189
#define TSDB_FILL_NEXT        7
190

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

201
#define TSDB_KILL_MSG_LEN 30
202

203
#define TSDB_TABLE_NUM_UNIT 100000
204

205
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
206
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
207
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
208

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

215
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
216
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
217
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
218
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
219

220
#define TD_SUPER_TABLE  TSDB_SUPER_TABLE
221
#define TD_CHILD_TABLE  TSDB_CHILD_TABLE
222
#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE
223

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

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

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

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

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

475
typedef struct {
476
  int32_t     vgId;
477
  uint8_t     option;  // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
478
  const char* dbFName;
479
  const char* tbName;
480
} SBuildTableInput;
481

482
typedef struct {
483
  char    db[TSDB_DB_FNAME_LEN];
484
  int64_t dbId;
485
  int32_t vgVersion;
486
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
487
  int64_t stateTs;
488
} SBuildUseDBInput;
489

490
typedef struct SField {
491
  char    name[TSDB_COL_NAME_LEN];
492
  uint8_t type;
493
  int8_t  flags;
494
  int32_t bytes;
495
} SField;
496
typedef struct SFieldWithOptions {
497
  char     name[TSDB_COL_NAME_LEN];
498
  uint8_t  type;
499
  int8_t   flags;
500
  int32_t  bytes;
501
  uint32_t compress;
502
} SFieldWithOptions;
503

504
typedef struct SRetention {
505
  int64_t freq;
506
  int64_t keep;
507
  int8_t  freqUnit;
508
  int8_t  keepUnit;
509
} SRetention;
510

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

513
#pragma pack(push, 1)
514

515
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
516
typedef struct SEp {
517
  char     fqdn[TSDB_FQDN_LEN];
518
  uint16_t port;
519
} SEp;
520

521
typedef struct {
522
  int32_t contLen;
523
  int32_t vgId;
524
} SMsgHead;
525

526
// Submit message for one table
527
typedef struct SSubmitBlk {
528
  int64_t uid;        // table unique id
529
  int64_t suid;       // stable id
530
  int32_t sversion;   // data schema version
531
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
532
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
533
  int32_t numOfRows;  // total number of rows in current submit block
534
  char    data[];
535
} SSubmitBlk;
536

537
// Submit message for this TSDB
538
typedef struct {
539
  SMsgHead header;
540
  int64_t  version;
541
  int32_t  length;
542
  int32_t  numOfBlocks;
543
  char     blocks[];
544
} SSubmitReq;
545

546
typedef struct {
547
  int32_t totalLen;
548
  int32_t len;
549
  STSRow* row;
550
} SSubmitBlkIter;
551

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

567
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
568
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
569
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
570
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
571
// for debug
572
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
573

574
struct SSchema {
575
  int8_t   type;
576
  int8_t   flags;
577
  col_id_t colId;
578
  int32_t  bytes;
579
  char     name[TSDB_COL_NAME_LEN];
580
};
581
struct SSchemaExt {
582
  col_id_t colId;
583
  uint32_t compress;
584
};
585

586
//
587

588
struct SSchema2 {
589
  int8_t   type;
590
  int8_t   flags;
591
  col_id_t colId;
592
  int32_t  bytes;
593
  char     name[TSDB_COL_NAME_LEN];
594
  uint32_t compress;
595
};
596

597
typedef struct {
598
  char        tbName[TSDB_TABLE_NAME_LEN];
599
  char        stbName[TSDB_TABLE_NAME_LEN];
600
  char        dbFName[TSDB_DB_FNAME_LEN];
601
  int64_t     dbId;
602
  int32_t     numOfTags;
603
  int32_t     numOfColumns;
604
  int8_t      precision;
605
  int8_t      tableType;
606
  int32_t     sversion;
607
  int32_t     tversion;
608
  uint64_t    suid;
609
  uint64_t    tuid;
610
  int32_t     vgId;
611
  int8_t      sysInfo;
612
  SSchema*    pSchemas;
613
  SSchemaExt* pSchemaExt;
614
} STableMetaRsp;
615

616
typedef struct {
617
  int32_t        code;
618
  int64_t        uid;
619
  char*          tblFName;
620
  int32_t        numOfRows;
621
  int32_t        affectedRows;
622
  int64_t        sver;
623
  STableMetaRsp* pMeta;
624
} SSubmitBlkRsp;
625

626
typedef struct {
627
  int32_t numOfRows;
628
  int32_t affectedRows;
629
  int32_t nBlocks;
630
  union {
631
    SArray*        pArray;
632
    SSubmitBlkRsp* pBlocks;
633
  };
634
} SSubmitRsp;
635

636
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
637
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
638
// void    tFreeSSubmitBlkRsp(void* param);
639
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
640

641
#define COL_SMA_ON     ((int8_t)0x1)
642
#define COL_IDX_ON     ((int8_t)0x2)
643
#define COL_IS_KEY     ((int8_t)0x4)
644
#define COL_SET_NULL   ((int8_t)0x10)
645
#define COL_SET_VAL    ((int8_t)0x20)
646
#define COL_IS_SYSINFO ((int8_t)0x40)
647

648
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
649
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
650

651
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
652
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
653
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
654

655
#define SSCHMEA_SET_IDX_ON(s) \
656
  do {                        \
657
    (s)->flags |= COL_IDX_ON; \
658
  } while (0)
659

660
#define SSCHMEA_SET_IDX_OFF(s)   \
661
  do {                           \
662
    (s)->flags &= (~COL_IDX_ON); \
663
  } while (0)
664

665
#define SSCHMEA_TYPE(s)  ((s)->type)
666
#define SSCHMEA_FLAGS(s) ((s)->flags)
667
#define SSCHMEA_COLID(s) ((s)->colId)
668
#define SSCHMEA_BYTES(s) ((s)->bytes)
669
#define SSCHMEA_NAME(s)  ((s)->name)
670

671
typedef struct {
672
  bool    tsEnableMonitor;
673
  int32_t tsMonitorInterval;
674
  int32_t tsSlowLogThreshold;
675
  int32_t tsSlowLogMaxLen;
676
  int32_t tsSlowLogScope;
677
  int32_t tsSlowLogThresholdTest;
678
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
679
} SMonitorParas;
680

681
typedef struct {
682
  int32_t  nCols;
683
  int32_t  version;
684
  SSchema* pSchema;
685
} SSchemaWrapper;
686

687
typedef struct {
688
  col_id_t id;
689
  uint32_t alg;
690
} SColCmpr;
691

692
typedef struct {
693
  int32_t   nCols;
694
  int32_t   version;
695
  SColCmpr* pColCmpr;
696
} SColCmprWrapper;
697

698
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
699
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1,452!
UNCOV
700
    terrno = TSDB_CODE_INVALID_PARA;
×
UNCOV
701
    return NULL;
×
702
  }
703

704
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1,452✔
705
  if (pDstWrapper == NULL) {
1,452!
UNCOV
706
    return NULL;
×
707
  }
708
  pDstWrapper->nCols = pSrcWrapper->nCols;
1,452✔
709
  pDstWrapper->version = pSrcWrapper->version;
1,452✔
710

711
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1,452✔
712
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1,452✔
713
  if (pDstWrapper->pColCmpr == NULL) {
1,452!
UNCOV
714
    taosMemoryFree(pDstWrapper);
×
UNCOV
715
    return NULL;
×
716
  }
717
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1,452✔
718

719
  return pDstWrapper;
1,452✔
720
}
721

722
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
723
  if (!(!pCmpr->pColCmpr)) {
6,504!
UNCOV
724
    return TSDB_CODE_INVALID_PARA;
×
725
  }
726
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,504✔
727
  if (pCmpr->pColCmpr == NULL) {
6,504!
UNCOV
728
    return terrno;
×
729
  }
730
  pCmpr->nCols = nCols;
6,504✔
731
  return 0;
6,504✔
732
}
733

734
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
735
  pCmpr->nCols = pSchema->nCols;
736
  if (!(!pCmpr->pColCmpr)) {
737
    return TSDB_CODE_INVALID_PARA;
738
  }
739
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
740
  if (pCmpr->pColCmpr == NULL) {
741
    return terrno;
742
  }
743
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
744
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
745
    SSchema*  pColSchema = &pSchema->pSchema[i];
746
    pColCmpr->id = pColSchema->colId;
747
    pColCmpr->alg = 0;
748
  }
749
  return 0;
750
}
751

752
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
753
  if (pWrapper == NULL) return;
1,452!
754

755
  taosMemoryFreeClear(pWrapper->pColCmpr);
1,452!
756
  taosMemoryFreeClear(pWrapper);
1,452!
757
}
758
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
759
  if (pSchemaWrapper->pSchema == NULL) return NULL;
442,862!
760

761
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
442,862✔
762
  if (pSW == NULL) {
442,890!
763
    return NULL;
10✔
764
  }
765
  pSW->nCols = pSchemaWrapper->nCols;
442,880✔
766
  pSW->version = pSchemaWrapper->version;
442,880✔
767
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
442,880✔
768
  if (pSW->pSchema == NULL) {
442,748!
UNCOV
769
    taosMemoryFree(pSW);
×
770
    return NULL;
5✔
771
  }
772

773
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
442,871✔
774
  return pSW;
442,871✔
775
}
776

777
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
244,527✔
778
  if (pSchemaWrapper) {
752,275!
779
    taosMemoryFree(pSchemaWrapper->pSchema);
523,337✔
780
    taosMemoryFree(pSchemaWrapper);
523,344✔
781
  }
782
}
752,288✔
783

UNCOV
784
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
×
UNCOV
785
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
×
786
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
×
787
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
×
788
  }
789
}
×
790

791
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
792
  int32_t tlen = 0;
3,492✔
793
  tlen += taosEncodeFixedI8(buf, pSchema->type);
6,984✔
794
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
3,492!
795
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
3,492!
796
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
3,492!
797
  tlen += taosEncodeString(buf, pSchema->name);
3,492✔
798
  return tlen;
3,492✔
799
}
800

801
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
802
  buf = taosDecodeFixedI8(buf, &pSchema->type);
33,356✔
803
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
16,678✔
804
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
16,678!
805
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
16,678!
806
  buf = taosDecodeStringTo(buf, pSchema->name);
16,678✔
807
  return (void*)buf;
16,678✔
808
}
809

810
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
811
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
9,847,683!
812
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
11,612,976!
813
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
11,612,976!
814
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
11,612,976!
815
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
11,612,976!
816
  return 0;
5,806,488✔
817
}
818

819
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
820
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
18,404,913!
821
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
35,109,065!
822
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
34,927,335!
823
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
35,106,883!
824
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
17,611,302!
825
  return 0;
18,167,514✔
826
}
827

828
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
829
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
5,174,830!
830
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
5,174,830!
831
  return 0;
2,587,415✔
832
}
833

834
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
835
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
1,181,611!
836
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
1,181,611!
837
  return 0;
590,805✔
838
}
839

840
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
841
  int32_t tlen = 0;
670✔
842
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
670✔
843
  tlen += taosEncodeVariantI32(buf, pSW->version);
670✔
844
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,162✔
845
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
6,984!
846
  }
847
  return tlen;
670✔
848
}
849

850
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
851
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
2,412✔
852
  buf = taosDecodeVariantI32(buf, &pSW->version);
2,412✔
853
  if (pSW->nCols > 0) {
2,412✔
854
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,625✔
855
    if (pSW->pSchema == NULL) {
1,625!
UNCOV
856
      return NULL;
×
857
    }
858

859
    for (int32_t i = 0; i < pSW->nCols; i++) {
18,303✔
860
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
33,356✔
861
    }
862
  } else {
863
    pSW->pSchema = NULL;
787✔
864
  }
865
  return (void*)buf;
2,412✔
866
}
867

868
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
869
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
304,142!
870
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
304,142!
871
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,917,364✔
872
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
3,530,586!
873
  }
874
  return 0;
152,071✔
875
}
876

877
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
878
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
481,488!
879
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
481,440!
880

881
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
240,702✔
882
  if (pSW->pSchema == NULL) {
240,709!
UNCOV
883
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
884
  }
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,504,703✔
886
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
8,528,548!
887
  }
888

889
  return 0;
240,143✔
890
}
891

892
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
893
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,903,384!
894
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,940,193!
895

896
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
969,818✔
897
  if (pSW->pSchema == NULL) {
973,232!
898
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
34✔
899
  }
900
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,149,123✔
901
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
26,391,157!
902
  }
903

904
  return 0;
933,891✔
905
}
906

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

938
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
939
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
940
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
941

942
typedef struct {
943
  STableMetaRsp* pMeta;
944
} SMCreateStbRsp;
945

946
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
947
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
948
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
949

950
typedef struct {
951
  char     name[TSDB_TABLE_FNAME_LEN];
952
  int8_t   igNotExists;
953
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
954
  int8_t   reserved[6];
955
  tb_uid_t suid;
956
  int32_t  sqlLen;
957
  char*    sql;
958
} SMDropStbReq;
959

960
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
961
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
962
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
963

964
typedef struct {
965
  char    name[TSDB_TABLE_FNAME_LEN];
966
  int8_t  alterType;
967
  int32_t numOfFields;
968
  SArray* pFields;
969
  int32_t ttl;
970
  int32_t commentLen;
971
  char*   comment;
972
  int32_t sqlLen;
973
  char*   sql;
974
} SMAlterStbReq;
975

976
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
977
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
978
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
979

980
typedef struct SEpSet {
981
  int8_t inUse;
982
  int8_t numOfEps;
983
  SEp    eps[TSDB_MAX_REPLICA];
984
} SEpSet;
985

986

987
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
988
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
989
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
990
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
991

992
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
993
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
994

995
typedef struct {
996
  int8_t  connType;
997
  int32_t pid;
998
  char    app[TSDB_APP_NAME_LEN];
999
  char    db[TSDB_DB_NAME_LEN];
1000
  char    user[TSDB_USER_LEN];
1001
  char    passwd[TSDB_PASSWORD_LEN];
1002
  int64_t startTime;
1003
  char    sVer[TSDB_VERSION_LEN];
1004
} SConnectReq;
1005

1006
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1007
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1008

1009
typedef struct {
1010
  int32_t       acctId;
1011
  int64_t       clusterId;
1012
  uint32_t      connId;
1013
  int32_t       dnodeNum;
1014
  int8_t        superUser;
1015
  int8_t        sysInfo;
1016
  int8_t        connType;
1017
  SEpSet        epSet;
1018
  int32_t       svrTimestamp;
1019
  int32_t       passVer;
1020
  int32_t       authVer;
1021
  char          sVer[TSDB_VERSION_LEN];
1022
  char          sDetailVer[128];
1023
  int64_t       whiteListVer;
1024
  SMonitorParas monitorParas;
1025
  int8_t        enableAuditDelete;
1026
} SConnectRsp;
1027

1028
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1029
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1030

1031
typedef struct {
1032
  char    user[TSDB_USER_LEN];
1033
  char    pass[TSDB_PASSWORD_LEN];
1034
  int32_t maxUsers;
1035
  int32_t maxDbs;
1036
  int32_t maxTimeSeries;
1037
  int32_t maxStreams;
1038
  int32_t accessState;  // Configured only by command
1039
  int64_t maxStorage;
1040
} SCreateAcctReq, SAlterAcctReq;
1041

1042
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1043
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1044

1045
typedef struct {
1046
  char    user[TSDB_USER_LEN];
1047
  int32_t sqlLen;
1048
  char*   sql;
1049
} SDropUserReq, SDropAcctReq;
1050

1051
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1052
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1053
void    tFreeSDropUserReq(SDropUserReq* pReq);
1054

1055
typedef struct SIpV4Range {
1056
  uint32_t ip;
1057
  uint32_t mask;
1058
} SIpV4Range;
1059

1060
typedef struct {
1061
  int32_t    num;
1062
  SIpV4Range pIpRange[];
1063
} SIpWhiteList;
1064

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

1081
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1082
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1083
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1084

1085
typedef struct {
1086
  int64_t     ver;
1087
  char        user[TSDB_USER_LEN];
1088
  int32_t     numOfRange;
1089
  SIpV4Range* pIpRanges;
1090
} SUpdateUserIpWhite;
1091
typedef struct {
1092
  int64_t             ver;
1093
  int                 numOfUser;
1094
  SUpdateUserIpWhite* pUserIpWhite;
1095
} SUpdateIpWhite;
1096

1097
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1098
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1099
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1100
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1101

1102
typedef struct {
1103
  int64_t ipWhiteVer;
1104
} SRetrieveIpWhiteReq;
1105

1106
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1107
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1108

1109
typedef struct {
1110
  int32_t dnodeId;
1111
  int64_t analVer;
1112
} SRetrieveAnalAlgoReq;
1113

1114
typedef struct {
1115
  int64_t   ver;
1116
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1117
} SRetrieveAnalAlgoRsp;
1118

1119
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1120
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1121
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1122
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1123
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1124

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

1151
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1152
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1153
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1154

1155
typedef struct {
1156
  char user[TSDB_USER_LEN];
1157
} SGetUserAuthReq;
1158

1159
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1160
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1161

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

1183
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1184
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1185
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1186

1187
typedef struct {
1188
  char user[TSDB_USER_LEN];
1189
} SGetUserWhiteListReq;
1190

1191
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1192
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1193

1194
typedef struct {
1195
  char        user[TSDB_USER_LEN];
1196
  int32_t     numWhiteLists;
1197
  SIpV4Range* pWhiteLists;
1198
} SGetUserWhiteListRsp;
1199

1200
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1201
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1202
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1203

1204
/*
1205
 * for client side struct, only column id, type, bytes are necessary
1206
 * But for data in vnode side, we need all the following information.
1207
 */
1208
typedef struct {
1209
  union {
1210
    col_id_t colId;
1211
    int16_t  slotId;
1212
  };
1213

1214
  uint8_t precision;
1215
  uint8_t scale;
1216
  int32_t bytes;
1217
  int8_t  type;
1218
  uint8_t pk;
1219
  bool    noData;
1220
} SColumnInfo;
1221

1222
typedef struct STimeWindow {
1223
  TSKEY skey;
1224
  TSKEY ekey;
1225
} STimeWindow;
1226

1227
typedef struct SQueryHint {
1228
  bool batchScan;
1229
} SQueryHint;
1230

1231
typedef struct {
1232
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1233
  int32_t tsLen;          // total length of ts comp block
1234
  int32_t tsNumOfBlocks;  // ts comp block numbers
1235
  int32_t tsOrder;        // ts comp block order
1236
} STsBufInfo;
1237

1238
typedef struct {
1239
  int32_t tz;  // query client timezone
1240
  char    intervalUnit;
1241
  char    slidingUnit;
1242
  char    offsetUnit;
1243
  int8_t  precision;
1244
  int64_t interval;
1245
  int64_t sliding;
1246
  int64_t offset;
1247
} SInterval;
1248

1249
typedef struct STbVerInfo {
1250
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1251
  int32_t sversion;
1252
  int32_t tversion;
1253
} STbVerInfo;
1254

1255
typedef struct {
1256
  int32_t code;
1257
  int64_t affectedRows;
1258
  SArray* tbVerInfo;  // STbVerInfo
1259
} SQueryTableRsp;
1260

1261
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1262

1263
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1264

1265
typedef struct {
1266
  SMsgHead header;
1267
  char     dbFName[TSDB_DB_FNAME_LEN];
1268
  char     tbName[TSDB_TABLE_NAME_LEN];
1269
} STableCfgReq;
1270

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

1292
typedef STableCfg STableCfgRsp;
1293

1294
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1295
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1296

1297
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1298
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1299
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1300

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

1345
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1346
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1347
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1348

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

1376
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1377
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1378
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1379

1380
typedef struct {
1381
  char    db[TSDB_DB_FNAME_LEN];
1382
  int8_t  ignoreNotExists;
1383
  int32_t sqlLen;
1384
  char*   sql;
1385
} SDropDbReq;
1386

1387
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1388
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1389
void    tFreeSDropDbReq(SDropDbReq* pReq);
1390

1391
typedef struct {
1392
  char    db[TSDB_DB_FNAME_LEN];
1393
  int64_t uid;
1394
} SDropDbRsp;
1395

1396
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1397
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1398

1399
typedef struct {
1400
  char    db[TSDB_DB_FNAME_LEN];
1401
  int64_t dbId;
1402
  int32_t vgVersion;
1403
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1404
  int64_t stateTs;     // ms
1405
} SUseDbReq;
1406

1407
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1408
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1409

1410
typedef struct {
1411
  char    db[TSDB_DB_FNAME_LEN];
1412
  int64_t uid;
1413
  int32_t vgVersion;
1414
  int32_t vgNum;
1415
  int16_t hashPrefix;
1416
  int16_t hashSuffix;
1417
  int8_t  hashMethod;
1418
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1419
  int32_t errCode;
1420
  int64_t stateTs;  // ms
1421
} SUseDbRsp;
1422

1423
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1424
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1425
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1426
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1427
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1428

1429
typedef struct {
1430
  char db[TSDB_DB_FNAME_LEN];
1431
} SDbCfgReq;
1432

1433
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1434
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1435

1436
typedef struct {
1437
  char    db[TSDB_DB_FNAME_LEN];
1438
  int32_t maxSpeed;
1439
} STrimDbReq;
1440

1441
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1442
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1443

1444
typedef struct {
1445
  int32_t timestamp;
1446
} SVTrimDbReq;
1447

1448
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1449
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1450

1451
typedef struct {
1452
  char db[TSDB_DB_FNAME_LEN];
1453
} SS3MigrateDbReq;
1454

1455
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1456
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1457

1458
typedef struct {
1459
  int32_t timestamp;
1460
} SVS3MigrateDbReq;
1461

1462
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1463
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1464

1465
typedef struct {
1466
  int32_t timestampSec;
1467
  int32_t ttlDropMaxCount;
1468
  int32_t nUids;
1469
  SArray* pTbUids;
1470
} SVDropTtlTableReq;
1471

1472
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1473
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1474

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

1518
typedef SDbCfgRsp SDbCfgInfo;
1519

1520
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1521
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1522
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1523
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1524
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1525

1526
typedef struct {
1527
  int32_t rowNum;
1528
} SQnodeListReq;
1529

1530
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1531
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1532

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

1537
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1538

1539
typedef struct {
1540
  int32_t useless;  // useless
1541
} SServerVerReq;
1542

1543
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1544
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1545

1546
typedef struct {
1547
  char ver[TSDB_VERSION_LEN];
1548
} SServerVerRsp;
1549

1550
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1551
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1552

1553
typedef struct SQueryNodeAddr {
1554
  int32_t nodeId;  // vgId or qnodeId
1555
  SEpSet  epSet;
1556
} SQueryNodeAddr;
1557

1558
typedef struct {
1559
  SQueryNodeAddr addr;
1560
  uint64_t       load;
1561
} SQueryNodeLoad;
1562

1563
typedef struct {
1564
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1565
} SQnodeListRsp;
1566

1567
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1568
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1569
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1570

1571
typedef struct {
1572
  SArray* dnodeList;  // SArray<SEpSet>
1573
} SDnodeListRsp;
1574

1575
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1576
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1577
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1578

1579
typedef struct {
1580
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1581
} STableTSMAInfoRsp;
1582

1583
typedef struct {
1584
  SUseDbRsp*         useDbRsp;
1585
  SDbCfgRsp*         cfgRsp;
1586
  STableTSMAInfoRsp* pTsmaRsp;
1587
  int32_t            dbTsmaVersion;
1588
  char               db[TSDB_DB_FNAME_LEN];
1589
  int64_t            dbId;
1590
} SDbHbRsp;
1591

1592
typedef struct {
1593
  SArray* pArray;  // Array of SDbHbRsp
1594
} SDbHbBatchRsp;
1595

1596
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1597
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1598
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1599

1600
typedef struct {
1601
  SArray* pArray;  // Array of SGetUserAuthRsp
1602
} SUserAuthBatchRsp;
1603

1604
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1605
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1606
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1607

1608
typedef struct {
1609
  char        db[TSDB_DB_FNAME_LEN];
1610
  STimeWindow timeRange;
1611
  int32_t     sqlLen;
1612
  char*       sql;
1613
} SCompactDbReq;
1614

1615
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1616
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1617
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1618

1619
typedef struct {
1620
  int32_t compactId;
1621
  int8_t  bAccepted;
1622
} SCompactDbRsp;
1623

1624
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1625
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1626

1627
typedef struct {
1628
  int32_t compactId;
1629
  int32_t sqlLen;
1630
  char*   sql;
1631
} SKillCompactReq;
1632

1633
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1634
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1635
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1636

1637
typedef struct {
1638
  char    name[TSDB_FUNC_NAME_LEN];
1639
  int8_t  igExists;
1640
  int8_t  funcType;
1641
  int8_t  scriptType;
1642
  int8_t  outputType;
1643
  int32_t outputLen;
1644
  int32_t bufSize;
1645
  int32_t codeLen;
1646
  int64_t signature;
1647
  char*   pComment;
1648
  char*   pCode;
1649
  int8_t  orReplace;
1650
} SCreateFuncReq;
1651

1652
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1653
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1654
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1655

1656
typedef struct {
1657
  char   name[TSDB_FUNC_NAME_LEN];
1658
  int8_t igNotExists;
1659
} SDropFuncReq;
1660

1661
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1662
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1663

1664
typedef struct {
1665
  int32_t numOfFuncs;
1666
  bool    ignoreCodeComment;
1667
  SArray* pFuncNames;
1668
} SRetrieveFuncReq;
1669

1670
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1671
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1672
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1673

1674
typedef struct {
1675
  char    name[TSDB_FUNC_NAME_LEN];
1676
  int8_t  funcType;
1677
  int8_t  scriptType;
1678
  int8_t  outputType;
1679
  int32_t outputLen;
1680
  int32_t bufSize;
1681
  int64_t signature;
1682
  int32_t commentSize;
1683
  int32_t codeSize;
1684
  char*   pComment;
1685
  char*   pCode;
1686
} SFuncInfo;
1687

1688
typedef struct {
1689
  int32_t funcVersion;
1690
  int64_t funcCreatedTime;
1691
} SFuncExtraInfo;
1692

1693
typedef struct {
1694
  int32_t numOfFuncs;
1695
  SArray* pFuncInfos;
1696
  SArray* pFuncExtraInfos;
1697
} SRetrieveFuncRsp;
1698

1699
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1700
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1701
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1702
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1703

1704
typedef struct {
1705
  int32_t       statusInterval;
1706
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1707
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1708
  char          locale[TD_LOCALE_LEN];      // tsLocale
1709
  char          charset[TD_LOCALE_LEN];     // tsCharset
1710
  int8_t        ttlChangeOnWrite;
1711
  int8_t        enableWhiteList;
1712
  int8_t        encryptionKeyStat;
1713
  uint32_t      encryptionKeyChksum;
1714
  SMonitorParas monitorParas;
1715
} SClusterCfg;
1716

1717
typedef struct {
1718
  int32_t openVnodes;
1719
  int32_t dropVnodes;
1720
  int32_t totalVnodes;
1721
  int32_t masterNum;
1722
  int64_t numOfSelectReqs;
1723
  int64_t numOfInsertReqs;
1724
  int64_t numOfInsertSuccessReqs;
1725
  int64_t numOfBatchInsertReqs;
1726
  int64_t numOfBatchInsertSuccessReqs;
1727
  int64_t errors;
1728
} SVnodesStat;
1729

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

1753
typedef struct {
1754
  int32_t vgId;
1755
  int64_t nTimeSeries;
1756
} SVnodeLoadLite;
1757

1758
typedef struct {
1759
  int8_t  syncState;
1760
  int64_t syncTerm;
1761
  int8_t  syncRestore;
1762
  int64_t roleTimeMs;
1763
} SMnodeLoad;
1764

1765
typedef struct {
1766
  int32_t dnodeId;
1767
  int64_t numOfProcessedQuery;
1768
  int64_t numOfProcessedCQuery;
1769
  int64_t numOfProcessedFetch;
1770
  int64_t numOfProcessedDrop;
1771
  int64_t numOfProcessedNotify;
1772
  int64_t numOfProcessedHb;
1773
  int64_t numOfProcessedDelete;
1774
  int64_t cacheDataSize;
1775
  int64_t numOfQueryInQueue;
1776
  int64_t numOfFetchInQueue;
1777
  int64_t timeInQueryQueue;
1778
  int64_t timeInFetchQueue;
1779
} SQnodeLoad;
1780

1781
typedef struct {
1782
  int32_t     sver;      // software version
1783
  int64_t     dnodeVer;  // dnode table version in sdb
1784
  int32_t     dnodeId;
1785
  int64_t     clusterId;
1786
  int64_t     rebootTime;
1787
  int64_t     updateTime;
1788
  float       numOfCores;
1789
  int32_t     numOfSupportVnodes;
1790
  int32_t     numOfDiskCfg;
1791
  int64_t     memTotal;
1792
  int64_t     memAvail;
1793
  char        dnodeEp[TSDB_EP_LEN];
1794
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1795
  SMnodeLoad  mload;
1796
  SQnodeLoad  qload;
1797
  SClusterCfg clusterCfg;
1798
  SArray*     pVloads;  // array of SVnodeLoad
1799
  int32_t     statusSeq;
1800
  int64_t     ipWhiteVer;
1801
  int64_t     analVer;
1802
} SStatusReq;
1803

1804
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1805
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1806
void    tFreeSStatusReq(SStatusReq* pReq);
1807

1808
typedef struct {
1809
  int32_t dnodeId;
1810
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1811
} SDnodeInfoReq;
1812

1813
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1814
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1815

1816
typedef enum {
1817
  MONITOR_TYPE_COUNTER = 0,
1818
  MONITOR_TYPE_SLOW_LOG = 1,
1819
} MONITOR_TYPE;
1820

1821
typedef struct {
1822
  int32_t      contLen;
1823
  char*        pCont;
1824
  MONITOR_TYPE type;
1825
} SStatisReq;
1826

1827
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1828
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1829
void    tFreeSStatisReq(SStatisReq* pReq);
1830

1831
typedef struct {
1832
  char    db[TSDB_DB_FNAME_LEN];
1833
  char    table[TSDB_TABLE_NAME_LEN];
1834
  char    operation[AUDIT_OPERATION_LEN];
1835
  int32_t sqlLen;
1836
  char*   pSql;
1837
} SAuditReq;
1838
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1839
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1840
void    tFreeSAuditReq(SAuditReq* pReq);
1841

1842
typedef struct {
1843
  int32_t dnodeId;
1844
  int64_t clusterId;
1845
  SArray* pVloads;
1846
} SNotifyReq;
1847

1848
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1849
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1850
void    tFreeSNotifyReq(SNotifyReq* pReq);
1851

1852
typedef struct {
1853
  int32_t dnodeId;
1854
  int64_t clusterId;
1855
} SDnodeCfg;
1856

1857
typedef struct {
1858
  int32_t id;
1859
  int8_t  isMnode;
1860
  SEp     ep;
1861
} SDnodeEp;
1862

1863
typedef struct {
1864
  int32_t id;
1865
  int8_t  isMnode;
1866
  int8_t  offlineReason;
1867
  SEp     ep;
1868
  char    active[TSDB_ACTIVE_KEY_LEN];
1869
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1870
} SDnodeInfo;
1871

1872
typedef struct {
1873
  int64_t   dnodeVer;
1874
  SDnodeCfg dnodeCfg;
1875
  SArray*   pDnodeEps;  // Array of SDnodeEp
1876
  int32_t   statusSeq;
1877
  int64_t   ipWhiteVer;
1878
  int64_t   analVer;
1879
} SStatusRsp;
1880

1881
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1882
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1883
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1884

1885
typedef struct {
1886
  int32_t reserved;
1887
} SMTimerReq;
1888

1889
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1890
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1891

1892
typedef struct SOrphanTask {
1893
  int64_t streamId;
1894
  int32_t taskId;
1895
  int32_t nodeId;
1896
} SOrphanTask;
1897

1898
typedef struct SMStreamDropOrphanMsg {
1899
  SArray* pList;  // SArray<SOrphanTask>
1900
} SMStreamDropOrphanMsg;
1901

1902
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1903
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1904
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1905

1906
typedef struct {
1907
  int32_t  id;
1908
  uint16_t port;                 // node sync Port
1909
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1910
} SReplica;
1911

1912
typedef struct {
1913
  int32_t  vgId;
1914
  char     db[TSDB_DB_FNAME_LEN];
1915
  int64_t  dbUid;
1916
  int32_t  vgVersion;
1917
  int32_t  numOfStables;
1918
  int32_t  buffer;
1919
  int32_t  pageSize;
1920
  int32_t  pages;
1921
  int32_t  cacheLastSize;
1922
  int32_t  daysPerFile;
1923
  int32_t  daysToKeep0;
1924
  int32_t  daysToKeep1;
1925
  int32_t  daysToKeep2;
1926
  int32_t  keepTimeOffset;
1927
  int32_t  minRows;
1928
  int32_t  maxRows;
1929
  int32_t  walFsyncPeriod;
1930
  uint32_t hashBegin;
1931
  uint32_t hashEnd;
1932
  int8_t   hashMethod;
1933
  int8_t   walLevel;
1934
  int8_t   precision;
1935
  int8_t   compression;
1936
  int8_t   strict;
1937
  int8_t   cacheLast;
1938
  int8_t   isTsma;
1939
  int8_t   replica;
1940
  int8_t   selfIndex;
1941
  SReplica replicas[TSDB_MAX_REPLICA];
1942
  int32_t  numOfRetensions;
1943
  SArray*  pRetensions;  // SRetention
1944
  void*    pTsma;
1945
  int32_t  walRetentionPeriod;
1946
  int64_t  walRetentionSize;
1947
  int32_t  walRollPeriod;
1948
  int64_t  walSegmentSize;
1949
  int16_t  sstTrigger;
1950
  int16_t  hashPrefix;
1951
  int16_t  hashSuffix;
1952
  int32_t  tsdbPageSize;
1953
  int32_t  s3ChunkSize;
1954
  int32_t  s3KeepLocal;
1955
  int8_t   s3Compact;
1956
  int64_t  reserved[6];
1957
  int8_t   learnerReplica;
1958
  int8_t   learnerSelfIndex;
1959
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
1960
  int32_t  changeVersion;
1961
  int8_t   encryptAlgorithm;
1962
} SCreateVnodeReq;
1963

1964
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1965
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1966
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
1967

1968
typedef struct {
1969
  int32_t compactId;
1970
  int32_t vgId;
1971
  int32_t dnodeId;
1972
} SQueryCompactProgressReq;
1973

1974
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1975
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1976

1977
typedef struct {
1978
  int32_t compactId;
1979
  int32_t vgId;
1980
  int32_t dnodeId;
1981
  int32_t numberFileset;
1982
  int32_t finished;
1983
} SQueryCompactProgressRsp;
1984

1985
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1986
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1987

1988
typedef struct {
1989
  int32_t vgId;
1990
  int32_t dnodeId;
1991
  int64_t dbUid;
1992
  char    db[TSDB_DB_FNAME_LEN];
1993
  int64_t reserved[8];
1994
} SDropVnodeReq;
1995

1996
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1997
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1998

1999
typedef struct {
2000
  char    colName[TSDB_COL_NAME_LEN];
2001
  char    stb[TSDB_TABLE_FNAME_LEN];
2002
  int64_t stbUid;
2003
  int64_t dbUid;
2004
  int64_t reserved[8];
2005
} SDropIndexReq;
2006

2007
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2008
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2009

2010
typedef struct {
2011
  int64_t     dbUid;
2012
  char        db[TSDB_DB_FNAME_LEN];
2013
  int64_t     compactStartTime;
2014
  STimeWindow tw;
2015
  int32_t     compactId;
2016
} SCompactVnodeReq;
2017

2018
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2019
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2020

2021
typedef struct {
2022
  int32_t compactId;
2023
  int32_t vgId;
2024
  int32_t dnodeId;
2025
} SVKillCompactReq;
2026

2027
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2028
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2029

2030
typedef struct {
2031
  int32_t vgVersion;
2032
  int32_t buffer;
2033
  int32_t pageSize;
2034
  int32_t pages;
2035
  int32_t cacheLastSize;
2036
  int32_t daysPerFile;
2037
  int32_t daysToKeep0;
2038
  int32_t daysToKeep1;
2039
  int32_t daysToKeep2;
2040
  int32_t keepTimeOffset;
2041
  int32_t walFsyncPeriod;
2042
  int8_t  walLevel;
2043
  int8_t  strict;
2044
  int8_t  cacheLast;
2045
  int64_t reserved[7];
2046
  // 1st modification
2047
  int16_t sttTrigger;
2048
  int32_t minRows;
2049
  // 2nd modification
2050
  int32_t walRetentionPeriod;
2051
  int32_t walRetentionSize;
2052
  int32_t s3KeepLocal;
2053
  int8_t  s3Compact;
2054
} SAlterVnodeConfigReq;
2055

2056
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2057
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2058

2059
typedef struct {
2060
  int32_t  vgId;
2061
  int8_t   strict;
2062
  int8_t   selfIndex;
2063
  int8_t   replica;
2064
  SReplica replicas[TSDB_MAX_REPLICA];
2065
  int64_t  reserved[8];
2066
  int8_t   learnerSelfIndex;
2067
  int8_t   learnerReplica;
2068
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2069
  int32_t  changeVersion;
2070
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2071

2072
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2073
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2074

2075
typedef struct {
2076
  int32_t vgId;
2077
  int8_t  disable;
2078
} SDisableVnodeWriteReq;
2079

2080
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2081
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2082

2083
typedef struct {
2084
  int32_t  srcVgId;
2085
  int32_t  dstVgId;
2086
  uint32_t hashBegin;
2087
  uint32_t hashEnd;
2088
  int32_t  changeVersion;
2089
  int32_t  reserved;
2090
} SAlterVnodeHashRangeReq;
2091

2092
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2093
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2094

2095
#define REQ_OPT_TBNAME 0x0
2096
#define REQ_OPT_TBUID  0x01
2097
typedef struct {
2098
  SMsgHead header;
2099
  char     dbFName[TSDB_DB_FNAME_LEN];
2100
  char     tbName[TSDB_TABLE_NAME_LEN];
2101
  uint8_t  option;
2102
} STableInfoReq;
2103

2104
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2105
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2106

2107
typedef struct {
2108
  int8_t  metaClone;  // create local clone of the cached table meta
2109
  int32_t numOfVgroups;
2110
  int32_t numOfTables;
2111
  int32_t numOfUdfs;
2112
  char    tableNames[];
2113
} SMultiTableInfoReq;
2114

2115
// todo refactor
2116
typedef struct SVgroupInfo {
2117
  int32_t  vgId;
2118
  uint32_t hashBegin;
2119
  uint32_t hashEnd;
2120
  SEpSet   epSet;
2121
  union {
2122
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2123
    int32_t taskId;      // used in stream
2124
  };
2125
} SVgroupInfo;
2126

2127
typedef struct {
2128
  int32_t     numOfVgroups;
2129
  SVgroupInfo vgroups[];
2130
} SVgroupsInfo;
2131

2132
typedef struct {
2133
  STableMetaRsp* pMeta;
2134
} SMAlterStbRsp;
2135

2136
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2137
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2138
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2139

2140
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2141
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2142
void    tFreeSTableMetaRsp(void* pRsp);
2143
void    tFreeSTableIndexRsp(void* info);
2144

2145
typedef struct {
2146
  SArray* pMetaRsp;   // Array of STableMetaRsp
2147
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2148
} SSTbHbRsp;
2149

2150
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2151
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2152
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2153

2154
typedef struct {
2155
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2156
} SViewHbRsp;
2157

2158
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2159
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2160
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2161

2162
typedef struct {
2163
  int32_t numOfTables;
2164
  int32_t numOfVgroup;
2165
  int32_t numOfUdf;
2166
  int32_t contLen;
2167
  int8_t  compressed;  // denote if compressed or not
2168
  int32_t rawLen;      // size before compress
2169
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2170
  char    meta[];
2171
} SMultiTableMeta;
2172

2173
typedef struct {
2174
  int32_t dataLen;
2175
  char    name[TSDB_TABLE_FNAME_LEN];
2176
  char*   data;
2177
} STagData;
2178

2179
typedef struct {
2180
  int32_t useless;  // useless
2181
} SShowVariablesReq;
2182

2183
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2184
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2185

2186
typedef struct {
2187
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2188
  char value[TSDB_CONFIG_VALUE_LEN + 1];
2189
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2190
} SVariablesInfo;
2191

2192
typedef struct {
2193
  SArray* variables;  // SArray<SVariablesInfo>
2194
} SShowVariablesRsp;
2195

2196
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2197
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2198

2199
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2200

2201
/*
2202
 * sql: show tables like '%a_%'
2203
 * payload is the query condition, e.g., '%a_%'
2204
 * payloadLen is the length of payload
2205
 */
2206
typedef struct {
2207
  int32_t type;
2208
  char    db[TSDB_DB_FNAME_LEN];
2209
  int32_t payloadLen;
2210
  char*   payload;
2211
} SShowReq;
2212

2213
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2214
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2215
void tFreeSShowReq(SShowReq* pReq);
2216

2217
typedef struct {
2218
  int64_t       showId;
2219
  STableMetaRsp tableMeta;
2220
} SShowRsp, SVShowTablesRsp;
2221

2222
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2223
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2224
// void    tFreeSShowRsp(SShowRsp* pRsp);
2225

2226
typedef struct {
2227
  char    db[TSDB_DB_FNAME_LEN];
2228
  char    tb[TSDB_TABLE_NAME_LEN];
2229
  char    user[TSDB_USER_LEN];
2230
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2231
  int64_t showId;
2232
  int64_t compactId;  // for compact
2233
  bool    withFull;   // for show users full
2234
} SRetrieveTableReq;
2235

2236
typedef struct SSysTableSchema {
2237
  int8_t   type;
2238
  col_id_t colId;
2239
  int32_t  bytes;
2240
} SSysTableSchema;
2241

2242
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2243
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2244

2245
typedef struct {
2246
  int64_t useconds;
2247
  int8_t  completed;  // all results are returned to client
2248
  int8_t  precision;
2249
  int8_t  compressed;
2250
  int8_t  streamBlockType;
2251
  int32_t payloadLen;
2252
  int32_t compLen;
2253
  int32_t numOfBlocks;
2254
  int64_t numOfRows;  // from int32_t change to int64_t
2255
  int64_t numOfCols;
2256
  int64_t skey;
2257
  int64_t ekey;
2258
  int64_t version;                         // for stream
2259
  TSKEY   watermark;                       // for stream
2260
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2261
  char    data[];
2262
} SRetrieveTableRsp;
2263

2264
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2265

2266
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2267
  do {                                          \
2268
    ((int32_t*)(_p))[0] = (_compLen);           \
2269
    ((int32_t*)(_p))[1] = (_fullLen);           \
2270
  } while (0);
2271

2272
typedef struct {
2273
  int64_t version;
2274
  int64_t numOfRows;
2275
  int8_t  compressed;
2276
  int8_t  precision;
2277
  char    data[];
2278
} SRetrieveTableRspForTmq;
2279

2280
typedef struct {
2281
  int64_t handle;
2282
  int64_t useconds;
2283
  int8_t  completed;  // all results are returned to client
2284
  int8_t  precision;
2285
  int8_t  compressed;
2286
  int32_t compLen;
2287
  int32_t numOfRows;
2288
  int32_t fullLen;
2289
  char    data[];
2290
} SRetrieveMetaTableRsp;
2291

2292
typedef struct SExplainExecInfo {
2293
  double   startupCost;
2294
  double   totalCost;
2295
  uint64_t numOfRows;
2296
  uint32_t verboseLen;
2297
  void*    verboseInfo;
2298
} SExplainExecInfo;
2299

2300
typedef struct {
2301
  int32_t           numOfPlans;
2302
  SExplainExecInfo* subplanInfo;
2303
} SExplainRsp;
2304

2305
typedef struct {
2306
  SExplainRsp rsp;
2307
  uint64_t    qId;
2308
  uint64_t    tId;
2309
  int64_t     rId;
2310
  int32_t     eId;
2311
} SExplainLocalRsp;
2312

2313
typedef struct STableScanAnalyzeInfo {
2314
  uint64_t totalRows;
2315
  uint64_t totalCheckedRows;
2316
  uint32_t totalBlocks;
2317
  uint32_t loadBlocks;
2318
  uint32_t loadBlockStatis;
2319
  uint32_t skipBlocks;
2320
  uint32_t filterOutBlocks;
2321
  double   elapsedTime;
2322
  double   filterTime;
2323
} STableScanAnalyzeInfo;
2324

2325
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2326
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2327
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2328

2329
typedef struct {
2330
  char    config[TSDB_DNODE_CONFIG_LEN];
2331
  char    value[TSDB_CLUSTER_VALUE_LEN];
2332
  int32_t sqlLen;
2333
  char*   sql;
2334
} SMCfgClusterReq;
2335

2336
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2337
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2338
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2339

2340
typedef struct {
2341
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2342
  int32_t port;
2343
  int32_t sqlLen;
2344
  char*   sql;
2345
} SCreateDnodeReq;
2346

2347
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2348
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2349
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2350

2351
typedef struct {
2352
  int32_t dnodeId;
2353
  char    fqdn[TSDB_FQDN_LEN];
2354
  int32_t port;
2355
  int8_t  force;
2356
  int8_t  unsafe;
2357
  int32_t sqlLen;
2358
  char*   sql;
2359
} SDropDnodeReq;
2360

2361
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2362
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2363
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2364

2365
enum {
2366
  RESTORE_TYPE__ALL = 1,
2367
  RESTORE_TYPE__MNODE,
2368
  RESTORE_TYPE__VNODE,
2369
  RESTORE_TYPE__QNODE,
2370
};
2371

2372
typedef struct {
2373
  int32_t dnodeId;
2374
  int8_t  restoreType;
2375
  int32_t sqlLen;
2376
  char*   sql;
2377
} SRestoreDnodeReq;
2378

2379
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2380
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2381
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2382

2383
typedef struct {
2384
  int32_t dnodeId;
2385
  char    config[TSDB_DNODE_CONFIG_LEN];
2386
  char    value[TSDB_DNODE_VALUE_LEN];
2387
  int32_t sqlLen;
2388
  char*   sql;
2389
} SMCfgDnodeReq;
2390

2391
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2392
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2393
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2394

2395
typedef struct {
2396
  char config[TSDB_DNODE_CONFIG_LEN];
2397
  char value[TSDB_DNODE_VALUE_LEN];
2398
} SDCfgDnodeReq;
2399

2400
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2401
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2402

2403
typedef struct {
2404
  int32_t dnodeId;
2405
  int32_t sqlLen;
2406
  char*   sql;
2407
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2408
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2409

2410
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2411
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2412
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2413
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2414
typedef struct {
2415
  int8_t   replica;
2416
  SReplica replicas[TSDB_MAX_REPLICA];
2417
  int8_t   learnerReplica;
2418
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2419
  int64_t  lastIndex;
2420
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2421

2422
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2423
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2424

2425
typedef struct {
2426
  int32_t urlLen;
2427
  int32_t sqlLen;
2428
  char*   url;
2429
  char*   sql;
2430
} SMCreateAnodeReq;
2431

2432
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2433
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2434
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2435

2436
typedef struct {
2437
  int32_t anodeId;
2438
  int32_t sqlLen;
2439
  char*   sql;
2440
} SMDropAnodeReq, SMUpdateAnodeReq;
2441

2442
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2443
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2444
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2445
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2446
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2447
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2448

2449
typedef struct {
2450
  int32_t vgId;
2451
  int32_t hbSeq;
2452
} SVArbHbReqMember;
2453

2454
typedef struct {
2455
  int32_t dnodeId;
2456
  char*   arbToken;
2457
  int64_t arbTerm;
2458
  SArray* hbMembers;  // SVArbHbReqMember
2459
} SVArbHeartBeatReq;
2460

2461
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2462
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2463
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2464

2465
typedef struct {
2466
  int32_t vgId;
2467
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2468
  int32_t hbSeq;
2469
} SVArbHbRspMember;
2470

2471
typedef struct {
2472
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2473
  int32_t dnodeId;
2474
  SArray* hbMembers;  // SVArbHbRspMember
2475
} SVArbHeartBeatRsp;
2476

2477
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2478
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2479
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2480

2481
typedef struct {
2482
  char*   arbToken;
2483
  int64_t arbTerm;
2484
  char*   member0Token;
2485
  char*   member1Token;
2486
} SVArbCheckSyncReq;
2487

2488
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2489
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2490
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2491

2492
typedef struct {
2493
  char*   arbToken;
2494
  char*   member0Token;
2495
  char*   member1Token;
2496
  int32_t vgId;
2497
  int32_t errCode;
2498
} SVArbCheckSyncRsp;
2499

2500
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2501
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2502
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2503

2504
typedef struct {
2505
  char*   arbToken;
2506
  int64_t arbTerm;
2507
  char*   memberToken;
2508
} SVArbSetAssignedLeaderReq;
2509

2510
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2511
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2512
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2513

2514
typedef struct {
2515
  char*   arbToken;
2516
  char*   memberToken;
2517
  int32_t vgId;
2518
} SVArbSetAssignedLeaderRsp;
2519

2520
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2521
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2522
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2523

2524
typedef struct {
2525
  int32_t dnodeId;
2526
  char*   token;
2527
} SMArbUpdateGroupMember;
2528

2529
typedef struct {
2530
  int32_t dnodeId;
2531
  char*   token;
2532
  int8_t  acked;
2533
} SMArbUpdateGroupAssigned;
2534

2535
typedef struct {
2536
  int32_t                  vgId;
2537
  int64_t                  dbUid;
2538
  SMArbUpdateGroupMember   members[2];
2539
  int8_t                   isSync;
2540
  int8_t                   assignedAcked;
2541
  SMArbUpdateGroupAssigned assignedLeader;
2542
  int64_t                  version;
2543
} SMArbUpdateGroup;
2544

2545
typedef struct {
2546
  SArray* updateArray;  // SMArbUpdateGroup
2547
} SMArbUpdateGroupBatchReq;
2548

2549
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2550
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2551
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2552

2553
typedef struct {
2554
  char queryStrId[TSDB_QUERY_ID_LEN];
2555
} SKillQueryReq;
2556

2557
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2558
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2559

2560
typedef struct {
2561
  uint32_t connId;
2562
} SKillConnReq;
2563

2564
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2565
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2566

2567
typedef struct {
2568
  int32_t transId;
2569
} SKillTransReq;
2570

2571
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2572
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2573

2574
typedef struct {
2575
  int32_t useless;  // useless
2576
  int32_t sqlLen;
2577
  char*   sql;
2578
} SBalanceVgroupReq;
2579

2580
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2581
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2582
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2583

2584
typedef struct {
2585
  int32_t vgId1;
2586
  int32_t vgId2;
2587
} SMergeVgroupReq;
2588

2589
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2590
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2591

2592
typedef struct {
2593
  int32_t vgId;
2594
  int32_t dnodeId1;
2595
  int32_t dnodeId2;
2596
  int32_t dnodeId3;
2597
  int32_t sqlLen;
2598
  char*   sql;
2599
} SRedistributeVgroupReq;
2600

2601
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2602
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2603
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2604

2605
typedef struct {
2606
  int32_t reserved;
2607
  int32_t vgId;
2608
  int32_t sqlLen;
2609
  char*   sql;
2610
  char    db[TSDB_DB_FNAME_LEN];
2611
} SBalanceVgroupLeaderReq;
2612

2613
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2614
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2615
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2616

2617
typedef struct {
2618
  int32_t vgId;
2619
} SForceBecomeFollowerReq;
2620

2621
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2622
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2623

2624
typedef struct {
2625
  int32_t vgId;
2626
} SSplitVgroupReq;
2627

2628
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2629
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2630

2631
typedef struct {
2632
  char user[TSDB_USER_LEN];
2633
  char spi;
2634
  char encrypt;
2635
  char secret[TSDB_PASSWORD_LEN];
2636
  char ckey[TSDB_PASSWORD_LEN];
2637
} SAuthReq, SAuthRsp;
2638

2639
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2640
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2641

2642
typedef struct {
2643
  int32_t statusCode;
2644
  char    details[1024];
2645
} SServerStatusRsp;
2646

2647
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2648
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2649

2650
/**
2651
 * The layout of the query message payload is as following:
2652
 * +--------------------+---------------------------------+
2653
 * |Sql statement       | Physical plan                   |
2654
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2655
 * +--------------------+---------------------------------+
2656
 */
2657
typedef struct SSubQueryMsg {
2658
  SMsgHead header;
2659
  uint64_t sId;
2660
  uint64_t queryId;
2661
  uint64_t taskId;
2662
  int64_t  refId;
2663
  int32_t  execId;
2664
  int32_t  msgMask;
2665
  int8_t   taskType;
2666
  int8_t   explain;
2667
  int8_t   needFetch;
2668
  int8_t   compress;
2669
  uint32_t sqlLen;
2670
  char*    sql;
2671
  uint32_t msgLen;
2672
  char*    msg;
2673
} SSubQueryMsg;
2674

2675
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2676
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2677
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2678

2679
typedef struct {
2680
  SMsgHead header;
2681
  uint64_t sId;
2682
  uint64_t queryId;
2683
  uint64_t taskId;
2684
} SSinkDataReq;
2685

2686
typedef struct {
2687
  SMsgHead header;
2688
  uint64_t sId;
2689
  uint64_t queryId;
2690
  uint64_t taskId;
2691
  int32_t  execId;
2692
} SQueryContinueReq;
2693

2694
typedef struct {
2695
  SMsgHead header;
2696
  uint64_t sId;
2697
  uint64_t queryId;
2698
  uint64_t taskId;
2699
} SResReadyReq;
2700

2701
typedef struct {
2702
  int32_t code;
2703
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2704
  int32_t sversion;
2705
  int32_t tversion;
2706
} SResReadyRsp;
2707

2708
typedef struct SOperatorParam {
2709
  int32_t opType;
2710
  int32_t downstreamIdx;
2711
  void*   value;
2712
  SArray* pChildren;  // SArray<SOperatorParam*>
2713
} SOperatorParam;
2714

2715
typedef struct STableScanOperatorParam {
2716
  bool    tableSeq;
2717
  SArray* pUidList;
2718
} STableScanOperatorParam;
2719

2720
typedef struct {
2721
  SMsgHead        header;
2722
  uint64_t        sId;
2723
  uint64_t        queryId;
2724
  uint64_t        taskId;
2725
  int32_t         execId;
2726
  SOperatorParam* pOpParam;
2727
} SResFetchReq;
2728

2729
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2730
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2731

2732
typedef struct {
2733
  SMsgHead header;
2734
  uint64_t sId;
2735
} SSchTasksStatusReq;
2736

2737
typedef struct {
2738
  uint64_t queryId;
2739
  uint64_t taskId;
2740
  int64_t  refId;
2741
  int32_t  execId;
2742
  int8_t   status;
2743
} STaskStatus;
2744

2745
typedef struct {
2746
  int64_t refId;
2747
  SArray* taskStatus;  // SArray<STaskStatus>
2748
} SSchedulerStatusRsp;
2749

2750
typedef struct {
2751
  uint64_t queryId;
2752
  uint64_t taskId;
2753
  int8_t   action;
2754
} STaskAction;
2755

2756
typedef struct SQueryNodeEpId {
2757
  int32_t nodeId;  // vgId or qnodeId
2758
  SEp     ep;
2759
} SQueryNodeEpId;
2760

2761
typedef struct {
2762
  SMsgHead       header;
2763
  uint64_t       sId;
2764
  SQueryNodeEpId epId;
2765
  SArray*        taskAction;  // SArray<STaskAction>
2766
} SSchedulerHbReq;
2767

2768
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2769
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2770
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2771

2772
typedef struct {
2773
  SQueryNodeEpId epId;
2774
  SArray*        taskStatus;  // SArray<STaskStatus>
2775
} SSchedulerHbRsp;
2776

2777
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2778
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2779
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2780

2781
typedef struct {
2782
  SMsgHead header;
2783
  uint64_t sId;
2784
  uint64_t queryId;
2785
  uint64_t taskId;
2786
  int64_t  refId;
2787
  int32_t  execId;
2788
} STaskCancelReq;
2789

2790
typedef struct {
2791
  int32_t code;
2792
} STaskCancelRsp;
2793

2794
typedef struct {
2795
  SMsgHead header;
2796
  uint64_t sId;
2797
  uint64_t queryId;
2798
  uint64_t taskId;
2799
  int64_t  refId;
2800
  int32_t  execId;
2801
} STaskDropReq;
2802

2803
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2804
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2805

2806
typedef enum {
2807
  TASK_NOTIFY_FINISHED = 1,
2808
} ETaskNotifyType;
2809

2810
typedef struct {
2811
  SMsgHead        header;
2812
  uint64_t        sId;
2813
  uint64_t        queryId;
2814
  uint64_t        taskId;
2815
  int64_t         refId;
2816
  int32_t         execId;
2817
  ETaskNotifyType type;
2818
} STaskNotifyReq;
2819

2820
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2821
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2822

2823
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2824
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2825

2826
typedef struct {
2827
  int32_t code;
2828
} STaskDropRsp;
2829

2830
#define STREAM_TRIGGER_AT_ONCE        1
2831
#define STREAM_TRIGGER_WINDOW_CLOSE   2
2832
#define STREAM_TRIGGER_MAX_DELAY      3
2833
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2834
#define STREAM_FILL_HISTORY_ON        1
2835
#define STREAM_FILL_HISTORY_OFF       0
2836
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2837
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2838
#define STREAM_CREATE_STABLE_TRUE     1
2839
#define STREAM_CREATE_STABLE_FALSE    0
2840

2841
typedef struct SColLocation {
2842
  int16_t  slotId;
2843
  col_id_t colId;
2844
  int8_t   type;
2845
} SColLocation;
2846

2847
typedef struct SVgroupVer {
2848
  int32_t vgId;
2849
  int64_t ver;
2850
} SVgroupVer;
2851

2852
typedef struct {
2853
  char    name[TSDB_STREAM_FNAME_LEN];
2854
  char    sourceDB[TSDB_DB_FNAME_LEN];
2855
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2856
  char*   sql;
2857
  char*   ast;
2858
  int8_t  igExists;
2859
  int8_t  triggerType;
2860
  int8_t  igExpired;
2861
  int8_t  fillHistory;  // process data inserted before creating stream
2862
  int64_t maxDelay;
2863
  int64_t watermark;
2864
  int32_t numOfTags;
2865
  SArray* pTags;  // array of SField
2866
  // 3.0.20
2867
  int64_t checkpointFreq;  // ms
2868
  // 3.0.2.3
2869
  int8_t   createStb;
2870
  uint64_t targetStbUid;
2871
  SArray*  fillNullCols;  // array of SColLocation
2872
  int64_t  deleteMark;
2873
  int8_t   igUpdate;
2874
  int64_t  lastTs;
2875
  SArray*  pVgroupVerList;
2876
  // 3.3.0.0
2877
  SArray* pCols;  // array of SField
2878
  int64_t smaId;
2879
} SCMCreateStreamReq;
2880

2881
typedef struct {
2882
  int64_t streamId;
2883
} SCMCreateStreamRsp;
2884

2885
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2886
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2887
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2888

2889
enum {
2890
  TOPIC_SUB_TYPE__DB = 1,
2891
  TOPIC_SUB_TYPE__TABLE,
2892
  TOPIC_SUB_TYPE__COLUMN,
2893
};
2894

2895
#define DEFAULT_MAX_POLL_INTERVAL 300000
2896
#define DEFAULT_SESSION_TIMEOUT   12000
2897

2898
typedef struct {
2899
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2900
  int8_t igExists;
2901
  int8_t subType;
2902
  int8_t withMeta;
2903
  char*  sql;
2904
  char   subDbName[TSDB_DB_FNAME_LEN];
2905
  char*  ast;
2906
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2907
} SCMCreateTopicReq;
2908

2909
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2910
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2911
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2912

2913
typedef struct {
2914
  int64_t consumerId;
2915
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2916

2917
typedef struct {
2918
  int64_t consumerId;
2919
  char    cgroup[TSDB_CGROUP_LEN];
2920
  char    clientId[TSDB_CLIENT_ID_LEN];
2921
  char    user[TSDB_USER_LEN];
2922
  char    fqdn[TSDB_FQDN_LEN];
2923
  SArray* topicNames;  // SArray<char**>
2924

2925
  int8_t  withTbName;
2926
  int8_t  autoCommit;
2927
  int32_t autoCommitInterval;
2928
  int8_t  resetOffsetCfg;
2929
  int8_t  enableReplay;
2930
  int8_t  enableBatchMeta;
2931
  int32_t sessionTimeoutMs;
2932
  int32_t maxPollIntervalMs;
2933
} SCMSubscribeReq;
2934

2935
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
2936
  int32_t tlen = 0;
1,418✔
2937
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
1,418!
2938
  tlen += taosEncodeString(buf, pReq->cgroup);
1,418✔
2939
  tlen += taosEncodeString(buf, pReq->clientId);
1,418✔
2940

2941
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
1,418!
2942
  tlen += taosEncodeFixedI32(buf, topicNum);
1,418✔
2943

2944
  for (int32_t i = 0; i < topicNum; i++) {
2,008✔
2945
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,180✔
2946
  }
2947

2948
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
1,418!
2949
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
1,418!
2950
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
1,418!
2951
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
1,418!
2952
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
1,418!
2953
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
1,418!
2954
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
1,418!
2955
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
1,418!
2956
  tlen += taosEncodeString(buf, pReq->user);
1,418✔
2957
  tlen += taosEncodeString(buf, pReq->fqdn);
1,418✔
2958

2959
  return tlen;
1,418✔
2960
}
2961

2962
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
2963
  void* start = buf;
117✔
2964
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
117!
2965
  buf = taosDecodeStringTo(buf, pReq->cgroup);
117✔
2966
  buf = taosDecodeStringTo(buf, pReq->clientId);
117✔
2967

2968
  int32_t topicNum = 0;
117!
2969
  buf = taosDecodeFixedI32(buf, &topicNum);
117✔
2970

2971
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
117✔
2972
  if (pReq->topicNames == NULL) {
117!
UNCOV
2973
    return terrno;
×
2974
  }
2975
  for (int32_t i = 0; i < topicNum; i++) {
200✔
2976
    char* name = NULL;
83✔
2977
    buf = taosDecodeString(buf, &name);
83✔
2978
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
166!
UNCOV
2979
      return terrno;
×
2980
    }
2981
  }
2982

2983
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
117✔
2984
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
117✔
2985
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
117!
2986
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
117✔
2987
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
117✔
2988
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
117✔
2989
  if ((char*)buf - (char*)start < len) {
117!
2990
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
117!
2991
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
117!
2992
    buf = taosDecodeStringTo(buf, pReq->user);
117✔
2993
    buf = taosDecodeStringTo(buf, pReq->fqdn);
234✔
2994
  } else {
UNCOV
2995
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
2996
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
2997
  }
2998

2999
  return 0;
117✔
3000
}
3001

3002
typedef struct {
3003
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3004
  SArray* removedConsumers;  // SArray<int64_t>
3005
  SArray* newConsumers;      // SArray<int64_t>
3006
} SMqRebInfo;
3007

3008
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3009
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
141✔
3010
  if (pRebInfo == NULL) {
141!
UNCOV
3011
    return NULL;
×
3012
  }
3013
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
141✔
3014
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
141✔
3015
  if (pRebInfo->removedConsumers == NULL) {
141!
UNCOV
3016
    goto _err;
×
3017
  }
3018
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
141✔
3019
  if (pRebInfo->newConsumers == NULL) {
141!
3020
    goto _err;
×
3021
  }
3022
  return pRebInfo;
141✔
UNCOV
3023
_err:
×
3024
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
3025
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3026
  taosMemoryFreeClear(pRebInfo);
×
3027
  return NULL;
×
3028
}
3029

3030
typedef struct {
3031
  int64_t streamId;
3032
  int64_t checkpointId;
3033
  char    streamName[TSDB_STREAM_FNAME_LEN];
3034
} SMStreamDoCheckpointMsg;
3035

3036
typedef struct {
3037
  int64_t status;
3038
} SMVSubscribeRsp;
3039

3040
typedef struct {
3041
  char    name[TSDB_TOPIC_FNAME_LEN];
3042
  int8_t  igNotExists;
3043
  int32_t sqlLen;
3044
  char*   sql;
3045
} SMDropTopicReq;
3046

3047
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3048
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3049
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3050

3051
typedef struct {
3052
  char   topic[TSDB_TOPIC_FNAME_LEN];
3053
  char   cgroup[TSDB_CGROUP_LEN];
3054
  int8_t igNotExists;
3055
} SMDropCgroupReq;
3056

3057
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3058
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3059

3060
typedef struct {
3061
  int8_t reserved;
3062
} SMDropCgroupRsp;
3063

3064
typedef struct {
3065
  char    name[TSDB_TABLE_FNAME_LEN];
3066
  int8_t  alterType;
3067
  SSchema schema;
3068
} SAlterTopicReq;
3069

3070
typedef struct {
3071
  SMsgHead head;
3072
  char     name[TSDB_TABLE_FNAME_LEN];
3073
  int64_t  tuid;
3074
  int32_t  sverson;
3075
  int32_t  execLen;
3076
  char*    executor;
3077
  int32_t  sqlLen;
3078
  char*    sql;
3079
} SDCreateTopicReq;
3080

3081
typedef struct {
3082
  SMsgHead head;
3083
  char     name[TSDB_TABLE_FNAME_LEN];
3084
  int64_t  tuid;
3085
} SDDropTopicReq;
3086

3087
typedef struct {
3088
  int64_t maxdelay[2];
3089
  int64_t watermark[2];
3090
  int64_t deleteMark[2];
3091
  int32_t qmsgLen[2];
3092
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3093
} SRSmaParam;
3094

3095
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3096
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3097

3098
// TDMT_VND_CREATE_STB ==============
3099
typedef struct SVCreateStbReq {
3100
  char*           name;
3101
  tb_uid_t        suid;
3102
  int8_t          rollup;
3103
  SSchemaWrapper  schemaRow;
3104
  SSchemaWrapper  schemaTag;
3105
  SRSmaParam      rsmaParam;
3106
  int32_t         alterOriDataLen;
3107
  void*           alterOriData;
3108
  int8_t          source;
3109
  int8_t          colCmpred;
3110
  SColCmprWrapper colCmpr;
3111
} SVCreateStbReq;
3112

3113
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3114
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3115

3116
// TDMT_VND_DROP_STB ==============
3117
typedef struct SVDropStbReq {
3118
  char*    name;
3119
  tb_uid_t suid;
3120
} SVDropStbReq;
3121

3122
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3123
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3124

3125
// TDMT_VND_CREATE_TABLE ==============
3126
#define TD_CREATE_IF_NOT_EXISTS 0x1
3127
typedef struct SVCreateTbReq {
3128
  int32_t  flags;
3129
  char*    name;
3130
  tb_uid_t uid;
3131
  int64_t  btime;
3132
  int32_t  ttl;
3133
  int32_t  commentLen;
3134
  char*    comment;
3135
  int8_t   type;
3136
  union {
3137
    struct {
3138
      char*    stbName;  // super table name
3139
      uint8_t  tagNum;
3140
      tb_uid_t suid;
3141
      SArray*  tagName;
3142
      uint8_t* pTag;
3143
    } ctb;
3144
    struct {
3145
      SSchemaWrapper schemaRow;
3146
    } ntb;
3147
  };
3148
  int32_t         sqlLen;
3149
  char*           sql;
3150
  SColCmprWrapper colCmpr;
3151
} SVCreateTbReq;
3152

3153
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3154
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3155
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3156

3157
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
1,127✔
3158
  if (NULL == req) {
4,049,767!
3159
    return;
3,980,094✔
3160
  }
3161

3162
  taosMemoryFreeClear(req->sql);
69,673!
3163
  taosMemoryFreeClear(req->name);
69,673!
3164
  taosMemoryFreeClear(req->comment);
69,677!
3165
  if (req->type == TSDB_CHILD_TABLE) {
69,677!
3166
    taosMemoryFreeClear(req->ctb.pTag);
63,174!
3167
    taosMemoryFreeClear(req->ctb.stbName);
63,174!
3168
    taosArrayDestroy(req->ctb.tagName);
63,173✔
3169
    req->ctb.tagName = NULL;
63,172✔
3170
  } else if (req->type == TSDB_NORMAL_TABLE) {
6,503!
3171
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
6,504!
3172
  }
3173
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
69,675!
3174
}
3175

3176
typedef struct {
3177
  int32_t nReqs;
3178
  union {
3179
    SVCreateTbReq* pReqs;
3180
    SArray*        pArray;
3181
  };
3182
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3183
} SVCreateTbBatchReq;
3184

3185
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3186
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3187
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3188

3189
typedef struct {
3190
  int32_t        code;
3191
  STableMetaRsp* pMeta;
3192
} SVCreateTbRsp, SVUpdateTbRsp;
3193

3194
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3195
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3196
void tFreeSVCreateTbRsp(void* param);
3197

3198
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3199
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3200

3201
typedef struct {
3202
  int32_t nRsps;
3203
  union {
3204
    SVCreateTbRsp* pRsps;
3205
    SArray*        pArray;
3206
  };
3207
} SVCreateTbBatchRsp;
3208

3209
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3210
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3211

3212
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3213
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3214

3215
// TDMT_VND_DROP_TABLE =================
3216
typedef struct {
3217
  char*    name;
3218
  uint64_t suid;  // for tmq in wal format
3219
  int8_t   igNotExists;
3220
} SVDropTbReq;
3221

3222
typedef struct {
3223
  int32_t code;
3224
} SVDropTbRsp;
3225

3226
typedef struct {
3227
  int32_t nReqs;
3228
  union {
3229
    SVDropTbReq* pReqs;
3230
    SArray*      pArray;
3231
  };
3232
} SVDropTbBatchReq;
3233

3234
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3235
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3236

3237
typedef struct {
3238
  int32_t nRsps;
3239
  union {
3240
    SVDropTbRsp* pRsps;
3241
    SArray*      pArray;
3242
  };
3243
} SVDropTbBatchRsp;
3244

3245
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3246
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3247

3248
// TDMT_VND_ALTER_TABLE =====================
3249
typedef struct {
3250
  char*   tbName;
3251
  int8_t  action;
3252
  char*   colName;
3253
  int32_t colId;
3254
  // TSDB_ALTER_TABLE_ADD_COLUMN
3255
  int8_t  type;
3256
  int8_t  flags;
3257
  int32_t bytes;
3258
  // TSDB_ALTER_TABLE_DROP_COLUMN
3259
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3260
  int8_t   colModType;
3261
  int32_t  colModBytes;
3262
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3263
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3264
  int8_t   isNull;
3265
  int8_t   tagType;
3266
  int8_t   tagFree;
3267
  uint32_t nTagVal;
3268
  uint8_t* pTagVal;
3269
  SArray*  pTagArray;
3270
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3271
  int8_t   updateTTL;
3272
  int32_t  newTTL;
3273
  int32_t  newCommentLen;
3274
  char*    newComment;
3275
  int64_t  ctimeMs;   // fill by vnode
3276
  int8_t   source;    // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3277
  uint32_t compress;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3278
} SVAlterTbReq;
3279

3280
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3281
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3282
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3283

3284
typedef struct {
3285
  int32_t        code;
3286
  STableMetaRsp* pMeta;
3287
} SVAlterTbRsp;
3288

3289
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3290
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3291
// ======================
3292

3293
typedef struct {
3294
  SMsgHead head;
3295
  int64_t  uid;
3296
  int32_t  tid;
3297
  int16_t  tversion;
3298
  int16_t  colId;
3299
  int8_t   type;
3300
  int16_t  bytes;
3301
  int32_t  tagValLen;
3302
  int16_t  numOfTags;
3303
  int32_t  schemaLen;
3304
  char     data[];
3305
} SUpdateTagValReq;
3306

3307
typedef struct {
3308
  SMsgHead head;
3309
} SUpdateTagValRsp;
3310

3311
typedef struct {
3312
  SMsgHead head;
3313
} SVShowTablesReq;
3314

3315
typedef struct {
3316
  SMsgHead head;
3317
  int32_t  id;
3318
} SVShowTablesFetchReq;
3319

3320
typedef struct {
3321
  int64_t useconds;
3322
  int8_t  completed;  // all results are returned to client
3323
  int8_t  precision;
3324
  int8_t  compressed;
3325
  int32_t compLen;
3326
  int32_t numOfRows;
3327
  char    data[];
3328
} SVShowTablesFetchRsp;
3329

3330
typedef struct {
3331
  int64_t consumerId;
3332
  int32_t epoch;
3333
  char    cgroup[TSDB_CGROUP_LEN];
3334
} SMqAskEpReq;
3335

3336
typedef struct {
3337
  int32_t key;
3338
  int32_t valueLen;
3339
  void*   value;
3340
} SKv;
3341

3342
typedef struct {
3343
  int64_t tscRid;
3344
  int8_t  connType;
3345
} SClientHbKey;
3346

3347
typedef struct {
3348
  int64_t tid;
3349
  char    status[TSDB_JOB_STATUS_LEN];
3350
} SQuerySubDesc;
3351

3352
typedef struct {
3353
  char     sql[TSDB_SHOW_SQL_LEN];
3354
  uint64_t queryId;
3355
  int64_t  useconds;
3356
  int64_t  stime;  // timestamp precision ms
3357
  int64_t  reqRid;
3358
  bool     stableQuery;
3359
  bool     isSubQuery;
3360
  char     fqdn[TSDB_FQDN_LEN];
3361
  int32_t  subPlanNum;
3362
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3363
} SQueryDesc;
3364

3365
typedef struct {
3366
  uint32_t connId;
3367
  SArray*  queryDesc;  // SArray<SQueryDesc>
3368
} SQueryHbReqBasic;
3369

3370
typedef struct {
3371
  uint32_t connId;
3372
  uint64_t killRid;
3373
  int32_t  totalDnodes;
3374
  int32_t  onlineDnodes;
3375
  int8_t   killConnection;
3376
  int8_t   align[3];
3377
  SEpSet   epSet;
3378
  SArray*  pQnodeList;
3379
} SQueryHbRspBasic;
3380

3381
typedef struct SAppClusterSummary {
3382
  uint64_t numOfInsertsReq;
3383
  uint64_t numOfInsertRows;
3384
  uint64_t insertElapsedTime;
3385
  uint64_t insertBytes;  // submit to tsdb since launched.
3386

3387
  uint64_t fetchBytes;
3388
  uint64_t numOfQueryReq;
3389
  uint64_t queryElapsedTime;
3390
  uint64_t numOfSlowQueries;
3391
  uint64_t totalRequests;
3392
  uint64_t currentRequests;  // the number of SRequestObj
3393
} SAppClusterSummary;
3394

3395
typedef struct {
3396
  int64_t            appId;
3397
  int32_t            pid;
3398
  char               name[TSDB_APP_NAME_LEN];
3399
  int64_t            startTime;
3400
  SAppClusterSummary summary;
3401
} SAppHbReq;
3402

3403
typedef struct {
3404
  SClientHbKey      connKey;
3405
  int64_t           clusterId;
3406
  SAppHbReq         app;
3407
  SQueryHbReqBasic* query;
3408
  SHashObj*         info;  // hash<Skv.key, Skv>
3409
} SClientHbReq;
3410

3411
typedef struct {
3412
  int64_t reqId;
3413
  SArray* reqs;  // SArray<SClientHbReq>
3414
  int64_t ipWhiteList;
3415
} SClientHbBatchReq;
3416

3417
typedef struct {
3418
  SClientHbKey      connKey;
3419
  int32_t           status;
3420
  SQueryHbRspBasic* query;
3421
  SArray*           info;  // Array<Skv>
3422
} SClientHbRsp;
3423

3424
typedef struct {
3425
  int64_t       reqId;
3426
  int64_t       rspId;
3427
  int32_t       svrTimestamp;
3428
  SArray*       rsps;  // SArray<SClientHbRsp>
3429
  SMonitorParas monitorParas;
3430
  int8_t        enableAuditDelete;
3431
} SClientHbBatchRsp;
3432

3433
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
110,165✔
3434

3435
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3436
  void* pIter = taosHashIterate(info, NULL);
293,039✔
3437
  while (pIter != NULL) {
455,632!
3438
    SKv* kv = (SKv*)pIter;
162,585✔
3439
    taosMemoryFreeClear(kv->value);
162,585!
3440
    pIter = taosHashIterate(info, pIter);
162,585✔
3441
  }
3442
}
293,047✔
3443

3444
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
90,963✔
3445
  SQueryDesc* desc = (SQueryDesc*)pDesc;
90,963✔
3446
  if (desc->subDesc) {
90,963✔
3447
    taosArrayDestroy(desc->subDesc);
86,983✔
3448
    desc->subDesc = NULL;
86,983✔
3449
  }
3450
}
90,963✔
3451

3452
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
307,781✔
3453
  SClientHbReq* req = (SClientHbReq*)pReq;
315,112✔
3454
  if (req->query) {
315,112!
3455
    if (req->query->queryDesc) {
304,561!
3456
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
16,679✔
3457
    }
3458
    taosMemoryFreeClear(req->query);
304,561!
3459
  }
3460

3461
  if (req->info) {
315,116!
3462
    tFreeReqKvHash(req->info);
293,039✔
3463
    taosHashCleanup(req->info);
293,047✔
3464
    req->info = NULL;
293,039✔
3465
  }
3466
}
272,574✔
3467

3468
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3469
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3470

3471
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3472
  if (pReq == NULL) return;
32,539!
3473
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
32,539✔
3474
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
32,539✔
3475
  taosMemoryFree(pReq);
32,539✔
3476
}
3477

3478
static FORCE_INLINE void tFreeClientKv(void* pKv) {
47,893✔
3479
  SKv* kv = (SKv*)pKv;
47,893✔
3480
  if (kv) {
47,893!
3481
    taosMemoryFreeClear(kv->value);
47,893!
3482
  }
3483
}
47,893✔
3484

3485
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
306,066✔
3486
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
306,066✔
3487
  if (rsp->query) {
306,066✔
3488
    taosArrayDestroy(rsp->query->pQnodeList);
303,000✔
3489
    taosMemoryFreeClear(rsp->query);
303,023!
3490
  }
3491
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
306,094!
3492
}
40,870✔
3493

3494
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3495
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
153,718✔
3496
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
153,718✔
3497
}
153,734✔
3498

3499
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3500
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3501
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3502

3503
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3504
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
298,260!
3505
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
298,260!
3506
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
298,260!
3507
  return 0;
149,130✔
3508
}
3509

3510
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3511
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
271,826!
3512
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
271,826!
3513
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
135,913✔
3514
  if (pKv->value == NULL) {
135,913!
UNCOV
3515
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3516
  }
3517
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
135,913!
3518
  return 0;
135,913✔
3519
}
3520

3521
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3522
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
1,231,048!
3523
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
1,231,048!
3524
  return 0;
615,524✔
3525
}
3526

3527
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3528
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
612,208!
3529
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
612,224!
3530
  return 0;
306,113✔
3531
}
3532

3533
typedef struct {
3534
  int32_t vgId;
3535
  // TODO stas
3536
} SMqReportVgInfo;
3537

3538
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3539
  int32_t tlen = 0;
3540
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3541
  return tlen;
3542
}
3543

3544
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3545
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3546
  return buf;
3547
}
3548

3549
typedef struct {
3550
  int32_t epoch;
3551
  int64_t topicUid;
3552
  char    name[TSDB_TOPIC_FNAME_LEN];
3553
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3554
} SMqTopicInfo;
3555

3556
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3557
  int32_t tlen = 0;
3558
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3559
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3560
  tlen += taosEncodeString(buf, pTopicInfo->name);
3561
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3562
  tlen += taosEncodeFixedI32(buf, sz);
3563
  for (int32_t i = 0; i < sz; i++) {
3564
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3565
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3566
  }
3567
  return tlen;
3568
}
3569

3570
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3571
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3572
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3573
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3574
  int32_t sz;
3575
  buf = taosDecodeFixedI32(buf, &sz);
3576
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3577
    return NULL;
3578
  }
3579
  for (int32_t i = 0; i < sz; i++) {
3580
    SMqReportVgInfo vgInfo;
3581
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3582
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3583
      return NULL;
3584
    }
3585
  }
3586
  return buf;
3587
}
3588

3589
typedef struct {
3590
  int32_t status;  // ask hb endpoint
3591
  int32_t epoch;
3592
  int64_t consumerId;
3593
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3594
} SMqReportReq;
3595

3596
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3597
  int32_t tlen = 0;
3598
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3599
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3600
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3601
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3602
  tlen += taosEncodeFixedI32(buf, sz);
3603
  for (int32_t i = 0; i < sz; i++) {
3604
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3605
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3606
  }
3607
  return tlen;
3608
}
3609

3610
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3611
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3612
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3613
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3614
  int32_t sz;
3615
  buf = taosDecodeFixedI32(buf, &sz);
3616
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3617
    return NULL;
3618
  }
3619
  for (int32_t i = 0; i < sz; i++) {
3620
    SMqTopicInfo topicInfo;
3621
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3622
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3623
      return NULL;
3624
    }
3625
  }
3626
  return buf;
3627
}
3628

3629
typedef struct {
3630
  SMsgHead head;
3631
  int64_t  leftForVer;
3632
  int32_t  vgId;
3633
  int64_t  consumerId;
3634
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3635
} SMqVDeleteReq;
3636

3637
typedef struct {
3638
  int8_t reserved;
3639
} SMqVDeleteRsp;
3640

3641
typedef struct {
3642
  char    name[TSDB_STREAM_FNAME_LEN];
3643
  int8_t  igNotExists;
3644
  int32_t sqlLen;
3645
  char*   sql;
3646
} SMDropStreamReq;
3647

3648
typedef struct {
3649
  int8_t reserved;
3650
} SMDropStreamRsp;
3651

3652
typedef struct {
3653
  SMsgHead head;
3654
  int64_t  resetRelHalt;  // reset related stream task halt status
3655
  int64_t  streamId;
3656
  int32_t  taskId;
3657
} SVDropStreamTaskReq;
3658

3659
typedef struct {
3660
  int8_t reserved;
3661
} SVDropStreamTaskRsp;
3662

3663
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3664
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3665
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3666

3667
typedef struct SVUpdateCheckpointInfoReq {
3668
  SMsgHead head;
3669
  int64_t  streamId;
3670
  int32_t  taskId;
3671
  int64_t  checkpointId;
3672
  int64_t  checkpointVer;
3673
  int64_t  checkpointTs;
3674
  int32_t  transId;
3675
  int64_t  hStreamId;  // add encode/decode
3676
  int64_t  hTaskId;
3677
  int8_t   dropRelHTask;
3678
} SVUpdateCheckpointInfoReq;
3679

3680
typedef struct {
3681
  int64_t leftForVer;
3682
  int32_t vgId;
3683
  int64_t oldConsumerId;
3684
  int64_t newConsumerId;
3685
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3686
  int8_t  subType;
3687
  int8_t  withMeta;
3688
  char*   qmsg;  // SubPlanToString
3689
  int64_t suid;
3690
} SMqRebVgReq;
3691

3692
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3693
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3694

3695
typedef struct {
3696
  char    topic[TSDB_TOPIC_FNAME_LEN];
3697
  int64_t ntbUid;
3698
  SArray* colIdList;  // SArray<int16_t>
3699
} STqCheckInfo;
3700

3701
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3702
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3703
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3704

3705
// tqOffset
3706
enum {
3707
  TMQ_OFFSET__RESET_NONE = -3,
3708
  TMQ_OFFSET__RESET_EARLIEST = -2,
3709
  TMQ_OFFSET__RESET_LATEST = -1,
3710
  TMQ_OFFSET__LOG = 1,
3711
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3712
  TMQ_OFFSET__SNAPSHOT_META = 3,
3713
};
3714

3715
enum {
3716
  WITH_DATA = 0,
3717
  WITH_META = 1,
3718
  ONLY_META = 2,
3719
};
3720

3721
#define TQ_OFFSET_VERSION 1
3722

3723
typedef struct {
3724
  int8_t type;
3725
  union {
3726
    // snapshot
3727
    struct {
3728
      int64_t uid;
3729
      int64_t ts;
3730
      SValue  primaryKey;
3731
    };
3732
    // log
3733
    struct {
3734
      int64_t version;
3735
    };
3736
  };
3737
} STqOffsetVal;
3738

3739
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3740
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
71✔
3741
  pOffsetVal->uid = uid;
71✔
3742
  pOffsetVal->ts = ts;
71✔
3743
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
71!
3744
    taosMemoryFree(pOffsetVal->primaryKey.pData);
1✔
3745
  }
3746
  pOffsetVal->primaryKey = primaryKey;
71✔
3747
}
71✔
3748

3749
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3750
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
4✔
3751
  pOffsetVal->uid = uid;
4✔
3752
}
4✔
3753

3754
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3755
  pOffsetVal->type = TMQ_OFFSET__LOG;
15,745✔
3756
  pOffsetVal->version = ver;
15,745✔
3757
}
15,745✔
3758

3759
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3760
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3761
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3762
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3763
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3764
void    tOffsetDestroy(void* pVal);
3765

3766
typedef struct {
3767
  STqOffsetVal val;
3768
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3769
} STqOffset;
3770

3771
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3772
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3773
void    tDeleteSTqOffset(void* val);
3774

3775
typedef struct SMqVgOffset {
3776
  int64_t   consumerId;
3777
  STqOffset offset;
3778
} SMqVgOffset;
3779

3780
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3781
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3782

3783
typedef struct {
3784
  SMsgHead head;
3785
  int64_t  streamId;
3786
  int32_t  taskId;
3787
} SVPauseStreamTaskReq, SVResetStreamTaskReq;
3788

3789
typedef struct {
3790
  char   name[TSDB_STREAM_FNAME_LEN];
3791
  int8_t igNotExists;
3792
} SMPauseStreamReq;
3793

3794
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3795
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3796

3797
typedef struct {
3798
  SMsgHead head;
3799
  int32_t  taskId;
3800
  int64_t  streamId;
3801
  int8_t   igUntreated;
3802
} SVResumeStreamTaskReq;
3803

3804
typedef struct {
3805
  int8_t reserved;
3806
} SVResumeStreamTaskRsp;
3807

3808
typedef struct {
3809
  char   name[TSDB_STREAM_FNAME_LEN];
3810
  int8_t igNotExists;
3811
  int8_t igUntreated;
3812
} SMResumeStreamReq;
3813

3814
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3815
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3816

3817
typedef struct {
3818
  char    name[TSDB_TABLE_FNAME_LEN];
3819
  char    stb[TSDB_TABLE_FNAME_LEN];
3820
  int8_t  igExists;
3821
  int8_t  intervalUnit;
3822
  int8_t  slidingUnit;
3823
  int8_t  timezone;
3824
  int32_t dstVgId;  // for stream
3825
  int64_t interval;
3826
  int64_t offset;
3827
  int64_t sliding;
3828
  int64_t maxDelay;
3829
  int64_t watermark;
3830
  int32_t exprLen;        // strlen + 1
3831
  int32_t tagsFilterLen;  // strlen + 1
3832
  int32_t sqlLen;         // strlen + 1
3833
  int32_t astLen;         // strlen + 1
3834
  char*   expr;
3835
  char*   tagsFilter;
3836
  char*   sql;
3837
  char*   ast;
3838
  int64_t deleteMark;
3839
  int64_t lastTs;
3840
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3841
  SArray* pVgroupVerList;
3842
  int8_t  recursiveTsma;
3843
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3844
} SMCreateSmaReq;
3845

3846
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3847
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3848
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3849

3850
typedef struct {
3851
  char   name[TSDB_TABLE_FNAME_LEN];
3852
  int8_t igNotExists;
3853
} SMDropSmaReq;
3854

3855
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3856
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3857

3858
typedef struct {
3859
  char   dbFName[TSDB_DB_FNAME_LEN];
3860
  char   stbName[TSDB_TABLE_NAME_LEN];
3861
  char   colName[TSDB_COL_NAME_LEN];
3862
  char   idxName[TSDB_INDEX_FNAME_LEN];
3863
  int8_t idxType;
3864
} SCreateTagIndexReq;
3865

3866
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3867
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3868

3869
typedef SMDropSmaReq SDropTagIndexReq;
3870

3871
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3872
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3873

3874
typedef struct {
3875
  int8_t         version;       // for compatibility(default 0)
3876
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3877
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3878
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3879
  int32_t        dstVgId;
3880
  char           indexName[TSDB_INDEX_NAME_LEN];
3881
  int32_t        exprLen;
3882
  int32_t        tagsFilterLen;
3883
  int64_t        indexUid;
3884
  tb_uid_t       tableUid;  // super/child/common table uid
3885
  tb_uid_t       dstTbUid;  // for dstVgroup
3886
  int64_t        interval;
3887
  int64_t        offset;  // use unit by precision of DB
3888
  int64_t        sliding;
3889
  char*          dstTbName;  // for dstVgroup
3890
  char*          expr;       // sma expression
3891
  char*          tagsFilter;
3892
  SSchemaWrapper schemaRow;  // for dstVgroup
3893
  SSchemaWrapper schemaTag;  // for dstVgroup
3894
} STSma;                     // Time-range-wise SMA
3895

3896
typedef STSma SVCreateTSmaReq;
3897

3898
typedef struct {
3899
  int8_t  type;  // 0 status report, 1 update data
3900
  int64_t indexUid;
3901
  int64_t skey;  // start TS key of interval/sliding window
3902
} STSmaMsg;
3903

3904
typedef struct {
3905
  int64_t indexUid;
3906
  char    indexName[TSDB_INDEX_NAME_LEN];
3907
} SVDropTSmaReq;
3908

3909
typedef struct {
3910
  int tmp;  // TODO: to avoid compile error
3911
} SVCreateTSmaRsp, SVDropTSmaRsp;
3912

3913
#if 0
3914
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3915
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3916
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3917
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3918
#endif
3919

3920
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3921
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3922
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3923
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3924

3925
typedef struct {
3926
  int32_t number;
3927
  STSma*  tSma;
3928
} STSmaWrapper;
3929

3930
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3931
  if (pSma) {
2!
3932
    taosMemoryFreeClear(pSma->dstTbName);
2!
3933
    taosMemoryFreeClear(pSma->expr);
2!
3934
    taosMemoryFreeClear(pSma->tagsFilter);
2!
3935
  }
3936
}
2✔
3937

3938
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
3939
  if (pSW) {
×
UNCOV
3940
    if (pSW->tSma) {
×
UNCOV
3941
      if (deepCopy) {
×
UNCOV
3942
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3943
          tDestroyTSma(pSW->tSma + i);
×
3944
        }
3945
      }
3946
      taosMemoryFreeClear(pSW->tSma);
×
3947
    }
3948
  }
UNCOV
3949
}
×
3950

3951
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
3952
  tDestroyTSmaWrapper(pSW, deepCopy);
×
3953
  taosMemoryFreeClear(pSW);
×
UNCOV
3954
  return NULL;
×
3955
}
3956

3957
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3958
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3959

3960
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
3961
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
3962

UNCOV
3963
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
3964
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
3965
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
3966
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
3967
  }
3968
  return 0;
×
3969
}
3970

UNCOV
3971
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
3972
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
3973
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
3974
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
3975
  }
3976
  return 0;
×
3977
}
3978

3979
typedef struct {
3980
  int idx;
3981
} SMCreateFullTextReq;
3982

3983
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3984
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3985
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
3986

3987
typedef struct {
3988
  char   name[TSDB_TABLE_FNAME_LEN];
3989
  int8_t igNotExists;
3990
} SMDropFullTextReq;
3991

3992
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
3993
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
3994

3995
typedef struct {
3996
  char indexFName[TSDB_INDEX_FNAME_LEN];
3997
} SUserIndexReq;
3998

3999
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4000
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4001

4002
typedef struct {
4003
  char dbFName[TSDB_DB_FNAME_LEN];
4004
  char tblFName[TSDB_TABLE_FNAME_LEN];
4005
  char colName[TSDB_COL_NAME_LEN];
4006
  char indexType[TSDB_INDEX_TYPE_LEN];
4007
  char indexExts[TSDB_INDEX_EXTS_LEN];
4008
} SUserIndexRsp;
4009

4010
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4011
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4012

4013
typedef struct {
4014
  char tbFName[TSDB_TABLE_FNAME_LEN];
4015
} STableIndexReq;
4016

4017
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4018
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4019

4020
typedef struct {
4021
  int8_t  intervalUnit;
4022
  int8_t  slidingUnit;
4023
  int64_t interval;
4024
  int64_t offset;
4025
  int64_t sliding;
4026
  int64_t dstTbUid;
4027
  int32_t dstVgId;
4028
  SEpSet  epSet;
4029
  char*   expr;
4030
} STableIndexInfo;
4031

4032
typedef struct {
4033
  char     tbName[TSDB_TABLE_NAME_LEN];
4034
  char     dbFName[TSDB_DB_FNAME_LEN];
4035
  uint64_t suid;
4036
  int32_t  version;
4037
  int32_t  indexSize;
4038
  SArray*  pIndex;  // STableIndexInfo
4039
} STableIndexRsp;
4040

4041
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4042
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4043
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4044

4045
void tFreeSTableIndexInfo(void* pInfo);
4046

4047
typedef struct {
4048
  int8_t  mqMsgType;
4049
  int32_t code;
4050
  int32_t epoch;
4051
  int64_t consumerId;
4052
  int64_t walsver;
4053
  int64_t walever;
4054
} SMqRspHead;
4055

4056
typedef struct {
4057
  SMsgHead     head;
4058
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4059
  int8_t       withTbName;
4060
  int8_t       useSnapshot;
4061
  int32_t      epoch;
4062
  uint64_t     reqId;
4063
  int64_t      consumerId;
4064
  int64_t      timeout;
4065
  STqOffsetVal reqOffset;
4066
  int8_t       enableReplay;
4067
  int8_t       sourceExcluded;
4068
  int8_t       enableBatchMeta;
4069
} SMqPollReq;
4070

4071
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4072
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4073
void    tDestroySMqPollReq(SMqPollReq* pReq);
4074

4075
typedef struct {
4076
  int32_t vgId;
4077
  int64_t offset;
4078
  SEpSet  epSet;
4079
} SMqSubVgEp;
4080

4081
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4082
  int32_t tlen = 0;
380✔
4083
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
380✔
4084
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
380✔
4085
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
380✔
4086
  return tlen;
380✔
4087
}
4088

4089
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4090
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
2,850!
4091
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
2,850!
4092
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
2,850✔
4093
  return buf;
2,850✔
4094
}
4095

4096
typedef struct {
4097
  char           topic[TSDB_TOPIC_FNAME_LEN];
4098
  char           db[TSDB_DB_FNAME_LEN];
4099
  SArray*        vgs;  // SArray<SMqSubVgEp>
4100
  SSchemaWrapper schema;
4101
} SMqSubTopicEp;
4102

4103
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4104
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4105
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4106

4107
typedef struct {
4108
  SMqRspHead   head;
4109
  STqOffsetVal rspOffset;
4110
  int16_t      resMsgType;
4111
  int32_t      metaRspLen;
4112
  void*        metaRsp;
4113
} SMqMetaRsp;
4114

4115
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4116
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4117
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4118

4119
#define MQ_DATA_RSP_VERSION 100
4120

4121
typedef struct {
4122
  SMqRspHead   head;
4123
  STqOffsetVal rspOffset;
4124
  STqOffsetVal reqOffset;
4125
  int32_t      blockNum;
4126
  int8_t       withTbName;
4127
  int8_t       withSchema;
4128
  SArray*      blockDataLen;
4129
  SArray*      blockData;
4130
  SArray*      blockTbName;
4131
  SArray*      blockSchema;
4132

4133
  union{
4134
    struct{
4135
      int64_t          sleepTime;
4136
    };
4137
    struct{
4138
      int32_t          createTableNum;
4139
      SArray*          createTableLen;
4140
      SArray*          createTableReq;
4141
    };
4142
  };
4143

4144
} SMqDataRsp;
4145

4146
int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj);
4147
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4148
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4149

4150
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4151
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4152
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4153

4154
typedef struct SMqBatchMetaRsp {
4155
  SMqRspHead   head;  // not serialize
4156
  STqOffsetVal rspOffset;
4157
  SArray*      batchMetaLen;
4158
  SArray*      batchMetaReq;
4159
  void*        pMetaBuff;    // not serialize
4160
  uint32_t     metaBuffLen;  // not serialize
4161
} SMqBatchMetaRsp;
4162

4163
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4164
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4165
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4166
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4167

4168
typedef struct {
4169
  SMqRspHead head;
4170
  char       cgroup[TSDB_CGROUP_LEN];
4171
  SArray*    topics;  // SArray<SMqSubTopicEp>
4172
} SMqAskEpRsp;
4173

4174
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4175
  int32_t tlen = 0;
438✔
4176
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4177
  int32_t sz = taosArrayGetSize(pRsp->topics);
438!
4178
  tlen += taosEncodeFixedI32(buf, sz);
438✔
4179
  for (int32_t i = 0; i < sz; i++) {
640✔
4180
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
202✔
4181
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
202✔
4182
  }
4183
  return tlen;
438✔
4184
}
4185

4186
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4187
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4188
  int32_t sz;
4189
  buf = taosDecodeFixedI32(buf, &sz);
5,557✔
4190
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
5,557✔
4191
  if (pRsp->topics == NULL) {
5,557!
UNCOV
4192
    return NULL;
×
4193
  }
4194
  for (int32_t i = 0; i < sz; i++) {
7,824✔
4195
    SMqSubTopicEp topicEp;
4196
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
2,267✔
4197
    if (buf == NULL) {
2,267!
UNCOV
4198
      return NULL;
×
4199
    }
4200
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
4,534!
UNCOV
4201
      return NULL;
×
4202
    }
4203
  }
4204
  return buf;
5,557✔
4205
}
4206

4207
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4208
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
6,064✔
4209
}
6,064✔
4210

4211
typedef struct {
4212
  int32_t      vgId;
4213
  STqOffsetVal offset;
4214
  int64_t      rows;
4215
  int64_t      ever;
4216
} OffsetRows;
4217

4218
typedef struct {
4219
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4220
  SArray* offsetRows;
4221
} TopicOffsetRows;
4222

4223
typedef struct {
4224
  int64_t consumerId;
4225
  int32_t epoch;
4226
  SArray* topics;
4227
  int8_t  pollFlag;
4228
} SMqHbReq;
4229

4230
typedef struct {
4231
  char   topic[TSDB_TOPIC_FNAME_LEN];
4232
  int8_t noPrivilege;
4233
} STopicPrivilege;
4234

4235
typedef struct {
4236
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4237
  int32_t debugFlag;
4238
} SMqHbRsp;
4239

4240
typedef struct {
4241
  SMsgHead head;
4242
  int64_t  consumerId;
4243
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4244
} SMqSeekReq;
4245

4246
#define TD_AUTO_CREATE_TABLE 0x1
4247
typedef struct {
4248
  int64_t       suid;
4249
  int64_t       uid;
4250
  int32_t       sver;
4251
  uint32_t      nData;
4252
  uint8_t*      pData;
4253
  SVCreateTbReq cTbReq;
4254
} SVSubmitBlk;
4255

4256
typedef struct {
4257
  SMsgHead header;
4258
  uint64_t sId;
4259
  uint64_t queryId;
4260
  uint64_t taskId;
4261
  uint32_t sqlLen;
4262
  uint32_t phyLen;
4263
  char*    sql;
4264
  char*    msg;
4265
  int8_t   source;
4266
} SVDeleteReq;
4267

4268
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4269
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4270

4271
typedef struct {
4272
  int64_t affectedRows;
4273
} SVDeleteRsp;
4274

4275
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4276
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4277

4278
typedef struct SDeleteRes {
4279
  uint64_t suid;
4280
  SArray*  uidList;
4281
  int64_t  skey;
4282
  int64_t  ekey;
4283
  int64_t  affectedRows;
4284
  char     tableFName[TSDB_TABLE_NAME_LEN];
4285
  char     tsColName[TSDB_COL_NAME_LEN];
4286
  int64_t  ctimeMs;  // fill by vnode
4287
  int8_t   source;
4288
} SDeleteRes;
4289

4290
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4291
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4292

4293
typedef struct {
4294
  // int64_t uid;
4295
  char    tbname[TSDB_TABLE_NAME_LEN];
4296
  int64_t startTs;
4297
  int64_t endTs;
4298
} SSingleDeleteReq;
4299

4300
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4301
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4302

4303
typedef struct {
4304
  int64_t suid;
4305
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4306
  int64_t ctimeMs;     // fill by vnode
4307
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4308
} SBatchDeleteReq;
4309

4310
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4311
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4312
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4313

4314
typedef struct {
4315
  int32_t msgIdx;
4316
  int32_t msgType;
4317
  int32_t msgLen;
4318
  void*   msg;
4319
} SBatchMsg;
4320

4321
typedef struct {
4322
  SMsgHead header;
4323
  SArray*  pMsgs;  // SArray<SBatchMsg>
4324
} SBatchReq;
4325

4326
typedef struct {
4327
  int32_t reqType;
4328
  int32_t msgIdx;
4329
  int32_t msgLen;
4330
  int32_t rspCode;
4331
  void*   msg;
4332
} SBatchRspMsg;
4333

4334
typedef struct {
4335
  SArray* pRsps;  // SArray<SBatchRspMsg>
4336
} SBatchRsp;
4337

4338
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4339
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4340
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
352,176✔
4341
  if (NULL == msg) {
352,176!
UNCOV
4342
    return;
×
4343
  }
4344
  SBatchMsg* pMsg = (SBatchMsg*)msg;
352,176✔
4345
  taosMemoryFree(pMsg->msg);
352,176✔
4346
}
4347

4348
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4349
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4350

4351
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
550,797✔
4352
  if (NULL == p) {
550,797!
UNCOV
4353
    return;
×
4354
  }
4355

4356
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
550,797✔
4357
  taosMemoryFree(pRsp->msg);
550,797✔
4358
}
4359

4360
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4361
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4362
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4363
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4364
void    tDestroySMqHbReq(SMqHbReq* pReq);
4365

4366
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4367
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4368
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4369

4370
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4371
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4372

4373
#define TD_REQ_FROM_APP               0x0
4374
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4375
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4376
#define SUBMIT_REQ_FROM_FILE          0x4
4377
#define TD_REQ_FROM_TAOX              0x8
4378
#define SUBMIT_REQUEST_VERSION        (1)
4379

4380
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4381

4382
typedef struct {
4383
  int32_t        flags;
4384
  SVCreateTbReq* pCreateTbReq;
4385
  int64_t        suid;
4386
  int64_t        uid;
4387
  int32_t        sver;
4388
  union {
4389
    SArray* aRowP;
4390
    SArray* aCol;
4391
  };
4392
  int64_t ctimeMs;
4393
} SSubmitTbData;
4394

4395
typedef struct {
4396
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4397
} SSubmitReq2;
4398

4399
typedef struct {
4400
  SMsgHead header;
4401
  int64_t  version;
4402
  char     data[];  // SSubmitReq2
4403
} SSubmitReq2Msg;
4404

4405
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4406
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4407
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4408
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4409

4410
typedef struct {
4411
  int32_t affectedRows;
4412
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4413
} SSubmitRsp2;
4414

4415
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4416
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4417
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4418

4419
#define TSDB_MSG_FLG_ENCODE 0x1
4420
#define TSDB_MSG_FLG_DECODE 0x2
4421
#define TSDB_MSG_FLG_CMPT   0x3
4422

4423
typedef struct {
4424
  union {
4425
    struct {
4426
      void*   msgStr;
4427
      int32_t msgLen;
4428
      int64_t ver;
4429
    };
4430
    void* pDataBlock;
4431
  };
4432
} SPackedData;
4433

4434
typedef struct {
4435
  char     fullname[TSDB_VIEW_FNAME_LEN];
4436
  char     name[TSDB_VIEW_NAME_LEN];
4437
  char     dbFName[TSDB_DB_FNAME_LEN];
4438
  char*    querySql;
4439
  char*    sql;
4440
  int8_t   orReplace;
4441
  int8_t   precision;
4442
  int32_t  numOfCols;
4443
  SSchema* pSchema;
4444
} SCMCreateViewReq;
4445

4446
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4447
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4448
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4449

4450
typedef struct {
4451
  char   fullname[TSDB_VIEW_FNAME_LEN];
4452
  char   name[TSDB_VIEW_NAME_LEN];
4453
  char   dbFName[TSDB_DB_FNAME_LEN];
4454
  char*  sql;
4455
  int8_t igNotExists;
4456
} SCMDropViewReq;
4457

4458
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4459
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4460
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4461

4462
typedef struct {
4463
  char fullname[TSDB_VIEW_FNAME_LEN];
4464
} SViewMetaReq;
4465
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4466
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4467

4468
typedef struct {
4469
  char     name[TSDB_VIEW_NAME_LEN];
4470
  char     dbFName[TSDB_DB_FNAME_LEN];
4471
  char*    user;
4472
  uint64_t dbId;
4473
  uint64_t viewId;
4474
  char*    querySql;
4475
  int8_t   precision;
4476
  int8_t   type;
4477
  int32_t  version;
4478
  int32_t  numOfCols;
4479
  SSchema* pSchema;
4480
} SViewMetaRsp;
4481
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4482
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4483
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4484
typedef struct {
4485
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4486
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4487
} STableTSMAInfoReq;
4488

4489
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4490
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4491

4492
typedef struct {
4493
  int32_t  funcId;
4494
  col_id_t colId;
4495
} STableTSMAFuncInfo;
4496

4497
typedef struct {
4498
  char     name[TSDB_TABLE_NAME_LEN];
4499
  uint64_t tsmaId;
4500
  char     targetTb[TSDB_TABLE_NAME_LEN];
4501
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4502
  char     tb[TSDB_TABLE_NAME_LEN];
4503
  char     dbFName[TSDB_DB_FNAME_LEN];
4504
  uint64_t suid;
4505
  uint64_t destTbUid;
4506
  uint64_t dbId;
4507
  int32_t  version;
4508
  int64_t  interval;
4509
  int8_t   unit;
4510
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4511
  SArray*  pTags;      // SArray<SSchema>
4512
  SArray*  pUsedCols;  // SArray<SSchema>
4513
  char*    ast;
4514

4515
  int64_t streamUid;
4516
  int64_t reqTs;
4517
  int64_t rspTs;
4518
  int64_t delayDuration;  // ms
4519
  bool    fillHistoryFinished;
4520
} STableTSMAInfo;
4521

4522
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4523
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4524
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4525
void    tFreeTableTSMAInfo(void* p);
4526
void    tFreeAndClearTableTSMAInfo(void* p);
4527
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4528

4529
#define STSMAHbRsp            STableTSMAInfoRsp
4530
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4531
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4532
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4533

4534
typedef struct SStreamProgressReq {
4535
  int64_t streamId;
4536
  int32_t vgId;
4537
  int32_t fetchIdx;
4538
  int32_t subFetchIdx;
4539
} SStreamProgressReq;
4540

4541
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4542
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4543

4544
typedef struct SStreamProgressRsp {
4545
  int64_t streamId;
4546
  int32_t vgId;
4547
  bool    fillHisFinished;
4548
  int64_t progressDelay;
4549
  int32_t fetchIdx;
4550
  int32_t subFetchIdx;
4551
} SStreamProgressRsp;
4552

4553
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4554
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4555

4556
typedef struct SDropCtbWithTsmaSingleVgReq {
4557
  SVgroupInfo vgInfo;
4558
  SArray*     pTbs;  // SVDropTbReq
4559
} SMDropTbReqsOnSingleVg;
4560

4561
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4562
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4563
void    tFreeSMDropTbReqOnSingleVg(void* p);
4564

4565
typedef struct SDropTbsReq {
4566
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4567
} SMDropTbsReq;
4568

4569
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4570
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4571
void    tFreeSMDropTbsReq(void*);
4572

4573
typedef struct SVFetchTtlExpiredTbsRsp {
4574
  SArray* pExpiredTbs;  // SVDropTbReq
4575
  int32_t vgId;
4576
} SVFetchTtlExpiredTbsRsp;
4577

4578
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4579
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4580

4581
void tFreeFetchTtlExpiredTbsRsp(void* p);
4582

4583
void setDefaultOptionsForField(SFieldWithOptions* field);
4584
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4585

4586
#pragma pack(pop)
4587

4588
#ifdef __cplusplus
4589
}
4590
#endif
4591

4592
#endif /*_TD_COMMON_TAOS_MSG_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc