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

taosdata / TDengine / #3519

05 Nov 2024 11:19AM UTC coverage: 57.706% (+8.4%) from 49.32%
#3519

push

travis-ci

web-flow
Merge pull request #28652 from taosdata/fix/3_liaohj

refactor: always successfully put the retrieve msg

109445 of 245179 branches covered (44.64%)

Branch coverage included in aggregate %.

187435 of 269288 relevant lines covered (69.6%)

12869818.21 hits per line

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

57.17
/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) {
50,021,792✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
50,021,792✔
74
  int    segIdx = TMSG_SEG_CODE(type);
50,021,792✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
50,021,792✔
76
    return type < tMsgRangeDict[segIdx];
50,023,044✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
5,678,403✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
5,666,219!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
11,344,622!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
32,650,454✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
32,650,454✔
91
}
92

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

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

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

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

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

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

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

201
#define TSDB_KILL_MSG_LEN 30
202

203
#define TSDB_TABLE_NUM_UNIT 100000
204

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

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

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

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

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

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

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

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

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

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

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

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

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

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

513
#pragma pack(push, 1)
514

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

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

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

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

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

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

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

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

586
//
587

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

719
  return pDstWrapper;
2,142✔
720
}
721

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

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

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

755
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,142!
756
  taosMemoryFreeClear(pWrapper);
2,142!
757
}
758
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
759
  if (pSchemaWrapper->pSchema == NULL) return NULL;
7,799,285!
760

761
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
7,799,285✔
762
  if (pSW == NULL) {
7,797,188!
763
    return NULL;
×
764
  }
765
  pSW->nCols = pSchemaWrapper->nCols;
7,797,188✔
766
  pSW->version = pSchemaWrapper->version;
7,797,188✔
767
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
7,797,188✔
768
  if (pSW->pSchema == NULL) {
7,789,008!
769
    taosMemoryFree(pSW);
×
770
    return NULL;
×
771
  }
772

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

777
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
368,908✔
778
  if (pSchemaWrapper) {
13,560,431!
779
    taosMemoryFree(pSchemaWrapper->pSchema);
8,041,186✔
780
    taosMemoryFree(pSchemaWrapper);
8,041,254✔
781
  }
782
}
13,560,654✔
783

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

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

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

810
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
811
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
526,870,649!
812
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
529,152,968!
813
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
529,152,968!
814
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
529,152,968!
815
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
529,152,968!
816
  return 0;
264,576,484✔
817
}
818

819
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
820
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
402,359,107!
821
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
799,222,025!
822
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
798,537,224!
823
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
798,984,777!
824
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
399,865,930!
825
  return 0;
400,103,682✔
826
}
827

828
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
829
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
332,061,562!
830
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
332,061,562!
831
  return 0;
166,030,781✔
832
}
833

834
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
835
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,778,320!
836
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,778,320!
837
  return 0;
1,889,159✔
838
}
839

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

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

859
    for (int32_t i = 0; i < pSW->nCols; i++) {
28,801✔
860
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
52,360✔
861
    }
862
  } else {
863
    pSW->pSchema = NULL;
1,295✔
864
  }
865
  return (void*)buf;
3,916✔
866
}
867

868
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
869
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
398,374!
870
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
398,374!
871
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,481,506✔
872
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
4,564,638!
873
  }
874
  return 0;
199,187✔
875
}
876

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

881
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
349,904✔
882
  if (pSW->pSchema == NULL) {
350,307!
883
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
884
  }
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
5,257,870✔
886
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
9,817,520!
887
  }
888

889
  return 0;
347,904✔
890
}
891

892
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
893
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
42,705,625!
894
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
42,790,873!
895

896
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
21,393,863✔
897
  if (pSW->pSchema == NULL) {
21,379,556!
898
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
899
  }
900
  for (int32_t i = 0; i < pSW->nCols; i++) {
414,020,226✔
901
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
785,337,760!
902
  }
903

904
  return 0;
21,323,136✔
905
}
906

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

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

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

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

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

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

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

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

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

986

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1213
  uint8_t precision;
1214
  uint8_t scale;
1215
  int32_t bytes;
1216
  int8_t  type;
1217
  uint8_t pk;
1218
} SColumnInfo;
1219

1220
typedef struct STimeWindow {
1221
  TSKEY skey;
1222
  TSKEY ekey;
1223
} STimeWindow;
1224

1225
typedef struct SQueryHint {
1226
  bool batchScan;
1227
} SQueryHint;
1228

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

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

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

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

1259
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1260

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

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

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

1290
typedef STableCfg STableCfgRsp;
1291

1292
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1293
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1294

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

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

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

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

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

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

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

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

1394
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1395
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1396

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

1405
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1406
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1407

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

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

1427
typedef struct {
1428
  char db[TSDB_DB_FNAME_LEN];
1429
} SDbCfgReq;
1430

1431
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1432
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1433

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

1439
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1440
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1441

1442
typedef struct {
1443
  int32_t timestamp;
1444
} SVTrimDbReq;
1445

1446
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1447
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1448

1449
typedef struct {
1450
  char db[TSDB_DB_FNAME_LEN];
1451
} SS3MigrateDbReq;
1452

1453
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1454
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1455

1456
typedef struct {
1457
  int32_t timestamp;
1458
} SVS3MigrateDbReq;
1459

1460
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1461
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1462

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

1470
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1471
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1472

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

1516
typedef SDbCfgRsp SDbCfgInfo;
1517

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

1524
typedef struct {
1525
  int32_t rowNum;
1526
} SQnodeListReq;
1527

1528
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1529
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1530

1531
typedef struct {
1532
  int32_t rowNum;
1533
} SDnodeListReq;
1534

1535
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1536

1537
typedef struct {
1538
  int32_t useless;  // useless
1539
} SServerVerReq;
1540

1541
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1542
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1543

1544
typedef struct {
1545
  char ver[TSDB_VERSION_LEN];
1546
} SServerVerRsp;
1547

1548
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1549
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1550

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

1556
typedef struct {
1557
  SQueryNodeAddr addr;
1558
  uint64_t       load;
1559
} SQueryNodeLoad;
1560

1561
typedef struct {
1562
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1563
} SQnodeListRsp;
1564

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

1569
typedef struct {
1570
  SArray* dnodeList;  // SArray<SEpSet>
1571
} SDnodeListRsp;
1572

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

1577
typedef struct {
1578
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1579
} STableTSMAInfoRsp;
1580

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

1590
typedef struct {
1591
  SArray* pArray;  // Array of SDbHbRsp
1592
} SDbHbBatchRsp;
1593

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

1598
typedef struct {
1599
  SArray* pArray;  // Array of SGetUserAuthRsp
1600
} SUserAuthBatchRsp;
1601

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

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

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

1617
typedef struct {
1618
  int32_t compactId;
1619
  int8_t  bAccepted;
1620
} SCompactDbRsp;
1621

1622
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1623
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1624

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

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

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

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

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

1659
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1660
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1661

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

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

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

1686
typedef struct {
1687
  int32_t funcVersion;
1688
  int64_t funcCreatedTime;
1689
} SFuncExtraInfo;
1690

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

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

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

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

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

1751
typedef struct {
1752
  int32_t vgId;
1753
  int64_t nTimeSeries;
1754
} SVnodeLoadLite;
1755

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

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

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

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

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

1811
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1812
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1813

1814
typedef enum {
1815
  MONITOR_TYPE_COUNTER = 0,
1816
  MONITOR_TYPE_SLOW_LOG = 1,
1817
} MONITOR_TYPE;
1818

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

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

1829
typedef struct {
1830
  int32_t dnodeId;
1831
  int64_t clusterId;
1832
  SArray* pVloads;
1833
} SNotifyReq;
1834

1835
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1836
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1837
void    tFreeSNotifyReq(SNotifyReq* pReq);
1838

1839
typedef struct {
1840
  int32_t dnodeId;
1841
  int64_t clusterId;
1842
} SDnodeCfg;
1843

1844
typedef struct {
1845
  int32_t id;
1846
  int8_t  isMnode;
1847
  SEp     ep;
1848
} SDnodeEp;
1849

1850
typedef struct {
1851
  int32_t id;
1852
  int8_t  isMnode;
1853
  int8_t  offlineReason;
1854
  SEp     ep;
1855
  char    active[TSDB_ACTIVE_KEY_LEN];
1856
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1857
} SDnodeInfo;
1858

1859
typedef struct {
1860
  int64_t   dnodeVer;
1861
  SDnodeCfg dnodeCfg;
1862
  SArray*   pDnodeEps;  // Array of SDnodeEp
1863
  int32_t   statusSeq;
1864
  int64_t   ipWhiteVer;
1865
  int64_t   analVer;
1866
} SStatusRsp;
1867

1868
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1869
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1870
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1871

1872
typedef struct {
1873
  int32_t reserved;
1874
} SMTimerReq;
1875

1876
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1877
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1878

1879
typedef struct SOrphanTask {
1880
  int64_t streamId;
1881
  int32_t taskId;
1882
  int32_t nodeId;
1883
} SOrphanTask;
1884

1885
typedef struct SMStreamDropOrphanMsg {
1886
  SArray* pList;  // SArray<SOrphanTask>
1887
} SMStreamDropOrphanMsg;
1888

1889
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1890
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1891
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1892

1893
typedef struct {
1894
  int32_t  id;
1895
  uint16_t port;                 // node sync Port
1896
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1897
} SReplica;
1898

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

1951
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1952
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1953
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
1954

1955
typedef struct {
1956
  int32_t compactId;
1957
  int32_t vgId;
1958
  int32_t dnodeId;
1959
} SQueryCompactProgressReq;
1960

1961
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1962
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1963

1964
typedef struct {
1965
  int32_t compactId;
1966
  int32_t vgId;
1967
  int32_t dnodeId;
1968
  int32_t numberFileset;
1969
  int32_t finished;
1970
} SQueryCompactProgressRsp;
1971

1972
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1973
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1974

1975
typedef struct {
1976
  int32_t vgId;
1977
  int32_t dnodeId;
1978
  int64_t dbUid;
1979
  char    db[TSDB_DB_FNAME_LEN];
1980
  int64_t reserved[8];
1981
} SDropVnodeReq;
1982

1983
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1984
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1985

1986
typedef struct {
1987
  char    colName[TSDB_COL_NAME_LEN];
1988
  char    stb[TSDB_TABLE_FNAME_LEN];
1989
  int64_t stbUid;
1990
  int64_t dbUid;
1991
  int64_t reserved[8];
1992
} SDropIndexReq;
1993

1994
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
1995
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
1996

1997
typedef struct {
1998
  int64_t     dbUid;
1999
  char        db[TSDB_DB_FNAME_LEN];
2000
  int64_t     compactStartTime;
2001
  STimeWindow tw;
2002
  int32_t     compactId;
2003
} SCompactVnodeReq;
2004

2005
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2006
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2007

2008
typedef struct {
2009
  int32_t compactId;
2010
  int32_t vgId;
2011
  int32_t dnodeId;
2012
} SVKillCompactReq;
2013

2014
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2015
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2016

2017
typedef struct {
2018
  int32_t vgVersion;
2019
  int32_t buffer;
2020
  int32_t pageSize;
2021
  int32_t pages;
2022
  int32_t cacheLastSize;
2023
  int32_t daysPerFile;
2024
  int32_t daysToKeep0;
2025
  int32_t daysToKeep1;
2026
  int32_t daysToKeep2;
2027
  int32_t keepTimeOffset;
2028
  int32_t walFsyncPeriod;
2029
  int8_t  walLevel;
2030
  int8_t  strict;
2031
  int8_t  cacheLast;
2032
  int64_t reserved[7];
2033
  // 1st modification
2034
  int16_t sttTrigger;
2035
  int32_t minRows;
2036
  // 2nd modification
2037
  int32_t walRetentionPeriod;
2038
  int32_t walRetentionSize;
2039
  int32_t s3KeepLocal;
2040
  int8_t  s3Compact;
2041
} SAlterVnodeConfigReq;
2042

2043
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2044
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2045

2046
typedef struct {
2047
  int32_t  vgId;
2048
  int8_t   strict;
2049
  int8_t   selfIndex;
2050
  int8_t   replica;
2051
  SReplica replicas[TSDB_MAX_REPLICA];
2052
  int64_t  reserved[8];
2053
  int8_t   learnerSelfIndex;
2054
  int8_t   learnerReplica;
2055
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2056
  int32_t  changeVersion;
2057
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2058

2059
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2060
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2061

2062
typedef struct {
2063
  int32_t vgId;
2064
  int8_t  disable;
2065
} SDisableVnodeWriteReq;
2066

2067
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2068
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2069

2070
typedef struct {
2071
  int32_t  srcVgId;
2072
  int32_t  dstVgId;
2073
  uint32_t hashBegin;
2074
  uint32_t hashEnd;
2075
  int32_t  changeVersion;
2076
  int32_t  reserved;
2077
} SAlterVnodeHashRangeReq;
2078

2079
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2080
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2081

2082
#define REQ_OPT_TBNAME 0x0
2083
#define REQ_OPT_TBUID  0x01
2084
typedef struct {
2085
  SMsgHead header;
2086
  char     dbFName[TSDB_DB_FNAME_LEN];
2087
  char     tbName[TSDB_TABLE_NAME_LEN];
2088
  uint8_t  option;
2089
} STableInfoReq;
2090

2091
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2092
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2093

2094
typedef struct {
2095
  int8_t  metaClone;  // create local clone of the cached table meta
2096
  int32_t numOfVgroups;
2097
  int32_t numOfTables;
2098
  int32_t numOfUdfs;
2099
  char    tableNames[];
2100
} SMultiTableInfoReq;
2101

2102
// todo refactor
2103
typedef struct SVgroupInfo {
2104
  int32_t  vgId;
2105
  uint32_t hashBegin;
2106
  uint32_t hashEnd;
2107
  SEpSet   epSet;
2108
  union {
2109
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2110
    int32_t taskId;      // used in stream
2111
  };
2112
} SVgroupInfo;
2113

2114
typedef struct {
2115
  int32_t     numOfVgroups;
2116
  SVgroupInfo vgroups[];
2117
} SVgroupsInfo;
2118

2119
typedef struct {
2120
  STableMetaRsp* pMeta;
2121
} SMAlterStbRsp;
2122

2123
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2124
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2125
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2126

2127
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2128
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2129
void    tFreeSTableMetaRsp(void* pRsp);
2130
void    tFreeSTableIndexRsp(void* info);
2131

2132
typedef struct {
2133
  SArray* pMetaRsp;   // Array of STableMetaRsp
2134
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2135
} SSTbHbRsp;
2136

2137
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2138
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2139
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2140

2141
typedef struct {
2142
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2143
} SViewHbRsp;
2144

2145
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2146
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2147
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2148

2149
typedef struct {
2150
  int32_t numOfTables;
2151
  int32_t numOfVgroup;
2152
  int32_t numOfUdf;
2153
  int32_t contLen;
2154
  int8_t  compressed;  // denote if compressed or not
2155
  int32_t rawLen;      // size before compress
2156
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2157
  char    meta[];
2158
} SMultiTableMeta;
2159

2160
typedef struct {
2161
  int32_t dataLen;
2162
  char    name[TSDB_TABLE_FNAME_LEN];
2163
  char*   data;
2164
} STagData;
2165

2166
typedef struct {
2167
  int32_t useless;  // useless
2168
} SShowVariablesReq;
2169

2170
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2171
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2172

2173
typedef struct {
2174
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2175
  char value[TSDB_CONFIG_VALUE_LEN + 1];
2176
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2177
} SVariablesInfo;
2178

2179
typedef struct {
2180
  SArray* variables;  // SArray<SVariablesInfo>
2181
} SShowVariablesRsp;
2182

2183
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2184
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2185

2186
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2187

2188
/*
2189
 * sql: show tables like '%a_%'
2190
 * payload is the query condition, e.g., '%a_%'
2191
 * payloadLen is the length of payload
2192
 */
2193
typedef struct {
2194
  int32_t type;
2195
  char    db[TSDB_DB_FNAME_LEN];
2196
  int32_t payloadLen;
2197
  char*   payload;
2198
} SShowReq;
2199

2200
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2201
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2202
void tFreeSShowReq(SShowReq* pReq);
2203

2204
typedef struct {
2205
  int64_t       showId;
2206
  STableMetaRsp tableMeta;
2207
} SShowRsp, SVShowTablesRsp;
2208

2209
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2210
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2211
// void    tFreeSShowRsp(SShowRsp* pRsp);
2212

2213
typedef struct {
2214
  char    db[TSDB_DB_FNAME_LEN];
2215
  char    tb[TSDB_TABLE_NAME_LEN];
2216
  char    user[TSDB_USER_LEN];
2217
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2218
  int64_t showId;
2219
  int64_t compactId;  // for compact
2220
  bool    withFull;   // for show users full
2221
} SRetrieveTableReq;
2222

2223
typedef struct SSysTableSchema {
2224
  int8_t   type;
2225
  col_id_t colId;
2226
  int32_t  bytes;
2227
} SSysTableSchema;
2228

2229
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2230
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2231

2232
typedef struct {
2233
  int64_t useconds;
2234
  int8_t  completed;  // all results are returned to client
2235
  int8_t  precision;
2236
  int8_t  compressed;
2237
  int8_t  streamBlockType;
2238
  int32_t payloadLen;
2239
  int32_t compLen;
2240
  int32_t numOfBlocks;
2241
  int64_t numOfRows;  // from int32_t change to int64_t
2242
  int64_t numOfCols;
2243
  int64_t skey;
2244
  int64_t ekey;
2245
  int64_t version;                         // for stream
2246
  TSKEY   watermark;                       // for stream
2247
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2248
  char    data[];
2249
} SRetrieveTableRsp;
2250

2251
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2252

2253
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2254
  do {                                          \
2255
    ((int32_t*)(_p))[0] = (_compLen);           \
2256
    ((int32_t*)(_p))[1] = (_fullLen);           \
2257
  } while (0);
2258

2259
typedef struct {
2260
  int64_t version;
2261
  int64_t numOfRows;
2262
  int8_t  compressed;
2263
  int8_t  precision;
2264
  char    data[];
2265
} SRetrieveTableRspForTmq;
2266

2267
typedef struct {
2268
  int64_t handle;
2269
  int64_t useconds;
2270
  int8_t  completed;  // all results are returned to client
2271
  int8_t  precision;
2272
  int8_t  compressed;
2273
  int32_t compLen;
2274
  int32_t numOfRows;
2275
  int32_t fullLen;
2276
  char    data[];
2277
} SRetrieveMetaTableRsp;
2278

2279
typedef struct SExplainExecInfo {
2280
  double   startupCost;
2281
  double   totalCost;
2282
  uint64_t numOfRows;
2283
  uint32_t verboseLen;
2284
  void*    verboseInfo;
2285
} SExplainExecInfo;
2286

2287
typedef struct {
2288
  int32_t           numOfPlans;
2289
  SExplainExecInfo* subplanInfo;
2290
} SExplainRsp;
2291

2292
typedef struct {
2293
  SExplainRsp rsp;
2294
  uint64_t    qId;
2295
  uint64_t    tId;
2296
  int64_t     rId;
2297
  int32_t     eId;
2298
} SExplainLocalRsp;
2299

2300
typedef struct STableScanAnalyzeInfo {
2301
  uint64_t totalRows;
2302
  uint64_t totalCheckedRows;
2303
  uint32_t totalBlocks;
2304
  uint32_t loadBlocks;
2305
  uint32_t loadBlockStatis;
2306
  uint32_t skipBlocks;
2307
  uint32_t filterOutBlocks;
2308
  double   elapsedTime;
2309
  double   filterTime;
2310
} STableScanAnalyzeInfo;
2311

2312
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2313
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2314
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2315

2316
typedef struct {
2317
  char    config[TSDB_DNODE_CONFIG_LEN];
2318
  char    value[TSDB_CLUSTER_VALUE_LEN];
2319
  int32_t sqlLen;
2320
  char*   sql;
2321
} SMCfgClusterReq;
2322

2323
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2324
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2325
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2326

2327
typedef struct {
2328
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2329
  int32_t port;
2330
  int32_t sqlLen;
2331
  char*   sql;
2332
} SCreateDnodeReq;
2333

2334
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2335
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2336
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2337

2338
typedef struct {
2339
  int32_t dnodeId;
2340
  char    fqdn[TSDB_FQDN_LEN];
2341
  int32_t port;
2342
  int8_t  force;
2343
  int8_t  unsafe;
2344
  int32_t sqlLen;
2345
  char*   sql;
2346
} SDropDnodeReq;
2347

2348
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2349
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2350
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2351

2352
enum {
2353
  RESTORE_TYPE__ALL = 1,
2354
  RESTORE_TYPE__MNODE,
2355
  RESTORE_TYPE__VNODE,
2356
  RESTORE_TYPE__QNODE,
2357
};
2358

2359
typedef struct {
2360
  int32_t dnodeId;
2361
  int8_t  restoreType;
2362
  int32_t sqlLen;
2363
  char*   sql;
2364
} SRestoreDnodeReq;
2365

2366
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2367
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2368
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2369

2370
typedef struct {
2371
  int32_t dnodeId;
2372
  char    config[TSDB_DNODE_CONFIG_LEN];
2373
  char    value[TSDB_DNODE_VALUE_LEN];
2374
  int32_t sqlLen;
2375
  char*   sql;
2376
} SMCfgDnodeReq;
2377

2378
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2379
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2380
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2381

2382
typedef struct {
2383
  char config[TSDB_DNODE_CONFIG_LEN];
2384
  char value[TSDB_DNODE_VALUE_LEN];
2385
} SDCfgDnodeReq;
2386

2387
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2388
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2389

2390
typedef struct {
2391
  int32_t dnodeId;
2392
  int32_t sqlLen;
2393
  char*   sql;
2394
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2395
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2396

2397
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2398
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2399
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2400
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2401
typedef struct {
2402
  int8_t   replica;
2403
  SReplica replicas[TSDB_MAX_REPLICA];
2404
  int8_t   learnerReplica;
2405
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2406
  int64_t  lastIndex;
2407
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2408

2409
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2410
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2411

2412
typedef struct {
2413
  int32_t urlLen;
2414
  int32_t sqlLen;
2415
  char*   url;
2416
  char*   sql;
2417
} SMCreateAnodeReq;
2418

2419
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2420
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2421
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2422

2423
typedef struct {
2424
  int32_t anodeId;
2425
  int32_t sqlLen;
2426
  char*   sql;
2427
} SMDropAnodeReq, SMUpdateAnodeReq;
2428

2429
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2430
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2431
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2432
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2433
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2434
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2435

2436
typedef struct {
2437
  int32_t vgId;
2438
  int32_t hbSeq;
2439
} SVArbHbReqMember;
2440

2441
typedef struct {
2442
  int32_t dnodeId;
2443
  char*   arbToken;
2444
  int64_t arbTerm;
2445
  SArray* hbMembers;  // SVArbHbReqMember
2446
} SVArbHeartBeatReq;
2447

2448
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2449
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2450
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2451

2452
typedef struct {
2453
  int32_t vgId;
2454
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2455
  int32_t hbSeq;
2456
} SVArbHbRspMember;
2457

2458
typedef struct {
2459
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2460
  int32_t dnodeId;
2461
  SArray* hbMembers;  // SVArbHbRspMember
2462
} SVArbHeartBeatRsp;
2463

2464
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2465
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2466
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2467

2468
typedef struct {
2469
  char*   arbToken;
2470
  int64_t arbTerm;
2471
  char*   member0Token;
2472
  char*   member1Token;
2473
} SVArbCheckSyncReq;
2474

2475
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2476
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2477
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2478

2479
typedef struct {
2480
  char*   arbToken;
2481
  char*   member0Token;
2482
  char*   member1Token;
2483
  int32_t vgId;
2484
  int32_t errCode;
2485
} SVArbCheckSyncRsp;
2486

2487
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2488
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2489
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2490

2491
typedef struct {
2492
  char*   arbToken;
2493
  int64_t arbTerm;
2494
  char*   memberToken;
2495
} SVArbSetAssignedLeaderReq;
2496

2497
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2498
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2499
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2500

2501
typedef struct {
2502
  char*   arbToken;
2503
  char*   memberToken;
2504
  int32_t vgId;
2505
} SVArbSetAssignedLeaderRsp;
2506

2507
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2508
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2509
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2510

2511
typedef struct {
2512
  int32_t dnodeId;
2513
  char*   token;
2514
} SMArbUpdateGroupMember;
2515

2516
typedef struct {
2517
  int32_t dnodeId;
2518
  char*   token;
2519
  int8_t  acked;
2520
} SMArbUpdateGroupAssigned;
2521

2522
typedef struct {
2523
  int32_t                  vgId;
2524
  int64_t                  dbUid;
2525
  SMArbUpdateGroupMember   members[2];
2526
  int8_t                   isSync;
2527
  int8_t                   assignedAcked;
2528
  SMArbUpdateGroupAssigned assignedLeader;
2529
  int64_t                  version;
2530
} SMArbUpdateGroup;
2531

2532
typedef struct {
2533
  SArray* updateArray;  // SMArbUpdateGroup
2534
} SMArbUpdateGroupBatchReq;
2535

2536
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2537
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2538
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2539

2540
typedef struct {
2541
  char queryStrId[TSDB_QUERY_ID_LEN];
2542
} SKillQueryReq;
2543

2544
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2545
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2546

2547
typedef struct {
2548
  uint32_t connId;
2549
} SKillConnReq;
2550

2551
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2552
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2553

2554
typedef struct {
2555
  int32_t transId;
2556
} SKillTransReq;
2557

2558
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2559
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2560

2561
typedef struct {
2562
  int32_t useless;  // useless
2563
  int32_t sqlLen;
2564
  char*   sql;
2565
} SBalanceVgroupReq;
2566

2567
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2568
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2569
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2570

2571
typedef struct {
2572
  int32_t vgId1;
2573
  int32_t vgId2;
2574
} SMergeVgroupReq;
2575

2576
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2577
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2578

2579
typedef struct {
2580
  int32_t vgId;
2581
  int32_t dnodeId1;
2582
  int32_t dnodeId2;
2583
  int32_t dnodeId3;
2584
  int32_t sqlLen;
2585
  char*   sql;
2586
} SRedistributeVgroupReq;
2587

2588
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2589
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2590
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2591

2592
typedef struct {
2593
  int32_t reserved;
2594
  int32_t vgId;
2595
  int32_t sqlLen;
2596
  char*   sql;
2597
  char    db[TSDB_DB_FNAME_LEN];
2598
} SBalanceVgroupLeaderReq;
2599

2600
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2601
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2602
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2603

2604
typedef struct {
2605
  int32_t vgId;
2606
} SForceBecomeFollowerReq;
2607

2608
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2609
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2610

2611
typedef struct {
2612
  int32_t vgId;
2613
} SSplitVgroupReq;
2614

2615
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2616
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2617

2618
typedef struct {
2619
  char user[TSDB_USER_LEN];
2620
  char spi;
2621
  char encrypt;
2622
  char secret[TSDB_PASSWORD_LEN];
2623
  char ckey[TSDB_PASSWORD_LEN];
2624
} SAuthReq, SAuthRsp;
2625

2626
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2627
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2628

2629
typedef struct {
2630
  int32_t statusCode;
2631
  char    details[1024];
2632
} SServerStatusRsp;
2633

2634
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2635
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2636

2637
/**
2638
 * The layout of the query message payload is as following:
2639
 * +--------------------+---------------------------------+
2640
 * |Sql statement       | Physical plan                   |
2641
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2642
 * +--------------------+---------------------------------+
2643
 */
2644
typedef struct SSubQueryMsg {
2645
  SMsgHead header;
2646
  uint64_t sId;
2647
  uint64_t queryId;
2648
  uint64_t taskId;
2649
  int64_t  refId;
2650
  int32_t  execId;
2651
  int32_t  msgMask;
2652
  int8_t   taskType;
2653
  int8_t   explain;
2654
  int8_t   needFetch;
2655
  int8_t   compress;
2656
  uint32_t sqlLen;
2657
  char*    sql;
2658
  uint32_t msgLen;
2659
  char*    msg;
2660
} SSubQueryMsg;
2661

2662
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2663
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2664
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2665

2666
typedef struct {
2667
  SMsgHead header;
2668
  uint64_t sId;
2669
  uint64_t queryId;
2670
  uint64_t taskId;
2671
} SSinkDataReq;
2672

2673
typedef struct {
2674
  SMsgHead header;
2675
  uint64_t sId;
2676
  uint64_t queryId;
2677
  uint64_t taskId;
2678
  int32_t  execId;
2679
} SQueryContinueReq;
2680

2681
typedef struct {
2682
  SMsgHead header;
2683
  uint64_t sId;
2684
  uint64_t queryId;
2685
  uint64_t taskId;
2686
} SResReadyReq;
2687

2688
typedef struct {
2689
  int32_t code;
2690
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2691
  int32_t sversion;
2692
  int32_t tversion;
2693
} SResReadyRsp;
2694

2695
typedef struct SOperatorParam {
2696
  int32_t opType;
2697
  int32_t downstreamIdx;
2698
  void*   value;
2699
  SArray* pChildren;  // SArray<SOperatorParam*>
2700
} SOperatorParam;
2701

2702
typedef struct STableScanOperatorParam {
2703
  bool    tableSeq;
2704
  SArray* pUidList;
2705
} STableScanOperatorParam;
2706

2707
typedef struct {
2708
  SMsgHead        header;
2709
  uint64_t        sId;
2710
  uint64_t        queryId;
2711
  uint64_t        taskId;
2712
  int32_t         execId;
2713
  SOperatorParam* pOpParam;
2714
} SResFetchReq;
2715

2716
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2717
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2718

2719
typedef struct {
2720
  SMsgHead header;
2721
  uint64_t sId;
2722
} SSchTasksStatusReq;
2723

2724
typedef struct {
2725
  uint64_t queryId;
2726
  uint64_t taskId;
2727
  int64_t  refId;
2728
  int32_t  execId;
2729
  int8_t   status;
2730
} STaskStatus;
2731

2732
typedef struct {
2733
  int64_t refId;
2734
  SArray* taskStatus;  // SArray<STaskStatus>
2735
} SSchedulerStatusRsp;
2736

2737
typedef struct {
2738
  uint64_t queryId;
2739
  uint64_t taskId;
2740
  int8_t   action;
2741
} STaskAction;
2742

2743
typedef struct SQueryNodeEpId {
2744
  int32_t nodeId;  // vgId or qnodeId
2745
  SEp     ep;
2746
} SQueryNodeEpId;
2747

2748
typedef struct {
2749
  SMsgHead       header;
2750
  uint64_t       sId;
2751
  SQueryNodeEpId epId;
2752
  SArray*        taskAction;  // SArray<STaskAction>
2753
} SSchedulerHbReq;
2754

2755
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2756
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2757
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2758

2759
typedef struct {
2760
  SQueryNodeEpId epId;
2761
  SArray*        taskStatus;  // SArray<STaskStatus>
2762
} SSchedulerHbRsp;
2763

2764
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2765
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2766
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2767

2768
typedef struct {
2769
  SMsgHead header;
2770
  uint64_t sId;
2771
  uint64_t queryId;
2772
  uint64_t taskId;
2773
  int64_t  refId;
2774
  int32_t  execId;
2775
} STaskCancelReq;
2776

2777
typedef struct {
2778
  int32_t code;
2779
} STaskCancelRsp;
2780

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

2790
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2791
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2792

2793
typedef enum {
2794
  TASK_NOTIFY_FINISHED = 1,
2795
} ETaskNotifyType;
2796

2797
typedef struct {
2798
  SMsgHead        header;
2799
  uint64_t        sId;
2800
  uint64_t        queryId;
2801
  uint64_t        taskId;
2802
  int64_t         refId;
2803
  int32_t         execId;
2804
  ETaskNotifyType type;
2805
} STaskNotifyReq;
2806

2807
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2808
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2809

2810
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2811
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2812

2813
typedef struct {
2814
  int32_t code;
2815
} STaskDropRsp;
2816

2817
#define STREAM_TRIGGER_AT_ONCE        1
2818
#define STREAM_TRIGGER_WINDOW_CLOSE   2
2819
#define STREAM_TRIGGER_MAX_DELAY      3
2820
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2821
#define STREAM_FILL_HISTORY_ON        1
2822
#define STREAM_FILL_HISTORY_OFF       0
2823
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2824
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2825
#define STREAM_CREATE_STABLE_TRUE     1
2826
#define STREAM_CREATE_STABLE_FALSE    0
2827

2828
typedef struct SColLocation {
2829
  int16_t  slotId;
2830
  col_id_t colId;
2831
  int8_t   type;
2832
} SColLocation;
2833

2834
typedef struct SVgroupVer {
2835
  int32_t vgId;
2836
  int64_t ver;
2837
} SVgroupVer;
2838

2839
typedef struct {
2840
  char    name[TSDB_STREAM_FNAME_LEN];
2841
  char    sourceDB[TSDB_DB_FNAME_LEN];
2842
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2843
  char*   sql;
2844
  char*   ast;
2845
  int8_t  igExists;
2846
  int8_t  triggerType;
2847
  int8_t  igExpired;
2848
  int8_t  fillHistory;  // process data inserted before creating stream
2849
  int64_t maxDelay;
2850
  int64_t watermark;
2851
  int32_t numOfTags;
2852
  SArray* pTags;  // array of SField
2853
  // 3.0.20
2854
  int64_t checkpointFreq;  // ms
2855
  // 3.0.2.3
2856
  int8_t   createStb;
2857
  uint64_t targetStbUid;
2858
  SArray*  fillNullCols;  // array of SColLocation
2859
  int64_t  deleteMark;
2860
  int8_t   igUpdate;
2861
  int64_t  lastTs;
2862
  SArray*  pVgroupVerList;
2863
  // 3.3.0.0
2864
  SArray* pCols;  // array of SField
2865
  int64_t smaId;
2866
} SCMCreateStreamReq;
2867

2868
typedef struct {
2869
  int64_t streamId;
2870
} SCMCreateStreamRsp;
2871

2872
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2873
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2874
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2875

2876
enum {
2877
  TOPIC_SUB_TYPE__DB = 1,
2878
  TOPIC_SUB_TYPE__TABLE,
2879
  TOPIC_SUB_TYPE__COLUMN,
2880
};
2881

2882
#define DEFAULT_MAX_POLL_INTERVAL 300000
2883
#define DEFAULT_SESSION_TIMEOUT   12000
2884

2885
typedef struct {
2886
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2887
  int8_t igExists;
2888
  int8_t subType;
2889
  int8_t withMeta;
2890
  char*  sql;
2891
  char   subDbName[TSDB_DB_FNAME_LEN];
2892
  char*  ast;
2893
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2894
} SCMCreateTopicReq;
2895

2896
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2897
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2898
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2899

2900
typedef struct {
2901
  int64_t consumerId;
2902
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2903

2904
typedef struct {
2905
  int64_t consumerId;
2906
  char    cgroup[TSDB_CGROUP_LEN];
2907
  char    clientId[TSDB_CLIENT_ID_LEN];
2908
  char    user[TSDB_USER_LEN];
2909
  char    fqdn[TSDB_FQDN_LEN];
2910
  SArray* topicNames;  // SArray<char**>
2911

2912
  int8_t  withTbName;
2913
  int8_t  autoCommit;
2914
  int32_t autoCommitInterval;
2915
  int8_t  resetOffsetCfg;
2916
  int8_t  enableReplay;
2917
  int8_t  enableBatchMeta;
2918
  int32_t sessionTimeoutMs;
2919
  int32_t maxPollIntervalMs;
2920
} SCMSubscribeReq;
2921

2922
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
2923
  int32_t tlen = 0;
2,600✔
2924
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,600!
2925
  tlen += taosEncodeString(buf, pReq->cgroup);
2,600✔
2926
  tlen += taosEncodeString(buf, pReq->clientId);
2,600✔
2927

2928
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,600!
2929
  tlen += taosEncodeFixedI32(buf, topicNum);
2,598✔
2930

2931
  for (int32_t i = 0; i < topicNum; i++) {
3,664✔
2932
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,132✔
2933
  }
2934

2935
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,598!
2936
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,598!
2937
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,598!
2938
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,598!
2939
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,598!
2940
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,598!
2941
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,598!
2942
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,598!
2943
  tlen += taosEncodeString(buf, pReq->user);
2,598✔
2944
  tlen += taosEncodeString(buf, pReq->fqdn);
2,598✔
2945

2946
  return tlen;
2,598✔
2947
}
2948

2949
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
2950
  void* start = buf;
330✔
2951
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
330!
2952
  buf = taosDecodeStringTo(buf, pReq->cgroup);
330✔
2953
  buf = taosDecodeStringTo(buf, pReq->clientId);
330✔
2954

2955
  int32_t topicNum = 0;
330!
2956
  buf = taosDecodeFixedI32(buf, &topicNum);
330✔
2957

2958
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
330✔
2959
  if (pReq->topicNames == NULL) {
330!
2960
    return terrno;
×
2961
  }
2962
  for (int32_t i = 0; i < topicNum; i++) {
504✔
2963
    char* name = NULL;
174✔
2964
    buf = taosDecodeString(buf, &name);
174✔
2965
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
348!
2966
      return terrno;
×
2967
    }
2968
  }
2969

2970
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
330✔
2971
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
330✔
2972
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
330!
2973
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
330✔
2974
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
330✔
2975
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
330✔
2976
  if ((char*)buf - (char*)start < len) {
330!
2977
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
330!
2978
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
330!
2979
    buf = taosDecodeStringTo(buf, pReq->user);
330✔
2980
    buf = taosDecodeStringTo(buf, pReq->fqdn);
660✔
2981
  } else {
2982
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
2983
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
2984
  }
2985

2986
  return 0;
330✔
2987
}
2988

2989
typedef struct {
2990
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
2991
  SArray* removedConsumers;  // SArray<int64_t>
2992
  SArray* newConsumers;      // SArray<int64_t>
2993
} SMqRebInfo;
2994

2995
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
2996
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
298✔
2997
  if (pRebInfo == NULL) {
298!
2998
    return NULL;
×
2999
  }
3000
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
298✔
3001
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
298✔
3002
  if (pRebInfo->removedConsumers == NULL) {
298!
3003
    goto _err;
×
3004
  }
3005
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
298✔
3006
  if (pRebInfo->newConsumers == NULL) {
298!
3007
    goto _err;
×
3008
  }
3009
  return pRebInfo;
298✔
3010
_err:
×
3011
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3012
  taosArrayDestroy(pRebInfo->newConsumers);
×
3013
  taosMemoryFreeClear(pRebInfo);
×
3014
  return NULL;
×
3015
}
3016

3017
typedef struct {
3018
  int64_t streamId;
3019
  int64_t checkpointId;
3020
  char    streamName[TSDB_STREAM_FNAME_LEN];
3021
} SMStreamDoCheckpointMsg;
3022

3023
typedef struct {
3024
  int64_t status;
3025
} SMVSubscribeRsp;
3026

3027
typedef struct {
3028
  char    name[TSDB_TOPIC_FNAME_LEN];
3029
  int8_t  igNotExists;
3030
  int32_t sqlLen;
3031
  char*   sql;
3032
} SMDropTopicReq;
3033

3034
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3035
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3036
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3037

3038
typedef struct {
3039
  char   topic[TSDB_TOPIC_FNAME_LEN];
3040
  char   cgroup[TSDB_CGROUP_LEN];
3041
  int8_t igNotExists;
3042
} SMDropCgroupReq;
3043

3044
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3045
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3046

3047
typedef struct {
3048
  int8_t reserved;
3049
} SMDropCgroupRsp;
3050

3051
typedef struct {
3052
  char    name[TSDB_TABLE_FNAME_LEN];
3053
  int8_t  alterType;
3054
  SSchema schema;
3055
} SAlterTopicReq;
3056

3057
typedef struct {
3058
  SMsgHead head;
3059
  char     name[TSDB_TABLE_FNAME_LEN];
3060
  int64_t  tuid;
3061
  int32_t  sverson;
3062
  int32_t  execLen;
3063
  char*    executor;
3064
  int32_t  sqlLen;
3065
  char*    sql;
3066
} SDCreateTopicReq;
3067

3068
typedef struct {
3069
  SMsgHead head;
3070
  char     name[TSDB_TABLE_FNAME_LEN];
3071
  int64_t  tuid;
3072
} SDDropTopicReq;
3073

3074
typedef struct {
3075
  int64_t maxdelay[2];
3076
  int64_t watermark[2];
3077
  int64_t deleteMark[2];
3078
  int32_t qmsgLen[2];
3079
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3080
} SRSmaParam;
3081

3082
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3083
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3084

3085
// TDMT_VND_CREATE_STB ==============
3086
typedef struct SVCreateStbReq {
3087
  char*           name;
3088
  tb_uid_t        suid;
3089
  int8_t          rollup;
3090
  SSchemaWrapper  schemaRow;
3091
  SSchemaWrapper  schemaTag;
3092
  SRSmaParam      rsmaParam;
3093
  int32_t         alterOriDataLen;
3094
  void*           alterOriData;
3095
  int8_t          source;
3096
  int8_t          colCmpred;
3097
  SColCmprWrapper colCmpr;
3098
} SVCreateStbReq;
3099

3100
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3101
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3102

3103
// TDMT_VND_DROP_STB ==============
3104
typedef struct SVDropStbReq {
3105
  char*    name;
3106
  tb_uid_t suid;
3107
} SVDropStbReq;
3108

3109
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3110
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3111

3112
// TDMT_VND_CREATE_TABLE ==============
3113
#define TD_CREATE_IF_NOT_EXISTS 0x1
3114
typedef struct SVCreateTbReq {
3115
  int32_t  flags;
3116
  char*    name;
3117
  tb_uid_t uid;
3118
  int64_t  btime;
3119
  int32_t  ttl;
3120
  int32_t  commentLen;
3121
  char*    comment;
3122
  int8_t   type;
3123
  union {
3124
    struct {
3125
      char*    stbName;  // super table name
3126
      uint8_t  tagNum;
3127
      tb_uid_t suid;
3128
      SArray*  tagName;
3129
      uint8_t* pTag;
3130
    } ctb;
3131
    struct {
3132
      SSchemaWrapper schemaRow;
3133
    } ntb;
3134
  };
3135
  int32_t         sqlLen;
3136
  char*           sql;
3137
  SColCmprWrapper colCmpr;
3138
} SVCreateTbReq;
3139

3140
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3141
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3142
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3143

3144
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3,414✔
3145
  if (NULL == req) {
21,774,907!
3146
    return;
21,600,274✔
3147
  }
3148

3149
  taosMemoryFreeClear(req->sql);
174,633!
3150
  taosMemoryFreeClear(req->name);
174,633!
3151
  taosMemoryFreeClear(req->comment);
174,636!
3152
  if (req->type == TSDB_CHILD_TABLE) {
174,636!
3153
    taosMemoryFreeClear(req->ctb.pTag);
161,139!
3154
    taosMemoryFreeClear(req->ctb.stbName);
161,136!
3155
    taosArrayDestroy(req->ctb.tagName);
161,138✔
3156
    req->ctb.tagName = NULL;
161,145✔
3157
  } else if (req->type == TSDB_NORMAL_TABLE) {
13,497!
3158
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,496!
3159
  }
3160
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
174,642!
3161
}
3162

3163
typedef struct {
3164
  int32_t nReqs;
3165
  union {
3166
    SVCreateTbReq* pReqs;
3167
    SArray*        pArray;
3168
  };
3169
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3170
} SVCreateTbBatchReq;
3171

3172
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3173
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3174
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3175

3176
typedef struct {
3177
  int32_t        code;
3178
  STableMetaRsp* pMeta;
3179
} SVCreateTbRsp, SVUpdateTbRsp;
3180

3181
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3182
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3183
void tFreeSVCreateTbRsp(void* param);
3184

3185
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3186
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3187

3188
typedef struct {
3189
  int32_t nRsps;
3190
  union {
3191
    SVCreateTbRsp* pRsps;
3192
    SArray*        pArray;
3193
  };
3194
} SVCreateTbBatchRsp;
3195

3196
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3197
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3198

3199
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3200
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3201

3202
// TDMT_VND_DROP_TABLE =================
3203
typedef struct {
3204
  char*    name;
3205
  uint64_t suid;  // for tmq in wal format
3206
  int8_t   igNotExists;
3207
} SVDropTbReq;
3208

3209
typedef struct {
3210
  int32_t code;
3211
} SVDropTbRsp;
3212

3213
typedef struct {
3214
  int32_t nReqs;
3215
  union {
3216
    SVDropTbReq* pReqs;
3217
    SArray*      pArray;
3218
  };
3219
} SVDropTbBatchReq;
3220

3221
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3222
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3223

3224
typedef struct {
3225
  int32_t nRsps;
3226
  union {
3227
    SVDropTbRsp* pRsps;
3228
    SArray*      pArray;
3229
  };
3230
} SVDropTbBatchRsp;
3231

3232
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3233
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3234

3235
// TDMT_VND_ALTER_TABLE =====================
3236
typedef struct {
3237
  char*   tbName;
3238
  int8_t  action;
3239
  char*   colName;
3240
  int32_t colId;
3241
  // TSDB_ALTER_TABLE_ADD_COLUMN
3242
  int8_t  type;
3243
  int8_t  flags;
3244
  int32_t bytes;
3245
  // TSDB_ALTER_TABLE_DROP_COLUMN
3246
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3247
  int8_t   colModType;
3248
  int32_t  colModBytes;
3249
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3250
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3251
  int8_t   isNull;
3252
  int8_t   tagType;
3253
  int8_t   tagFree;
3254
  uint32_t nTagVal;
3255
  uint8_t* pTagVal;
3256
  SArray*  pTagArray;
3257
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3258
  int8_t   updateTTL;
3259
  int32_t  newTTL;
3260
  int32_t  newCommentLen;
3261
  char*    newComment;
3262
  int64_t  ctimeMs;   // fill by vnode
3263
  int8_t   source;    // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3264
  uint32_t compress;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3265
} SVAlterTbReq;
3266

3267
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3268
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3269
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3270

3271
typedef struct {
3272
  int32_t        code;
3273
  STableMetaRsp* pMeta;
3274
} SVAlterTbRsp;
3275

3276
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3277
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3278
// ======================
3279

3280
typedef struct {
3281
  SMsgHead head;
3282
  int64_t  uid;
3283
  int32_t  tid;
3284
  int16_t  tversion;
3285
  int16_t  colId;
3286
  int8_t   type;
3287
  int16_t  bytes;
3288
  int32_t  tagValLen;
3289
  int16_t  numOfTags;
3290
  int32_t  schemaLen;
3291
  char     data[];
3292
} SUpdateTagValReq;
3293

3294
typedef struct {
3295
  SMsgHead head;
3296
} SUpdateTagValRsp;
3297

3298
typedef struct {
3299
  SMsgHead head;
3300
} SVShowTablesReq;
3301

3302
typedef struct {
3303
  SMsgHead head;
3304
  int32_t  id;
3305
} SVShowTablesFetchReq;
3306

3307
typedef struct {
3308
  int64_t useconds;
3309
  int8_t  completed;  // all results are returned to client
3310
  int8_t  precision;
3311
  int8_t  compressed;
3312
  int32_t compLen;
3313
  int32_t numOfRows;
3314
  char    data[];
3315
} SVShowTablesFetchRsp;
3316

3317
typedef struct {
3318
  int64_t consumerId;
3319
  int32_t epoch;
3320
  char    cgroup[TSDB_CGROUP_LEN];
3321
} SMqAskEpReq;
3322

3323
typedef struct {
3324
  int32_t key;
3325
  int32_t valueLen;
3326
  void*   value;
3327
} SKv;
3328

3329
typedef struct {
3330
  int64_t tscRid;
3331
  int8_t  connType;
3332
} SClientHbKey;
3333

3334
typedef struct {
3335
  int64_t tid;
3336
  char    status[TSDB_JOB_STATUS_LEN];
3337
} SQuerySubDesc;
3338

3339
typedef struct {
3340
  char     sql[TSDB_SHOW_SQL_LEN];
3341
  uint64_t queryId;
3342
  int64_t  useconds;
3343
  int64_t  stime;  // timestamp precision ms
3344
  int64_t  reqRid;
3345
  bool     stableQuery;
3346
  bool     isSubQuery;
3347
  char     fqdn[TSDB_FQDN_LEN];
3348
  int32_t  subPlanNum;
3349
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3350
} SQueryDesc;
3351

3352
typedef struct {
3353
  uint32_t connId;
3354
  SArray*  queryDesc;  // SArray<SQueryDesc>
3355
} SQueryHbReqBasic;
3356

3357
typedef struct {
3358
  uint32_t connId;
3359
  uint64_t killRid;
3360
  int32_t  totalDnodes;
3361
  int32_t  onlineDnodes;
3362
  int8_t   killConnection;
3363
  int8_t   align[3];
3364
  SEpSet   epSet;
3365
  SArray*  pQnodeList;
3366
} SQueryHbRspBasic;
3367

3368
typedef struct SAppClusterSummary {
3369
  uint64_t numOfInsertsReq;
3370
  uint64_t numOfInsertRows;
3371
  uint64_t insertElapsedTime;
3372
  uint64_t insertBytes;  // submit to tsdb since launched.
3373

3374
  uint64_t fetchBytes;
3375
  uint64_t numOfQueryReq;
3376
  uint64_t queryElapsedTime;
3377
  uint64_t numOfSlowQueries;
3378
  uint64_t totalRequests;
3379
  uint64_t currentRequests;  // the number of SRequestObj
3380
} SAppClusterSummary;
3381

3382
typedef struct {
3383
  int64_t            appId;
3384
  int32_t            pid;
3385
  char               name[TSDB_APP_NAME_LEN];
3386
  int64_t            startTime;
3387
  SAppClusterSummary summary;
3388
} SAppHbReq;
3389

3390
typedef struct {
3391
  SClientHbKey      connKey;
3392
  int64_t           clusterId;
3393
  SAppHbReq         app;
3394
  SQueryHbReqBasic* query;
3395
  SHashObj*         info;  // hash<Skv.key, Skv>
3396
} SClientHbReq;
3397

3398
typedef struct {
3399
  int64_t reqId;
3400
  SArray* reqs;  // SArray<SClientHbReq>
3401
  int64_t ipWhiteList;
3402
} SClientHbBatchReq;
3403

3404
typedef struct {
3405
  SClientHbKey      connKey;
3406
  int32_t           status;
3407
  SQueryHbRspBasic* query;
3408
  SArray*           info;  // Array<Skv>
3409
} SClientHbRsp;
3410

3411
typedef struct {
3412
  int64_t       reqId;
3413
  int64_t       rspId;
3414
  int32_t       svrTimestamp;
3415
  SArray*       rsps;  // SArray<SClientHbRsp>
3416
  SMonitorParas monitorParas;
3417
} SClientHbBatchRsp;
3418

3419
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
202,250✔
3420

3421
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3422
  void* pIter = taosHashIterate(info, NULL);
487,622✔
3423
  while (pIter != NULL) {
839,000!
3424
    SKv* kv = (SKv*)pIter;
351,331✔
3425
    taosMemoryFreeClear(kv->value);
351,331!
3426
    pIter = taosHashIterate(info, pIter);
351,329✔
3427
  }
3428
}
487,669✔
3429

3430
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
310,768✔
3431
  SQueryDesc* desc = (SQueryDesc*)pDesc;
310,768✔
3432
  if (desc->subDesc) {
310,768✔
3433
    taosArrayDestroy(desc->subDesc);
304,139✔
3434
    desc->subDesc = NULL;
304,137✔
3435
  }
3436
}
310,766✔
3437

3438
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
572,126✔
3439
  SClientHbReq* req = (SClientHbReq*)pReq;
584,063✔
3440
  if (req->query) {
584,063!
3441
    if (req->query->queryDesc) {
566,754!
3442
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
42,271✔
3443
    }
3444
    taosMemoryFreeClear(req->query);
566,754!
3445
  }
3446

3447
  if (req->info) {
584,065!
3448
    tFreeReqKvHash(req->info);
487,622✔
3449
    taosHashCleanup(req->info);
487,669✔
3450
    req->info = NULL;
487,637✔
3451
  }
3452
}
469,372✔
3453

3454
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3455
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3456

3457
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3458
  if (pReq == NULL) return;
37,920!
3459
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
37,920✔
3460
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
37,920✔
3461
  taosMemoryFree(pReq);
37,920✔
3462
}
3463

3464
static FORCE_INLINE void tFreeClientKv(void* pKv) {
130,152✔
3465
  SKv* kv = (SKv*)pKv;
130,152✔
3466
  if (kv) {
130,152!
3467
    taosMemoryFreeClear(kv->value);
130,152!
3468
  }
3469
}
130,152✔
3470

3471
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
569,907✔
3472
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
569,907✔
3473
  if (rsp->query) {
569,907✔
3474
    taosArrayDestroy(rsp->query->pQnodeList);
564,699✔
3475
    taosMemoryFreeClear(rsp->query);
564,843!
3476
  }
3477
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
570,125!
3478
}
112,751✔
3479

3480
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3481
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
412,469✔
3482
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
412,469✔
3483
}
412,535✔
3484

3485
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3486
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3487
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3488

3489
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3490
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
634,566!
3491
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
634,566!
3492
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
634,566!
3493
  return 0;
317,283✔
3494
}
3495

3496
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3497
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
645,637!
3498
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
645,637!
3499
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
322,818✔
3500
  if (pKv->value == NULL) {
322,828!
3501
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3502
  }
3503
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
322,828!
3504
  return 0;
322,818✔
3505
}
3506

3507
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3508
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,287,438!
3509
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,287,438!
3510
  return 0;
1,143,719✔
3511
}
3512

3513
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3514
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,140,281!
3515
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,140,311!
3516
  return 0;
570,163✔
3517
}
3518

3519
typedef struct {
3520
  int32_t vgId;
3521
  // TODO stas
3522
} SMqReportVgInfo;
3523

3524
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3525
  int32_t tlen = 0;
3526
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3527
  return tlen;
3528
}
3529

3530
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3531
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3532
  return buf;
3533
}
3534

3535
typedef struct {
3536
  int32_t epoch;
3537
  int64_t topicUid;
3538
  char    name[TSDB_TOPIC_FNAME_LEN];
3539
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3540
} SMqTopicInfo;
3541

3542
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3543
  int32_t tlen = 0;
3544
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3545
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3546
  tlen += taosEncodeString(buf, pTopicInfo->name);
3547
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3548
  tlen += taosEncodeFixedI32(buf, sz);
3549
  for (int32_t i = 0; i < sz; i++) {
3550
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3551
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3552
  }
3553
  return tlen;
3554
}
3555

3556
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3557
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3558
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3559
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3560
  int32_t sz;
3561
  buf = taosDecodeFixedI32(buf, &sz);
3562
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3563
    return NULL;
3564
  }
3565
  for (int32_t i = 0; i < sz; i++) {
3566
    SMqReportVgInfo vgInfo;
3567
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3568
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3569
      return NULL;
3570
    }
3571
  }
3572
  return buf;
3573
}
3574

3575
typedef struct {
3576
  int32_t status;  // ask hb endpoint
3577
  int32_t epoch;
3578
  int64_t consumerId;
3579
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3580
} SMqReportReq;
3581

3582
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3583
  int32_t tlen = 0;
3584
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3585
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3586
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3587
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3588
  tlen += taosEncodeFixedI32(buf, sz);
3589
  for (int32_t i = 0; i < sz; i++) {
3590
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3591
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3592
  }
3593
  return tlen;
3594
}
3595

3596
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3597
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3598
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3599
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3600
  int32_t sz;
3601
  buf = taosDecodeFixedI32(buf, &sz);
3602
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3603
    return NULL;
3604
  }
3605
  for (int32_t i = 0; i < sz; i++) {
3606
    SMqTopicInfo topicInfo;
3607
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3608
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3609
      return NULL;
3610
    }
3611
  }
3612
  return buf;
3613
}
3614

3615
typedef struct {
3616
  SMsgHead head;
3617
  int64_t  leftForVer;
3618
  int32_t  vgId;
3619
  int64_t  consumerId;
3620
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3621
} SMqVDeleteReq;
3622

3623
typedef struct {
3624
  int8_t reserved;
3625
} SMqVDeleteRsp;
3626

3627
typedef struct {
3628
  char    name[TSDB_STREAM_FNAME_LEN];
3629
  int8_t  igNotExists;
3630
  int32_t sqlLen;
3631
  char*   sql;
3632
} SMDropStreamReq;
3633

3634
typedef struct {
3635
  int8_t reserved;
3636
} SMDropStreamRsp;
3637

3638
typedef struct {
3639
  SMsgHead head;
3640
  int64_t  resetRelHalt;  // reset related stream task halt status
3641
  int64_t  streamId;
3642
  int32_t  taskId;
3643
} SVDropStreamTaskReq;
3644

3645
typedef struct {
3646
  int8_t reserved;
3647
} SVDropStreamTaskRsp;
3648

3649
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3650
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3651
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3652

3653
typedef struct SVUpdateCheckpointInfoReq {
3654
  SMsgHead head;
3655
  int64_t  streamId;
3656
  int32_t  taskId;
3657
  int64_t  checkpointId;
3658
  int64_t  checkpointVer;
3659
  int64_t  checkpointTs;
3660
  int32_t  transId;
3661
  int64_t  hStreamId;  // add encode/decode
3662
  int64_t  hTaskId;
3663
  int8_t   dropRelHTask;
3664
} SVUpdateCheckpointInfoReq;
3665

3666
typedef struct {
3667
  int64_t leftForVer;
3668
  int32_t vgId;
3669
  int64_t oldConsumerId;
3670
  int64_t newConsumerId;
3671
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3672
  int8_t  subType;
3673
  int8_t  withMeta;
3674
  char*   qmsg;  // SubPlanToString
3675
  int64_t suid;
3676
} SMqRebVgReq;
3677

3678
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3679
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3680

3681
typedef struct {
3682
  char    topic[TSDB_TOPIC_FNAME_LEN];
3683
  int64_t ntbUid;
3684
  SArray* colIdList;  // SArray<int16_t>
3685
} STqCheckInfo;
3686

3687
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3688
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3689
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3690

3691
// tqOffset
3692
enum {
3693
  TMQ_OFFSET__RESET_NONE = -3,
3694
  TMQ_OFFSET__RESET_EARLIEST = -2,
3695
  TMQ_OFFSET__RESET_LATEST = -1,
3696
  TMQ_OFFSET__LOG = 1,
3697
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3698
  TMQ_OFFSET__SNAPSHOT_META = 3,
3699
};
3700

3701
enum {
3702
  WITH_DATA = 0,
3703
  WITH_META = 1,
3704
  ONLY_META = 2,
3705
};
3706

3707
#define TQ_OFFSET_VERSION 1
3708

3709
typedef struct {
3710
  int8_t type;
3711
  union {
3712
    // snapshot
3713
    struct {
3714
      int64_t uid;
3715
      int64_t ts;
3716
      SValue  primaryKey;
3717
    };
3718
    // log
3719
    struct {
3720
      int64_t version;
3721
    };
3722
  };
3723
} STqOffsetVal;
3724

3725
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3726
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
481✔
3727
  pOffsetVal->uid = uid;
481✔
3728
  pOffsetVal->ts = ts;
481✔
3729
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
481!
3730
    taosMemoryFree(pOffsetVal->primaryKey.pData);
1✔
3731
  }
3732
  pOffsetVal->primaryKey = primaryKey;
481✔
3733
}
481✔
3734

3735
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3736
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
4✔
3737
  pOffsetVal->uid = uid;
4✔
3738
}
4✔
3739

3740
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3741
  pOffsetVal->type = TMQ_OFFSET__LOG;
35,325✔
3742
  pOffsetVal->version = ver;
35,325✔
3743
}
35,325✔
3744

3745
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3746
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3747
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3748
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3749
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3750
void    tOffsetDestroy(void* pVal);
3751

3752
typedef struct {
3753
  STqOffsetVal val;
3754
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3755
} STqOffset;
3756

3757
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3758
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3759
void    tDeleteSTqOffset(void* val);
3760

3761
typedef struct SMqVgOffset {
3762
  int64_t   consumerId;
3763
  STqOffset offset;
3764
} SMqVgOffset;
3765

3766
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3767
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3768

3769
typedef struct {
3770
  SMsgHead head;
3771
  int64_t  streamId;
3772
  int32_t  taskId;
3773
} SVPauseStreamTaskReq, SVResetStreamTaskReq;
3774

3775
typedef struct {
3776
  char   name[TSDB_STREAM_FNAME_LEN];
3777
  int8_t igNotExists;
3778
} SMPauseStreamReq;
3779

3780
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3781
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3782

3783
typedef struct {
3784
  SMsgHead head;
3785
  int32_t  taskId;
3786
  int64_t  streamId;
3787
  int8_t   igUntreated;
3788
} SVResumeStreamTaskReq;
3789

3790
typedef struct {
3791
  int8_t reserved;
3792
} SVResumeStreamTaskRsp;
3793

3794
typedef struct {
3795
  char   name[TSDB_STREAM_FNAME_LEN];
3796
  int8_t igNotExists;
3797
  int8_t igUntreated;
3798
} SMResumeStreamReq;
3799

3800
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3801
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3802

3803
typedef struct {
3804
  char    name[TSDB_TABLE_FNAME_LEN];
3805
  char    stb[TSDB_TABLE_FNAME_LEN];
3806
  int8_t  igExists;
3807
  int8_t  intervalUnit;
3808
  int8_t  slidingUnit;
3809
  int8_t  timezone;
3810
  int32_t dstVgId;  // for stream
3811
  int64_t interval;
3812
  int64_t offset;
3813
  int64_t sliding;
3814
  int64_t maxDelay;
3815
  int64_t watermark;
3816
  int32_t exprLen;        // strlen + 1
3817
  int32_t tagsFilterLen;  // strlen + 1
3818
  int32_t sqlLen;         // strlen + 1
3819
  int32_t astLen;         // strlen + 1
3820
  char*   expr;
3821
  char*   tagsFilter;
3822
  char*   sql;
3823
  char*   ast;
3824
  int64_t deleteMark;
3825
  int64_t lastTs;
3826
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3827
  SArray* pVgroupVerList;
3828
  int8_t  recursiveTsma;
3829
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3830
} SMCreateSmaReq;
3831

3832
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3833
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3834
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3835

3836
typedef struct {
3837
  char   name[TSDB_TABLE_FNAME_LEN];
3838
  int8_t igNotExists;
3839
} SMDropSmaReq;
3840

3841
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3842
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3843

3844
typedef struct {
3845
  char   dbFName[TSDB_DB_FNAME_LEN];
3846
  char   stbName[TSDB_TABLE_NAME_LEN];
3847
  char   colName[TSDB_COL_NAME_LEN];
3848
  char   idxName[TSDB_INDEX_FNAME_LEN];
3849
  int8_t idxType;
3850
} SCreateTagIndexReq;
3851

3852
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3853
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3854

3855
typedef SMDropSmaReq SDropTagIndexReq;
3856

3857
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3858
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3859

3860
typedef struct {
3861
  int8_t         version;       // for compatibility(default 0)
3862
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3863
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3864
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3865
  int32_t        dstVgId;
3866
  char           indexName[TSDB_INDEX_NAME_LEN];
3867
  int32_t        exprLen;
3868
  int32_t        tagsFilterLen;
3869
  int64_t        indexUid;
3870
  tb_uid_t       tableUid;  // super/child/common table uid
3871
  tb_uid_t       dstTbUid;  // for dstVgroup
3872
  int64_t        interval;
3873
  int64_t        offset;  // use unit by precision of DB
3874
  int64_t        sliding;
3875
  char*          dstTbName;  // for dstVgroup
3876
  char*          expr;       // sma expression
3877
  char*          tagsFilter;
3878
  SSchemaWrapper schemaRow;  // for dstVgroup
3879
  SSchemaWrapper schemaTag;  // for dstVgroup
3880
} STSma;                     // Time-range-wise SMA
3881

3882
typedef STSma SVCreateTSmaReq;
3883

3884
typedef struct {
3885
  int8_t  type;  // 0 status report, 1 update data
3886
  int64_t indexUid;
3887
  int64_t skey;  // start TS key of interval/sliding window
3888
} STSmaMsg;
3889

3890
typedef struct {
3891
  int64_t indexUid;
3892
  char    indexName[TSDB_INDEX_NAME_LEN];
3893
} SVDropTSmaReq;
3894

3895
typedef struct {
3896
  int tmp;  // TODO: to avoid compile error
3897
} SVCreateTSmaRsp, SVDropTSmaRsp;
3898

3899
#if 0
3900
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3901
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3902
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3903
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3904
#endif
3905

3906
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3907
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3908
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3909
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3910

3911
typedef struct {
3912
  int32_t number;
3913
  STSma*  tSma;
3914
} STSmaWrapper;
3915

3916
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3917
  if (pSma) {
2!
3918
    taosMemoryFreeClear(pSma->dstTbName);
2!
3919
    taosMemoryFreeClear(pSma->expr);
2!
3920
    taosMemoryFreeClear(pSma->tagsFilter);
2!
3921
  }
3922
}
2✔
3923

3924
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3925
  if (pSW) {
×
3926
    if (pSW->tSma) {
×
3927
      if (deepCopy) {
×
3928
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3929
          tDestroyTSma(pSW->tSma + i);
×
3930
        }
3931
      }
3932
      taosMemoryFreeClear(pSW->tSma);
×
3933
    }
3934
  }
3935
}
×
3936

3937
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3938
  tDestroyTSmaWrapper(pSW, deepCopy);
×
3939
  taosMemoryFreeClear(pSW);
×
3940
  return NULL;
×
3941
}
3942

3943
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3944
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3945

3946
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
3947
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
3948

3949
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
3950
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
3951
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3952
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
3953
  }
3954
  return 0;
×
3955
}
3956

3957
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
3958
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
3959
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3960
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
3961
  }
3962
  return 0;
×
3963
}
3964

3965
typedef struct {
3966
  int idx;
3967
} SMCreateFullTextReq;
3968

3969
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3970
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3971
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
3972

3973
typedef struct {
3974
  char   name[TSDB_TABLE_FNAME_LEN];
3975
  int8_t igNotExists;
3976
} SMDropFullTextReq;
3977

3978
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
3979
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
3980

3981
typedef struct {
3982
  char indexFName[TSDB_INDEX_FNAME_LEN];
3983
} SUserIndexReq;
3984

3985
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
3986
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
3987

3988
typedef struct {
3989
  char dbFName[TSDB_DB_FNAME_LEN];
3990
  char tblFName[TSDB_TABLE_FNAME_LEN];
3991
  char colName[TSDB_COL_NAME_LEN];
3992
  char indexType[TSDB_INDEX_TYPE_LEN];
3993
  char indexExts[TSDB_INDEX_EXTS_LEN];
3994
} SUserIndexRsp;
3995

3996
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
3997
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
3998

3999
typedef struct {
4000
  char tbFName[TSDB_TABLE_FNAME_LEN];
4001
} STableIndexReq;
4002

4003
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4004
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4005

4006
typedef struct {
4007
  int8_t  intervalUnit;
4008
  int8_t  slidingUnit;
4009
  int64_t interval;
4010
  int64_t offset;
4011
  int64_t sliding;
4012
  int64_t dstTbUid;
4013
  int32_t dstVgId;
4014
  SEpSet  epSet;
4015
  char*   expr;
4016
} STableIndexInfo;
4017

4018
typedef struct {
4019
  char     tbName[TSDB_TABLE_NAME_LEN];
4020
  char     dbFName[TSDB_DB_FNAME_LEN];
4021
  uint64_t suid;
4022
  int32_t  version;
4023
  int32_t  indexSize;
4024
  SArray*  pIndex;  // STableIndexInfo
4025
} STableIndexRsp;
4026

4027
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4028
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4029
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4030

4031
void tFreeSTableIndexInfo(void* pInfo);
4032

4033
typedef struct {
4034
  int8_t  mqMsgType;
4035
  int32_t code;
4036
  int32_t epoch;
4037
  int64_t consumerId;
4038
  int64_t walsver;
4039
  int64_t walever;
4040
} SMqRspHead;
4041

4042
typedef struct {
4043
  SMsgHead     head;
4044
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4045
  int8_t       withTbName;
4046
  int8_t       useSnapshot;
4047
  int32_t      epoch;
4048
  uint64_t     reqId;
4049
  int64_t      consumerId;
4050
  int64_t      timeout;
4051
  STqOffsetVal reqOffset;
4052
  int8_t       enableReplay;
4053
  int8_t       sourceExcluded;
4054
  int8_t       enableBatchMeta;
4055
} SMqPollReq;
4056

4057
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4058
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4059
void    tDestroySMqPollReq(SMqPollReq* pReq);
4060

4061
typedef struct {
4062
  int32_t vgId;
4063
  int64_t offset;
4064
  SEpSet  epSet;
4065
} SMqSubVgEp;
4066

4067
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4068
  int32_t tlen = 0;
830✔
4069
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
830✔
4070
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
830✔
4071
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
830✔
4072
  return tlen;
830✔
4073
}
4074

4075
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4076
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,701!
4077
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,701!
4078
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,701✔
4079
  return buf;
4,701✔
4080
}
4081

4082
typedef struct {
4083
  char           topic[TSDB_TOPIC_FNAME_LEN];
4084
  char           db[TSDB_DB_FNAME_LEN];
4085
  SArray*        vgs;  // SArray<SMqSubVgEp>
4086
  SSchemaWrapper schema;
4087
} SMqSubTopicEp;
4088

4089
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4090
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4091
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4092

4093
typedef struct {
4094
  SMqRspHead   head;
4095
  STqOffsetVal rspOffset;
4096
  int16_t      resMsgType;
4097
  int32_t      metaRspLen;
4098
  void*        metaRsp;
4099
} SMqMetaRsp;
4100

4101
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4102
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4103
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4104

4105
#define MQ_DATA_RSP_VERSION 100
4106

4107
typedef struct {
4108
  SMqRspHead   head;
4109
  STqOffsetVal rspOffset;
4110
  STqOffsetVal reqOffset;
4111
  int32_t      blockNum;
4112
  int8_t       withTbName;
4113
  int8_t       withSchema;
4114
  SArray*      blockDataLen;
4115
  SArray*      blockData;
4116
  SArray*      blockTbName;
4117
  SArray*      blockSchema;
4118

4119
  union{
4120
    struct{
4121
      int64_t          sleepTime;
4122
    };
4123
    struct{
4124
      int32_t          createTableNum;
4125
      SArray*          createTableLen;
4126
      SArray*          createTableReq;
4127
    };
4128
  };
4129

4130
} SMqDataRsp;
4131

4132
int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj);
4133
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4134
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4135

4136
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4137
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4138
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4139

4140
typedef struct SMqBatchMetaRsp {
4141
  SMqRspHead   head;  // not serialize
4142
  STqOffsetVal rspOffset;
4143
  SArray*      batchMetaLen;
4144
  SArray*      batchMetaReq;
4145
  void*        pMetaBuff;    // not serialize
4146
  uint32_t     metaBuffLen;  // not serialize
4147
} SMqBatchMetaRsp;
4148

4149
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4150
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4151
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4152
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4153

4154
typedef struct {
4155
  SMqRspHead head;
4156
  char       cgroup[TSDB_CGROUP_LEN];
4157
  SArray*    topics;  // SArray<SMqSubTopicEp>
4158
} SMqAskEpRsp;
4159

4160
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4161
  int32_t tlen = 0;
1,382✔
4162
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4163
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,382!
4164
  tlen += taosEncodeFixedI32(buf, sz);
1,382✔
4165
  for (int32_t i = 0; i < sz; i++) {
1,908✔
4166
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
526✔
4167
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
526✔
4168
  }
4169
  return tlen;
1,382✔
4170
}
4171

4172
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4173
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4174
  int32_t sz;
4175
  buf = taosDecodeFixedI32(buf, &sz);
9,161✔
4176
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
9,161✔
4177
  if (pRsp->topics == NULL) {
9,161!
4178
    return NULL;
×
4179
  }
4180
  for (int32_t i = 0; i < sz; i++) {
12,868✔
4181
    SMqSubTopicEp topicEp;
4182
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,707✔
4183
    if (buf == NULL) {
3,707!
4184
      return NULL;
×
4185
    }
4186
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
7,414!
4187
      return NULL;
×
4188
    }
4189
  }
4190
  return buf;
9,161✔
4191
}
4192

4193
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4194
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
10,562✔
4195
}
10,562✔
4196

4197
typedef struct {
4198
  int32_t      vgId;
4199
  STqOffsetVal offset;
4200
  int64_t      rows;
4201
  int64_t      ever;
4202
} OffsetRows;
4203

4204
typedef struct {
4205
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4206
  SArray* offsetRows;
4207
} TopicOffsetRows;
4208

4209
typedef struct {
4210
  int64_t consumerId;
4211
  int32_t epoch;
4212
  SArray* topics;
4213
  int8_t  pollFlag;
4214
} SMqHbReq;
4215

4216
typedef struct {
4217
  char   topic[TSDB_TOPIC_FNAME_LEN];
4218
  int8_t noPrivilege;
4219
} STopicPrivilege;
4220

4221
typedef struct {
4222
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4223
  int32_t debugFlag;
4224
} SMqHbRsp;
4225

4226
typedef struct {
4227
  SMsgHead head;
4228
  int64_t  consumerId;
4229
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4230
} SMqSeekReq;
4231

4232
#define TD_AUTO_CREATE_TABLE 0x1
4233
typedef struct {
4234
  int64_t       suid;
4235
  int64_t       uid;
4236
  int32_t       sver;
4237
  uint32_t      nData;
4238
  uint8_t*      pData;
4239
  SVCreateTbReq cTbReq;
4240
} SVSubmitBlk;
4241

4242
typedef struct {
4243
  SMsgHead header;
4244
  uint64_t sId;
4245
  uint64_t queryId;
4246
  uint64_t taskId;
4247
  uint32_t sqlLen;
4248
  uint32_t phyLen;
4249
  char*    sql;
4250
  char*    msg;
4251
  int8_t   source;
4252
} SVDeleteReq;
4253

4254
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4255
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4256

4257
typedef struct {
4258
  int64_t affectedRows;
4259
} SVDeleteRsp;
4260

4261
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4262
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4263

4264
typedef struct SDeleteRes {
4265
  uint64_t suid;
4266
  SArray*  uidList;
4267
  int64_t  skey;
4268
  int64_t  ekey;
4269
  int64_t  affectedRows;
4270
  char     tableFName[TSDB_TABLE_NAME_LEN];
4271
  char     tsColName[TSDB_COL_NAME_LEN];
4272
  int64_t  ctimeMs;  // fill by vnode
4273
  int8_t   source;
4274
} SDeleteRes;
4275

4276
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4277
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4278

4279
typedef struct {
4280
  // int64_t uid;
4281
  char    tbname[TSDB_TABLE_NAME_LEN];
4282
  int64_t startTs;
4283
  int64_t endTs;
4284
} SSingleDeleteReq;
4285

4286
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4287
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4288

4289
typedef struct {
4290
  int64_t suid;
4291
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4292
  int64_t ctimeMs;     // fill by vnode
4293
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4294
} SBatchDeleteReq;
4295

4296
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4297
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4298
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4299

4300
typedef struct {
4301
  int32_t msgIdx;
4302
  int32_t msgType;
4303
  int32_t msgLen;
4304
  void*   msg;
4305
} SBatchMsg;
4306

4307
typedef struct {
4308
  SMsgHead header;
4309
  SArray*  pMsgs;  // SArray<SBatchMsg>
4310
} SBatchReq;
4311

4312
typedef struct {
4313
  int32_t reqType;
4314
  int32_t msgIdx;
4315
  int32_t msgLen;
4316
  int32_t rspCode;
4317
  void*   msg;
4318
} SBatchRspMsg;
4319

4320
typedef struct {
4321
  SArray* pRsps;  // SArray<SBatchRspMsg>
4322
} SBatchRsp;
4323

4324
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4325
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4326
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
13,111,733✔
4327
  if (NULL == msg) {
13,111,733!
4328
    return;
×
4329
  }
4330
  SBatchMsg* pMsg = (SBatchMsg*)msg;
13,111,733✔
4331
  taosMemoryFree(pMsg->msg);
13,111,733✔
4332
}
4333

4334
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4335
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4336

4337
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
4,021,204✔
4338
  if (NULL == p) {
4,021,204!
4339
    return;
×
4340
  }
4341

4342
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
4,021,204✔
4343
  taosMemoryFree(pRsp->msg);
4,021,204✔
4344
}
4345

4346
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4347
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4348
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4349
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4350
void    tDestroySMqHbReq(SMqHbReq* pReq);
4351

4352
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4353
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4354
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4355

4356
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4357
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4358

4359
#define TD_REQ_FROM_APP               0x0
4360
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4361
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4362
#define SUBMIT_REQ_FROM_FILE          0x4
4363
#define TD_REQ_FROM_TAOX              0x8
4364
#define SUBMIT_REQUEST_VERSION        (1)
4365

4366
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4367

4368
typedef struct {
4369
  int32_t        flags;
4370
  SVCreateTbReq* pCreateTbReq;
4371
  int64_t        suid;
4372
  int64_t        uid;
4373
  int32_t        sver;
4374
  union {
4375
    SArray* aRowP;
4376
    SArray* aCol;
4377
  };
4378
  int64_t ctimeMs;
4379
} SSubmitTbData;
4380

4381
typedef struct {
4382
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4383
} SSubmitReq2;
4384

4385
typedef struct {
4386
  SMsgHead header;
4387
  int64_t  version;
4388
  char     data[];  // SSubmitReq2
4389
} SSubmitReq2Msg;
4390

4391
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4392
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4393
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4394
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4395

4396
typedef struct {
4397
  int32_t affectedRows;
4398
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4399
} SSubmitRsp2;
4400

4401
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4402
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4403
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4404

4405
#define TSDB_MSG_FLG_ENCODE 0x1
4406
#define TSDB_MSG_FLG_DECODE 0x2
4407
#define TSDB_MSG_FLG_CMPT   0x3
4408

4409
typedef struct {
4410
  union {
4411
    struct {
4412
      void*   msgStr;
4413
      int32_t msgLen;
4414
      int64_t ver;
4415
    };
4416
    void* pDataBlock;
4417
  };
4418
} SPackedData;
4419

4420
typedef struct {
4421
  char     fullname[TSDB_VIEW_FNAME_LEN];
4422
  char     name[TSDB_VIEW_NAME_LEN];
4423
  char     dbFName[TSDB_DB_FNAME_LEN];
4424
  char*    querySql;
4425
  char*    sql;
4426
  int8_t   orReplace;
4427
  int8_t   precision;
4428
  int32_t  numOfCols;
4429
  SSchema* pSchema;
4430
} SCMCreateViewReq;
4431

4432
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4433
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4434
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4435

4436
typedef struct {
4437
  char   fullname[TSDB_VIEW_FNAME_LEN];
4438
  char   name[TSDB_VIEW_NAME_LEN];
4439
  char   dbFName[TSDB_DB_FNAME_LEN];
4440
  char*  sql;
4441
  int8_t igNotExists;
4442
} SCMDropViewReq;
4443

4444
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4445
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4446
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4447

4448
typedef struct {
4449
  char fullname[TSDB_VIEW_FNAME_LEN];
4450
} SViewMetaReq;
4451
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4452
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4453

4454
typedef struct {
4455
  char     name[TSDB_VIEW_NAME_LEN];
4456
  char     dbFName[TSDB_DB_FNAME_LEN];
4457
  char*    user;
4458
  uint64_t dbId;
4459
  uint64_t viewId;
4460
  char*    querySql;
4461
  int8_t   precision;
4462
  int8_t   type;
4463
  int32_t  version;
4464
  int32_t  numOfCols;
4465
  SSchema* pSchema;
4466
} SViewMetaRsp;
4467
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4468
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4469
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4470
typedef struct {
4471
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4472
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4473
} STableTSMAInfoReq;
4474

4475
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4476
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4477

4478
typedef struct {
4479
  int32_t  funcId;
4480
  col_id_t colId;
4481
} STableTSMAFuncInfo;
4482

4483
typedef struct {
4484
  char     name[TSDB_TABLE_NAME_LEN];
4485
  uint64_t tsmaId;
4486
  char     targetTb[TSDB_TABLE_NAME_LEN];
4487
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4488
  char     tb[TSDB_TABLE_NAME_LEN];
4489
  char     dbFName[TSDB_DB_FNAME_LEN];
4490
  uint64_t suid;
4491
  uint64_t destTbUid;
4492
  uint64_t dbId;
4493
  int32_t  version;
4494
  int64_t  interval;
4495
  int8_t   unit;
4496
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4497
  SArray*  pTags;      // SArray<SSchema>
4498
  SArray*  pUsedCols;  // SArray<SSchema>
4499
  char*    ast;
4500

4501
  int64_t streamUid;
4502
  int64_t reqTs;
4503
  int64_t rspTs;
4504
  int64_t delayDuration;  // ms
4505
  bool    fillHistoryFinished;
4506
} STableTSMAInfo;
4507

4508
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4509
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4510
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4511
void    tFreeTableTSMAInfo(void* p);
4512
void    tFreeAndClearTableTSMAInfo(void* p);
4513
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4514

4515
#define STSMAHbRsp            STableTSMAInfoRsp
4516
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4517
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4518
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4519

4520
typedef struct SStreamProgressReq {
4521
  int64_t streamId;
4522
  int32_t vgId;
4523
  int32_t fetchIdx;
4524
  int32_t subFetchIdx;
4525
} SStreamProgressReq;
4526

4527
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4528
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4529

4530
typedef struct SStreamProgressRsp {
4531
  int64_t streamId;
4532
  int32_t vgId;
4533
  bool    fillHisFinished;
4534
  int64_t progressDelay;
4535
  int32_t fetchIdx;
4536
  int32_t subFetchIdx;
4537
} SStreamProgressRsp;
4538

4539
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4540
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4541

4542
typedef struct SDropCtbWithTsmaSingleVgReq {
4543
  SVgroupInfo vgInfo;
4544
  SArray*     pTbs;  // SVDropTbReq
4545
} SMDropTbReqsOnSingleVg;
4546

4547
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4548
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4549
void    tFreeSMDropTbReqOnSingleVg(void* p);
4550

4551
typedef struct SDropTbsReq {
4552
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4553
} SMDropTbsReq;
4554

4555
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4556
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4557
void    tFreeSMDropTbsReq(void*);
4558

4559
typedef struct SVFetchTtlExpiredTbsRsp {
4560
  SArray* pExpiredTbs;  // SVDropTbReq
4561
  int32_t vgId;
4562
} SVFetchTtlExpiredTbsRsp;
4563

4564
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4565
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4566

4567
void tFreeFetchTtlExpiredTbsRsp(void* p);
4568

4569
void setDefaultOptionsForField(SFieldWithOptions* field);
4570
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4571

4572
#pragma pack(pop)
4573

4574
#ifdef __cplusplus
4575
}
4576
#endif
4577

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

© 2026 Coveralls, Inc