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

taosdata / TDengine / #3544

30 Nov 2024 03:06AM UTC coverage: 60.88% (+0.04%) from 60.842%
#3544

push

travis-ci

web-flow
Merge pull request #28988 from taosdata/main

merge: from main to 3.0 branch

120724 of 253479 branches covered (47.63%)

Branch coverage included in aggregate %.

407 of 489 new or added lines in 21 files covered. (83.23%)

1148 existing lines in 113 files now uncovered.

201919 of 276488 relevant lines covered (73.03%)

18898587.44 hits per line

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

58.84
/include/common/tmsg.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include "taosdef.h"
20
#include "taoserror.h"
21
#include "tarray.h"
22
#include "tcoding.h"
23
#include "tcol.h"
24
#include "tencode.h"
25
#include "thash.h"
26
#include "tlist.h"
27
#include "tname.h"
28
#include "trow.h"
29
#include "tuuid.h"
30

31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34

35
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
36

37
#define TD_MSG_NUMBER_
38
#undef TD_MSG_DICT_
39
#undef TD_MSG_INFO_
40
#undef TD_MSG_TYPE_INFO_
41
#undef TD_MSG_RANGE_CODE_
42
#undef TD_MSG_SEG_CODE_
43
#include "tmsgdef.h"
44

45
#undef TD_MSG_NUMBER_
46
#undef TD_MSG_DICT_
47
#undef TD_MSG_INFO_
48
#undef TD_MSG_TYPE_INFO_
49
#undef TD_MSG_RANGE_CODE_
50
#define TD_MSG_SEG_CODE_
51
#include "tmsgdef.h"
52

53
#undef TD_MSG_NUMBER_
54
#undef TD_MSG_DICT_
55
#undef TD_MSG_INFO_
56
#undef TD_MSG_TYPE_INFO_
57
#undef TD_MSG_SEG_CODE_
58
#undef TD_MSG_RANGE_CODE_
59
#include "tmsgdef.h"
60

61
extern char*   tMsgInfo[];
62
extern int32_t tMsgDict[];
63
extern int32_t tMsgRangeDict[];
64

65
typedef uint16_t tmsg_t;
66

67
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
68
#define TMSG_SEG_SEQ(TYPE)  ((TYPE)&0xff)
69
#define TMSG_INDEX(TYPE)    (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
70

71
static inline bool tmsgIsValid(tmsg_t type) {
65,900,194✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
65,900,194✔
74
  int    segIdx = TMSG_SEG_CODE(type);
65,900,194✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
65,900,194✔
76
    return type < tMsgRangeDict[segIdx];
65,901,796✔
77
  }
UNCOV
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,693,937✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,668,778✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,362,715!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
37,586,233✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
37,586,233✔
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
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
182

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

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

203
#define TSDB_KILL_MSG_LEN 30
204

205
#define TSDB_TABLE_NUM_UNIT 100000
206

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

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

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

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

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

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

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

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

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

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

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

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

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

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

518
#pragma pack(push, 1)
519

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

526
typedef struct {
527
  int32_t contLen;
528
  int32_t vgId;
529
} SMsgHead;
530

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

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

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

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

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

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

591
//
592

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

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

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

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

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

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

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

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

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

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

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

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

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

692
typedef struct {
693
  col_id_t id;
694
  uint32_t alg;
695
} SColCmpr;
696

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

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

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

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

724
  return pDstWrapper;
2,160✔
725
}
726

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

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

757
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
758
  if (pWrapper == NULL) return;
2,160!
759

760
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,160!
761
  taosMemoryFreeClear(pWrapper);
2,160!
762
}
763
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
764
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,754,092!
765

766
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,754,092✔
767
  if (pSW == NULL) {
11,750,298!
768
    return NULL;
×
769
  }
770
  pSW->nCols = pSchemaWrapper->nCols;
11,750,298✔
771
  pSW->version = pSchemaWrapper->version;
11,750,298✔
772
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,750,298✔
773
  if (pSW->pSchema == NULL) {
11,740,707!
774
    taosMemoryFree(pSW);
4✔
775
    return NULL;
×
776
  }
777

778
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
11,758,811✔
779
  return pSW;
11,758,811✔
780
}
781

782
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
490,800✔
783
  if (pSchemaWrapper) {
19,362,342!
784
    taosMemoryFree(pSchemaWrapper->pSchema);
10,790,779✔
785
    taosMemoryFree(pSchemaWrapper);
10,790,915✔
786
  }
787
}
19,362,959✔
788

789
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,317,369✔
790
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,317,369!
791
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,317,735✔
792
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,321,481✔
793
  }
794
}
1,320,645✔
795

796
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
797
  int32_t tlen = 0;
53,958✔
798
  tlen += taosEncodeFixedI8(buf, pSchema->type);
107,916✔
799
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
53,958!
800
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
53,958!
801
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
53,958!
802
  tlen += taosEncodeString(buf, pSchema->name);
53,958✔
803
  return tlen;
53,958✔
804
}
805

806
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
807
  buf = taosDecodeFixedI8(buf, &pSchema->type);
49,796✔
808
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
24,898✔
809
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
24,898!
810
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
24,898!
811
  buf = taosDecodeStringTo(buf, pSchema->name);
24,898✔
812
  return (void*)buf;
24,898✔
813
}
814

815
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
816
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
358,811,006!
817
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
372,198,148!
818
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
372,198,148!
819
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
372,198,148!
820
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
372,198,148!
821
  return 0;
186,099,074✔
822
}
823

824
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
825
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
629,768,053!
826
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,246,113,909!
827
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,241,513,432!
828
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,251,812,540!
829
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
628,710,409!
830
  return 0;
653,589,004✔
831
}
832

833
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
834
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
214,476,956!
835
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
214,476,956!
836
  return 0;
107,238,478✔
837
}
838

839
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
840
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,107,932!
841
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,107,936!
842
  return 0;
1,553,967✔
843
}
844

845
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
846
  int32_t tlen = 0;
8,370✔
847
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,370✔
848
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,370✔
849
  for (int32_t i = 0; i < pSW->nCols; i++) {
62,328✔
850
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
107,916!
851
  }
852
  return tlen;
8,370✔
853
}
854

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

864
    for (int32_t i = 0; i < pSW->nCols; i++) {
27,668✔
865
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
49,796✔
866
    }
867
  } else {
868
    pSW->pSchema = NULL;
1,122✔
869
  }
870
  return (void*)buf;
3,892✔
871
}
872

873
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
874
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,522,670!
875
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,522,670!
876
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,148,477✔
877
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
26,774,284!
878
  }
879
  return 0;
761,335✔
880
}
881

882
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
883
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,588,846!
884
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,588,358!
885

886
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
794,030✔
887
  if (pSW->pSchema == NULL) {
794,563✔
888
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
56✔
889
  }
890
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,117,873✔
891
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
26,650,454!
892
  }
893

894
  return 0;
790,748✔
895
}
896

897
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
898
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
70,170,279!
899
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
72,202,506!
900

901
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
36,095,265✔
902
  if (pSW->pSchema == NULL) {
36,214,098!
903
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
904
  }
905
  for (int32_t i = 0; i < pSW->nCols; i++) {
674,414,326✔
906
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,278,389,023!
907
  }
908

909
  return 0;
34,225,531✔
910
}
911

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

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

947
typedef struct {
948
  STableMetaRsp* pMeta;
949
} SMCreateStbRsp;
950

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

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

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

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

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

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

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

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

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

1010
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1011
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1012

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

1032
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1033
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1034

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

1046
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1047
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1048

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

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

1059
typedef struct SIpV4Range {
1060
  uint32_t ip;
1061
  uint32_t mask;
1062
} SIpV4Range;
1063

1064
typedef struct {
1065
  int32_t    num;
1066
  SIpV4Range pIpRange[];
1067
} SIpWhiteList;
1068

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

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

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

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

1106
typedef struct {
1107
  int64_t ipWhiteVer;
1108
} SRetrieveIpWhiteReq;
1109

1110
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1111
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1112

1113
typedef struct {
1114
  int32_t dnodeId;
1115
  int64_t analVer;
1116
} SRetrieveAnalAlgoReq;
1117

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

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

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

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

1159
typedef struct {
1160
  char user[TSDB_USER_LEN];
1161
} SGetUserAuthReq;
1162

1163
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1164
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1165

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

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

1191
typedef struct {
1192
  char user[TSDB_USER_LEN];
1193
} SGetUserWhiteListReq;
1194

1195
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1196
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1197

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

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

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

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

1226
typedef struct STimeWindow {
1227
  TSKEY skey;
1228
  TSKEY ekey;
1229
} STimeWindow;
1230

1231
typedef struct SQueryHint {
1232
  bool batchScan;
1233
} SQueryHint;
1234

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

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

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

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

1265
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1266

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

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

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

1296
typedef STableCfg STableCfgRsp;
1297

1298
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1299
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1300

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

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

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

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

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

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

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

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

1400
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1401
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1402

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

1411
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1412
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1413

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

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

1433
typedef struct {
1434
  char db[TSDB_DB_FNAME_LEN];
1435
} SDbCfgReq;
1436

1437
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1438
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1439

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

1445
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1446
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1447

1448
typedef struct {
1449
  int32_t timestamp;
1450
} SVTrimDbReq;
1451

1452
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1453
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1454

1455
typedef struct {
1456
  char db[TSDB_DB_FNAME_LEN];
1457
} SS3MigrateDbReq;
1458

1459
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1460
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1461

1462
typedef struct {
1463
  int32_t timestamp;
1464
} SVS3MigrateDbReq;
1465

1466
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1467
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1468

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

1476
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1477
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1478

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

1522
typedef SDbCfgRsp SDbCfgInfo;
1523

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

1530
typedef struct {
1531
  int32_t rowNum;
1532
} SQnodeListReq;
1533

1534
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1535
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1536

1537
typedef struct {
1538
  int32_t rowNum;
1539
} SDnodeListReq;
1540

1541
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1542

1543
typedef struct {
1544
  int32_t useless;  // useless
1545
} SServerVerReq;
1546

1547
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1548
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1549

1550
typedef struct {
1551
  char ver[TSDB_VERSION_LEN];
1552
} SServerVerRsp;
1553

1554
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1555
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1556

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

1562
typedef struct {
1563
  SQueryNodeAddr addr;
1564
  uint64_t       load;
1565
} SQueryNodeLoad;
1566

1567
typedef struct {
1568
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1569
} SQnodeListRsp;
1570

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

1575
typedef struct {
1576
  SArray* dnodeList;  // SArray<SEpSet>
1577
} SDnodeListRsp;
1578

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

1583
typedef struct {
1584
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1585
} STableTSMAInfoRsp;
1586

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

1596
typedef struct {
1597
  SArray* pArray;  // Array of SDbHbRsp
1598
} SDbHbBatchRsp;
1599

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

1604
typedef struct {
1605
  SArray* pArray;  // Array of SGetUserAuthRsp
1606
} SUserAuthBatchRsp;
1607

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

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

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

1623
typedef struct {
1624
  int32_t compactId;
1625
  int8_t  bAccepted;
1626
} SCompactDbRsp;
1627

1628
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1629
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1630

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

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

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

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

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

1665
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1666
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1667

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

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

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

1692
typedef struct {
1693
  int32_t funcVersion;
1694
  int64_t funcCreatedTime;
1695
} SFuncExtraInfo;
1696

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

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

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

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

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

1757
typedef struct {
1758
  int32_t vgId;
1759
  int64_t nTimeSeries;
1760
} SVnodeLoadLite;
1761

1762
typedef struct {
1763
  int8_t  syncState;
1764
  int64_t syncTerm;
1765
  int8_t  syncRestore;
1766
  int64_t roleTimeMs;
1767
} SMnodeLoad;
1768

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

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

1808
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1809
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1810
void    tFreeSStatusReq(SStatusReq* pReq);
1811

1812
typedef struct {
1813
  int32_t dnodeId;
1814
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1815
} SDnodeInfoReq;
1816

1817
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1818
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1819

1820
typedef enum {
1821
  MONITOR_TYPE_COUNTER = 0,
1822
  MONITOR_TYPE_SLOW_LOG = 1,
1823
} MONITOR_TYPE;
1824

1825
typedef struct {
1826
  int32_t      contLen;
1827
  char*        pCont;
1828
  MONITOR_TYPE type;
1829
} SStatisReq;
1830

1831
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1832
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1833
void    tFreeSStatisReq(SStatisReq* pReq);
1834

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

1846
typedef struct {
1847
  int32_t dnodeId;
1848
  int64_t clusterId;
1849
  SArray* pVloads;
1850
} SNotifyReq;
1851

1852
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1853
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1854
void    tFreeSNotifyReq(SNotifyReq* pReq);
1855

1856
typedef struct {
1857
  int32_t dnodeId;
1858
  int64_t clusterId;
1859
} SDnodeCfg;
1860

1861
typedef struct {
1862
  int32_t id;
1863
  int8_t  isMnode;
1864
  SEp     ep;
1865
} SDnodeEp;
1866

1867
typedef struct {
1868
  int32_t id;
1869
  int8_t  isMnode;
1870
  int8_t  offlineReason;
1871
  SEp     ep;
1872
  char    active[TSDB_ACTIVE_KEY_LEN];
1873
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1874
} SDnodeInfo;
1875

1876
typedef struct {
1877
  int64_t   dnodeVer;
1878
  SDnodeCfg dnodeCfg;
1879
  SArray*   pDnodeEps;  // Array of SDnodeEp
1880
  int32_t   statusSeq;
1881
  int64_t   ipWhiteVer;
1882
  int64_t   analVer;
1883
} SStatusRsp;
1884

1885
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1886
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1887
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1888

1889
typedef struct {
1890
  int32_t reserved;
1891
} SMTimerReq;
1892

1893
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1894
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1895

1896
typedef struct SOrphanTask {
1897
  int64_t streamId;
1898
  int32_t taskId;
1899
  int32_t nodeId;
1900
} SOrphanTask;
1901

1902
typedef struct SMStreamDropOrphanMsg {
1903
  SArray* pList;  // SArray<SOrphanTask>
1904
} SMStreamDropOrphanMsg;
1905

1906
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1907
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1908
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1909

1910
typedef struct {
1911
  int32_t  id;
1912
  uint16_t port;                 // node sync Port
1913
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1914
} SReplica;
1915

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

1968
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1969
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1970
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
1971

1972
typedef struct {
1973
  int32_t compactId;
1974
  int32_t vgId;
1975
  int32_t dnodeId;
1976
} SQueryCompactProgressReq;
1977

1978
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1979
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1980

1981
typedef struct {
1982
  int32_t compactId;
1983
  int32_t vgId;
1984
  int32_t dnodeId;
1985
  int32_t numberFileset;
1986
  int32_t finished;
1987
} SQueryCompactProgressRsp;
1988

1989
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1990
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1991

1992
typedef struct {
1993
  int32_t vgId;
1994
  int32_t dnodeId;
1995
  int64_t dbUid;
1996
  char    db[TSDB_DB_FNAME_LEN];
1997
  int64_t reserved[8];
1998
} SDropVnodeReq;
1999

2000
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2001
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2002

2003
typedef struct {
2004
  char    colName[TSDB_COL_NAME_LEN];
2005
  char    stb[TSDB_TABLE_FNAME_LEN];
2006
  int64_t stbUid;
2007
  int64_t dbUid;
2008
  int64_t reserved[8];
2009
} SDropIndexReq;
2010

2011
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2012
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2013

2014
typedef struct {
2015
  int64_t     dbUid;
2016
  char        db[TSDB_DB_FNAME_LEN];
2017
  int64_t     compactStartTime;
2018
  STimeWindow tw;
2019
  int32_t     compactId;
2020
} SCompactVnodeReq;
2021

2022
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2023
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2024

2025
typedef struct {
2026
  int32_t compactId;
2027
  int32_t vgId;
2028
  int32_t dnodeId;
2029
} SVKillCompactReq;
2030

2031
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2032
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2033

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

2060
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2061
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2062

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

2076
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2077
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2078

2079
typedef struct {
2080
  int32_t vgId;
2081
  int8_t  disable;
2082
} SDisableVnodeWriteReq;
2083

2084
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2085
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2086

2087
typedef struct {
2088
  int32_t  srcVgId;
2089
  int32_t  dstVgId;
2090
  uint32_t hashBegin;
2091
  uint32_t hashEnd;
2092
  int32_t  changeVersion;
2093
  int32_t  reserved;
2094
} SAlterVnodeHashRangeReq;
2095

2096
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2097
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2098

2099
#define REQ_OPT_TBNAME 0x0
2100
#define REQ_OPT_TBUID  0x01
2101
typedef struct {
2102
  SMsgHead header;
2103
  char     dbFName[TSDB_DB_FNAME_LEN];
2104
  char     tbName[TSDB_TABLE_NAME_LEN];
2105
  uint8_t  option;
2106
} STableInfoReq;
2107

2108
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2109
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2110

2111
typedef struct {
2112
  int8_t  metaClone;  // create local clone of the cached table meta
2113
  int32_t numOfVgroups;
2114
  int32_t numOfTables;
2115
  int32_t numOfUdfs;
2116
  char    tableNames[];
2117
} SMultiTableInfoReq;
2118

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

2131
typedef struct {
2132
  int32_t     numOfVgroups;
2133
  SVgroupInfo vgroups[];
2134
} SVgroupsInfo;
2135

2136
typedef struct {
2137
  STableMetaRsp* pMeta;
2138
} SMAlterStbRsp;
2139

2140
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2141
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2142
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2143

2144
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2145
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2146
void    tFreeSTableMetaRsp(void* pRsp);
2147
void    tFreeSTableIndexRsp(void* info);
2148

2149
typedef struct {
2150
  SArray* pMetaRsp;   // Array of STableMetaRsp
2151
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2152
} SSTbHbRsp;
2153

2154
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2155
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2156
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2157

2158
typedef struct {
2159
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2160
} SViewHbRsp;
2161

2162
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2163
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2164
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2165

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

2177
typedef struct {
2178
  int32_t dataLen;
2179
  char    name[TSDB_TABLE_FNAME_LEN];
2180
  char*   data;
2181
} STagData;
2182

2183
typedef struct {
2184
  int32_t useless;  // useless
2185
} SShowVariablesReq;
2186

2187
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2188
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2189

2190
typedef struct {
2191
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2192
  char value[TSDB_CONFIG_PATH_LEN + 1];
2193
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2194
  char info[TSDB_CONFIG_INFO_LEN + 1];
2195
} SVariablesInfo;
2196

2197
typedef struct {
2198
  SArray* variables;  // SArray<SVariablesInfo>
2199
} SShowVariablesRsp;
2200

2201
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2202
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2203

2204
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2205

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

2218
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2219
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2220
void tFreeSShowReq(SShowReq* pReq);
2221

2222
typedef struct {
2223
  int64_t       showId;
2224
  STableMetaRsp tableMeta;
2225
} SShowRsp, SVShowTablesRsp;
2226

2227
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2228
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2229
// void    tFreeSShowRsp(SShowRsp* pRsp);
2230

2231
typedef struct {
2232
  char    db[TSDB_DB_FNAME_LEN];
2233
  char    tb[TSDB_TABLE_NAME_LEN];
2234
  char    user[TSDB_USER_LEN];
2235
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2236
  int64_t showId;
2237
  int64_t compactId;  // for compact
2238
  bool    withFull;   // for show users full
2239
} SRetrieveTableReq;
2240

2241
typedef struct SSysTableSchema {
2242
  int8_t   type;
2243
  col_id_t colId;
2244
  int32_t  bytes;
2245
} SSysTableSchema;
2246

2247
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2248
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2249

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

2269
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2270

2271
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2272
  do {                                          \
2273
    ((int32_t*)(_p))[0] = (_compLen);           \
2274
    ((int32_t*)(_p))[1] = (_fullLen);           \
2275
  } while (0);
2276

2277
typedef struct {
2278
  int64_t version;
2279
  int64_t numOfRows;
2280
  int8_t  compressed;
2281
  int8_t  precision;
2282
  char    data[];
2283
} SRetrieveTableRspForTmq;
2284

2285
typedef struct {
2286
  int64_t handle;
2287
  int64_t useconds;
2288
  int8_t  completed;  // all results are returned to client
2289
  int8_t  precision;
2290
  int8_t  compressed;
2291
  int32_t compLen;
2292
  int32_t numOfRows;
2293
  int32_t fullLen;
2294
  char    data[];
2295
} SRetrieveMetaTableRsp;
2296

2297
typedef struct SExplainExecInfo {
2298
  double   startupCost;
2299
  double   totalCost;
2300
  uint64_t numOfRows;
2301
  uint32_t verboseLen;
2302
  void*    verboseInfo;
2303
} SExplainExecInfo;
2304

2305
typedef struct {
2306
  int32_t           numOfPlans;
2307
  SExplainExecInfo* subplanInfo;
2308
} SExplainRsp;
2309

2310
typedef struct {
2311
  SExplainRsp rsp;
2312
  uint64_t    qId;
2313
  uint64_t    cId;
2314
  uint64_t    tId;
2315
  int64_t     rId;
2316
  int32_t     eId;
2317
} SExplainLocalRsp;
2318

2319
typedef struct STableScanAnalyzeInfo {
2320
  uint64_t totalRows;
2321
  uint64_t totalCheckedRows;
2322
  uint32_t totalBlocks;
2323
  uint32_t loadBlocks;
2324
  uint32_t loadBlockStatis;
2325
  uint32_t skipBlocks;
2326
  uint32_t filterOutBlocks;
2327
  double   elapsedTime;
2328
  double   filterTime;
2329
} STableScanAnalyzeInfo;
2330

2331
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2332
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2333
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2334

2335
typedef struct {
2336
  char    config[TSDB_DNODE_CONFIG_LEN];
2337
  char    value[TSDB_CLUSTER_VALUE_LEN];
2338
  int32_t sqlLen;
2339
  char*   sql;
2340
} SMCfgClusterReq;
2341

2342
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2343
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2344
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2345

2346
typedef struct {
2347
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2348
  int32_t port;
2349
  int32_t sqlLen;
2350
  char*   sql;
2351
} SCreateDnodeReq;
2352

2353
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2354
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2355
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2356

2357
typedef struct {
2358
  int32_t dnodeId;
2359
  char    fqdn[TSDB_FQDN_LEN];
2360
  int32_t port;
2361
  int8_t  force;
2362
  int8_t  unsafe;
2363
  int32_t sqlLen;
2364
  char*   sql;
2365
} SDropDnodeReq;
2366

2367
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2368
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2369
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2370

2371
enum {
2372
  RESTORE_TYPE__ALL = 1,
2373
  RESTORE_TYPE__MNODE,
2374
  RESTORE_TYPE__VNODE,
2375
  RESTORE_TYPE__QNODE,
2376
};
2377

2378
typedef struct {
2379
  int32_t dnodeId;
2380
  int8_t  restoreType;
2381
  int32_t sqlLen;
2382
  char*   sql;
2383
} SRestoreDnodeReq;
2384

2385
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2386
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2387
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2388

2389
typedef struct {
2390
  int32_t dnodeId;
2391
  char    config[TSDB_DNODE_CONFIG_LEN];
2392
  char    value[TSDB_DNODE_VALUE_LEN];
2393
  int32_t sqlLen;
2394
  char*   sql;
2395
} SMCfgDnodeReq;
2396

2397
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2398
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2399
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2400

2401
typedef struct {
2402
  char config[TSDB_DNODE_CONFIG_LEN];
2403
  char value[TSDB_DNODE_VALUE_LEN];
2404
} SDCfgDnodeReq;
2405

2406
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2407
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2408

2409
typedef struct {
2410
  int32_t dnodeId;
2411
  int32_t sqlLen;
2412
  char*   sql;
2413
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2414
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2415

2416
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2417
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2418
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2419
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2420
typedef struct {
2421
  int8_t   replica;
2422
  SReplica replicas[TSDB_MAX_REPLICA];
2423
  int8_t   learnerReplica;
2424
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2425
  int64_t  lastIndex;
2426
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2427

2428
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2429
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2430

2431
typedef struct {
2432
  int32_t urlLen;
2433
  int32_t sqlLen;
2434
  char*   url;
2435
  char*   sql;
2436
} SMCreateAnodeReq;
2437

2438
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2439
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2440
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2441

2442
typedef struct {
2443
  int32_t anodeId;
2444
  int32_t sqlLen;
2445
  char*   sql;
2446
} SMDropAnodeReq, SMUpdateAnodeReq;
2447

2448
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2449
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2450
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2451
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2452
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2453
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2454

2455
typedef struct {
2456
  int32_t vgId;
2457
  int32_t hbSeq;
2458
} SVArbHbReqMember;
2459

2460
typedef struct {
2461
  int32_t dnodeId;
2462
  char*   arbToken;
2463
  int64_t arbTerm;
2464
  SArray* hbMembers;  // SVArbHbReqMember
2465
} SVArbHeartBeatReq;
2466

2467
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2468
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2469
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2470

2471
typedef struct {
2472
  int32_t vgId;
2473
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2474
  int32_t hbSeq;
2475
} SVArbHbRspMember;
2476

2477
typedef struct {
2478
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2479
  int32_t dnodeId;
2480
  SArray* hbMembers;  // SVArbHbRspMember
2481
} SVArbHeartBeatRsp;
2482

2483
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2484
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2485
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2486

2487
typedef struct {
2488
  char*   arbToken;
2489
  int64_t arbTerm;
2490
  char*   member0Token;
2491
  char*   member1Token;
2492
} SVArbCheckSyncReq;
2493

2494
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2495
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2496
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2497

2498
typedef struct {
2499
  char*   arbToken;
2500
  char*   member0Token;
2501
  char*   member1Token;
2502
  int32_t vgId;
2503
  int32_t errCode;
2504
} SVArbCheckSyncRsp;
2505

2506
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2507
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2508
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2509

2510
typedef struct {
2511
  char*   arbToken;
2512
  int64_t arbTerm;
2513
  char*   memberToken;
2514
} SVArbSetAssignedLeaderReq;
2515

2516
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2517
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2518
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2519

2520
typedef struct {
2521
  char*   arbToken;
2522
  char*   memberToken;
2523
  int32_t vgId;
2524
} SVArbSetAssignedLeaderRsp;
2525

2526
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2527
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2528
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2529

2530
typedef struct {
2531
  int32_t dnodeId;
2532
  char*   token;
2533
} SMArbUpdateGroupMember;
2534

2535
typedef struct {
2536
  int32_t dnodeId;
2537
  char*   token;
2538
  int8_t  acked;
2539
} SMArbUpdateGroupAssigned;
2540

2541
typedef struct {
2542
  int32_t                  vgId;
2543
  int64_t                  dbUid;
2544
  SMArbUpdateGroupMember   members[2];
2545
  int8_t                   isSync;
2546
  int8_t                   assignedAcked;
2547
  SMArbUpdateGroupAssigned assignedLeader;
2548
  int64_t                  version;
2549
} SMArbUpdateGroup;
2550

2551
typedef struct {
2552
  SArray* updateArray;  // SMArbUpdateGroup
2553
} SMArbUpdateGroupBatchReq;
2554

2555
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2556
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2557
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2558

2559
typedef struct {
2560
  char queryStrId[TSDB_QUERY_ID_LEN];
2561
} SKillQueryReq;
2562

2563
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2564
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2565

2566
typedef struct {
2567
  uint32_t connId;
2568
} SKillConnReq;
2569

2570
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2571
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2572

2573
typedef struct {
2574
  int32_t transId;
2575
} SKillTransReq;
2576

2577
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2578
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2579

2580
typedef struct {
2581
  int32_t useless;  // useless
2582
  int32_t sqlLen;
2583
  char*   sql;
2584
} SBalanceVgroupReq;
2585

2586
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2587
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2588
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2589

2590
typedef struct {
2591
  int32_t vgId1;
2592
  int32_t vgId2;
2593
} SMergeVgroupReq;
2594

2595
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2596
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2597

2598
typedef struct {
2599
  int32_t vgId;
2600
  int32_t dnodeId1;
2601
  int32_t dnodeId2;
2602
  int32_t dnodeId3;
2603
  int32_t sqlLen;
2604
  char*   sql;
2605
} SRedistributeVgroupReq;
2606

2607
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2608
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2609
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2610

2611
typedef struct {
2612
  int32_t reserved;
2613
  int32_t vgId;
2614
  int32_t sqlLen;
2615
  char*   sql;
2616
  char    db[TSDB_DB_FNAME_LEN];
2617
} SBalanceVgroupLeaderReq;
2618

2619
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2620
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2621
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2622

2623
typedef struct {
2624
  int32_t vgId;
2625
} SForceBecomeFollowerReq;
2626

2627
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2628
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2629

2630
typedef struct {
2631
  int32_t vgId;
2632
} SSplitVgroupReq;
2633

2634
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2635
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2636

2637
typedef struct {
2638
  char user[TSDB_USER_LEN];
2639
  char spi;
2640
  char encrypt;
2641
  char secret[TSDB_PASSWORD_LEN];
2642
  char ckey[TSDB_PASSWORD_LEN];
2643
} SAuthReq, SAuthRsp;
2644

2645
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2646
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2647

2648
typedef struct {
2649
  int32_t statusCode;
2650
  char    details[1024];
2651
} SServerStatusRsp;
2652

2653
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2654
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2655

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

2682
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2683
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2684
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2685

2686
typedef struct {
2687
  SMsgHead header;
2688
  uint64_t sId;
2689
  uint64_t queryId;
2690
  uint64_t taskId;
2691
} SSinkDataReq;
2692

2693
typedef struct {
2694
  SMsgHead header;
2695
  uint64_t sId;
2696
  uint64_t queryId;
2697
  uint64_t clientId;
2698
  uint64_t taskId;
2699
  int32_t  execId;
2700
} SQueryContinueReq;
2701

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

2709
typedef struct {
2710
  int32_t code;
2711
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2712
  int32_t sversion;
2713
  int32_t tversion;
2714
} SResReadyRsp;
2715

2716
typedef struct SOperatorParam {
2717
  int32_t opType;
2718
  int32_t downstreamIdx;
2719
  void*   value;
2720
  SArray* pChildren;  // SArray<SOperatorParam*>
2721
} SOperatorParam;
2722

2723
typedef struct STableScanOperatorParam {
2724
  bool    tableSeq;
2725
  SArray* pUidList;
2726
} STableScanOperatorParam;
2727

2728
typedef struct {
2729
  SMsgHead        header;
2730
  uint64_t        sId;
2731
  uint64_t        queryId;
2732
  uint64_t        clientId;
2733
  uint64_t        taskId;
2734
  int32_t         execId;
2735
  SOperatorParam* pOpParam;
2736
} SResFetchReq;
2737

2738
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2739
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2740

2741
typedef struct {
2742
  SMsgHead header;
2743
  uint64_t sId;
2744
} SSchTasksStatusReq;
2745

2746
typedef struct {
2747
  uint64_t queryId;
2748
  uint64_t clientId;
2749
  uint64_t taskId;
2750
  int64_t  refId;
2751
  int32_t  execId;
2752
  int8_t   status;
2753
} STaskStatus;
2754

2755
typedef struct {
2756
  int64_t refId;
2757
  SArray* taskStatus;  // SArray<STaskStatus>
2758
} SSchedulerStatusRsp;
2759

2760
typedef struct {
2761
  uint64_t queryId;
2762
  uint64_t taskId;
2763
  int8_t   action;
2764
} STaskAction;
2765

2766
typedef struct SQueryNodeEpId {
2767
  int32_t nodeId;  // vgId or qnodeId
2768
  SEp     ep;
2769
} SQueryNodeEpId;
2770

2771
typedef struct {
2772
  SMsgHead       header;
2773
  uint64_t       sId;
2774
  SQueryNodeEpId epId;
2775
  SArray*        taskAction;  // SArray<STaskAction>
2776
} SSchedulerHbReq;
2777

2778
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2779
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2780
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2781

2782
typedef struct {
2783
  SQueryNodeEpId epId;
2784
  SArray*        taskStatus;  // SArray<STaskStatus>
2785
} SSchedulerHbRsp;
2786

2787
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2788
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2789
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2790

2791
typedef struct {
2792
  SMsgHead header;
2793
  uint64_t sId;
2794
  uint64_t queryId;
2795
  uint64_t clientId;
2796
  uint64_t taskId;
2797
  int64_t  refId;
2798
  int32_t  execId;
2799
} STaskCancelReq;
2800

2801
typedef struct {
2802
  int32_t code;
2803
} STaskCancelRsp;
2804

2805
typedef struct {
2806
  SMsgHead header;
2807
  uint64_t sId;
2808
  uint64_t queryId;
2809
  uint64_t clientId;
2810
  uint64_t taskId;
2811
  int64_t  refId;
2812
  int32_t  execId;
2813
} STaskDropReq;
2814

2815
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2816
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2817

2818
typedef enum {
2819
  TASK_NOTIFY_FINISHED = 1,
2820
} ETaskNotifyType;
2821

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

2833
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2834
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2835

2836
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2837
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2838

2839
typedef struct {
2840
  int32_t code;
2841
} STaskDropRsp;
2842

2843
#define STREAM_TRIGGER_AT_ONCE            1
2844
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2845
#define STREAM_TRIGGER_MAX_DELAY          3
2846
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2847

2848
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2849
#define STREAM_FILL_HISTORY_ON        1
2850
#define STREAM_FILL_HISTORY_OFF       0
2851
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2852
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2853
#define STREAM_CREATE_STABLE_TRUE     1
2854
#define STREAM_CREATE_STABLE_FALSE    0
2855

2856
typedef struct SColLocation {
2857
  int16_t  slotId;
2858
  col_id_t colId;
2859
  int8_t   type;
2860
} SColLocation;
2861

2862
typedef struct SVgroupVer {
2863
  int32_t vgId;
2864
  int64_t ver;
2865
} SVgroupVer;
2866

2867
typedef struct {
2868
  char    name[TSDB_STREAM_FNAME_LEN];
2869
  char    sourceDB[TSDB_DB_FNAME_LEN];
2870
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2871
  char*   sql;
2872
  char*   ast;
2873
  int8_t  igExists;
2874
  int8_t  triggerType;
2875
  int8_t  igExpired;
2876
  int8_t  fillHistory;  // process data inserted before creating stream
2877
  int64_t maxDelay;
2878
  int64_t watermark;
2879
  int32_t numOfTags;
2880
  SArray* pTags;  // array of SField
2881
  // 3.0.20
2882
  int64_t checkpointFreq;  // ms
2883
  // 3.0.2.3
2884
  int8_t   createStb;
2885
  uint64_t targetStbUid;
2886
  SArray*  fillNullCols;  // array of SColLocation
2887
  int64_t  deleteMark;
2888
  int8_t   igUpdate;
2889
  int64_t  lastTs;
2890
  SArray*  pVgroupVerList;
2891
  // 3.3.0.0
2892
  SArray* pCols;  // array of SField
2893
  int64_t smaId;
2894
} SCMCreateStreamReq;
2895

2896
typedef struct {
2897
  int64_t streamId;
2898
} SCMCreateStreamRsp;
2899

2900
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2901
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2902
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2903

2904
enum {
2905
  TOPIC_SUB_TYPE__DB = 1,
2906
  TOPIC_SUB_TYPE__TABLE,
2907
  TOPIC_SUB_TYPE__COLUMN,
2908
};
2909

2910
#define DEFAULT_MAX_POLL_INTERVAL 300000
2911
#define DEFAULT_SESSION_TIMEOUT   12000
2912

2913
typedef struct {
2914
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2915
  int8_t igExists;
2916
  int8_t subType;
2917
  int8_t withMeta;
2918
  char*  sql;
2919
  char   subDbName[TSDB_DB_FNAME_LEN];
2920
  char*  ast;
2921
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2922
} SCMCreateTopicReq;
2923

2924
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2925
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2926
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2927

2928
typedef struct {
2929
  int64_t consumerId;
2930
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2931

2932
typedef struct {
2933
  int64_t consumerId;
2934
  char    cgroup[TSDB_CGROUP_LEN];
2935
  char    clientId[TSDB_CLIENT_ID_LEN];
2936
  char    user[TSDB_USER_LEN];
2937
  char    fqdn[TSDB_FQDN_LEN];
2938
  SArray* topicNames;  // SArray<char**>
2939

2940
  int8_t  withTbName;
2941
  int8_t  autoCommit;
2942
  int32_t autoCommitInterval;
2943
  int8_t  resetOffsetCfg;
2944
  int8_t  enableReplay;
2945
  int8_t  enableBatchMeta;
2946
  int32_t sessionTimeoutMs;
2947
  int32_t maxPollIntervalMs;
2948
} SCMSubscribeReq;
2949

2950
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
2951
  int32_t tlen = 0;
2,584✔
2952
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,584!
2953
  tlen += taosEncodeString(buf, pReq->cgroup);
2,584✔
2954
  tlen += taosEncodeString(buf, pReq->clientId);
2,584✔
2955

2956
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,584!
2957
  tlen += taosEncodeFixedI32(buf, topicNum);
2,584✔
2958

2959
  for (int32_t i = 0; i < topicNum; i++) {
3,646✔
2960
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,124✔
2961
  }
2962

2963
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,584!
2964
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,584!
2965
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,584!
2966
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,584!
2967
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,584!
2968
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,584!
2969
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,584!
2970
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,584!
2971
  tlen += taosEncodeString(buf, pReq->user);
2,584✔
2972
  tlen += taosEncodeString(buf, pReq->fqdn);
2,584✔
2973

2974
  return tlen;
2,584✔
2975
}
2976

2977
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
2978
  void* start = buf;
1,402✔
2979
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,402!
2980
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,402✔
2981
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,402✔
2982

2983
  int32_t topicNum = 0;
1,402!
2984
  buf = taosDecodeFixedI32(buf, &topicNum);
1,402✔
2985

2986
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,402✔
2987
  if (pReq->topicNames == NULL) {
1,402!
2988
    return terrno;
×
2989
  }
2990
  for (int32_t i = 0; i < topicNum; i++) {
2,044✔
2991
    char* name = NULL;
642✔
2992
    buf = taosDecodeString(buf, &name);
642✔
2993
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,284!
2994
      return terrno;
×
2995
    }
2996
  }
2997

2998
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,402✔
2999
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,402✔
3000
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,402!
3001
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,402✔
3002
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,402✔
3003
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,402✔
3004
  if ((char*)buf - (char*)start < len) {
1,402!
3005
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,402!
3006
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,402!
3007
    buf = taosDecodeStringTo(buf, pReq->user);
1,402✔
3008
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,804✔
3009
  } else {
3010
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3011
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3012
  }
3013

3014
  return 0;
1,402✔
3015
}
3016

3017
typedef struct {
3018
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3019
  SArray* removedConsumers;  // SArray<int64_t>
3020
  SArray* newConsumers;      // SArray<int64_t>
3021
} SMqRebInfo;
3022

3023
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3024
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,320✔
3025
  if (pRebInfo == NULL) {
1,320!
3026
    return NULL;
×
3027
  }
3028
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,320✔
3029
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3030
  if (pRebInfo->removedConsumers == NULL) {
1,320!
3031
    goto _err;
×
3032
  }
3033
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3034
  if (pRebInfo->newConsumers == NULL) {
1,320!
3035
    goto _err;
×
3036
  }
3037
  return pRebInfo;
1,320✔
3038
_err:
×
3039
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3040
  taosArrayDestroy(pRebInfo->newConsumers);
×
3041
  taosMemoryFreeClear(pRebInfo);
×
3042
  return NULL;
×
3043
}
3044

3045
typedef struct {
3046
  int64_t streamId;
3047
  int64_t checkpointId;
3048
  char    streamName[TSDB_STREAM_FNAME_LEN];
3049
} SMStreamDoCheckpointMsg;
3050

3051
typedef struct {
3052
  int64_t status;
3053
} SMVSubscribeRsp;
3054

3055
typedef struct {
3056
  char    name[TSDB_TOPIC_FNAME_LEN];
3057
  int8_t  igNotExists;
3058
  int32_t sqlLen;
3059
  char*   sql;
3060
} SMDropTopicReq;
3061

3062
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3063
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3064
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3065

3066
typedef struct {
3067
  char   topic[TSDB_TOPIC_FNAME_LEN];
3068
  char   cgroup[TSDB_CGROUP_LEN];
3069
  int8_t igNotExists;
3070
} SMDropCgroupReq;
3071

3072
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3073
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3074

3075
typedef struct {
3076
  int8_t reserved;
3077
} SMDropCgroupRsp;
3078

3079
typedef struct {
3080
  char    name[TSDB_TABLE_FNAME_LEN];
3081
  int8_t  alterType;
3082
  SSchema schema;
3083
} SAlterTopicReq;
3084

3085
typedef struct {
3086
  SMsgHead head;
3087
  char     name[TSDB_TABLE_FNAME_LEN];
3088
  int64_t  tuid;
3089
  int32_t  sverson;
3090
  int32_t  execLen;
3091
  char*    executor;
3092
  int32_t  sqlLen;
3093
  char*    sql;
3094
} SDCreateTopicReq;
3095

3096
typedef struct {
3097
  SMsgHead head;
3098
  char     name[TSDB_TABLE_FNAME_LEN];
3099
  int64_t  tuid;
3100
} SDDropTopicReq;
3101

3102
typedef struct {
3103
  int64_t maxdelay[2];
3104
  int64_t watermark[2];
3105
  int64_t deleteMark[2];
3106
  int32_t qmsgLen[2];
3107
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3108
} SRSmaParam;
3109

3110
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3111
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3112

3113
// TDMT_VND_CREATE_STB ==============
3114
typedef struct SVCreateStbReq {
3115
  char*           name;
3116
  tb_uid_t        suid;
3117
  int8_t          rollup;
3118
  SSchemaWrapper  schemaRow;
3119
  SSchemaWrapper  schemaTag;
3120
  SRSmaParam      rsmaParam;
3121
  int32_t         alterOriDataLen;
3122
  void*           alterOriData;
3123
  int8_t          source;
3124
  int8_t          colCmpred;
3125
  SColCmprWrapper colCmpr;
3126
} SVCreateStbReq;
3127

3128
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3129
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3130

3131
// TDMT_VND_DROP_STB ==============
3132
typedef struct SVDropStbReq {
3133
  char*    name;
3134
  tb_uid_t suid;
3135
} SVDropStbReq;
3136

3137
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3138
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3139

3140
// TDMT_VND_CREATE_TABLE ==============
3141
#define TD_CREATE_IF_NOT_EXISTS 0x1
3142
typedef struct SVCreateTbReq {
3143
  int32_t  flags;
3144
  char*    name;
3145
  tb_uid_t uid;
3146
  int64_t  btime;
3147
  int32_t  ttl;
3148
  int32_t  commentLen;
3149
  char*    comment;
3150
  int8_t   type;
3151
  union {
3152
    struct {
3153
      char*    stbName;  // super table name
3154
      uint8_t  tagNum;
3155
      tb_uid_t suid;
3156
      SArray*  tagName;
3157
      uint8_t* pTag;
3158
    } ctb;
3159
    struct {
3160
      SSchemaWrapper schemaRow;
3161
    } ntb;
3162
  };
3163
  int32_t         sqlLen;
3164
  char*           sql;
3165
  SColCmprWrapper colCmpr;
3166
} SVCreateTbReq;
3167

3168
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3169
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3170
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3171

3172
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,683✔
3173
  if (NULL == req) {
21,702,619!
3174
    return;
21,525,113✔
3175
  }
3176

3177
  taosMemoryFreeClear(req->sql);
177,506!
3178
  taosMemoryFreeClear(req->name);
177,506!
3179
  taosMemoryFreeClear(req->comment);
177,511!
3180
  if (req->type == TSDB_CHILD_TABLE) {
177,511!
3181
    taosMemoryFreeClear(req->ctb.pTag);
163,992!
3182
    taosMemoryFreeClear(req->ctb.stbName);
164,000!
3183
    taosArrayDestroy(req->ctb.tagName);
163,998✔
3184
    req->ctb.tagName = NULL;
163,996✔
3185
  } else if (req->type == TSDB_NORMAL_TABLE) {
13,520!
3186
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,517!
3187
  }
3188
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
177,515!
3189
}
3190

3191
typedef struct {
3192
  int32_t nReqs;
3193
  union {
3194
    SVCreateTbReq* pReqs;
3195
    SArray*        pArray;
3196
  };
3197
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3198
} SVCreateTbBatchReq;
3199

3200
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3201
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3202
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3203

3204
typedef struct {
3205
  int32_t        code;
3206
  STableMetaRsp* pMeta;
3207
} SVCreateTbRsp, SVUpdateTbRsp;
3208

3209
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3210
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3211
void tFreeSVCreateTbRsp(void* param);
3212

3213
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3214
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3215

3216
typedef struct {
3217
  int32_t nRsps;
3218
  union {
3219
    SVCreateTbRsp* pRsps;
3220
    SArray*        pArray;
3221
  };
3222
} SVCreateTbBatchRsp;
3223

3224
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3225
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3226

3227
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3228
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3229

3230
// TDMT_VND_DROP_TABLE =================
3231
typedef struct {
3232
  char*    name;
3233
  uint64_t suid;  // for tmq in wal format
3234
  int64_t  uid;
3235
  int8_t   igNotExists;
3236
} SVDropTbReq;
3237

3238
typedef struct {
3239
  int32_t code;
3240
} SVDropTbRsp;
3241

3242
typedef struct {
3243
  int32_t nReqs;
3244
  union {
3245
    SVDropTbReq* pReqs;
3246
    SArray*      pArray;
3247
  };
3248
} SVDropTbBatchReq;
3249

3250
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3251
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3252

3253
typedef struct {
3254
  int32_t nRsps;
3255
  union {
3256
    SVDropTbRsp* pRsps;
3257
    SArray*      pArray;
3258
  };
3259
} SVDropTbBatchRsp;
3260

3261
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3262
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3263

3264
// TDMT_VND_ALTER_TABLE =====================
3265
typedef struct SMultiTagUpateVal {
3266
  char*    tagName;
3267
  int32_t  colId;
3268
  int8_t   tagType;
3269
  int8_t   tagFree;
3270
  uint32_t nTagVal;
3271
  uint8_t* pTagVal;
3272
  int8_t   isNull;
3273
  SArray*  pTagArray;
3274
} SMultiTagUpateVal;
3275
typedef struct {
3276
  char*   tbName;
3277
  int8_t  action;
3278
  char*   colName;
3279
  int32_t colId;
3280
  // TSDB_ALTER_TABLE_ADD_COLUMN
3281
  int8_t  type;
3282
  int8_t  flags;
3283
  int32_t bytes;
3284
  // TSDB_ALTER_TABLE_DROP_COLUMN
3285
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3286
  int8_t   colModType;
3287
  int32_t  colModBytes;
3288
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3289
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3290
  int8_t   isNull;
3291
  int8_t   tagType;
3292
  int8_t   tagFree;
3293
  uint32_t nTagVal;
3294
  uint8_t* pTagVal;
3295
  SArray*  pTagArray;
3296
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3297
  int8_t   updateTTL;
3298
  int32_t  newTTL;
3299
  int32_t  newCommentLen;
3300
  char*    newComment;
3301
  int64_t  ctimeMs;    // fill by vnode
3302
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3303
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3304
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3305
} SVAlterTbReq;
3306

3307
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3308
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3309
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3310
void    tfreeMultiTagUpateVal(void* pMultiTag);
3311

3312
typedef struct {
3313
  int32_t        code;
3314
  STableMetaRsp* pMeta;
3315
} SVAlterTbRsp;
3316

3317
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3318
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3319
// ======================
3320

3321
typedef struct {
3322
  SMsgHead head;
3323
  int64_t  uid;
3324
  int32_t  tid;
3325
  int16_t  tversion;
3326
  int16_t  colId;
3327
  int8_t   type;
3328
  int16_t  bytes;
3329
  int32_t  tagValLen;
3330
  int16_t  numOfTags;
3331
  int32_t  schemaLen;
3332
  char     data[];
3333
} SUpdateTagValReq;
3334

3335
typedef struct {
3336
  SMsgHead head;
3337
} SUpdateTagValRsp;
3338

3339
typedef struct {
3340
  SMsgHead head;
3341
} SVShowTablesReq;
3342

3343
typedef struct {
3344
  SMsgHead head;
3345
  int32_t  id;
3346
} SVShowTablesFetchReq;
3347

3348
typedef struct {
3349
  int64_t useconds;
3350
  int8_t  completed;  // all results are returned to client
3351
  int8_t  precision;
3352
  int8_t  compressed;
3353
  int32_t compLen;
3354
  int32_t numOfRows;
3355
  char    data[];
3356
} SVShowTablesFetchRsp;
3357

3358
typedef struct {
3359
  int64_t consumerId;
3360
  int32_t epoch;
3361
  char    cgroup[TSDB_CGROUP_LEN];
3362
} SMqAskEpReq;
3363

3364
typedef struct {
3365
  int32_t key;
3366
  int32_t valueLen;
3367
  void*   value;
3368
} SKv;
3369

3370
typedef struct {
3371
  int64_t tscRid;
3372
  int8_t  connType;
3373
} SClientHbKey;
3374

3375
typedef struct {
3376
  int64_t tid;
3377
  char    status[TSDB_JOB_STATUS_LEN];
3378
} SQuerySubDesc;
3379

3380
typedef struct {
3381
  char     sql[TSDB_SHOW_SQL_LEN];
3382
  uint64_t queryId;
3383
  int64_t  useconds;
3384
  int64_t  stime;  // timestamp precision ms
3385
  int64_t  reqRid;
3386
  bool     stableQuery;
3387
  bool     isSubQuery;
3388
  char     fqdn[TSDB_FQDN_LEN];
3389
  int32_t  subPlanNum;
3390
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3391
} SQueryDesc;
3392

3393
typedef struct {
3394
  uint32_t connId;
3395
  SArray*  queryDesc;  // SArray<SQueryDesc>
3396
} SQueryHbReqBasic;
3397

3398
typedef struct {
3399
  uint32_t connId;
3400
  uint64_t killRid;
3401
  int32_t  totalDnodes;
3402
  int32_t  onlineDnodes;
3403
  int8_t   killConnection;
3404
  int8_t   align[3];
3405
  SEpSet   epSet;
3406
  SArray*  pQnodeList;
3407
} SQueryHbRspBasic;
3408

3409
typedef struct SAppClusterSummary {
3410
  uint64_t numOfInsertsReq;
3411
  uint64_t numOfInsertRows;
3412
  uint64_t insertElapsedTime;
3413
  uint64_t insertBytes;  // submit to tsdb since launched.
3414

3415
  uint64_t fetchBytes;
3416
  uint64_t numOfQueryReq;
3417
  uint64_t queryElapsedTime;
3418
  uint64_t numOfSlowQueries;
3419
  uint64_t totalRequests;
3420
  uint64_t currentRequests;  // the number of SRequestObj
3421
} SAppClusterSummary;
3422

3423
typedef struct {
3424
  int64_t            appId;
3425
  int32_t            pid;
3426
  char               name[TSDB_APP_NAME_LEN];
3427
  int64_t            startTime;
3428
  SAppClusterSummary summary;
3429
} SAppHbReq;
3430

3431
typedef struct {
3432
  SClientHbKey      connKey;
3433
  int64_t           clusterId;
3434
  SAppHbReq         app;
3435
  SQueryHbReqBasic* query;
3436
  SHashObj*         info;  // hash<Skv.key, Skv>
3437
} SClientHbReq;
3438

3439
typedef struct {
3440
  int64_t reqId;
3441
  SArray* reqs;  // SArray<SClientHbReq>
3442
  int64_t ipWhiteList;
3443
} SClientHbBatchReq;
3444

3445
typedef struct {
3446
  SClientHbKey      connKey;
3447
  int32_t           status;
3448
  SQueryHbRspBasic* query;
3449
  SArray*           info;  // Array<Skv>
3450
} SClientHbRsp;
3451

3452
typedef struct {
3453
  int64_t       reqId;
3454
  int64_t       rspId;
3455
  int32_t       svrTimestamp;
3456
  SArray*       rsps;  // SArray<SClientHbRsp>
3457
  SMonitorParas monitorParas;
3458
  int8_t        enableAuditDelete;
3459
} SClientHbBatchRsp;
3460

3461
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
225,322✔
3462

3463
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3464
  void* pIter = taosHashIterate(info, NULL);
546,276✔
3465
  while (pIter != NULL) {
937,335!
3466
    SKv* kv = (SKv*)pIter;
391,019✔
3467
    taosMemoryFreeClear(kv->value);
391,019!
3468
    pIter = taosHashIterate(info, pIter);
391,019✔
3469
  }
3470
}
546,316✔
3471

3472
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
344,274✔
3473
  SQueryDesc* desc = (SQueryDesc*)pDesc;
344,274✔
3474
  if (desc->subDesc) {
344,274✔
3475
    taosArrayDestroy(desc->subDesc);
338,356✔
3476
    desc->subDesc = NULL;
338,356✔
3477
  }
3478
}
344,274✔
3479

3480
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
645,944✔
3481
  SClientHbReq* req = (SClientHbReq*)pReq;
658,505✔
3482
  if (req->query) {
658,505!
3483
    if (req->query->queryDesc) {
637,158!
3484
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
46,104✔
3485
    }
3486
    taosMemoryFreeClear(req->query);
637,158!
3487
  }
3488

3489
  if (req->info) {
658,503!
3490
    tFreeReqKvHash(req->info);
546,276✔
3491
    taosHashCleanup(req->info);
546,316✔
3492
    req->info = NULL;
546,275✔
3493
  }
3494
}
526,498✔
3495

3496
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3497
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3498

3499
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3500
  if (pReq == NULL) return;
39,990!
3501
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
39,990✔
3502
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
39,990✔
3503
  taosMemoryFree(pReq);
39,990✔
3504
}
3505

3506
static FORCE_INLINE void tFreeClientKv(void* pKv) {
148,143✔
3507
  SKv* kv = (SKv*)pKv;
148,143✔
3508
  if (kv) {
148,143!
3509
    taosMemoryFreeClear(kv->value);
148,143!
3510
  }
3511
}
148,142✔
3512

3513
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
643,560✔
3514
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
643,560✔
3515
  if (rsp->query) {
643,560✔
3516
    taosArrayDestroy(rsp->query->pQnodeList);
634,891✔
3517
    taosMemoryFreeClear(rsp->query);
634,964!
3518
  }
3519
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
643,740!
3520
}
129,909✔
3521

3522
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3523
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
434,782✔
3524
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
434,782✔
3525
}
434,809✔
3526

3527
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3528
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3529
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3530

3531
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3532
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
715,848!
3533
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
715,848!
3534
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
715,848!
3535
  return 0;
357,924✔
3536
}
3537

3538
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3539
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
720,328!
3540
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
720,341!
3541
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
360,174✔
3542
  if (pKv->value == NULL) {
360,182!
3543
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3544
  }
3545
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
360,182!
3546
  return 0;
360,176✔
3547
}
3548

3549
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3550
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,582,240!
3551
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,582,240!
3552
  return 0;
1,291,120✔
3553
}
3554

3555
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3556
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,287,484!
3557
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,287,493!
3558
  return 0;
643,749✔
3559
}
3560

3561
typedef struct {
3562
  int32_t vgId;
3563
  // TODO stas
3564
} SMqReportVgInfo;
3565

3566
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3567
  int32_t tlen = 0;
3568
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3569
  return tlen;
3570
}
3571

3572
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3573
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3574
  return buf;
3575
}
3576

3577
typedef struct {
3578
  int32_t epoch;
3579
  int64_t topicUid;
3580
  char    name[TSDB_TOPIC_FNAME_LEN];
3581
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3582
} SMqTopicInfo;
3583

3584
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3585
  int32_t tlen = 0;
3586
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3587
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3588
  tlen += taosEncodeString(buf, pTopicInfo->name);
3589
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3590
  tlen += taosEncodeFixedI32(buf, sz);
3591
  for (int32_t i = 0; i < sz; i++) {
3592
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3593
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3594
  }
3595
  return tlen;
3596
}
3597

3598
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3599
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3600
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3601
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3602
  int32_t sz;
3603
  buf = taosDecodeFixedI32(buf, &sz);
3604
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3605
    return NULL;
3606
  }
3607
  for (int32_t i = 0; i < sz; i++) {
3608
    SMqReportVgInfo vgInfo;
3609
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3610
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3611
      return NULL;
3612
    }
3613
  }
3614
  return buf;
3615
}
3616

3617
typedef struct {
3618
  int32_t status;  // ask hb endpoint
3619
  int32_t epoch;
3620
  int64_t consumerId;
3621
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3622
} SMqReportReq;
3623

3624
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3625
  int32_t tlen = 0;
3626
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3627
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3628
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3629
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3630
  tlen += taosEncodeFixedI32(buf, sz);
3631
  for (int32_t i = 0; i < sz; i++) {
3632
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3633
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3634
  }
3635
  return tlen;
3636
}
3637

3638
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3639
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3640
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3641
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3642
  int32_t sz;
3643
  buf = taosDecodeFixedI32(buf, &sz);
3644
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3645
    return NULL;
3646
  }
3647
  for (int32_t i = 0; i < sz; i++) {
3648
    SMqTopicInfo topicInfo;
3649
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3650
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3651
      return NULL;
3652
    }
3653
  }
3654
  return buf;
3655
}
3656

3657
typedef struct {
3658
  SMsgHead head;
3659
  int64_t  leftForVer;
3660
  int32_t  vgId;
3661
  int64_t  consumerId;
3662
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3663
} SMqVDeleteReq;
3664

3665
typedef struct {
3666
  int8_t reserved;
3667
} SMqVDeleteRsp;
3668

3669
typedef struct {
3670
  char    name[TSDB_STREAM_FNAME_LEN];
3671
  int8_t  igNotExists;
3672
  int32_t sqlLen;
3673
  char*   sql;
3674
} SMDropStreamReq;
3675

3676
typedef struct {
3677
  int8_t reserved;
3678
} SMDropStreamRsp;
3679

3680
typedef struct {
3681
  SMsgHead head;
3682
  int64_t  resetRelHalt;  // reset related stream task halt status
3683
  int64_t  streamId;
3684
  int32_t  taskId;
3685
} SVDropStreamTaskReq;
3686

3687
typedef struct {
3688
  int8_t reserved;
3689
} SVDropStreamTaskRsp;
3690

3691
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3692
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3693
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3694

3695
typedef struct SVUpdateCheckpointInfoReq {
3696
  SMsgHead head;
3697
  int64_t  streamId;
3698
  int32_t  taskId;
3699
  int64_t  checkpointId;
3700
  int64_t  checkpointVer;
3701
  int64_t  checkpointTs;
3702
  int32_t  transId;
3703
  int64_t  hStreamId;  // add encode/decode
3704
  int64_t  hTaskId;
3705
  int8_t   dropRelHTask;
3706
} SVUpdateCheckpointInfoReq;
3707

3708
typedef struct {
3709
  int64_t leftForVer;
3710
  int32_t vgId;
3711
  int64_t oldConsumerId;
3712
  int64_t newConsumerId;
3713
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3714
  int8_t  subType;
3715
  int8_t  withMeta;
3716
  char*   qmsg;  // SubPlanToString
3717
  int64_t suid;
3718
} SMqRebVgReq;
3719

3720
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3721
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3722

3723
typedef struct {
3724
  char    topic[TSDB_TOPIC_FNAME_LEN];
3725
  int64_t ntbUid;
3726
  SArray* colIdList;  // SArray<int16_t>
3727
} STqCheckInfo;
3728

3729
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3730
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3731
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3732

3733
// tqOffset
3734
enum {
3735
  TMQ_OFFSET__RESET_NONE = -3,
3736
  TMQ_OFFSET__RESET_EARLIEST = -2,
3737
  TMQ_OFFSET__RESET_LATEST = -1,
3738
  TMQ_OFFSET__LOG = 1,
3739
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3740
  TMQ_OFFSET__SNAPSHOT_META = 3,
3741
};
3742

3743
enum {
3744
  WITH_DATA = 0,
3745
  WITH_META = 1,
3746
  ONLY_META = 2,
3747
};
3748

3749
#define TQ_OFFSET_VERSION 1
3750

3751
typedef struct {
3752
  int8_t type;
3753
  union {
3754
    // snapshot
3755
    struct {
3756
      int64_t uid;
3757
      int64_t ts;
3758
      SValue  primaryKey;
3759
    };
3760
    // log
3761
    struct {
3762
      int64_t version;
3763
    };
3764
  };
3765
} STqOffsetVal;
3766

3767
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3768
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,816✔
3769
  pOffsetVal->uid = uid;
25,816✔
3770
  pOffsetVal->ts = ts;
25,816✔
3771
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,816!
3772
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3773
  }
3774
  pOffsetVal->primaryKey = primaryKey;
25,856✔
3775
}
25,856✔
3776

3777
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3778
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3779
  pOffsetVal->uid = uid;
149✔
3780
}
149✔
3781

3782
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3783
  pOffsetVal->type = TMQ_OFFSET__LOG;
629,017✔
3784
  pOffsetVal->version = ver;
629,017✔
3785
}
629,017✔
3786

3787
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3788
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3789
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3790
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3791
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3792
void    tOffsetDestroy(void* pVal);
3793

3794
typedef struct {
3795
  STqOffsetVal val;
3796
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3797
} STqOffset;
3798

3799
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3800
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3801
void    tDeleteSTqOffset(void* val);
3802

3803
typedef struct SMqVgOffset {
3804
  int64_t   consumerId;
3805
  STqOffset offset;
3806
} SMqVgOffset;
3807

3808
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3809
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3810

3811
typedef struct {
3812
  SMsgHead head;
3813
  int64_t  streamId;
3814
  int32_t  taskId;
3815
} SVPauseStreamTaskReq;
3816

3817
typedef struct {
3818
  SMsgHead head;
3819
  int64_t  streamId;
3820
  int32_t  taskId;
3821
  int64_t  chkptId;
3822
} SVResetStreamTaskReq;
3823

3824
typedef struct {
3825
  char   name[TSDB_STREAM_FNAME_LEN];
3826
  int8_t igNotExists;
3827
} SMPauseStreamReq;
3828

3829
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3830
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3831

3832
typedef struct {
3833
  SMsgHead head;
3834
  int32_t  taskId;
3835
  int64_t  streamId;
3836
  int8_t   igUntreated;
3837
} SVResumeStreamTaskReq;
3838

3839
typedef struct {
3840
  int8_t reserved;
3841
} SVResumeStreamTaskRsp;
3842

3843
typedef struct {
3844
  char   name[TSDB_STREAM_FNAME_LEN];
3845
  int8_t igNotExists;
3846
  int8_t igUntreated;
3847
} SMResumeStreamReq;
3848

3849
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3850
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3851

3852
typedef struct {
3853
  char    name[TSDB_TABLE_FNAME_LEN];
3854
  char    stb[TSDB_TABLE_FNAME_LEN];
3855
  int8_t  igExists;
3856
  int8_t  intervalUnit;
3857
  int8_t  slidingUnit;
3858
  int8_t  timezone;
3859
  int32_t dstVgId;  // for stream
3860
  int64_t interval;
3861
  int64_t offset;
3862
  int64_t sliding;
3863
  int64_t maxDelay;
3864
  int64_t watermark;
3865
  int32_t exprLen;        // strlen + 1
3866
  int32_t tagsFilterLen;  // strlen + 1
3867
  int32_t sqlLen;         // strlen + 1
3868
  int32_t astLen;         // strlen + 1
3869
  char*   expr;
3870
  char*   tagsFilter;
3871
  char*   sql;
3872
  char*   ast;
3873
  int64_t deleteMark;
3874
  int64_t lastTs;
3875
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3876
  SArray* pVgroupVerList;
3877
  int8_t  recursiveTsma;
3878
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3879
} SMCreateSmaReq;
3880

3881
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3882
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3883
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3884

3885
typedef struct {
3886
  char   name[TSDB_TABLE_FNAME_LEN];
3887
  int8_t igNotExists;
3888
} SMDropSmaReq;
3889

3890
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3891
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3892

3893
typedef struct {
3894
  char   dbFName[TSDB_DB_FNAME_LEN];
3895
  char   stbName[TSDB_TABLE_NAME_LEN];
3896
  char   colName[TSDB_COL_NAME_LEN];
3897
  char   idxName[TSDB_INDEX_FNAME_LEN];
3898
  int8_t idxType;
3899
} SCreateTagIndexReq;
3900

3901
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3902
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3903

3904
typedef SMDropSmaReq SDropTagIndexReq;
3905

3906
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3907
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3908

3909
typedef struct {
3910
  int8_t         version;       // for compatibility(default 0)
3911
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3912
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3913
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3914
  int32_t        dstVgId;
3915
  char           indexName[TSDB_INDEX_NAME_LEN];
3916
  int32_t        exprLen;
3917
  int32_t        tagsFilterLen;
3918
  int64_t        indexUid;
3919
  tb_uid_t       tableUid;  // super/child/common table uid
3920
  tb_uid_t       dstTbUid;  // for dstVgroup
3921
  int64_t        interval;
3922
  int64_t        offset;  // use unit by precision of DB
3923
  int64_t        sliding;
3924
  char*          dstTbName;  // for dstVgroup
3925
  char*          expr;       // sma expression
3926
  char*          tagsFilter;
3927
  SSchemaWrapper schemaRow;  // for dstVgroup
3928
  SSchemaWrapper schemaTag;  // for dstVgroup
3929
} STSma;                     // Time-range-wise SMA
3930

3931
typedef STSma SVCreateTSmaReq;
3932

3933
typedef struct {
3934
  int8_t  type;  // 0 status report, 1 update data
3935
  int64_t indexUid;
3936
  int64_t skey;  // start TS key of interval/sliding window
3937
} STSmaMsg;
3938

3939
typedef struct {
3940
  int64_t indexUid;
3941
  char    indexName[TSDB_INDEX_NAME_LEN];
3942
} SVDropTSmaReq;
3943

3944
typedef struct {
3945
  int tmp;  // TODO: to avoid compile error
3946
} SVCreateTSmaRsp, SVDropTSmaRsp;
3947

3948
#if 0
3949
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3950
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3951
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3952
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3953
#endif
3954

3955
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3956
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3957
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3958
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3959

3960
typedef struct {
3961
  int32_t number;
3962
  STSma*  tSma;
3963
} STSmaWrapper;
3964

3965
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3966
  if (pSma) {
3!
3967
    taosMemoryFreeClear(pSma->dstTbName);
3!
3968
    taosMemoryFreeClear(pSma->expr);
3!
3969
    taosMemoryFreeClear(pSma->tagsFilter);
3!
3970
  }
3971
}
3✔
3972

3973
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3974
  if (pSW) {
×
3975
    if (pSW->tSma) {
×
3976
      if (deepCopy) {
×
3977
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3978
          tDestroyTSma(pSW->tSma + i);
×
3979
        }
3980
      }
3981
      taosMemoryFreeClear(pSW->tSma);
×
3982
    }
3983
  }
3984
}
×
3985

3986
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3987
  tDestroyTSmaWrapper(pSW, deepCopy);
×
3988
  taosMemoryFreeClear(pSW);
×
3989
  return NULL;
×
3990
}
3991

3992
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3993
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3994

3995
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
3996
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
3997

3998
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
3999
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4000
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4001
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4002
  }
4003
  return 0;
×
4004
}
4005

4006
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4007
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4008
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4009
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4010
  }
4011
  return 0;
×
4012
}
4013

4014
typedef struct {
4015
  int idx;
4016
} SMCreateFullTextReq;
4017

4018
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4019
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4020
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4021

4022
typedef struct {
4023
  char   name[TSDB_TABLE_FNAME_LEN];
4024
  int8_t igNotExists;
4025
} SMDropFullTextReq;
4026

4027
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4028
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4029

4030
typedef struct {
4031
  char indexFName[TSDB_INDEX_FNAME_LEN];
4032
} SUserIndexReq;
4033

4034
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4035
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4036

4037
typedef struct {
4038
  char dbFName[TSDB_DB_FNAME_LEN];
4039
  char tblFName[TSDB_TABLE_FNAME_LEN];
4040
  char colName[TSDB_COL_NAME_LEN];
4041
  char indexType[TSDB_INDEX_TYPE_LEN];
4042
  char indexExts[TSDB_INDEX_EXTS_LEN];
4043
} SUserIndexRsp;
4044

4045
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4046
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4047

4048
typedef struct {
4049
  char tbFName[TSDB_TABLE_FNAME_LEN];
4050
} STableIndexReq;
4051

4052
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4053
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4054

4055
typedef struct {
4056
  int8_t  intervalUnit;
4057
  int8_t  slidingUnit;
4058
  int64_t interval;
4059
  int64_t offset;
4060
  int64_t sliding;
4061
  int64_t dstTbUid;
4062
  int32_t dstVgId;
4063
  SEpSet  epSet;
4064
  char*   expr;
4065
} STableIndexInfo;
4066

4067
typedef struct {
4068
  char     tbName[TSDB_TABLE_NAME_LEN];
4069
  char     dbFName[TSDB_DB_FNAME_LEN];
4070
  uint64_t suid;
4071
  int32_t  version;
4072
  int32_t  indexSize;
4073
  SArray*  pIndex;  // STableIndexInfo
4074
} STableIndexRsp;
4075

4076
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4077
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4078
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4079

4080
void tFreeSTableIndexInfo(void* pInfo);
4081

4082
typedef struct {
4083
  int8_t  mqMsgType;
4084
  int32_t code;
4085
  int32_t epoch;
4086
  int64_t consumerId;
4087
  int64_t walsver;
4088
  int64_t walever;
4089
} SMqRspHead;
4090

4091
typedef struct {
4092
  SMsgHead     head;
4093
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4094
  int8_t       withTbName;
4095
  int8_t       useSnapshot;
4096
  int32_t      epoch;
4097
  uint64_t     reqId;
4098
  int64_t      consumerId;
4099
  int64_t      timeout;
4100
  STqOffsetVal reqOffset;
4101
  int8_t       enableReplay;
4102
  int8_t       sourceExcluded;
4103
  int8_t       enableBatchMeta;
4104
} SMqPollReq;
4105

4106
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4107
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4108
void    tDestroySMqPollReq(SMqPollReq* pReq);
4109

4110
typedef struct {
4111
  int32_t vgId;
4112
  int64_t offset;
4113
  SEpSet  epSet;
4114
} SMqSubVgEp;
4115

4116
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4117
  int32_t tlen = 0;
8,534✔
4118
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,534✔
4119
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,534✔
4120
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,534✔
4121
  return tlen;
8,534✔
4122
}
4123

4124
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4125
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,138!
4126
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,138!
4127
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,138✔
4128
  return buf;
4,138✔
4129
}
4130

4131
typedef struct {
4132
  char           topic[TSDB_TOPIC_FNAME_LEN];
4133
  char           db[TSDB_DB_FNAME_LEN];
4134
  SArray*        vgs;  // SArray<SMqSubVgEp>
4135
  SSchemaWrapper schema;
4136
} SMqSubTopicEp;
4137

4138
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4139
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4140
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4141

4142
typedef struct {
4143
  SMqRspHead   head;
4144
  STqOffsetVal rspOffset;
4145
  int16_t      resMsgType;
4146
  int32_t      metaRspLen;
4147
  void*        metaRsp;
4148
} SMqMetaRsp;
4149

4150
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4151
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4152
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4153

4154
#define MQ_DATA_RSP_VERSION 100
4155

4156
typedef struct {
4157
  SMqRspHead   head;
4158
  STqOffsetVal rspOffset;
4159
  STqOffsetVal reqOffset;
4160
  int32_t      blockNum;
4161
  int8_t       withTbName;
4162
  int8_t       withSchema;
4163
  SArray*      blockDataLen;
4164
  SArray*      blockData;
4165
  SArray*      blockTbName;
4166
  SArray*      blockSchema;
4167

4168
  union {
4169
    struct {
4170
      int64_t sleepTime;
4171
    };
4172
    struct {
4173
      int32_t createTableNum;
4174
      SArray* createTableLen;
4175
      SArray* createTableReq;
4176
    };
4177
  };
4178

4179
} SMqDataRsp;
4180

4181
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4182
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4183
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4184

4185
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4186
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4187
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4188

4189
typedef struct SMqBatchMetaRsp {
4190
  SMqRspHead   head;  // not serialize
4191
  STqOffsetVal rspOffset;
4192
  SArray*      batchMetaLen;
4193
  SArray*      batchMetaReq;
4194
  void*        pMetaBuff;    // not serialize
4195
  uint32_t     metaBuffLen;  // not serialize
4196
} SMqBatchMetaRsp;
4197

4198
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4199
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4200
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4201
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4202

4203
typedef struct {
4204
  SMqRspHead head;
4205
  char       cgroup[TSDB_CGROUP_LEN];
4206
  SArray*    topics;  // SArray<SMqSubTopicEp>
4207
} SMqAskEpRsp;
4208

4209
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4210
  int32_t tlen = 0;
17,262✔
4211
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4212
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,262!
4213
  tlen += taosEncodeFixedI32(buf, sz);
17,261✔
4214
  for (int32_t i = 0; i < sz; i++) {
23,754✔
4215
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,492✔
4216
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,492✔
4217
  }
4218
  return tlen;
17,262✔
4219
}
4220

4221
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4222
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4223
  int32_t sz;
4224
  buf = taosDecodeFixedI32(buf, &sz);
7,994✔
4225
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
7,994✔
4226
  if (pRsp->topics == NULL) {
7,994!
4227
    return NULL;
×
4228
  }
4229
  for (int32_t i = 0; i < sz; i++) {
11,129✔
4230
    SMqSubTopicEp topicEp;
4231
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,135✔
4232
    if (buf == NULL) {
3,135!
4233
      return NULL;
×
4234
    }
4235
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,270!
4236
      return NULL;
×
4237
    }
4238
  }
4239
  return buf;
7,994✔
4240
}
4241

4242
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4243
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
19,692✔
4244
}
19,691✔
4245

4246
typedef struct {
4247
  int32_t      vgId;
4248
  STqOffsetVal offset;
4249
  int64_t      rows;
4250
  int64_t      ever;
4251
} OffsetRows;
4252

4253
typedef struct {
4254
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4255
  SArray* offsetRows;
4256
} TopicOffsetRows;
4257

4258
typedef struct {
4259
  int64_t consumerId;
4260
  int32_t epoch;
4261
  SArray* topics;
4262
  int8_t  pollFlag;
4263
} SMqHbReq;
4264

4265
typedef struct {
4266
  char   topic[TSDB_TOPIC_FNAME_LEN];
4267
  int8_t noPrivilege;
4268
} STopicPrivilege;
4269

4270
typedef struct {
4271
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4272
  int32_t debugFlag;
4273
} SMqHbRsp;
4274

4275
typedef struct {
4276
  SMsgHead head;
4277
  int64_t  consumerId;
4278
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4279
} SMqSeekReq;
4280

4281
#define TD_AUTO_CREATE_TABLE 0x1
4282
typedef struct {
4283
  int64_t       suid;
4284
  int64_t       uid;
4285
  int32_t       sver;
4286
  uint32_t      nData;
4287
  uint8_t*      pData;
4288
  SVCreateTbReq cTbReq;
4289
} SVSubmitBlk;
4290

4291
typedef struct {
4292
  SMsgHead header;
4293
  uint64_t sId;
4294
  uint64_t queryId;
4295
  uint64_t clientId;
4296
  uint64_t taskId;
4297
  uint32_t sqlLen;
4298
  uint32_t phyLen;
4299
  char*    sql;
4300
  char*    msg;
4301
  int8_t   source;
4302
} SVDeleteReq;
4303

4304
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4305
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4306

4307
typedef struct {
4308
  int64_t affectedRows;
4309
} SVDeleteRsp;
4310

4311
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4312
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4313

4314
typedef struct SDeleteRes {
4315
  uint64_t suid;
4316
  SArray*  uidList;
4317
  int64_t  skey;
4318
  int64_t  ekey;
4319
  int64_t  affectedRows;
4320
  char     tableFName[TSDB_TABLE_NAME_LEN];
4321
  char     tsColName[TSDB_COL_NAME_LEN];
4322
  int64_t  ctimeMs;  // fill by vnode
4323
  int8_t   source;
4324
} SDeleteRes;
4325

4326
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4327
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4328

4329
typedef struct {
4330
  // int64_t uid;
4331
  char    tbname[TSDB_TABLE_NAME_LEN];
4332
  int64_t startTs;
4333
  int64_t endTs;
4334
} SSingleDeleteReq;
4335

4336
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4337
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4338

4339
typedef struct {
4340
  int64_t suid;
4341
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4342
  int64_t ctimeMs;     // fill by vnode
4343
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4344
} SBatchDeleteReq;
4345

4346
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4347
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4348
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4349

4350
typedef struct {
4351
  int32_t msgIdx;
4352
  int32_t msgType;
4353
  int32_t msgLen;
4354
  void*   msg;
4355
} SBatchMsg;
4356

4357
typedef struct {
4358
  SMsgHead header;
4359
  SArray*  pMsgs;  // SArray<SBatchMsg>
4360
} SBatchReq;
4361

4362
typedef struct {
4363
  int32_t reqType;
4364
  int32_t msgIdx;
4365
  int32_t msgLen;
4366
  int32_t rspCode;
4367
  void*   msg;
4368
} SBatchRspMsg;
4369

4370
typedef struct {
4371
  SArray* pRsps;  // SArray<SBatchRspMsg>
4372
} SBatchRsp;
4373

4374
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4375
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4376
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
7,053,854✔
4377
  if (NULL == msg) {
7,053,854!
4378
    return;
×
4379
  }
4380
  SBatchMsg* pMsg = (SBatchMsg*)msg;
7,053,854✔
4381
  taosMemoryFree(pMsg->msg);
7,053,854✔
4382
}
4383

4384
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4385
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4386

4387
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,514,395✔
4388
  if (NULL == p) {
1,514,395!
4389
    return;
×
4390
  }
4391

4392
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,514,395✔
4393
  taosMemoryFree(pRsp->msg);
1,514,395✔
4394
}
4395

4396
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4397
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4398
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4399
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4400
void    tDestroySMqHbReq(SMqHbReq* pReq);
4401

4402
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4403
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4404
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4405

4406
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4407
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4408

4409
#define TD_REQ_FROM_APP               0x0
4410
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4411
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4412
#define SUBMIT_REQ_FROM_FILE          0x4
4413
#define TD_REQ_FROM_TAOX              0x8
4414
#define SUBMIT_REQUEST_VERSION        (1)
4415

4416
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4417

4418
typedef struct {
4419
  int32_t        flags;
4420
  SVCreateTbReq* pCreateTbReq;
4421
  int64_t        suid;
4422
  int64_t        uid;
4423
  int32_t        sver;
4424
  union {
4425
    SArray* aRowP;
4426
    SArray* aCol;
4427
  };
4428
  int64_t ctimeMs;
4429
} SSubmitTbData;
4430

4431
typedef struct {
4432
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4433
} SSubmitReq2;
4434

4435
typedef struct {
4436
  SMsgHead header;
4437
  int64_t  version;
4438
  char     data[];  // SSubmitReq2
4439
} SSubmitReq2Msg;
4440

4441
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4442
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4443
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4444
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4445

4446
typedef struct {
4447
  int32_t affectedRows;
4448
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4449
} SSubmitRsp2;
4450

4451
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4452
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4453
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4454

4455
#define TSDB_MSG_FLG_ENCODE 0x1
4456
#define TSDB_MSG_FLG_DECODE 0x2
4457
#define TSDB_MSG_FLG_CMPT   0x3
4458

4459
typedef struct {
4460
  union {
4461
    struct {
4462
      void*   msgStr;
4463
      int32_t msgLen;
4464
      int64_t ver;
4465
    };
4466
    void* pDataBlock;
4467
  };
4468
} SPackedData;
4469

4470
typedef struct {
4471
  char     fullname[TSDB_VIEW_FNAME_LEN];
4472
  char     name[TSDB_VIEW_NAME_LEN];
4473
  char     dbFName[TSDB_DB_FNAME_LEN];
4474
  char*    querySql;
4475
  char*    sql;
4476
  int8_t   orReplace;
4477
  int8_t   precision;
4478
  int32_t  numOfCols;
4479
  SSchema* pSchema;
4480
} SCMCreateViewReq;
4481

4482
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4483
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4484
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4485

4486
typedef struct {
4487
  char   fullname[TSDB_VIEW_FNAME_LEN];
4488
  char   name[TSDB_VIEW_NAME_LEN];
4489
  char   dbFName[TSDB_DB_FNAME_LEN];
4490
  char*  sql;
4491
  int8_t igNotExists;
4492
} SCMDropViewReq;
4493

4494
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4495
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4496
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4497

4498
typedef struct {
4499
  char fullname[TSDB_VIEW_FNAME_LEN];
4500
} SViewMetaReq;
4501
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4502
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4503

4504
typedef struct {
4505
  char     name[TSDB_VIEW_NAME_LEN];
4506
  char     dbFName[TSDB_DB_FNAME_LEN];
4507
  char*    user;
4508
  uint64_t dbId;
4509
  uint64_t viewId;
4510
  char*    querySql;
4511
  int8_t   precision;
4512
  int8_t   type;
4513
  int32_t  version;
4514
  int32_t  numOfCols;
4515
  SSchema* pSchema;
4516
} SViewMetaRsp;
4517
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4518
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4519
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4520
typedef struct {
4521
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4522
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4523
} STableTSMAInfoReq;
4524

4525
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4526
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4527

4528
typedef struct {
4529
  int32_t  funcId;
4530
  col_id_t colId;
4531
} STableTSMAFuncInfo;
4532

4533
typedef struct {
4534
  char     name[TSDB_TABLE_NAME_LEN];
4535
  uint64_t tsmaId;
4536
  char     targetTb[TSDB_TABLE_NAME_LEN];
4537
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4538
  char     tb[TSDB_TABLE_NAME_LEN];
4539
  char     dbFName[TSDB_DB_FNAME_LEN];
4540
  uint64_t suid;
4541
  uint64_t destTbUid;
4542
  uint64_t dbId;
4543
  int32_t  version;
4544
  int64_t  interval;
4545
  int8_t   unit;
4546
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4547
  SArray*  pTags;      // SArray<SSchema>
4548
  SArray*  pUsedCols;  // SArray<SSchema>
4549
  char*    ast;
4550

4551
  int64_t streamUid;
4552
  int64_t reqTs;
4553
  int64_t rspTs;
4554
  int64_t delayDuration;  // ms
4555
  bool    fillHistoryFinished;
4556
} STableTSMAInfo;
4557

4558
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4559
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4560
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4561
void    tFreeTableTSMAInfo(void* p);
4562
void    tFreeAndClearTableTSMAInfo(void* p);
4563
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4564

4565
#define STSMAHbRsp            STableTSMAInfoRsp
4566
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4567
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4568
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4569

4570
typedef struct SStreamProgressReq {
4571
  int64_t streamId;
4572
  int32_t vgId;
4573
  int32_t fetchIdx;
4574
  int32_t subFetchIdx;
4575
} SStreamProgressReq;
4576

4577
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4578
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4579

4580
typedef struct SStreamProgressRsp {
4581
  int64_t streamId;
4582
  int32_t vgId;
4583
  bool    fillHisFinished;
4584
  int64_t progressDelay;
4585
  int32_t fetchIdx;
4586
  int32_t subFetchIdx;
4587
} SStreamProgressRsp;
4588

4589
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4590
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4591

4592
typedef struct SDropCtbWithTsmaSingleVgReq {
4593
  SVgroupInfo vgInfo;
4594
  SArray*     pTbs;  // SVDropTbReq
4595
} SMDropTbReqsOnSingleVg;
4596

4597
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4598
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4599
void    tFreeSMDropTbReqOnSingleVg(void* p);
4600

4601
typedef struct SDropTbsReq {
4602
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4603
} SMDropTbsReq;
4604

4605
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4606
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4607
void    tFreeSMDropTbsReq(void*);
4608

4609
typedef struct SVFetchTtlExpiredTbsRsp {
4610
  SArray* pExpiredTbs;  // SVDropTbReq
4611
  int32_t vgId;
4612
} SVFetchTtlExpiredTbsRsp;
4613

4614
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4615
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4616

4617
void tFreeFetchTtlExpiredTbsRsp(void* p);
4618

4619
void setDefaultOptionsForField(SFieldWithOptions* field);
4620
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4621

4622
#pragma pack(pop)
4623

4624
#ifdef __cplusplus
4625
}
4626
#endif
4627

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

© 2025 Coveralls, Inc