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

taosdata / TDengine / #3542

27 Nov 2024 02:52AM UTC coverage: 60.819% (+0.04%) from 60.776%
#3542

push

travis-ci

web-flow
Merge pull request #28931 from taosdata/enh/jdbc-demo-3.0

update jdbc demo, and version history

120305 of 252779 branches covered (47.59%)

Branch coverage included in aggregate %.

201010 of 275538 relevant lines covered (72.95%)

19989893.51 hits per line

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

58.55
/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) {
64,052,595✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
64,052,595✔
74
  int    segIdx = TMSG_SEG_CODE(type);
64,052,595✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
64,052,595!
76
    return type < tMsgRangeDict[segIdx];
64,054,692✔
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) {
7,983,212✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
7,948,160!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
15,931,372!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
38,889,221✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
38,889,221✔
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_STREAM_CONTINUE_INTERVAL,
471
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
472
  QUERY_NODE_PHYSICAL_PLAN_STREAM_ANOMALY,
473
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
474
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC,
475
} ENodeType;
476

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

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

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

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

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

515
#pragma pack(push, 1)
516

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

523
typedef struct {
524
  int32_t contLen;
525
  int32_t vgId;
526
} SMsgHead;
527

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

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

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

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

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

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

588
//
589

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

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

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

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

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

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

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

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

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

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

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

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

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

689
typedef struct {
690
  col_id_t id;
691
  uint32_t alg;
692
} SColCmpr;
693

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

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

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

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

721
  return pDstWrapper;
2,154✔
722
}
723

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

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

754
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
755
  if (pWrapper == NULL) return;
2,154!
756

757
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,154!
758
  taosMemoryFreeClear(pWrapper);
2,154!
759
}
760
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
761
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,633,794!
762

763
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,633,794✔
764
  if (pSW == NULL) {
11,632,898!
765
    return NULL;
×
766
  }
767
  pSW->nCols = pSchemaWrapper->nCols;
11,632,898✔
768
  pSW->version = pSchemaWrapper->version;
11,632,898✔
769
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,632,898✔
770
  if (pSW->pSchema == NULL) {
11,619,728!
771
    taosMemoryFree(pSW);
×
772
    return NULL;
×
773
  }
774

775
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
11,637,820✔
776
  return pSW;
11,637,820✔
777
}
778

779
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
491,535✔
780
  if (pSchemaWrapper) {
19,216,892!
781
    taosMemoryFree(pSchemaWrapper->pSchema);
10,694,649✔
782
    taosMemoryFree(pSchemaWrapper);
10,694,804✔
783
  }
784
}
19,217,320✔
785

786
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,321,375✔
787
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,321,375!
788
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,321,565✔
789
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,322,895✔
790
  }
791
}
1,324,359✔
792

793
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
794
  int32_t tlen = 0;
55,922✔
795
  tlen += taosEncodeFixedI8(buf, pSchema->type);
111,844✔
796
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
55,922!
797
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
55,922!
798
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
55,922!
799
  tlen += taosEncodeString(buf, pSchema->name);
55,922✔
800
  return tlen;
55,922✔
801
}
802

803
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
804
  buf = taosDecodeFixedI8(buf, &pSchema->type);
51,844✔
805
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
25,922✔
806
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
25,922!
807
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
25,922!
808
  buf = taosDecodeStringTo(buf, pSchema->name);
25,922✔
809
  return (void*)buf;
25,922✔
810
}
811

812
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
813
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
355,049,007!
814
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
368,524,618!
815
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
368,524,618!
816
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
368,524,618!
817
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
368,524,618!
818
  return 0;
184,262,309✔
819
}
820

821
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
822
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
612,732,968!
823
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,214,286,018!
824
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,210,838,097!
825
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,219,276,897!
826
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
612,181,468!
827
  return 0;
621,836,031✔
828
}
829

830
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
831
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
211,558,272!
832
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
211,558,272!
833
  return 0;
105,779,136✔
834
}
835

836
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,088,473!
838
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,088,471!
839
  return 0;
1,544,235✔
840
}
841

842
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
843
  int32_t tlen = 0;
8,556✔
844
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,556✔
845
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,556✔
846
  for (int32_t i = 0; i < pSW->nCols; i++) {
64,478✔
847
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
111,844!
848
  }
849
  return tlen;
8,556✔
850
}
851

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

861
    for (int32_t i = 0; i < pSW->nCols; i++) {
28,777✔
862
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
51,844✔
863
    }
864
  } else {
865
    pSW->pSchema = NULL;
1,132✔
866
  }
867
  return (void*)buf;
3,987✔
868
}
869

870
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
871
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,523,644!
872
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,523,644!
873
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,237,433✔
874
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
26,951,222!
875
  }
876
  return 0;
761,822✔
877
}
878

879
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
880
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,552,195!
881
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,552,125!
882

883
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
776,069✔
884
  if (pSW->pSchema == NULL) {
775,988!
885
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
886
  }
887
  for (int32_t i = 0; i < pSW->nCols; i++) {
13,637,611✔
888
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
25,724,338!
889
  }
890

891
  return 0;
774,855✔
892
}
893

894
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
895
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
67,141,146!
896
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
69,194,976!
897

898
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
34,594,834✔
899
  if (pSW->pSchema == NULL) {
34,635,127!
900
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
901
  }
902
  for (int32_t i = 0; i < pSW->nCols; i++) {
641,419,955✔
903
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,215,857,310!
904
  }
905

906
  return 0;
32,347,473✔
907
}
908

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

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

944
typedef struct {
945
  STableMetaRsp* pMeta;
946
} SMCreateStbRsp;
947

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

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

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

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

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

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

988

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

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

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

1008
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1009
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1010

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

1030
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1031
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1032

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

1044
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1045
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1046

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

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

1057
typedef struct SIpV4Range {
1058
  uint32_t ip;
1059
  uint32_t mask;
1060
} SIpV4Range;
1061

1062
typedef struct {
1063
  int32_t    num;
1064
  SIpV4Range pIpRange[];
1065
} SIpWhiteList;
1066

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

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

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

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

1104
typedef struct {
1105
  int64_t ipWhiteVer;
1106
} SRetrieveIpWhiteReq;
1107

1108
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1109
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1110

1111
typedef struct {
1112
  int32_t dnodeId;
1113
  int64_t analVer;
1114
} SRetrieveAnalAlgoReq;
1115

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

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

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

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

1157
typedef struct {
1158
  char user[TSDB_USER_LEN];
1159
} SGetUserAuthReq;
1160

1161
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1162
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1163

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

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

1189
typedef struct {
1190
  char user[TSDB_USER_LEN];
1191
} SGetUserWhiteListReq;
1192

1193
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1194
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1195

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

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

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

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

1224
typedef struct STimeWindow {
1225
  TSKEY skey;
1226
  TSKEY ekey;
1227
} STimeWindow;
1228

1229
typedef struct SQueryHint {
1230
  bool batchScan;
1231
} SQueryHint;
1232

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

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

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

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

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

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

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

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

1294
typedef STableCfg STableCfgRsp;
1295

1296
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1297
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1298

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

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

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

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

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

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

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

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

1398
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1399
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1400

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

1409
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1410
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1411

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

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

1431
typedef struct {
1432
  char db[TSDB_DB_FNAME_LEN];
1433
} SDbCfgReq;
1434

1435
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1436
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1437

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

1443
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1444
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1445

1446
typedef struct {
1447
  int32_t timestamp;
1448
} SVTrimDbReq;
1449

1450
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1451
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1452

1453
typedef struct {
1454
  char db[TSDB_DB_FNAME_LEN];
1455
} SS3MigrateDbReq;
1456

1457
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1458
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1459

1460
typedef struct {
1461
  int32_t timestamp;
1462
} SVS3MigrateDbReq;
1463

1464
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1465
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1466

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

1474
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1475
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1476

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

1520
typedef SDbCfgRsp SDbCfgInfo;
1521

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

1528
typedef struct {
1529
  int32_t rowNum;
1530
} SQnodeListReq;
1531

1532
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1533
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1534

1535
typedef struct {
1536
  int32_t rowNum;
1537
} SDnodeListReq;
1538

1539
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1540

1541
typedef struct {
1542
  int32_t useless;  // useless
1543
} SServerVerReq;
1544

1545
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1546
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1547

1548
typedef struct {
1549
  char ver[TSDB_VERSION_LEN];
1550
} SServerVerRsp;
1551

1552
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1553
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1554

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

1560
typedef struct {
1561
  SQueryNodeAddr addr;
1562
  uint64_t       load;
1563
} SQueryNodeLoad;
1564

1565
typedef struct {
1566
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1567
} SQnodeListRsp;
1568

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

1573
typedef struct {
1574
  SArray* dnodeList;  // SArray<SEpSet>
1575
} SDnodeListRsp;
1576

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

1581
typedef struct {
1582
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1583
} STableTSMAInfoRsp;
1584

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

1594
typedef struct {
1595
  SArray* pArray;  // Array of SDbHbRsp
1596
} SDbHbBatchRsp;
1597

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

1602
typedef struct {
1603
  SArray* pArray;  // Array of SGetUserAuthRsp
1604
} SUserAuthBatchRsp;
1605

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

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

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

1621
typedef struct {
1622
  int32_t compactId;
1623
  int8_t  bAccepted;
1624
} SCompactDbRsp;
1625

1626
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1627
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1628

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

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

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

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

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

1663
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1664
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1665

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

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

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

1690
typedef struct {
1691
  int32_t funcVersion;
1692
  int64_t funcCreatedTime;
1693
} SFuncExtraInfo;
1694

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

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

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

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

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

1755
typedef struct {
1756
  int32_t vgId;
1757
  int64_t nTimeSeries;
1758
} SVnodeLoadLite;
1759

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

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

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

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

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

1815
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1816
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1817

1818
typedef enum {
1819
  MONITOR_TYPE_COUNTER = 0,
1820
  MONITOR_TYPE_SLOW_LOG = 1,
1821
} MONITOR_TYPE;
1822

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

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

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

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

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

1854
typedef struct {
1855
  int32_t dnodeId;
1856
  int64_t clusterId;
1857
} SDnodeCfg;
1858

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

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

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

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

1887
typedef struct {
1888
  int32_t reserved;
1889
} SMTimerReq;
1890

1891
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1892
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1893

1894
typedef struct SOrphanTask {
1895
  int64_t streamId;
1896
  int32_t taskId;
1897
  int32_t nodeId;
1898
} SOrphanTask;
1899

1900
typedef struct SMStreamDropOrphanMsg {
1901
  SArray* pList;  // SArray<SOrphanTask>
1902
} SMStreamDropOrphanMsg;
1903

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

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

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

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

1970
typedef struct {
1971
  int32_t compactId;
1972
  int32_t vgId;
1973
  int32_t dnodeId;
1974
} SQueryCompactProgressReq;
1975

1976
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1977
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1978

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

1987
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1988
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1989

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

1998
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1999
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2000

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

2009
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2010
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2011

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

2020
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2021
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2022

2023
typedef struct {
2024
  int32_t compactId;
2025
  int32_t vgId;
2026
  int32_t dnodeId;
2027
} SVKillCompactReq;
2028

2029
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2030
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2031

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

2058
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2059
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2060

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

2074
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2075
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2076

2077
typedef struct {
2078
  int32_t vgId;
2079
  int8_t  disable;
2080
} SDisableVnodeWriteReq;
2081

2082
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2083
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2084

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

2094
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2095
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2096

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

2106
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2107
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2108

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

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

2129
typedef struct {
2130
  int32_t     numOfVgroups;
2131
  SVgroupInfo vgroups[];
2132
} SVgroupsInfo;
2133

2134
typedef struct {
2135
  STableMetaRsp* pMeta;
2136
} SMAlterStbRsp;
2137

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

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

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

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

2156
typedef struct {
2157
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2158
} SViewHbRsp;
2159

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

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

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

2181
typedef struct {
2182
  int32_t useless;  // useless
2183
} SShowVariablesReq;
2184

2185
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2186
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2187

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

2195
typedef struct {
2196
  SArray* variables;  // SArray<SVariablesInfo>
2197
} SShowVariablesRsp;
2198

2199
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2200
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2201

2202
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2203

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

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

2220
typedef struct {
2221
  int64_t       showId;
2222
  STableMetaRsp tableMeta;
2223
} SShowRsp, SVShowTablesRsp;
2224

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

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

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

2245
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2246
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2247

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

2267
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2268

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

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

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

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

2303
typedef struct {
2304
  int32_t           numOfPlans;
2305
  SExplainExecInfo* subplanInfo;
2306
} SExplainRsp;
2307

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2404
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2405
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2406

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

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

2426
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2427
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2428

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

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

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

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

2453
typedef struct {
2454
  int32_t vgId;
2455
  int32_t hbSeq;
2456
} SVArbHbReqMember;
2457

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

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

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

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

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

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

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

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

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

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

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

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

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

2528
typedef struct {
2529
  int32_t dnodeId;
2530
  char*   token;
2531
} SMArbUpdateGroupMember;
2532

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

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

2549
typedef struct {
2550
  SArray* updateArray;  // SMArbUpdateGroup
2551
} SMArbUpdateGroupBatchReq;
2552

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

2557
typedef struct {
2558
  char queryStrId[TSDB_QUERY_ID_LEN];
2559
} SKillQueryReq;
2560

2561
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2562
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2563

2564
typedef struct {
2565
  uint32_t connId;
2566
} SKillConnReq;
2567

2568
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2569
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2570

2571
typedef struct {
2572
  int32_t transId;
2573
} SKillTransReq;
2574

2575
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2576
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2577

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

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

2588
typedef struct {
2589
  int32_t vgId1;
2590
  int32_t vgId2;
2591
} SMergeVgroupReq;
2592

2593
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2594
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2595

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

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

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

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

2621
typedef struct {
2622
  int32_t vgId;
2623
} SForceBecomeFollowerReq;
2624

2625
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2626
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2627

2628
typedef struct {
2629
  int32_t vgId;
2630
} SSplitVgroupReq;
2631

2632
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2633
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2634

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

2643
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2644
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2645

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

2651
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2652
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2653

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

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

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

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

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

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

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

2721
typedef struct STableScanOperatorParam {
2722
  bool    tableSeq;
2723
  SArray* pUidList;
2724
} STableScanOperatorParam;
2725

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

2736
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2737
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2738

2739
typedef struct {
2740
  SMsgHead header;
2741
  uint64_t sId;
2742
} SSchTasksStatusReq;
2743

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

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

2758
typedef struct {
2759
  uint64_t queryId;
2760
  uint64_t taskId;
2761
  int8_t   action;
2762
} STaskAction;
2763

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

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

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

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

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

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

2799
typedef struct {
2800
  int32_t code;
2801
} STaskCancelRsp;
2802

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

2813
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2814
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2815

2816
typedef enum {
2817
  TASK_NOTIFY_FINISHED = 1,
2818
} ETaskNotifyType;
2819

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

2831
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2832
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2833

2834
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2835
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2836

2837
typedef struct {
2838
  int32_t code;
2839
} STaskDropRsp;
2840

2841
#define STREAM_TRIGGER_AT_ONCE            1
2842
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2843
#define STREAM_TRIGGER_MAX_DELAY          3
2844
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2845

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

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

2860
typedef struct SVgroupVer {
2861
  int32_t vgId;
2862
  int64_t ver;
2863
} SVgroupVer;
2864

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

2894
typedef struct {
2895
  int64_t streamId;
2896
} SCMCreateStreamRsp;
2897

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

2902
enum {
2903
  TOPIC_SUB_TYPE__DB = 1,
2904
  TOPIC_SUB_TYPE__TABLE,
2905
  TOPIC_SUB_TYPE__COLUMN,
2906
};
2907

2908
#define DEFAULT_MAX_POLL_INTERVAL 300000
2909
#define DEFAULT_SESSION_TIMEOUT   12000
2910

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

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

2926
typedef struct {
2927
  int64_t consumerId;
2928
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2929

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

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

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

2954
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,616!
2955
  tlen += taosEncodeFixedI32(buf, topicNum);
2,616✔
2956

2957
  for (int32_t i = 0; i < topicNum; i++) {
3,688✔
2958
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,144✔
2959
  }
2960

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

2972
  return tlen;
2,616✔
2973
}
2974

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

2981
  int32_t topicNum = 0;
1,418!
2982
  buf = taosDecodeFixedI32(buf, &topicNum);
1,418✔
2983

2984
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,418✔
2985
  if (pReq->topicNames == NULL) {
1,418!
2986
    return terrno;
×
2987
  }
2988
  for (int32_t i = 0; i < topicNum; i++) {
2,065✔
2989
    char* name = NULL;
647✔
2990
    buf = taosDecodeString(buf, &name);
647✔
2991
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,294!
2992
      return terrno;
×
2993
    }
2994
  }
2995

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

3012
  return 0;
1,418✔
3013
}
3014

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

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

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

3049
typedef struct {
3050
  int64_t status;
3051
} SMVSubscribeRsp;
3052

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

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

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

3070
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3071
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3072

3073
typedef struct {
3074
  int8_t reserved;
3075
} SMDropCgroupRsp;
3076

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

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

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

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

3108
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3109
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3110

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

3126
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3127
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3128

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

3135
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3136
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3137

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

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

3170
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,736✔
3171
  if (NULL == req) {
21,683,980!
3172
    return;
21,512,059✔
3173
  }
3174

3175
  taosMemoryFreeClear(req->sql);
171,921!
3176
  taosMemoryFreeClear(req->name);
171,921!
3177
  taosMemoryFreeClear(req->comment);
171,926!
3178
  if (req->type == TSDB_CHILD_TABLE) {
171,926!
3179
    taosMemoryFreeClear(req->ctb.pTag);
158,404!
3180
    taosMemoryFreeClear(req->ctb.stbName);
158,412!
3181
    taosArrayDestroy(req->ctb.tagName);
158,412✔
3182
    req->ctb.tagName = NULL;
158,404✔
3183
  } else if (req->type == TSDB_NORMAL_TABLE) {
13,522!
3184
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,518!
3185
  }
3186
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
171,926!
3187
}
3188

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

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

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

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

3211
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3212
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3213

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

3222
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3223
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3224

3225
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3226
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3227

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

3236
typedef struct {
3237
  int32_t code;
3238
} SVDropTbRsp;
3239

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

3248
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3249
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3250

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

3259
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3260
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3261

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

3294
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3295
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3296
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3297

3298
typedef struct {
3299
  int32_t        code;
3300
  STableMetaRsp* pMeta;
3301
} SVAlterTbRsp;
3302

3303
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3304
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3305
// ======================
3306

3307
typedef struct {
3308
  SMsgHead head;
3309
  int64_t  uid;
3310
  int32_t  tid;
3311
  int16_t  tversion;
3312
  int16_t  colId;
3313
  int8_t   type;
3314
  int16_t  bytes;
3315
  int32_t  tagValLen;
3316
  int16_t  numOfTags;
3317
  int32_t  schemaLen;
3318
  char     data[];
3319
} SUpdateTagValReq;
3320

3321
typedef struct {
3322
  SMsgHead head;
3323
} SUpdateTagValRsp;
3324

3325
typedef struct {
3326
  SMsgHead head;
3327
} SVShowTablesReq;
3328

3329
typedef struct {
3330
  SMsgHead head;
3331
  int32_t  id;
3332
} SVShowTablesFetchReq;
3333

3334
typedef struct {
3335
  int64_t useconds;
3336
  int8_t  completed;  // all results are returned to client
3337
  int8_t  precision;
3338
  int8_t  compressed;
3339
  int32_t compLen;
3340
  int32_t numOfRows;
3341
  char    data[];
3342
} SVShowTablesFetchRsp;
3343

3344
typedef struct {
3345
  int64_t consumerId;
3346
  int32_t epoch;
3347
  char    cgroup[TSDB_CGROUP_LEN];
3348
} SMqAskEpReq;
3349

3350
typedef struct {
3351
  int32_t key;
3352
  int32_t valueLen;
3353
  void*   value;
3354
} SKv;
3355

3356
typedef struct {
3357
  int64_t tscRid;
3358
  int8_t  connType;
3359
} SClientHbKey;
3360

3361
typedef struct {
3362
  int64_t tid;
3363
  char    status[TSDB_JOB_STATUS_LEN];
3364
} SQuerySubDesc;
3365

3366
typedef struct {
3367
  char     sql[TSDB_SHOW_SQL_LEN];
3368
  uint64_t queryId;
3369
  int64_t  useconds;
3370
  int64_t  stime;  // timestamp precision ms
3371
  int64_t  reqRid;
3372
  bool     stableQuery;
3373
  bool     isSubQuery;
3374
  char     fqdn[TSDB_FQDN_LEN];
3375
  int32_t  subPlanNum;
3376
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3377
} SQueryDesc;
3378

3379
typedef struct {
3380
  uint32_t connId;
3381
  SArray*  queryDesc;  // SArray<SQueryDesc>
3382
} SQueryHbReqBasic;
3383

3384
typedef struct {
3385
  uint32_t connId;
3386
  uint64_t killRid;
3387
  int32_t  totalDnodes;
3388
  int32_t  onlineDnodes;
3389
  int8_t   killConnection;
3390
  int8_t   align[3];
3391
  SEpSet   epSet;
3392
  SArray*  pQnodeList;
3393
} SQueryHbRspBasic;
3394

3395
typedef struct SAppClusterSummary {
3396
  uint64_t numOfInsertsReq;
3397
  uint64_t numOfInsertRows;
3398
  uint64_t insertElapsedTime;
3399
  uint64_t insertBytes;  // submit to tsdb since launched.
3400

3401
  uint64_t fetchBytes;
3402
  uint64_t numOfQueryReq;
3403
  uint64_t queryElapsedTime;
3404
  uint64_t numOfSlowQueries;
3405
  uint64_t totalRequests;
3406
  uint64_t currentRequests;  // the number of SRequestObj
3407
} SAppClusterSummary;
3408

3409
typedef struct {
3410
  int64_t            appId;
3411
  int32_t            pid;
3412
  char               name[TSDB_APP_NAME_LEN];
3413
  int64_t            startTime;
3414
  SAppClusterSummary summary;
3415
} SAppHbReq;
3416

3417
typedef struct {
3418
  SClientHbKey      connKey;
3419
  int64_t           clusterId;
3420
  SAppHbReq         app;
3421
  SQueryHbReqBasic* query;
3422
  SHashObj*         info;  // hash<Skv.key, Skv>
3423
} SClientHbReq;
3424

3425
typedef struct {
3426
  int64_t reqId;
3427
  SArray* reqs;  // SArray<SClientHbReq>
3428
  int64_t ipWhiteList;
3429
} SClientHbBatchReq;
3430

3431
typedef struct {
3432
  SClientHbKey      connKey;
3433
  int32_t           status;
3434
  SQueryHbRspBasic* query;
3435
  SArray*           info;  // Array<Skv>
3436
} SClientHbRsp;
3437

3438
typedef struct {
3439
  int64_t       reqId;
3440
  int64_t       rspId;
3441
  int32_t       svrTimestamp;
3442
  SArray*       rsps;  // SArray<SClientHbRsp>
3443
  SMonitorParas monitorParas;
3444
  int8_t        enableAuditDelete;
3445
} SClientHbBatchRsp;
3446

3447
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
200,565✔
3448

3449
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3450
  void* pIter = taosHashIterate(info, NULL);
523,128✔
3451
  while (pIter != NULL) {
914,069!
3452
    SKv* kv = (SKv*)pIter;
390,935✔
3453
    taosMemoryFreeClear(kv->value);
390,935!
3454
    pIter = taosHashIterate(info, pIter);
390,936✔
3455
  }
3456
}
523,134✔
3457

3458
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
344,304✔
3459
  SQueryDesc* desc = (SQueryDesc*)pDesc;
344,304✔
3460
  if (desc->subDesc) {
344,304✔
3461
    taosArrayDestroy(desc->subDesc);
338,075✔
3462
    desc->subDesc = NULL;
338,079✔
3463
  }
3464
}
344,308✔
3465

3466
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
598,022✔
3467
  SClientHbReq* req = (SClientHbReq*)pReq;
610,496✔
3468
  if (req->query) {
610,496!
3469
    if (req->query->queryDesc) {
588,804!
3470
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
41,981✔
3471
    }
3472
    taosMemoryFreeClear(req->query);
588,804!
3473
  }
3474

3475
  if (req->info) {
610,487!
3476
    tFreeReqKvHash(req->info);
523,128✔
3477
    taosHashCleanup(req->info);
523,134✔
3478
    req->info = NULL;
523,122✔
3479
  }
3480
}
503,026✔
3481

3482
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3483
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3484

3485
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3486
  if (pReq == NULL) return;
39,955!
3487
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
39,955✔
3488
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
39,955✔
3489
  taosMemoryFree(pReq);
39,955✔
3490
}
3491

3492
static FORCE_INLINE void tFreeClientKv(void* pKv) {
147,371✔
3493
  SKv* kv = (SKv*)pKv;
147,371✔
3494
  if (kv) {
147,371!
3495
    taosMemoryFreeClear(kv->value);
147,371!
3496
  }
3497
}
147,372✔
3498

3499
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
595,564✔
3500
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
595,564✔
3501
  if (rsp->query) {
595,564✔
3502
    taosArrayDestroy(rsp->query->pQnodeList);
586,397✔
3503
    taosMemoryFreeClear(rsp->query);
586,526!
3504
  }
3505
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
595,822!
3506
}
105,353✔
3507

3508
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3509
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
433,837✔
3510
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
433,837✔
3511
}
433,846✔
3512

3513
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3514
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3515
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3516

3517
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3518
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
713,228!
3519
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
713,228!
3520
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
713,228!
3521
  return 0;
356,614✔
3522
}
3523

3524
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3525
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
719,935!
3526
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
719,931!
3527
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
359,966✔
3528
  if (pKv->value == NULL) {
359,970!
3529
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3530
  }
3531
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
359,970!
3532
  return 0;
359,973✔
3533
}
3534

3535
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3536
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,390,470!
3537
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,390,470!
3538
  return 0;
1,195,235✔
3539
}
3540

3541
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3542
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,191,406!
3543
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,191,373!
3544
  return 0;
595,712✔
3545
}
3546

3547
typedef struct {
3548
  int32_t vgId;
3549
  // TODO stas
3550
} SMqReportVgInfo;
3551

3552
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3553
  int32_t tlen = 0;
3554
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3555
  return tlen;
3556
}
3557

3558
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3559
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3560
  return buf;
3561
}
3562

3563
typedef struct {
3564
  int32_t epoch;
3565
  int64_t topicUid;
3566
  char    name[TSDB_TOPIC_FNAME_LEN];
3567
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3568
} SMqTopicInfo;
3569

3570
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3571
  int32_t tlen = 0;
3572
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3573
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3574
  tlen += taosEncodeString(buf, pTopicInfo->name);
3575
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3576
  tlen += taosEncodeFixedI32(buf, sz);
3577
  for (int32_t i = 0; i < sz; i++) {
3578
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3579
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3580
  }
3581
  return tlen;
3582
}
3583

3584
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3585
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3586
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3587
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3588
  int32_t sz;
3589
  buf = taosDecodeFixedI32(buf, &sz);
3590
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3591
    return NULL;
3592
  }
3593
  for (int32_t i = 0; i < sz; i++) {
3594
    SMqReportVgInfo vgInfo;
3595
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3596
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3597
      return NULL;
3598
    }
3599
  }
3600
  return buf;
3601
}
3602

3603
typedef struct {
3604
  int32_t status;  // ask hb endpoint
3605
  int32_t epoch;
3606
  int64_t consumerId;
3607
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3608
} SMqReportReq;
3609

3610
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3611
  int32_t tlen = 0;
3612
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3613
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3614
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3615
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3616
  tlen += taosEncodeFixedI32(buf, sz);
3617
  for (int32_t i = 0; i < sz; i++) {
3618
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3619
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3620
  }
3621
  return tlen;
3622
}
3623

3624
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3625
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3626
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3627
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3628
  int32_t sz;
3629
  buf = taosDecodeFixedI32(buf, &sz);
3630
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3631
    return NULL;
3632
  }
3633
  for (int32_t i = 0; i < sz; i++) {
3634
    SMqTopicInfo topicInfo;
3635
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3636
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3637
      return NULL;
3638
    }
3639
  }
3640
  return buf;
3641
}
3642

3643
typedef struct {
3644
  SMsgHead head;
3645
  int64_t  leftForVer;
3646
  int32_t  vgId;
3647
  int64_t  consumerId;
3648
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3649
} SMqVDeleteReq;
3650

3651
typedef struct {
3652
  int8_t reserved;
3653
} SMqVDeleteRsp;
3654

3655
typedef struct {
3656
  char    name[TSDB_STREAM_FNAME_LEN];
3657
  int8_t  igNotExists;
3658
  int32_t sqlLen;
3659
  char*   sql;
3660
} SMDropStreamReq;
3661

3662
typedef struct {
3663
  int8_t reserved;
3664
} SMDropStreamRsp;
3665

3666
typedef struct {
3667
  SMsgHead head;
3668
  int64_t  resetRelHalt;  // reset related stream task halt status
3669
  int64_t  streamId;
3670
  int32_t  taskId;
3671
} SVDropStreamTaskReq;
3672

3673
typedef struct {
3674
  int8_t reserved;
3675
} SVDropStreamTaskRsp;
3676

3677
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3678
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3679
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3680

3681
typedef struct SVUpdateCheckpointInfoReq {
3682
  SMsgHead head;
3683
  int64_t  streamId;
3684
  int32_t  taskId;
3685
  int64_t  checkpointId;
3686
  int64_t  checkpointVer;
3687
  int64_t  checkpointTs;
3688
  int32_t  transId;
3689
  int64_t  hStreamId;  // add encode/decode
3690
  int64_t  hTaskId;
3691
  int8_t   dropRelHTask;
3692
} SVUpdateCheckpointInfoReq;
3693

3694
typedef struct {
3695
  int64_t leftForVer;
3696
  int32_t vgId;
3697
  int64_t oldConsumerId;
3698
  int64_t newConsumerId;
3699
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3700
  int8_t  subType;
3701
  int8_t  withMeta;
3702
  char*   qmsg;  // SubPlanToString
3703
  int64_t suid;
3704
} SMqRebVgReq;
3705

3706
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3707
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3708

3709
typedef struct {
3710
  char    topic[TSDB_TOPIC_FNAME_LEN];
3711
  int64_t ntbUid;
3712
  SArray* colIdList;  // SArray<int16_t>
3713
} STqCheckInfo;
3714

3715
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3716
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3717
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3718

3719
// tqOffset
3720
enum {
3721
  TMQ_OFFSET__RESET_NONE = -3,
3722
  TMQ_OFFSET__RESET_EARLIEST = -2,
3723
  TMQ_OFFSET__RESET_LATEST = -1,
3724
  TMQ_OFFSET__LOG = 1,
3725
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3726
  TMQ_OFFSET__SNAPSHOT_META = 3,
3727
};
3728

3729
enum {
3730
  WITH_DATA = 0,
3731
  WITH_META = 1,
3732
  ONLY_META = 2,
3733
};
3734

3735
#define TQ_OFFSET_VERSION 1
3736

3737
typedef struct {
3738
  int8_t type;
3739
  union {
3740
    // snapshot
3741
    struct {
3742
      int64_t uid;
3743
      int64_t ts;
3744
      SValue  primaryKey;
3745
    };
3746
    // log
3747
    struct {
3748
      int64_t version;
3749
    };
3750
  };
3751
} STqOffsetVal;
3752

3753
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3754
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,442✔
3755
  pOffsetVal->uid = uid;
26,442✔
3756
  pOffsetVal->ts = ts;
26,442✔
3757
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,442!
3758
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3759
  }
3760
  pOffsetVal->primaryKey = primaryKey;
26,442✔
3761
}
26,442✔
3762

3763
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3764
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
3765
  pOffsetVal->uid = uid;
148✔
3766
}
148✔
3767

3768
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3769
  pOffsetVal->type = TMQ_OFFSET__LOG;
645,049✔
3770
  pOffsetVal->version = ver;
645,049✔
3771
}
645,049✔
3772

3773
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3774
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3775
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3776
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3777
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3778
void    tOffsetDestroy(void* pVal);
3779

3780
typedef struct {
3781
  STqOffsetVal val;
3782
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3783
} STqOffset;
3784

3785
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3786
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3787
void    tDeleteSTqOffset(void* val);
3788

3789
typedef struct SMqVgOffset {
3790
  int64_t   consumerId;
3791
  STqOffset offset;
3792
} SMqVgOffset;
3793

3794
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3795
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3796

3797
typedef struct {
3798
  SMsgHead head;
3799
  int64_t  streamId;
3800
  int32_t  taskId;
3801
} SVPauseStreamTaskReq;
3802

3803
typedef struct {
3804
  SMsgHead head;
3805
  int64_t  streamId;
3806
  int32_t  taskId;
3807
  int64_t  chkptId;
3808
} SVResetStreamTaskReq;
3809

3810
typedef struct {
3811
  char   name[TSDB_STREAM_FNAME_LEN];
3812
  int8_t igNotExists;
3813
} SMPauseStreamReq;
3814

3815
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3816
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3817

3818
typedef struct {
3819
  SMsgHead head;
3820
  int32_t  taskId;
3821
  int64_t  streamId;
3822
  int8_t   igUntreated;
3823
} SVResumeStreamTaskReq;
3824

3825
typedef struct {
3826
  int8_t reserved;
3827
} SVResumeStreamTaskRsp;
3828

3829
typedef struct {
3830
  char   name[TSDB_STREAM_FNAME_LEN];
3831
  int8_t igNotExists;
3832
  int8_t igUntreated;
3833
} SMResumeStreamReq;
3834

3835
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3836
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3837

3838
typedef struct {
3839
  char    name[TSDB_TABLE_FNAME_LEN];
3840
  char    stb[TSDB_TABLE_FNAME_LEN];
3841
  int8_t  igExists;
3842
  int8_t  intervalUnit;
3843
  int8_t  slidingUnit;
3844
  int8_t  timezone;
3845
  int32_t dstVgId;  // for stream
3846
  int64_t interval;
3847
  int64_t offset;
3848
  int64_t sliding;
3849
  int64_t maxDelay;
3850
  int64_t watermark;
3851
  int32_t exprLen;        // strlen + 1
3852
  int32_t tagsFilterLen;  // strlen + 1
3853
  int32_t sqlLen;         // strlen + 1
3854
  int32_t astLen;         // strlen + 1
3855
  char*   expr;
3856
  char*   tagsFilter;
3857
  char*   sql;
3858
  char*   ast;
3859
  int64_t deleteMark;
3860
  int64_t lastTs;
3861
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3862
  SArray* pVgroupVerList;
3863
  int8_t  recursiveTsma;
3864
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3865
} SMCreateSmaReq;
3866

3867
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3868
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3869
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3870

3871
typedef struct {
3872
  char   name[TSDB_TABLE_FNAME_LEN];
3873
  int8_t igNotExists;
3874
} SMDropSmaReq;
3875

3876
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3877
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3878

3879
typedef struct {
3880
  char   dbFName[TSDB_DB_FNAME_LEN];
3881
  char   stbName[TSDB_TABLE_NAME_LEN];
3882
  char   colName[TSDB_COL_NAME_LEN];
3883
  char   idxName[TSDB_INDEX_FNAME_LEN];
3884
  int8_t idxType;
3885
} SCreateTagIndexReq;
3886

3887
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3888
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3889

3890
typedef SMDropSmaReq SDropTagIndexReq;
3891

3892
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3893
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3894

3895
typedef struct {
3896
  int8_t         version;       // for compatibility(default 0)
3897
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3898
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3899
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3900
  int32_t        dstVgId;
3901
  char           indexName[TSDB_INDEX_NAME_LEN];
3902
  int32_t        exprLen;
3903
  int32_t        tagsFilterLen;
3904
  int64_t        indexUid;
3905
  tb_uid_t       tableUid;  // super/child/common table uid
3906
  tb_uid_t       dstTbUid;  // for dstVgroup
3907
  int64_t        interval;
3908
  int64_t        offset;  // use unit by precision of DB
3909
  int64_t        sliding;
3910
  char*          dstTbName;  // for dstVgroup
3911
  char*          expr;       // sma expression
3912
  char*          tagsFilter;
3913
  SSchemaWrapper schemaRow;  // for dstVgroup
3914
  SSchemaWrapper schemaTag;  // for dstVgroup
3915
} STSma;                     // Time-range-wise SMA
3916

3917
typedef STSma SVCreateTSmaReq;
3918

3919
typedef struct {
3920
  int8_t  type;  // 0 status report, 1 update data
3921
  int64_t indexUid;
3922
  int64_t skey;  // start TS key of interval/sliding window
3923
} STSmaMsg;
3924

3925
typedef struct {
3926
  int64_t indexUid;
3927
  char    indexName[TSDB_INDEX_NAME_LEN];
3928
} SVDropTSmaReq;
3929

3930
typedef struct {
3931
  int tmp;  // TODO: to avoid compile error
3932
} SVCreateTSmaRsp, SVDropTSmaRsp;
3933

3934
#if 0
3935
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3936
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3937
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3938
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3939
#endif
3940

3941
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3942
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3943
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3944
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3945

3946
typedef struct {
3947
  int32_t number;
3948
  STSma*  tSma;
3949
} STSmaWrapper;
3950

3951
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3952
  if (pSma) {
3!
3953
    taosMemoryFreeClear(pSma->dstTbName);
3!
3954
    taosMemoryFreeClear(pSma->expr);
3!
3955
    taosMemoryFreeClear(pSma->tagsFilter);
3!
3956
  }
3957
}
3✔
3958

3959
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3960
  if (pSW) {
×
3961
    if (pSW->tSma) {
×
3962
      if (deepCopy) {
×
3963
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3964
          tDestroyTSma(pSW->tSma + i);
×
3965
        }
3966
      }
3967
      taosMemoryFreeClear(pSW->tSma);
×
3968
    }
3969
  }
3970
}
×
3971

3972
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3973
  tDestroyTSmaWrapper(pSW, deepCopy);
×
3974
  taosMemoryFreeClear(pSW);
×
3975
  return NULL;
×
3976
}
3977

3978
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3979
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3980

3981
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
3982
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
3983

3984
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
3985
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
3986
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3987
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
3988
  }
3989
  return 0;
×
3990
}
3991

3992
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
3993
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
3994
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3995
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
3996
  }
3997
  return 0;
×
3998
}
3999

4000
typedef struct {
4001
  int idx;
4002
} SMCreateFullTextReq;
4003

4004
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4005
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4006
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4007

4008
typedef struct {
4009
  char   name[TSDB_TABLE_FNAME_LEN];
4010
  int8_t igNotExists;
4011
} SMDropFullTextReq;
4012

4013
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4014
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4015

4016
typedef struct {
4017
  char indexFName[TSDB_INDEX_FNAME_LEN];
4018
} SUserIndexReq;
4019

4020
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4021
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4022

4023
typedef struct {
4024
  char dbFName[TSDB_DB_FNAME_LEN];
4025
  char tblFName[TSDB_TABLE_FNAME_LEN];
4026
  char colName[TSDB_COL_NAME_LEN];
4027
  char indexType[TSDB_INDEX_TYPE_LEN];
4028
  char indexExts[TSDB_INDEX_EXTS_LEN];
4029
} SUserIndexRsp;
4030

4031
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4032
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4033

4034
typedef struct {
4035
  char tbFName[TSDB_TABLE_FNAME_LEN];
4036
} STableIndexReq;
4037

4038
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4039
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4040

4041
typedef struct {
4042
  int8_t  intervalUnit;
4043
  int8_t  slidingUnit;
4044
  int64_t interval;
4045
  int64_t offset;
4046
  int64_t sliding;
4047
  int64_t dstTbUid;
4048
  int32_t dstVgId;
4049
  SEpSet  epSet;
4050
  char*   expr;
4051
} STableIndexInfo;
4052

4053
typedef struct {
4054
  char     tbName[TSDB_TABLE_NAME_LEN];
4055
  char     dbFName[TSDB_DB_FNAME_LEN];
4056
  uint64_t suid;
4057
  int32_t  version;
4058
  int32_t  indexSize;
4059
  SArray*  pIndex;  // STableIndexInfo
4060
} STableIndexRsp;
4061

4062
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4063
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4064
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4065

4066
void tFreeSTableIndexInfo(void* pInfo);
4067

4068
typedef struct {
4069
  int8_t  mqMsgType;
4070
  int32_t code;
4071
  int32_t epoch;
4072
  int64_t consumerId;
4073
  int64_t walsver;
4074
  int64_t walever;
4075
} SMqRspHead;
4076

4077
typedef struct {
4078
  SMsgHead     head;
4079
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4080
  int8_t       withTbName;
4081
  int8_t       useSnapshot;
4082
  int32_t      epoch;
4083
  uint64_t     reqId;
4084
  int64_t      consumerId;
4085
  int64_t      timeout;
4086
  STqOffsetVal reqOffset;
4087
  int8_t       enableReplay;
4088
  int8_t       sourceExcluded;
4089
  int8_t       enableBatchMeta;
4090
} SMqPollReq;
4091

4092
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4093
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4094
void    tDestroySMqPollReq(SMqPollReq* pReq);
4095

4096
typedef struct {
4097
  int32_t vgId;
4098
  int64_t offset;
4099
  SEpSet  epSet;
4100
} SMqSubVgEp;
4101

4102
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4103
  int32_t tlen = 0;
8,714✔
4104
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,714✔
4105
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,714✔
4106
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,714✔
4107
  return tlen;
8,714✔
4108
}
4109

4110
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4111
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,236!
4112
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,236!
4113
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,236✔
4114
  return buf;
4,236✔
4115
}
4116

4117
typedef struct {
4118
  char           topic[TSDB_TOPIC_FNAME_LEN];
4119
  char           db[TSDB_DB_FNAME_LEN];
4120
  SArray*        vgs;  // SArray<SMqSubVgEp>
4121
  SSchemaWrapper schema;
4122
} SMqSubTopicEp;
4123

4124
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4125
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4126
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4127

4128
typedef struct {
4129
  SMqRspHead   head;
4130
  STqOffsetVal rspOffset;
4131
  int16_t      resMsgType;
4132
  int32_t      metaRspLen;
4133
  void*        metaRsp;
4134
} SMqMetaRsp;
4135

4136
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4137
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4138
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4139

4140
#define MQ_DATA_RSP_VERSION 100
4141

4142
typedef struct {
4143
  SMqRspHead   head;
4144
  STqOffsetVal rspOffset;
4145
  STqOffsetVal reqOffset;
4146
  int32_t      blockNum;
4147
  int8_t       withTbName;
4148
  int8_t       withSchema;
4149
  SArray*      blockDataLen;
4150
  SArray*      blockData;
4151
  SArray*      blockTbName;
4152
  SArray*      blockSchema;
4153

4154
  union{
4155
    struct{
4156
      int64_t          sleepTime;
4157
    };
4158
    struct{
4159
      int32_t          createTableNum;
4160
      SArray*          createTableLen;
4161
      SArray*          createTableReq;
4162
    };
4163
  };
4164

4165
} SMqDataRsp;
4166

4167
int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj);
4168
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4169
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4170

4171
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4172
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4173
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4174

4175
typedef struct SMqBatchMetaRsp {
4176
  SMqRspHead   head;  // not serialize
4177
  STqOffsetVal rspOffset;
4178
  SArray*      batchMetaLen;
4179
  SArray*      batchMetaReq;
4180
  void*        pMetaBuff;    // not serialize
4181
  uint32_t     metaBuffLen;  // not serialize
4182
} SMqBatchMetaRsp;
4183

4184
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4185
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4186
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4187
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4188

4189
typedef struct {
4190
  SMqRspHead head;
4191
  char       cgroup[TSDB_CGROUP_LEN];
4192
  SArray*    topics;  // SArray<SMqSubTopicEp>
4193
} SMqAskEpRsp;
4194

4195
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4196
  int32_t tlen = 0;
17,686✔
4197
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4198
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,686!
4199
  tlen += taosEncodeFixedI32(buf, sz);
17,686✔
4200
  for (int32_t i = 0; i < sz; i++) {
24,362✔
4201
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,676✔
4202
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,676✔
4203
  }
4204
  return tlen;
17,686✔
4205
}
4206

4207
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4208
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4209
  int32_t sz;
4210
  buf = taosDecodeFixedI32(buf, &sz);
8,193✔
4211
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,193✔
4212
  if (pRsp->topics == NULL) {
8,195!
4213
    return NULL;
×
4214
  }
4215
  for (int32_t i = 0; i < sz; i++) {
11,426✔
4216
    SMqSubTopicEp topicEp;
4217
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,231✔
4218
    if (buf == NULL) {
3,231!
4219
      return NULL;
×
4220
    }
4221
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,462!
4222
      return NULL;
×
4223
    }
4224
  }
4225
  return buf;
8,195✔
4226
}
4227

4228
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4229
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,277✔
4230
}
20,277✔
4231

4232
typedef struct {
4233
  int32_t      vgId;
4234
  STqOffsetVal offset;
4235
  int64_t      rows;
4236
  int64_t      ever;
4237
} OffsetRows;
4238

4239
typedef struct {
4240
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4241
  SArray* offsetRows;
4242
} TopicOffsetRows;
4243

4244
typedef struct {
4245
  int64_t consumerId;
4246
  int32_t epoch;
4247
  SArray* topics;
4248
  int8_t  pollFlag;
4249
} SMqHbReq;
4250

4251
typedef struct {
4252
  char   topic[TSDB_TOPIC_FNAME_LEN];
4253
  int8_t noPrivilege;
4254
} STopicPrivilege;
4255

4256
typedef struct {
4257
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4258
  int32_t debugFlag;
4259
} SMqHbRsp;
4260

4261
typedef struct {
4262
  SMsgHead head;
4263
  int64_t  consumerId;
4264
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4265
} SMqSeekReq;
4266

4267
#define TD_AUTO_CREATE_TABLE 0x1
4268
typedef struct {
4269
  int64_t       suid;
4270
  int64_t       uid;
4271
  int32_t       sver;
4272
  uint32_t      nData;
4273
  uint8_t*      pData;
4274
  SVCreateTbReq cTbReq;
4275
} SVSubmitBlk;
4276

4277
typedef struct {
4278
  SMsgHead header;
4279
  uint64_t sId;
4280
  uint64_t queryId;
4281
  uint64_t clientId;
4282
  uint64_t taskId;
4283
  uint32_t sqlLen;
4284
  uint32_t phyLen;
4285
  char*    sql;
4286
  char*    msg;
4287
  int8_t   source;
4288
} SVDeleteReq;
4289

4290
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4291
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4292

4293
typedef struct {
4294
  int64_t affectedRows;
4295
} SVDeleteRsp;
4296

4297
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4298
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4299

4300
typedef struct SDeleteRes {
4301
  uint64_t suid;
4302
  SArray*  uidList;
4303
  int64_t  skey;
4304
  int64_t  ekey;
4305
  int64_t  affectedRows;
4306
  char     tableFName[TSDB_TABLE_NAME_LEN];
4307
  char     tsColName[TSDB_COL_NAME_LEN];
4308
  int64_t  ctimeMs;  // fill by vnode
4309
  int8_t   source;
4310
} SDeleteRes;
4311

4312
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4313
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4314

4315
typedef struct {
4316
  // int64_t uid;
4317
  char    tbname[TSDB_TABLE_NAME_LEN];
4318
  int64_t startTs;
4319
  int64_t endTs;
4320
} SSingleDeleteReq;
4321

4322
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4323
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4324

4325
typedef struct {
4326
  int64_t suid;
4327
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4328
  int64_t ctimeMs;     // fill by vnode
4329
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4330
} SBatchDeleteReq;
4331

4332
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4333
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4334
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4335

4336
typedef struct {
4337
  int32_t msgIdx;
4338
  int32_t msgType;
4339
  int32_t msgLen;
4340
  void*   msg;
4341
} SBatchMsg;
4342

4343
typedef struct {
4344
  SMsgHead header;
4345
  SArray*  pMsgs;  // SArray<SBatchMsg>
4346
} SBatchReq;
4347

4348
typedef struct {
4349
  int32_t reqType;
4350
  int32_t msgIdx;
4351
  int32_t msgLen;
4352
  int32_t rspCode;
4353
  void*   msg;
4354
} SBatchRspMsg;
4355

4356
typedef struct {
4357
  SArray* pRsps;  // SArray<SBatchRspMsg>
4358
} SBatchRsp;
4359

4360
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4361
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4362
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6,959,009✔
4363
  if (NULL == msg) {
6,959,009!
4364
    return;
×
4365
  }
4366
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6,959,009✔
4367
  taosMemoryFree(pMsg->msg);
6,959,009✔
4368
}
4369

4370
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4371
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4372

4373
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,499,618✔
4374
  if (NULL == p) {
1,499,618!
4375
    return;
×
4376
  }
4377

4378
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,499,618✔
4379
  taosMemoryFree(pRsp->msg);
1,499,618✔
4380
}
4381

4382
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4383
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4384
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4385
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4386
void    tDestroySMqHbReq(SMqHbReq* pReq);
4387

4388
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4389
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4390
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4391

4392
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4393
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4394

4395
#define TD_REQ_FROM_APP               0x0
4396
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4397
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4398
#define SUBMIT_REQ_FROM_FILE          0x4
4399
#define TD_REQ_FROM_TAOX              0x8
4400
#define SUBMIT_REQUEST_VERSION        (1)
4401

4402
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4403

4404
typedef struct {
4405
  int32_t        flags;
4406
  SVCreateTbReq* pCreateTbReq;
4407
  int64_t        suid;
4408
  int64_t        uid;
4409
  int32_t        sver;
4410
  union {
4411
    SArray* aRowP;
4412
    SArray* aCol;
4413
  };
4414
  int64_t ctimeMs;
4415
} SSubmitTbData;
4416

4417
typedef struct {
4418
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4419
} SSubmitReq2;
4420

4421
typedef struct {
4422
  SMsgHead header;
4423
  int64_t  version;
4424
  char     data[];  // SSubmitReq2
4425
} SSubmitReq2Msg;
4426

4427
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4428
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4429
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4430
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4431

4432
typedef struct {
4433
  int32_t affectedRows;
4434
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4435
} SSubmitRsp2;
4436

4437
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4438
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4439
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4440

4441
#define TSDB_MSG_FLG_ENCODE 0x1
4442
#define TSDB_MSG_FLG_DECODE 0x2
4443
#define TSDB_MSG_FLG_CMPT   0x3
4444

4445
typedef struct {
4446
  union {
4447
    struct {
4448
      void*   msgStr;
4449
      int32_t msgLen;
4450
      int64_t ver;
4451
    };
4452
    void* pDataBlock;
4453
  };
4454
} SPackedData;
4455

4456
typedef struct {
4457
  char     fullname[TSDB_VIEW_FNAME_LEN];
4458
  char     name[TSDB_VIEW_NAME_LEN];
4459
  char     dbFName[TSDB_DB_FNAME_LEN];
4460
  char*    querySql;
4461
  char*    sql;
4462
  int8_t   orReplace;
4463
  int8_t   precision;
4464
  int32_t  numOfCols;
4465
  SSchema* pSchema;
4466
} SCMCreateViewReq;
4467

4468
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4469
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4470
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4471

4472
typedef struct {
4473
  char   fullname[TSDB_VIEW_FNAME_LEN];
4474
  char   name[TSDB_VIEW_NAME_LEN];
4475
  char   dbFName[TSDB_DB_FNAME_LEN];
4476
  char*  sql;
4477
  int8_t igNotExists;
4478
} SCMDropViewReq;
4479

4480
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4481
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4482
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4483

4484
typedef struct {
4485
  char fullname[TSDB_VIEW_FNAME_LEN];
4486
} SViewMetaReq;
4487
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4488
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4489

4490
typedef struct {
4491
  char     name[TSDB_VIEW_NAME_LEN];
4492
  char     dbFName[TSDB_DB_FNAME_LEN];
4493
  char*    user;
4494
  uint64_t dbId;
4495
  uint64_t viewId;
4496
  char*    querySql;
4497
  int8_t   precision;
4498
  int8_t   type;
4499
  int32_t  version;
4500
  int32_t  numOfCols;
4501
  SSchema* pSchema;
4502
} SViewMetaRsp;
4503
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4504
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4505
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4506
typedef struct {
4507
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4508
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4509
} STableTSMAInfoReq;
4510

4511
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4512
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4513

4514
typedef struct {
4515
  int32_t  funcId;
4516
  col_id_t colId;
4517
} STableTSMAFuncInfo;
4518

4519
typedef struct {
4520
  char     name[TSDB_TABLE_NAME_LEN];
4521
  uint64_t tsmaId;
4522
  char     targetTb[TSDB_TABLE_NAME_LEN];
4523
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4524
  char     tb[TSDB_TABLE_NAME_LEN];
4525
  char     dbFName[TSDB_DB_FNAME_LEN];
4526
  uint64_t suid;
4527
  uint64_t destTbUid;
4528
  uint64_t dbId;
4529
  int32_t  version;
4530
  int64_t  interval;
4531
  int8_t   unit;
4532
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4533
  SArray*  pTags;      // SArray<SSchema>
4534
  SArray*  pUsedCols;  // SArray<SSchema>
4535
  char*    ast;
4536

4537
  int64_t streamUid;
4538
  int64_t reqTs;
4539
  int64_t rspTs;
4540
  int64_t delayDuration;  // ms
4541
  bool    fillHistoryFinished;
4542
} STableTSMAInfo;
4543

4544
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4545
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4546
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4547
void    tFreeTableTSMAInfo(void* p);
4548
void    tFreeAndClearTableTSMAInfo(void* p);
4549
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4550

4551
#define STSMAHbRsp            STableTSMAInfoRsp
4552
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4553
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4554
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4555

4556
typedef struct SStreamProgressReq {
4557
  int64_t streamId;
4558
  int32_t vgId;
4559
  int32_t fetchIdx;
4560
  int32_t subFetchIdx;
4561
} SStreamProgressReq;
4562

4563
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4564
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4565

4566
typedef struct SStreamProgressRsp {
4567
  int64_t streamId;
4568
  int32_t vgId;
4569
  bool    fillHisFinished;
4570
  int64_t progressDelay;
4571
  int32_t fetchIdx;
4572
  int32_t subFetchIdx;
4573
} SStreamProgressRsp;
4574

4575
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4576
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4577

4578
typedef struct SDropCtbWithTsmaSingleVgReq {
4579
  SVgroupInfo vgInfo;
4580
  SArray*     pTbs;  // SVDropTbReq
4581
} SMDropTbReqsOnSingleVg;
4582

4583
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4584
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4585
void    tFreeSMDropTbReqOnSingleVg(void* p);
4586

4587
typedef struct SDropTbsReq {
4588
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4589
} SMDropTbsReq;
4590

4591
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4592
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4593
void    tFreeSMDropTbsReq(void*);
4594

4595
typedef struct SVFetchTtlExpiredTbsRsp {
4596
  SArray* pExpiredTbs;  // SVDropTbReq
4597
  int32_t vgId;
4598
} SVFetchTtlExpiredTbsRsp;
4599

4600
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4601
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4602

4603
void tFreeFetchTtlExpiredTbsRsp(void* p);
4604

4605
void setDefaultOptionsForField(SFieldWithOptions* field);
4606
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4607

4608
#pragma pack(pop)
4609

4610
#ifdef __cplusplus
4611
}
4612
#endif
4613

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

© 2025 Coveralls, Inc