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

taosdata / TDengine / #4791

13 Oct 2025 06:50AM UTC coverage: 57.628% (-0.8%) from 58.476%
#4791

push

travis-ci

web-flow
Merge pull request #33213 from taosdata/fix/huoh/timemoe_model_directory

fix: fix tdgpt timemoe model directory

136628 of 303332 branches covered (45.04%)

Branch coverage included in aggregate %.

208121 of 294900 relevant lines covered (70.57%)

4250784.02 hits per line

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

39.15
/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

72
#define DECODESQL()                                                               \
73
  do {                                                                            \
74
    if (!tDecodeIsEnd(&decoder)) {                                                \
75
      TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->sqlLen));                       \
76
      if (pReq->sqlLen > 0) {                                                     \
77
        TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, (void **)&pReq->sql, NULL)); \
78
      }                                                                           \
79
    }                                                                             \
80
  } while (0)
81

82
#define ENCODESQL()                                                                       \
83
  do {                                                                                    \
84
    TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->sqlLen));                                  \
85
    if (pReq->sqlLen > 0) {                                                               \
86
      TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->sql, pReq->sqlLen)); \
87
    }                                                                                     \
88
  } while (0)
89

90
#define FREESQL()                \
91
  do {                           \
92
    if (pReq->sql != NULL) {     \
93
      taosMemoryFree(pReq->sql); \
94
    }                            \
95
    pReq->sql = NULL;            \
96
  } while (0)
97

98

99
static inline bool tmsgIsValid(tmsg_t type) {
19,650,167✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
19,650,167✔
102
  int    segIdx = TMSG_SEG_CODE(type);
19,650,167✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
19,650,167!
104
    return type < tMsgRangeDict[segIdx];
19,653,277✔
105
  }
106
  return false;
1✔
107
}
108

109
#define TMSG_INFO(type) (tmsgIsValid(type) ? tMsgInfo[TMSG_INDEX(type)] : "unKnown")
110

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,280,402✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,202,968!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
4,483,370✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
4,980,807✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
4,980,807✔
119
}
120

121
/* ------------------------ OTHER DEFINITIONS ------------------------ */
122
// IE type
123
#define TSDB_IE_TYPE_SEC         1
124
#define TSDB_IE_TYPE_META        2
125
#define TSDB_IE_TYPE_MGMT_IP     3
126
#define TSDB_IE_TYPE_DNODE_CFG   4
127
#define TSDB_IE_TYPE_NEW_VERSION 5
128
#define TSDB_IE_TYPE_DNODE_EXT   6
129
#define TSDB_IE_TYPE_DNODE_STATE 7
130

131
enum {
132
  CONN_TYPE__QUERY = 1,
133
  CONN_TYPE__TMQ,
134
  CONN_TYPE__UDFD,
135
  CONN_TYPE__MAX,
136
};
137

138
enum {
139
  HEARTBEAT_KEY_USER_AUTHINFO = 1,
140
  HEARTBEAT_KEY_DBINFO,
141
  HEARTBEAT_KEY_STBINFO,
142
  HEARTBEAT_KEY_TMQ,
143
  HEARTBEAT_KEY_DYN_VIEW,
144
  HEARTBEAT_KEY_VIEWINFO,
145
  HEARTBEAT_KEY_TSMA,
146
};
147

148
typedef enum _mgmt_table {
149
  TSDB_MGMT_TABLE_START,
150
  TSDB_MGMT_TABLE_DNODE,
151
  TSDB_MGMT_TABLE_MNODE,
152
  TSDB_MGMT_TABLE_MODULE,
153
  TSDB_MGMT_TABLE_QNODE,
154
  TSDB_MGMT_TABLE_SNODE,
155
  TSDB_MGMT_TABLE_BACKUP_NODE,  // no longer used
156
  TSDB_MGMT_TABLE_CLUSTER,
157
  TSDB_MGMT_TABLE_DB,
158
  TSDB_MGMT_TABLE_FUNC,
159
  TSDB_MGMT_TABLE_INDEX,
160
  TSDB_MGMT_TABLE_STB,
161
  TSDB_MGMT_TABLE_STREAMS,
162
  TSDB_MGMT_TABLE_TABLE,
163
  TSDB_MGMT_TABLE_TAG,
164
  TSDB_MGMT_TABLE_COL,
165
  TSDB_MGMT_TABLE_USER,
166
  TSDB_MGMT_TABLE_GRANTS,
167
  TSDB_MGMT_TABLE_VGROUP,
168
  TSDB_MGMT_TABLE_TOPICS,
169
  TSDB_MGMT_TABLE_CONSUMERS,
170
  TSDB_MGMT_TABLE_SUBSCRIPTIONS,
171
  TSDB_MGMT_TABLE_TRANS,
172
  TSDB_MGMT_TABLE_SMAS,
173
  TSDB_MGMT_TABLE_CONFIGS,
174
  TSDB_MGMT_TABLE_CONNS,
175
  TSDB_MGMT_TABLE_QUERIES,
176
  TSDB_MGMT_TABLE_VNODES,
177
  TSDB_MGMT_TABLE_APPS,
178
  TSDB_MGMT_TABLE_STREAM_TASKS,
179
  TSDB_MGMT_TABLE_STREAM_RECALCULATES,
180
  TSDB_MGMT_TABLE_PRIVILEGES,
181
  TSDB_MGMT_TABLE_VIEWS,
182
  TSDB_MGMT_TABLE_TSMAS,
183
  TSDB_MGMT_TABLE_COMPACT,
184
  TSDB_MGMT_TABLE_COMPACT_DETAIL,
185
  TSDB_MGMT_TABLE_GRANTS_FULL,
186
  TSDB_MGMT_TABLE_GRANTS_LOGS,
187
  TSDB_MGMT_TABLE_MACHINES,
188
  TSDB_MGMT_TABLE_ARBGROUP,
189
  TSDB_MGMT_TABLE_ENCRYPTIONS,
190
  TSDB_MGMT_TABLE_USER_FULL,
191
  TSDB_MGMT_TABLE_ANODE,
192
  TSDB_MGMT_TABLE_ANODE_FULL,
193
  TSDB_MGMT_TABLE_USAGE,
194
  TSDB_MGMT_TABLE_FILESETS,
195
  TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
196
  TSDB_MGMT_TABLE_VC_COL,
197
  TSDB_MGMT_TABLE_BNODE,
198
  TSDB_MGMT_TABLE_MOUNT,
199
  TSDB_MGMT_TABLE_SSMIGRATE,
200
  TSDB_MGMT_TABLE_SCAN,
201
  TSDB_MGMT_TABLE_SCAN_DETAIL,
202
  TSDB_MGMT_TABLE_RSMA,
203
  TSDB_MGMT_TABLE_RETENTION,
204
  TSDB_MGMT_TABLE_RETENTION_DETAIL,
205
  TSDB_MGMT_TABLE_MAX,
206
} EShowType;
207

208
typedef enum {
209
  TSDB_OPTR_NORMAL = 0,  // default
210
  TSDB_OPTR_SSMIGRATE = 1,
211
  TSDB_OPTR_ROLLUP = 2,
212
} ETsdbOpType;
213

214
typedef enum {
215
  TSDB_TRIGGER_MANUAL = 0,  // default
216
  TSDB_TRIGGER_AUTO = 1,
217
} ETriggerType;
218

219
#define TSDB_ALTER_TABLE_ADD_TAG                         1
220
#define TSDB_ALTER_TABLE_DROP_TAG                        2
221
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
222
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
223
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
224
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
225
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
226
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
227
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
228
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
229
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
230
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
231
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
232
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
233
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
234
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
235
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
236
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
237

238
#define TSDB_FILL_NONE        0
239
#define TSDB_FILL_NULL        1
240
#define TSDB_FILL_NULL_F      2
241
#define TSDB_FILL_SET_VALUE   3
242
#define TSDB_FILL_SET_VALUE_F 4
243
#define TSDB_FILL_LINEAR      5
244
#define TSDB_FILL_PREV        6
245
#define TSDB_FILL_NEXT        7
246
#define TSDB_FILL_NEAR        8
247

248
#define TSDB_ALTER_USER_PASSWD          0x1
249
#define TSDB_ALTER_USER_SUPERUSER       0x2
250
#define TSDB_ALTER_USER_ENABLE          0x3
251
#define TSDB_ALTER_USER_SYSINFO         0x4
252
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
253
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
254
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
255
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
256
#define TSDB_ALTER_USER_CREATEDB        0x9
257

258
#define TSDB_ALTER_RSMA_FUNCTION        0x1
259

260
#define TSDB_KILL_MSG_LEN 30
261

262
#define TSDB_TABLE_NUM_UNIT 100000
263

264
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
265
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
266
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
267

268
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
269
#define TSDB_COL_TAG    0x1u  // the tag column type
270
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
271
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
272
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
273

274
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
275
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
276
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
277
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
278

279
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
280
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
281
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
282
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
283
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
284

285
typedef enum ENodeType {
286
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
287
  // VALUE, OPERATOR, FUNCTION and so on.
288
  QUERY_NODE_COLUMN = 1,
289
  QUERY_NODE_VALUE,
290
  QUERY_NODE_OPERATOR,
291
  QUERY_NODE_LOGIC_CONDITION,
292
  QUERY_NODE_FUNCTION,
293
  QUERY_NODE_REAL_TABLE,
294
  QUERY_NODE_TEMP_TABLE,
295
  QUERY_NODE_JOIN_TABLE,
296
  QUERY_NODE_GROUPING_SET,
297
  QUERY_NODE_ORDER_BY_EXPR,
298
  QUERY_NODE_LIMIT,
299
  QUERY_NODE_STATE_WINDOW,
300
  QUERY_NODE_SESSION_WINDOW,
301
  QUERY_NODE_INTERVAL_WINDOW,
302
  QUERY_NODE_NODE_LIST,
303
  QUERY_NODE_FILL,
304
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
305
  QUERY_NODE_TARGET,
306
  QUERY_NODE_DATABLOCK_DESC,
307
  QUERY_NODE_SLOT_DESC,
308
  QUERY_NODE_COLUMN_DEF,
309
  QUERY_NODE_DOWNSTREAM_SOURCE,
310
  QUERY_NODE_DATABASE_OPTIONS,
311
  QUERY_NODE_TABLE_OPTIONS,
312
  QUERY_NODE_INDEX_OPTIONS,
313
  QUERY_NODE_EXPLAIN_OPTIONS,
314
  QUERY_NODE_LEFT_VALUE,
315
  QUERY_NODE_COLUMN_REF,
316
  QUERY_NODE_WHEN_THEN,
317
  QUERY_NODE_CASE_WHEN,
318
  QUERY_NODE_EVENT_WINDOW,
319
  QUERY_NODE_HINT,
320
  QUERY_NODE_VIEW,
321
  QUERY_NODE_WINDOW_OFFSET,
322
  QUERY_NODE_COUNT_WINDOW,
323
  QUERY_NODE_COLUMN_OPTIONS,
324
  QUERY_NODE_TSMA_OPTIONS,
325
  QUERY_NODE_ANOMALY_WINDOW,
326
  QUERY_NODE_RANGE_AROUND,
327
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
328
  QUERY_NODE_VIRTUAL_TABLE,
329
  QUERY_NODE_SLIDING_WINDOW,
330
  QUERY_NODE_PERIOD_WINDOW,
331
  QUERY_NODE_STREAM_TRIGGER,
332
  QUERY_NODE_STREAM,
333
  QUERY_NODE_STREAM_TAG_DEF,
334
  QUERY_NODE_EXTERNAL_WINDOW,
335
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
336
  QUERY_NODE_PLACE_HOLDER_TABLE,
337
  QUERY_NODE_TIME_RANGE,
338
  QUERY_NODE_STREAM_OUT_TABLE,
339
  QUERY_NODE_STREAM_CALC_RANGE,
340
  QUERY_NODE_COUNT_WINDOW_ARGS,
341
  QUERY_NODE_BNODE_OPTIONS,
342

343
  // Statement nodes are used in parser and planner module.
344
  QUERY_NODE_SET_OPERATOR = 100,
345
  QUERY_NODE_SELECT_STMT,
346
  QUERY_NODE_VNODE_MODIFY_STMT,
347
  QUERY_NODE_CREATE_DATABASE_STMT,
348
  QUERY_NODE_DROP_DATABASE_STMT,
349
  QUERY_NODE_ALTER_DATABASE_STMT,
350
  QUERY_NODE_FLUSH_DATABASE_STMT,
351
  QUERY_NODE_TRIM_DATABASE_STMT,
352
  QUERY_NODE_CREATE_TABLE_STMT,
353
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
354
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
355
  QUERY_NODE_DROP_TABLE_CLAUSE,
356
  QUERY_NODE_DROP_TABLE_STMT,
357
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
358
  QUERY_NODE_ALTER_TABLE_STMT,
359
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
360
  QUERY_NODE_CREATE_USER_STMT,
361
  QUERY_NODE_ALTER_USER_STMT,
362
  QUERY_NODE_DROP_USER_STMT,
363
  QUERY_NODE_USE_DATABASE_STMT,
364
  QUERY_NODE_CREATE_DNODE_STMT,
365
  QUERY_NODE_DROP_DNODE_STMT,
366
  QUERY_NODE_ALTER_DNODE_STMT,
367
  QUERY_NODE_CREATE_INDEX_STMT,
368
  QUERY_NODE_DROP_INDEX_STMT,
369
  QUERY_NODE_CREATE_QNODE_STMT,
370
  QUERY_NODE_DROP_QNODE_STMT,
371
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
372
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
373
  QUERY_NODE_CREATE_SNODE_STMT,
374
  QUERY_NODE_DROP_SNODE_STMT,
375
  QUERY_NODE_CREATE_MNODE_STMT,
376
  QUERY_NODE_DROP_MNODE_STMT,
377
  QUERY_NODE_CREATE_TOPIC_STMT,
378
  QUERY_NODE_DROP_TOPIC_STMT,
379
  QUERY_NODE_DROP_CGROUP_STMT,
380
  QUERY_NODE_ALTER_LOCAL_STMT,
381
  QUERY_NODE_EXPLAIN_STMT,
382
  QUERY_NODE_DESCRIBE_STMT,
383
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
384
  QUERY_NODE_COMPACT_DATABASE_STMT,
385
  QUERY_NODE_COMPACT_VGROUPS_STMT,
386
  QUERY_NODE_CREATE_FUNCTION_STMT,
387
  QUERY_NODE_DROP_FUNCTION_STMT,
388
  QUERY_NODE_CREATE_STREAM_STMT,
389
  QUERY_NODE_DROP_STREAM_STMT,
390
  QUERY_NODE_BALANCE_VGROUP_STMT,
391
  QUERY_NODE_MERGE_VGROUP_STMT,
392
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
393
  QUERY_NODE_SPLIT_VGROUP_STMT,
394
  QUERY_NODE_SYNCDB_STMT,
395
  QUERY_NODE_GRANT_STMT,
396
  QUERY_NODE_REVOKE_STMT,
397
  QUERY_NODE_ALTER_CLUSTER_STMT,
398
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
399
  QUERY_NODE_CREATE_TSMA_STMT,
400
  QUERY_NODE_DROP_TSMA_STMT,
401
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
402
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
403
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
404
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
405
  QUERY_NODE_CREATE_MOUNT_STMT,
406
  QUERY_NODE_DROP_MOUNT_STMT,
407
  QUERY_NODE_SCAN_DATABASE_STMT,
408
  QUERY_NODE_SCAN_VGROUPS_STMT,
409

410
  // placeholder for [154, 180]
411
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
412
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
413
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
414
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
415
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
416
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
417
  QUERY_NODE_SHOW_SCORES_STMT,
418
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
419
  QUERY_NODE_KILL_CONNECTION_STMT,
420
  QUERY_NODE_KILL_QUERY_STMT,
421
  QUERY_NODE_KILL_TRANSACTION_STMT,
422
  QUERY_NODE_KILL_COMPACT_STMT,
423
  QUERY_NODE_DELETE_STMT,
424
  QUERY_NODE_INSERT_STMT,
425
  QUERY_NODE_QUERY,
426
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
427
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
428
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
429
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
430
  QUERY_NODE_RESTORE_DNODE_STMT,
431
  QUERY_NODE_RESTORE_QNODE_STMT,
432
  QUERY_NODE_RESTORE_MNODE_STMT,
433
  QUERY_NODE_RESTORE_VNODE_STMT,
434
  QUERY_NODE_PAUSE_STREAM_STMT,
435
  QUERY_NODE_RESUME_STREAM_STMT,
436
  QUERY_NODE_CREATE_VIEW_STMT,
437
  QUERY_NODE_DROP_VIEW_STMT,
438
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
439
  QUERY_NODE_CREATE_ANODE_STMT,
440
  QUERY_NODE_DROP_ANODE_STMT,
441
  QUERY_NODE_UPDATE_ANODE_STMT,
442
  QUERY_NODE_ASSIGN_LEADER_STMT,
443
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
444
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
445
  QUERY_NODE_RECALCULATE_STREAM_STMT,
446
  QUERY_NODE_CREATE_BNODE_STMT,
447
  QUERY_NODE_DROP_BNODE_STMT,
448
  QUERY_NODE_KILL_SSMIGRATE_STMT,
449
  QUERY_NODE_KILL_SCAN_STMT,
450
  QUERY_NODE_CREATE_RSMA_STMT,
451
  QUERY_NODE_DROP_RSMA_STMT,
452
  QUERY_NODE_ALTER_RSMA_STMT,
453
  QUERY_NODE_SHOW_CREATE_RSMA_STMT,
454
  QUERY_NODE_ROLLUP_DATABASE_STMT,
455
  QUERY_NODE_ROLLUP_VGROUPS_STMT,
456
  QUERY_NODE_KILL_RETENTION_STMT,
457

458
  // show statement nodes
459
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
460
  QUERY_NODE_SHOW_DNODES_STMT = 400,
461
  QUERY_NODE_SHOW_MNODES_STMT,
462
  QUERY_NODE_SHOW_MODULES_STMT,
463
  QUERY_NODE_SHOW_QNODES_STMT,
464
  QUERY_NODE_SHOW_SNODES_STMT,
465
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
466
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
467
  QUERY_NODE_SHOW_CLUSTER_STMT,
468
  QUERY_NODE_SHOW_DATABASES_STMT,
469
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
470
  QUERY_NODE_SHOW_INDEXES_STMT,
471
  QUERY_NODE_SHOW_STABLES_STMT,
472
  QUERY_NODE_SHOW_STREAMS_STMT,
473
  QUERY_NODE_SHOW_TABLES_STMT,
474
  QUERY_NODE_SHOW_TAGS_STMT,
475
  QUERY_NODE_SHOW_USERS_STMT,
476
  QUERY_NODE_SHOW_USERS_FULL_STMT,
477
  QUERY_NODE_SHOW_LICENCES_STMT,
478
  QUERY_NODE_SHOW_VGROUPS_STMT,
479
  QUERY_NODE_SHOW_TOPICS_STMT,
480
  QUERY_NODE_SHOW_CONSUMERS_STMT,
481
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
482
  QUERY_NODE_SHOW_QUERIES_STMT,
483
  QUERY_NODE_SHOW_APPS_STMT,
484
  QUERY_NODE_SHOW_VARIABLES_STMT,
485
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
486
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
487
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
488
  QUERY_NODE_SHOW_VNODES_STMT,
489
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
490
  QUERY_NODE_SHOW_VIEWS_STMT,
491
  QUERY_NODE_SHOW_COMPACTS_STMT,
492
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
493
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
494
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
495
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
496
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
497
  QUERY_NODE_SHOW_TSMAS_STMT,
498
  QUERY_NODE_SHOW_ANODES_STMT,
499
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
500
  QUERY_NODE_SHOW_USAGE_STMT,
501
  QUERY_NODE_SHOW_FILESETS_STMT,
502
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
503
  QUERY_NODE_SHOW_VTABLES_STMT,
504
  QUERY_NODE_SHOW_BNODES_STMT,
505
  QUERY_NODE_SHOW_MOUNTS_STMT,
506
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
507
  QUERY_NODE_SHOW_SCANS_STMT,
508
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
509
  QUERY_NODE_SHOW_RSMAS_STMT,
510
  QUERY_NODE_SHOW_RETENTIONS_STMT,
511
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
512

513
  // logic plan node
514
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
515
  QUERY_NODE_LOGIC_PLAN_JOIN,
516
  QUERY_NODE_LOGIC_PLAN_AGG,
517
  QUERY_NODE_LOGIC_PLAN_PROJECT,
518
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
519
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
520
  QUERY_NODE_LOGIC_PLAN_MERGE,
521
  QUERY_NODE_LOGIC_PLAN_WINDOW,
522
  QUERY_NODE_LOGIC_PLAN_FILL,
523
  QUERY_NODE_LOGIC_PLAN_SORT,
524
  QUERY_NODE_LOGIC_PLAN_PARTITION,
525
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
526
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
527
  QUERY_NODE_LOGIC_SUBPLAN,
528
  QUERY_NODE_LOGIC_PLAN,
529
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
530
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
531
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
532
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
533
  QUERY_NODE_LOGIC_PLAN_IMPUTATION_FUNC,
534

535
  // physical plan node
536
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
537
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
538
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
539
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
540
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
541
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
542
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
543
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
544
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
545
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
546
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
547
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
548
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
549
  QUERY_NODE_PHYSICAL_PLAN_SORT,
550
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
551
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
552
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
553
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
554
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
555
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
556
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
557
  QUERY_NODE_PHYSICAL_PLAN_FILL,
558
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
559
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
560
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
561
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
562
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
563
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
564
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
565
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
566
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
567
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
568
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
569
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
570
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
571
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
572
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
573
  QUERY_NODE_PHYSICAL_SUBPLAN,
574
  QUERY_NODE_PHYSICAL_PLAN,
575
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
576
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
577
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
578
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
579
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
580
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
581
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
582
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
583
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
584
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
585
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
586
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
587
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
588
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
589
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
590
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
591
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
592
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
593
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
594
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
595
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
596
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
597
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
598
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
599
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
600
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
601
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
602
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
603
  QUERY_NODE_PHYSICAL_PLAN_IMPUTATION_FUNC,
604
} ENodeType;
605

606
typedef struct {
607
  int32_t     vgId;
608
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
609
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
610
  const char* dbFName;
611
  const char* tbName;
612
} SBuildTableInput;
613

614
typedef struct {
615
  char    db[TSDB_DB_FNAME_LEN];
616
  int64_t dbId;
617
  int32_t vgVersion;
618
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
619
  int64_t stateTs;
620
} SBuildUseDBInput;
621

622
typedef struct SField {
623
  char    name[TSDB_COL_NAME_LEN];
624
  uint8_t type;
625
  int8_t  flags;
626
  int32_t bytes;
627
} SField;
628

629
typedef struct SFieldWithOptions {
630
  char     name[TSDB_COL_NAME_LEN];
631
  uint8_t  type;
632
  int8_t   flags;
633
  int32_t  bytes;
634
  uint32_t compress;
635
  STypeMod typeMod;
636
} SFieldWithOptions;
637

638
typedef struct SRetention {
639
  int64_t freq;
640
  int64_t keep;
641
  int8_t  freqUnit;
642
  int8_t  keepUnit;
643
} SRetention;
644

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

647
#pragma pack(push, 1)
648
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
649
typedef struct SEp {
650
  char     fqdn[TSDB_FQDN_LEN];
651
  uint16_t port;
652
} SEp;
653

654
typedef struct {
655
  int32_t contLen;
656
  int32_t vgId;
657
} SMsgHead;
658

659
// Submit message for one table
660
typedef struct SSubmitBlk {
661
  int64_t uid;        // table unique id
662
  int64_t suid;       // stable id
663
  int32_t sversion;   // data schema version
664
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
665
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
666
  int32_t numOfRows;  // total number of rows in current submit block
667
  char    data[];
668
} SSubmitBlk;
669

670
// Submit message for this TSDB
671
typedef struct {
672
  SMsgHead header;
673
  int64_t  version;
674
  int32_t  length;
675
  int32_t  numOfBlocks;
676
  char     blocks[];
677
} SSubmitReq;
678

679
typedef struct {
680
  int32_t totalLen;
681
  int32_t len;
682
  STSRow* row;
683
} SSubmitBlkIter;
684

685
typedef struct {
686
  int32_t totalLen;
687
  int32_t len;
688
  // head of SSubmitBlk
689
  int64_t uid;        // table unique id
690
  int64_t suid;       // stable id
691
  int32_t sversion;   // data schema version
692
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
693
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
694
  int32_t numOfRows;  // total number of rows in current submit block
695
  // head of SSubmitBlk
696
  int32_t     numOfBlocks;
697
  const void* pMsg;
698
} SSubmitMsgIter;
699

700
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
701
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
702
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
703
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
704
// for debug
705
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
706

707
typedef struct {
708
  bool     hasRef;
709
  col_id_t id;
710
  char     refDbName[TSDB_DB_NAME_LEN];
711
  char     refTableName[TSDB_TABLE_NAME_LEN];
712
  char     refColName[TSDB_COL_NAME_LEN];
713
} SColRef;
714

715
typedef struct {
716
  int32_t  nCols;
717
  int32_t  version;
718
  SColRef* pColRef;
719
} SColRefWrapper;
720

721
int32_t tEncodeSColRefWrapper(SEncoder *pCoder, const SColRefWrapper *pWrapper);
722
int32_t tDecodeSColRefWrapperEx(SDecoder *pDecoder, SColRefWrapper *pWrapper, bool decoderMalloc);
723
typedef struct {
724
  int32_t vgId;
725
  SColRef colRef;
726
} SColRefEx;
727

728
typedef struct {
729
  int16_t colId;
730
  char    refDbName[TSDB_DB_NAME_LEN];
731
  char    refTableName[TSDB_TABLE_NAME_LEN];
732
  char    refColName[TSDB_COL_NAME_LEN];
733
} SRefColInfo;
734

735
typedef struct SVCTableRefCols {
736
  uint64_t     uid;
737
  int32_t      numOfSrcTbls;
738
  int32_t      numOfColRefs;
739
  SRefColInfo* refCols;
740
} SVCTableRefCols;
741

742
typedef struct SVCTableMergeInfo {
743
  uint64_t uid;
744
  int32_t  numOfSrcTbls;
745
} SVCTableMergeInfo;
746

747
typedef struct {
748
  int32_t    nCols;
749
  SColRefEx* pColRefEx;
750
} SColRefExWrapper;
751

752
struct SSchema {
753
  int8_t   type;
754
  int8_t   flags;
755
  col_id_t colId;
756
  int32_t  bytes;
757
  char     name[TSDB_COL_NAME_LEN];
758
};
759
struct SSchemaExt {
760
  col_id_t colId;
761
  uint32_t compress;
762
  STypeMod typeMod;
763
};
764

765
struct SSchemaRsma {
766
  int64_t    interval[2];
767
  int32_t    nFuncs;
768
  int8_t     tbType;
769
  tb_uid_t   tbUid;
770
  func_id_t* funcIds;
771
  char       tbName[TSDB_TABLE_NAME_LEN];
772
};
773

774
struct SSchema2 {
775
  int8_t   type;
776
  int8_t   flags;
777
  col_id_t colId;
778
  int32_t  bytes;
779
  char     name[TSDB_COL_NAME_LEN];
780
  uint32_t compress;
781
};
782

783
typedef struct {
784
  char        tbName[TSDB_TABLE_NAME_LEN];
785
  char        stbName[TSDB_TABLE_NAME_LEN];
786
  char        dbFName[TSDB_DB_FNAME_LEN];
787
  int64_t     dbId;
788
  int32_t     numOfTags;
789
  int32_t     numOfColumns;
790
  int8_t      precision;
791
  int8_t      tableType;
792
  int32_t     sversion;
793
  int32_t     tversion;
794
  int32_t     rversion;
795
  uint64_t    suid;
796
  uint64_t    tuid;
797
  int32_t     vgId;
798
  int8_t      sysInfo;
799
  SSchema*    pSchemas;
800
  SSchemaExt* pSchemaExt;
801
  int8_t      virtualStb;
802
  int32_t     numOfColRefs;
803
  SColRef*    pColRefs;
804
} STableMetaRsp;
805

806
typedef struct {
807
  int32_t        code;
808
  int64_t        uid;
809
  char*          tblFName;
810
  int32_t        numOfRows;
811
  int32_t        affectedRows;
812
  int64_t        sver;
813
  STableMetaRsp* pMeta;
814
} SSubmitBlkRsp;
815

816
typedef struct {
817
  int32_t numOfRows;
818
  int32_t affectedRows;
819
  int32_t nBlocks;
820
  union {
821
    SArray*        pArray;
822
    SSubmitBlkRsp* pBlocks;
823
  };
824
} SSubmitRsp;
825

826
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
827
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
828
// void    tFreeSSubmitBlkRsp(void* param);
829
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
830

831
#define COL_SMA_ON       ((int8_t)0x1)
832
#define COL_IDX_ON       ((int8_t)0x2)
833
#define COL_IS_KEY       ((int8_t)0x4)
834
#define COL_SET_NULL     ((int8_t)0x10)
835
#define COL_SET_VAL      ((int8_t)0x20)
836
#define COL_IS_SYSINFO   ((int8_t)0x40)
837
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
838
#define COL_REF_BY_STM   ((int8_t)0x08)
839

840
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
841
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
842

843
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
844
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
845
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
846

847
#define SSCHMEA_SET_IDX_ON(s) \
848
  do {                        \
849
    (s)->flags |= COL_IDX_ON; \
850
  } while (0)
851

852
#define SSCHMEA_SET_IDX_OFF(s)   \
853
  do {                           \
854
    (s)->flags &= (~COL_IDX_ON); \
855
  } while (0)
856

857
#define SSCHEMA_SET_TYPE_MOD(s)     \
858
  do {                              \
859
    (s)->flags |= COL_HAS_TYPE_MOD; \
860
  } while (0)
861

862
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
863

864
#define SSCHMEA_TYPE(s)  ((s)->type)
865
#define SSCHMEA_FLAGS(s) ((s)->flags)
866
#define SSCHMEA_COLID(s) ((s)->colId)
867
#define SSCHMEA_BYTES(s) ((s)->bytes)
868
#define SSCHMEA_NAME(s)  ((s)->name)
869

870
typedef struct {
871
  bool    tsEnableMonitor;
872
  int32_t tsMonitorInterval;
873
  int32_t tsSlowLogThreshold;
874
  int32_t tsSlowLogMaxLen;
875
  int32_t tsSlowLogScope;
876
  int32_t tsSlowLogThresholdTest;  // Obsolete
877
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
878
} SMonitorParas;
879

880
typedef struct {
881
  STypeMod typeMod;
882
} SExtSchema;
883

884
bool hasExtSchema(const SExtSchema* pExtSchema);
885

886
typedef struct {
887
  int32_t      nCols;
888
  int32_t      version;
889
  SSchema*     pSchema;
890
  SSchemaRsma* pRsma;
891
} SSchemaWrapper;
892

893
typedef struct {
894
  col_id_t id;
895
  uint32_t alg;
896
} SColCmpr;
897

898
typedef struct {
899
  int32_t   nCols;
900
  int32_t   version;
901
  SColCmpr* pColCmpr;
902
} SColCmprWrapper;
903

904
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
905
  if (pRef->pColRef) {
2!
906
    return TSDB_CODE_INVALID_PARA;
×
907
  }
908
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
2!
909
  if (pRef->pColRef == NULL) {
2!
910
    return terrno;
×
911
  }
912
  pRef->nCols = nCols;
2✔
913
  for (int32_t i = 0; i < nCols; i++) {
6✔
914
    pRef->pColRef[i].hasRef = false;
4✔
915
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4✔
916
  }
917
  return 0;
2✔
918
}
919

920
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
921
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
922
    terrno = TSDB_CODE_INVALID_PARA;
923
    return NULL;
924
  }
925

926
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
927
  if (pDstWrapper == NULL) {
928
    return NULL;
929
  }
930
  pDstWrapper->nCols = pSrcWrapper->nCols;
931
  pDstWrapper->version = pSrcWrapper->version;
932

933
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
934
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
935
  if (pDstWrapper->pColCmpr == NULL) {
936
    taosMemoryFree(pDstWrapper);
937
    return NULL;
938
  }
939
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
940

941
  return pDstWrapper;
942
}
943

944
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
945
  if (!(!pCmpr->pColCmpr)) {
184!
946
    return TSDB_CODE_INVALID_PARA;
×
947
  }
948
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
184!
949
  if (pCmpr->pColCmpr == NULL) {
184!
950
    return terrno;
×
951
  }
952
  pCmpr->nCols = nCols;
184✔
953
  return 0;
184✔
954
}
955

956
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
957
  pCmpr->nCols = pSchema->nCols;
958
  if (!(!pCmpr->pColCmpr)) {
959
    return TSDB_CODE_INVALID_PARA;
960
  }
961
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
962
  if (pCmpr->pColCmpr == NULL) {
963
    return terrno;
964
  }
965
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
966
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
967
    SSchema*  pColSchema = &pSchema->pSchema[i];
968
    pColCmpr->id = pColSchema->colId;
969
    pColCmpr->alg = 0;
970
  }
971
  return 0;
972
}
973

974
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
975
  if (pWrapper == NULL) return;
976

977
  taosMemoryFreeClear(pWrapper->pColCmpr);
978
  taosMemoryFreeClear(pWrapper);
979
}
980
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
981
  if (pSchemaWrapper->pSchema == NULL) return NULL;
1,008,803!
982

983
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
1,008,803!
984
  if (pSW == NULL) {
1,009,320!
985
    return NULL;
×
986
  }
987
  pSW->nCols = pSchemaWrapper->nCols;
1,009,320✔
988
  pSW->version = pSchemaWrapper->version;
1,009,320✔
989
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,009,320!
990
  if (pSW->pSchema == NULL) {
1,008,961!
991
    taosMemoryFree(pSW);
×
992
    return NULL;
×
993
  }
994

995
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
1,008,961✔
996
  return pSW;
1,008,961✔
997
}
998

999
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
262,277✔
1000
  if (pSchemaWrapper) {
2,845,092!
1001
    taosMemoryFree(pSchemaWrapper->pSchema);
1,526,064!
1002
    if(pSchemaWrapper->pRsma) {
1,526,125!
1003
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
34!
1004
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
34!
1005
    }
1006
    taosMemoryFree(pSchemaWrapper);
1,526,125!
1007
  }
1008
}
2,715,387✔
1009

1010
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1011
  if (pSchemaWrapper) {
1012
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1013
    if(pSchemaWrapper->pRsma) {
1014
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1015
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1016
    }
1017
  }
1018
}
1019

1020
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
3,581✔
1021
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
3,581!
1022
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
3,581!
1023
  }
1024
}
3,581✔
1025

1026
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1027
  int32_t tlen = 0;
55,526✔
1028
  tlen += taosEncodeFixedI8(buf, pSchema->type);
111,052✔
1029
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
55,526!
1030
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
55,526!
1031
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
55,526!
1032
  tlen += taosEncodeString(buf, pSchema->name);
55,526✔
1033
  return tlen;
55,526✔
1034
}
1035

1036
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1037
  buf = taosDecodeFixedI8(buf, &pSchema->type);
8,690✔
1038
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
4,345✔
1039
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
4,345!
1040
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
4,345!
1041
  buf = taosDecodeStringTo(buf, pSchema->name);
4,345✔
1042
  return (void*)buf;
4,345✔
1043
}
1044

1045
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1046
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
96,495,426!
1047
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
147,908,072!
1048
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
147,908,072!
1049
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
147,908,072!
1050
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
147,908,072!
1051
  return 0;
73,954,036✔
1052
}
1053

1054
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1055
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
69,691,251!
1056
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
138,840,031!
1057
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
138,736,150!
1058
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
138,742,511!
1059
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
69,401,269!
1060
  return 0;
69,478,986✔
1061
}
1062

1063
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1064
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
43,246,116!
1065
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
43,246,116!
1066
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
43,246,116!
1067
  return 0;
21,623,058✔
1068
}
1069

1070
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1071
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
323,171!
1072
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
323,172!
1073
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
323,170!
1074
  return 0;
161,584✔
1075
}
1076

1077
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1078
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
45,748!
1079
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
45,748!
1080
  if (pColRef->hasRef) {
22,874✔
1081
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
28,000!
1082
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
28,000!
1083
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
28,000!
1084
  }
1085
  return 0;
22,874✔
1086
}
1087

1088
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1089
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
3,736!
1090
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
3,736!
1091
  if (pColRef->hasRef) {
1,868✔
1092
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
1,514!
1093
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
1,514!
1094
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
1,514!
1095
  }
1096

1097
  return 0;
1,868✔
1098
}
1099

1100
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1101
  int32_t tlen = 0;
7,524✔
1102
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
7,524✔
1103
  tlen += taosEncodeVariantI32(buf, pSW->version);
7,524✔
1104
  for (int32_t i = 0; i < pSW->nCols; i++) {
63,050✔
1105
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
111,052!
1106
  }
1107
  return tlen;
7,524✔
1108
}
1109

1110
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1111
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
610✔
1112
  buf = taosDecodeVariantI32(buf, &pSW->version);
610✔
1113
  if (pSW->nCols > 0) {
610✔
1114
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
572!
1115
    if (pSW->pSchema == NULL) {
572!
1116
      return NULL;
×
1117
    }
1118

1119
    for (int32_t i = 0; i < pSW->nCols; i++) {
4,917✔
1120
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
8,690✔
1121
    }
1122
  } else {
1123
    pSW->pSchema = NULL;
38✔
1124
  }
1125
  return (void*)buf;
610✔
1126
}
1127

1128
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1129
  if (pSW == NULL) {
648,765!
1130
    return TSDB_CODE_INVALID_PARA;
×
1131
  }
1132
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,297,530!
1133
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,297,530!
1134
  for (int32_t i = 0; i < pSW->nCols; i++) {
52,061,411!
1135
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
102,825,292!
1136
  }
1137
  return 0;
648,765✔
1138
}
1139

1140
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1141
  if (pSW == NULL) {
70,005!
1142
    return TSDB_CODE_INVALID_PARA;
×
1143
  }
1144
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
139,977!
1145
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
139,890!
1146

1147
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
69,918✔
1148
  if (pSW->pSchema == NULL) {
70,053!
1149
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1150
  }
1151
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,293,734✔
1152
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,447,748!
1153
  }
1154

1155
  return 0;
69,667✔
1156
}
1157

1158
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1159
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
7,840,842!
1160
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
7,851,770!
1161

1162
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
3,925,498!
1163
  if (pSW->pSchema == NULL) {
3,928,812!
1164
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1165
  }
1166
  for (int32_t i = 0; i < pSW->nCols; i++) {
71,937,989!
1167
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
136,037,429!
1168
  }
1169

1170
  return 0;
3,909,737✔
1171
}
1172

1173
typedef struct {
1174
  char     name[TSDB_TABLE_FNAME_LEN];
1175
  int8_t   igExists;
1176
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1177
  int8_t   reserved[6];
1178
  tb_uid_t suid;
1179
  int64_t  delay1;
1180
  int64_t  delay2;
1181
  int64_t  watermark1;
1182
  int64_t  watermark2;
1183
  int32_t  ttl;
1184
  int32_t  colVer;
1185
  int32_t  tagVer;
1186
  int32_t  numOfColumns;
1187
  int32_t  numOfTags;
1188
  int32_t  numOfFuncs;
1189
  int32_t  commentLen;
1190
  int32_t  ast1Len;
1191
  int32_t  ast2Len;
1192
  SArray*  pColumns;  // array of SFieldWithOptions
1193
  SArray*  pTags;     // array of SField
1194
  SArray*  pFuncs;
1195
  char*    pComment;
1196
  char*    pAst1;
1197
  char*    pAst2;
1198
  int64_t  deleteMark1;
1199
  int64_t  deleteMark2;
1200
  int32_t  sqlLen;
1201
  char*    sql;
1202
  int64_t  keep;
1203
  int8_t   virtualStb;
1204
} SMCreateStbReq;
1205

1206
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1207
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1208
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1209

1210
typedef struct {
1211
  STableMetaRsp* pMeta;
1212
} SMCreateStbRsp;
1213

1214
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1215
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1216
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1217

1218
typedef struct {
1219
  char     name[TSDB_TABLE_FNAME_LEN];
1220
  int8_t   igNotExists;
1221
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1222
  int8_t   reserved[6];
1223
  tb_uid_t suid;
1224
  int32_t  sqlLen;
1225
  char*    sql;
1226
} SMDropStbReq;
1227

1228
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1229
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1230
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1231

1232
typedef struct {
1233
  char    name[TSDB_TABLE_FNAME_LEN];
1234
  int8_t  alterType;
1235
  int32_t numOfFields;
1236
  SArray* pFields;
1237
  int32_t ttl;
1238
  int32_t commentLen;
1239
  char*   comment;
1240
  int32_t sqlLen;
1241
  char*   sql;
1242
  int64_t keep;
1243
  SArray* pTypeMods;
1244
} SMAlterStbReq;
1245

1246
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1247
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1248
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1249

1250
typedef struct SEpSet {
1251
  int8_t inUse;
1252
  int8_t numOfEps;
1253
  SEp    eps[TSDB_MAX_REPLICA];
1254
} SEpSet;
1255

1256
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1257
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1258
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1259
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1260

1261
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1262
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1263

1264
typedef struct {
1265
  int8_t  connType;
1266
  int32_t pid;
1267
  char    app[TSDB_APP_NAME_LEN];
1268
  char    db[TSDB_DB_NAME_LEN];
1269
  char    user[TSDB_USER_LEN];
1270
  char    passwd[TSDB_PASSWORD_LEN];
1271
  int64_t startTime;
1272
  char    sVer[TSDB_VERSION_LEN];
1273
} SConnectReq;
1274

1275
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1276
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1277

1278
typedef struct {
1279
  int32_t       acctId;
1280
  int64_t       clusterId;
1281
  uint32_t      connId;
1282
  int32_t       dnodeNum;
1283
  int8_t        superUser;
1284
  int8_t        sysInfo;
1285
  int8_t        connType;
1286
  SEpSet        epSet;
1287
  int32_t       svrTimestamp;
1288
  int32_t       passVer;
1289
  int32_t       authVer;
1290
  char          sVer[TSDB_VERSION_LEN];
1291
  char          sDetailVer[128];
1292
  int64_t       whiteListVer;
1293
  SMonitorParas monitorParas;
1294
  int8_t        enableAuditDelete;
1295
} SConnectRsp;
1296

1297
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1298
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1299

1300
typedef struct {
1301
  char    user[TSDB_USER_LEN];
1302
  char    pass[TSDB_PASSWORD_LEN];
1303
  int32_t maxUsers;
1304
  int32_t maxDbs;
1305
  int32_t maxTimeSeries;
1306
  int32_t maxStreams;
1307
  int32_t accessState;  // Configured only by command
1308
  int64_t maxStorage;
1309
} SCreateAcctReq, SAlterAcctReq;
1310

1311
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1312
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1313

1314
typedef struct {
1315
  char    user[TSDB_USER_LEN];
1316
  int32_t sqlLen;
1317
  char*   sql;
1318
} SDropUserReq, SDropAcctReq;
1319

1320
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1321
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1322
void    tFreeSDropUserReq(SDropUserReq* pReq);
1323

1324
typedef struct SIpV4Range {
1325
  uint32_t ip;
1326
  uint32_t mask;
1327
} SIpV4Range;
1328

1329
typedef struct SIpv6Range {
1330
  uint64_t addr[2];
1331
  uint32_t mask;
1332
} SIpV6Range;
1333

1334
typedef struct {
1335
  int8_t type;
1336
  union {
1337
    SIpV4Range ipV4;
1338
    SIpV6Range ipV6;
1339
  };
1340
} SIpRange;
1341

1342
typedef struct {
1343
  int32_t    num;
1344
  SIpV4Range pIpRange[];
1345
} SIpWhiteList;
1346

1347
typedef struct {
1348
  int32_t  num;
1349
  SIpRange pIpRanges[];
1350
} SIpWhiteListDual;
1351

1352
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1353
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1354
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1355
int32_t           createDefaultIp6Range(SIpRange* pRange);
1356
int32_t           createDefaultIp4Range(SIpRange* pRange);
1357

1358
typedef struct {
1359
  int8_t  createType;
1360
  int8_t  superUser;  // denote if it is a super user or not
1361
  int8_t  sysInfo;
1362
  int8_t  enable;
1363
  char    user[TSDB_USER_LEN];
1364
  char    pass[TSDB_USET_PASSWORD_LEN];
1365
  int32_t numIpRanges;
1366

1367
  SIpV4Range* pIpRanges;
1368
  int32_t     sqlLen;
1369
  char*       sql;
1370
  int8_t      isImport;
1371
  int8_t      createDb;
1372
  int8_t      passIsMd5;
1373
  SIpRange*   pIpDualRanges;
1374
} SCreateUserReq;
1375

1376
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1377
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1378
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1379

1380
typedef struct {
1381
  int32_t dnodeId;
1382
  int64_t analVer;
1383
} SRetrieveAnalyticsAlgoReq;
1384

1385
typedef struct {
1386
  int64_t   ver;
1387
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1388
} SRetrieveAnalyticAlgoRsp;
1389

1390
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1391
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1392
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1393
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1394
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1395

1396
typedef struct {
1397
  int8_t alterType;
1398
  int8_t superUser;
1399
  int8_t sysInfo;
1400
  int8_t enable;
1401
  int8_t isView;
1402
  union {
1403
    uint8_t flag;
1404
    struct {
1405
      uint8_t createdb : 1;
1406
      uint8_t reserve : 7;
1407
    };
1408
  };
1409
  char        user[TSDB_USER_LEN];
1410
  char        pass[TSDB_USET_PASSWORD_LEN];
1411
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1412
  char        tabName[TSDB_TABLE_NAME_LEN];
1413
  char*       tagCond;
1414
  int32_t     tagCondLen;
1415
  int32_t     numIpRanges;
1416
  SIpV4Range* pIpRanges;
1417
  int64_t     privileges;
1418
  int32_t     sqlLen;
1419
  char*       sql;
1420
  int8_t      passIsMd5;
1421
  SIpRange*   pIpDualRanges;
1422
} SAlterUserReq;
1423

1424
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1425
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1426
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1427

1428
typedef struct {
1429
  char user[TSDB_USER_LEN];
1430
} SGetUserAuthReq;
1431

1432
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1433
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1434

1435
typedef struct {
1436
  char      user[TSDB_USER_LEN];
1437
  int32_t   version;
1438
  int32_t   passVer;
1439
  int8_t    superAuth;
1440
  int8_t    sysInfo;
1441
  int8_t    enable;
1442
  int8_t    dropped;
1443
  SHashObj* createdDbs;
1444
  SHashObj* readDbs;
1445
  SHashObj* writeDbs;
1446
  SHashObj* readTbs;
1447
  SHashObj* writeTbs;
1448
  SHashObj* alterTbs;
1449
  SHashObj* readViews;
1450
  SHashObj* writeViews;
1451
  SHashObj* alterViews;
1452
  SHashObj* useDbs;
1453
  int64_t   whiteListVer;
1454
} SGetUserAuthRsp;
1455

1456
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1457
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1458
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1459

1460
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1461
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1462
typedef struct {
1463
  int64_t ver;
1464
  char    user[TSDB_USER_LEN];
1465
  int32_t numOfRange;
1466
  union {
1467
    SIpV4Range* pIpRanges;
1468
    SIpRange*   pIpDualRanges;
1469
  };
1470
} SUpdateUserIpWhite;
1471

1472
typedef struct {
1473
  int64_t             ver;
1474
  int                 numOfUser;
1475
  SUpdateUserIpWhite* pUserIpWhite;
1476
} SUpdateIpWhite;
1477

1478
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1479
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1480
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1481
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1482

1483
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1484
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1485
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1486

1487
typedef struct {
1488
  int64_t ipWhiteVer;
1489
} SRetrieveIpWhiteReq;
1490

1491
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1492
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1493
typedef struct {
1494
  char user[TSDB_USER_LEN];
1495
} SGetUserWhiteListReq;
1496

1497
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1498
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1499

1500
typedef struct {
1501
  char    user[TSDB_USER_LEN];
1502
  int32_t numWhiteLists;
1503
  union {
1504
    SIpV4Range* pWhiteLists;
1505
    SIpRange*   pWhiteListsDual;
1506
  };
1507
} SGetUserWhiteListRsp;
1508

1509
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1510
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1511
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1512
void    tIpRangeSetDefaultMask(SIpRange* range);
1513

1514
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1515
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1516
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1517

1518
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1519
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1520
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1521

1522
/*
1523
 * for client side struct, only column id, type, bytes are necessary
1524
 * But for data in vnode side, we need all the following information.
1525
 */
1526
typedef struct {
1527
  union {
1528
    col_id_t colId;
1529
    int16_t  slotId;
1530
  };
1531

1532
  uint8_t precision;
1533
  uint8_t scale;
1534
  int32_t bytes;
1535
  int8_t  type;
1536
  uint8_t pk;
1537
  bool    noData;
1538
} SColumnInfo;
1539

1540
typedef struct STimeWindow {
1541
  TSKEY skey;
1542
  TSKEY ekey;
1543
} STimeWindow;
1544

1545
typedef struct SQueryHint {
1546
  bool batchScan;
1547
} SQueryHint;
1548

1549
typedef struct {
1550
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1551
  int32_t tsLen;          // total length of ts comp block
1552
  int32_t tsNumOfBlocks;  // ts comp block numbers
1553
  int32_t tsOrder;        // ts comp block order
1554
} STsBufInfo;
1555

1556
typedef struct {
1557
  void*       timezone;
1558
  char        intervalUnit;
1559
  char        slidingUnit;
1560
  char        offsetUnit;
1561
  int8_t      precision;
1562
  int64_t     interval;
1563
  int64_t     sliding;
1564
  int64_t     offset;
1565
  STimeWindow timeRange;
1566
} SInterval;
1567

1568
typedef struct STbVerInfo {
1569
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1570
  int32_t sversion;
1571
  int32_t tversion;
1572
  int32_t rversion;  // virtual table's column ref's version
1573
} STbVerInfo;
1574

1575
typedef struct {
1576
  int32_t code;
1577
  int64_t affectedRows;
1578
  SArray* tbVerInfo;  // STbVerInfo
1579
} SQueryTableRsp;
1580

1581
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1582

1583
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1584

1585
typedef struct {
1586
  SMsgHead header;
1587
  char     dbFName[TSDB_DB_FNAME_LEN];
1588
  char     tbName[TSDB_TABLE_NAME_LEN];
1589
} STableCfgReq;
1590

1591
typedef struct {
1592
  char        tbName[TSDB_TABLE_NAME_LEN];
1593
  char        stbName[TSDB_TABLE_NAME_LEN];
1594
  char        dbFName[TSDB_DB_FNAME_LEN];
1595
  int32_t     numOfTags;
1596
  int32_t     numOfColumns;
1597
  int8_t      tableType;
1598
  int64_t     delay1;
1599
  int64_t     delay2;
1600
  int64_t     watermark1;
1601
  int64_t     watermark2;
1602
  int32_t     ttl;
1603
  int32_t     keep;
1604
  SArray*     pFuncs;
1605
  int32_t     commentLen;
1606
  char*       pComment;
1607
  SSchema*    pSchemas;
1608
  int32_t     tagsLen;
1609
  char*       pTags;
1610
  SSchemaExt* pSchemaExt;
1611
  int8_t      virtualStb;
1612
  SColRef*    pColRefs;
1613
} STableCfg;
1614

1615
typedef STableCfg STableCfgRsp;
1616

1617
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1618
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1619

1620
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1621
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1622
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1623

1624
typedef struct {
1625
  SMsgHead header;
1626
  tb_uid_t suid;
1627
} SVSubTablesReq;
1628

1629
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1630
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1631

1632
typedef struct {
1633
  int32_t vgId;
1634
  SArray* pTables;  // SArray<SVCTableRefCols*>
1635
} SVSubTablesRsp;
1636

1637
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1638
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1639
void    tDestroySVSubTablesRsp(void* rsp);
1640

1641
typedef struct {
1642
  SMsgHead header;
1643
  tb_uid_t suid;
1644
} SVStbRefDbsReq;
1645

1646
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1647
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1648

1649
typedef struct {
1650
  int32_t vgId;
1651
  SArray* pDbs;  // SArray<char* (db name)>
1652
} SVStbRefDbsRsp;
1653

1654
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1655
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1656
void    tDestroySVStbRefDbsRsp(void* rsp);
1657

1658
typedef struct {
1659
  char    db[TSDB_DB_FNAME_LEN];
1660
  int32_t numOfVgroups;
1661
  int32_t numOfStables;  // single_stable
1662
  int32_t buffer;        // MB
1663
  int32_t pageSize;
1664
  int32_t pages;
1665
  int32_t cacheLastSize;
1666
  int32_t daysPerFile;
1667
  int32_t daysToKeep0;
1668
  int32_t daysToKeep1;
1669
  int32_t daysToKeep2;
1670
  int32_t keepTimeOffset;
1671
  int32_t minRows;
1672
  int32_t maxRows;
1673
  int32_t walFsyncPeriod;
1674
  int8_t  walLevel;
1675
  int8_t  precision;  // time resolution
1676
  int8_t  compression;
1677
  int8_t  replications;
1678
  int8_t  strict;
1679
  int8_t  cacheLast;
1680
  int8_t  schemaless;
1681
  int8_t  ignoreExist;
1682
  int32_t numOfRetensions;
1683
  SArray* pRetensions;  // SRetention
1684
  int32_t walRetentionPeriod;
1685
  int64_t walRetentionSize;
1686
  int32_t walRollPeriod;
1687
  int64_t walSegmentSize;
1688
  int32_t sstTrigger;
1689
  int16_t hashPrefix;
1690
  int16_t hashSuffix;
1691
  int32_t ssChunkSize;
1692
  int32_t ssKeepLocal;
1693
  int8_t  ssCompact;
1694
  int32_t tsdbPageSize;
1695
  int32_t sqlLen;
1696
  char*   sql;
1697
  int8_t  withArbitrator;
1698
  int8_t  encryptAlgorithm;
1699
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1700
  // 1. add auto-compact parameters
1701
  int32_t compactInterval;    // minutes
1702
  int32_t compactStartTime;   // minutes
1703
  int32_t compactEndTime;     // minutes
1704
  int8_t  compactTimeOffset;  // hour
1705
} SCreateDbReq;
1706

1707
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1708
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1709
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1710

1711
typedef struct {
1712
  char    db[TSDB_DB_FNAME_LEN];
1713
  int32_t buffer;
1714
  int32_t pageSize;
1715
  int32_t pages;
1716
  int32_t cacheLastSize;
1717
  int32_t daysPerFile;
1718
  int32_t daysToKeep0;
1719
  int32_t daysToKeep1;
1720
  int32_t daysToKeep2;
1721
  int32_t keepTimeOffset;
1722
  int32_t walFsyncPeriod;
1723
  int8_t  walLevel;
1724
  int8_t  strict;
1725
  int8_t  cacheLast;
1726
  int8_t  replications;
1727
  int32_t sstTrigger;
1728
  int32_t minRows;
1729
  int32_t walRetentionPeriod;
1730
  int32_t walRetentionSize;
1731
  int32_t ssKeepLocal;
1732
  int8_t  ssCompact;
1733
  int32_t sqlLen;
1734
  char*   sql;
1735
  int8_t  withArbitrator;
1736
  // 1. add auto-compact parameters
1737
  int32_t compactInterval;
1738
  int32_t compactStartTime;
1739
  int32_t compactEndTime;
1740
  int8_t  compactTimeOffset;
1741
} SAlterDbReq;
1742

1743
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1744
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1745
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1746

1747
typedef struct {
1748
  char    db[TSDB_DB_FNAME_LEN];
1749
  int8_t  ignoreNotExists;
1750
  int8_t  force;
1751
  int32_t sqlLen;
1752
  char*   sql;
1753
} SDropDbReq;
1754

1755
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1756
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1757
void    tFreeSDropDbReq(SDropDbReq* pReq);
1758

1759
typedef struct {
1760
  char    db[TSDB_DB_FNAME_LEN];
1761
  int64_t uid;
1762
} SDropDbRsp;
1763

1764
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1765
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1766

1767
typedef struct {
1768
  char    name[TSDB_MOUNT_NAME_LEN];
1769
  int64_t uid;
1770
} SDropMountRsp;
1771

1772
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1773
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1774

1775
typedef struct {
1776
  char    db[TSDB_DB_FNAME_LEN];
1777
  int64_t dbId;
1778
  int32_t vgVersion;
1779
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1780
  int64_t stateTs;     // ms
1781
} SUseDbReq;
1782

1783
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1784
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1785

1786
typedef struct {
1787
  char    db[TSDB_DB_FNAME_LEN];
1788
  int64_t uid;
1789
  int32_t vgVersion;
1790
  int32_t vgNum;
1791
  int16_t hashPrefix;
1792
  int16_t hashSuffix;
1793
  int8_t  hashMethod;
1794
  union {
1795
    uint8_t flags;
1796
    struct {
1797
      uint8_t isMount : 1;  // TS-5868
1798
      uint8_t padding : 7;
1799
    };
1800
  };
1801
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1802
  int32_t errCode;
1803
  int64_t stateTs;  // ms
1804
} SUseDbRsp;
1805

1806
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1807
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1808
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1809
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1810
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1811

1812
typedef struct {
1813
  char db[TSDB_DB_FNAME_LEN];
1814
} SDbCfgReq;
1815

1816
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1817
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1818

1819
typedef struct {
1820
  char db[TSDB_DB_FNAME_LEN];
1821
} SSsMigrateDbReq;
1822

1823
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1824
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1825

1826
typedef struct {
1827
  int32_t ssMigrateId;
1828
  bool    bAccepted;
1829
} SSsMigrateDbRsp;
1830

1831
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1832
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1833

1834

1835
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
1836
typedef struct {
1837
  int32_t ssMigrateId;
1838
} SListSsMigrateFileSetsReq;
1839

1840
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1841
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1842

1843
typedef struct {
1844
  int32_t ssMigrateId;
1845
  int32_t vgId;   // vgroup id
1846
  SArray* pFileSets; // SArray<int32_t>
1847
} SListSsMigrateFileSetsRsp;
1848

1849
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1850
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1851
void tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
1852

1853

1854
// Request and response for TDMT_VND_SSMIGRATE_FILESET
1855
typedef struct {
1856
  int32_t ssMigrateId;
1857
  int32_t nodeId; // node id of the leader vnode, filled by vnode
1858
  int32_t fid;
1859
  int64_t startTimeSec;
1860
} SSsMigrateFileSetReq;
1861

1862
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1863
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1864

1865
typedef struct {
1866
  int32_t ssMigrateId;
1867
  int32_t nodeId; // node id of the leader vnode
1868
  int32_t vgId;
1869
  int32_t fid;
1870
} SSsMigrateFileSetRsp;
1871

1872
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1873
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1874

1875

1876
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS  0
1877
#define SSMIGRATE_FILESET_STATE_SUCCEEDED    1
1878
#define SSMIGRATE_FILESET_STATE_COMPACT      2
1879
#define SSMIGRATE_FILESET_STATE_SKIPPED      3
1880
#define SSMIGRATE_FILESET_STATE_FAILED       4
1881

1882
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
1883
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
1884
// while as a request, the 'state' field is not used.
1885
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
1886
typedef struct {
1887
  int32_t ssMigrateId; // ss migrate id
1888
  int32_t nodeId;      // node id of the leader vnode
1889
  int32_t vgId;        // vgroup id
1890
  int32_t fid;         // file set id
1891
  int32_t state;       // SSMIGRATE_FILESET_STATE_*
1892
} SSsMigrateProgress;
1893

1894
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1895
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1896

1897

1898
// Request for TDMT_MND_KILL_SSMIGRATE
1899
typedef struct {
1900
  int32_t ssMigrateId;
1901
  int32_t sqlLen;
1902
  char*   sql;
1903
} SKillSsMigrateReq;
1904

1905
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
1906
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
1907
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
1908

1909
// Request for TDMT_VND_KILL_SSMIGRATE
1910
typedef struct {
1911
  int32_t ssMigrateId;
1912
} SVnodeKillSsMigrateReq;
1913

1914
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1915
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1916

1917

1918
typedef struct {
1919
  int32_t timestampSec;
1920
  int32_t ttlDropMaxCount;
1921
  int32_t nUids;
1922
  SArray* pTbUids;
1923
} SVDropTtlTableReq;
1924

1925
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1926
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1927

1928
typedef struct {
1929
  char    db[TSDB_DB_FNAME_LEN];
1930
  int64_t dbId;
1931
  int32_t cfgVersion;
1932
  int32_t numOfVgroups;
1933
  int32_t numOfStables;
1934
  int32_t buffer;
1935
  int32_t cacheSize;
1936
  int32_t pageSize;
1937
  int32_t pages;
1938
  int32_t daysPerFile;
1939
  int32_t daysToKeep0;
1940
  int32_t daysToKeep1;
1941
  int32_t daysToKeep2;
1942
  int32_t keepTimeOffset;
1943
  int32_t minRows;
1944
  int32_t maxRows;
1945
  int32_t walFsyncPeriod;
1946
  int16_t hashPrefix;
1947
  int16_t hashSuffix;
1948
  int8_t  hashMethod;
1949
  int8_t  walLevel;
1950
  int8_t  precision;
1951
  int8_t  compression;
1952
  int8_t  replications;
1953
  int8_t  strict;
1954
  int8_t  cacheLast;
1955
  int8_t  encryptAlgorithm;
1956
  int32_t ssChunkSize;
1957
  int32_t ssKeepLocal;
1958
  int8_t  ssCompact;
1959
  union {
1960
    uint8_t flags;
1961
    struct {
1962
      uint8_t isMount : 1;  // TS-5868
1963
      uint8_t padding : 7;
1964
    };
1965
  };
1966
  int8_t  compactTimeOffset;
1967
  int32_t compactInterval;
1968
  int32_t compactStartTime;
1969
  int32_t compactEndTime;
1970
  int32_t tsdbPageSize;
1971
  int32_t walRetentionPeriod;
1972
  int32_t walRollPeriod;
1973
  int64_t walRetentionSize;
1974
  int64_t walSegmentSize;
1975
  int32_t numOfRetensions;
1976
  SArray* pRetensions;
1977
  int8_t  schemaless;
1978
  int16_t sstTrigger;
1979
  int8_t  withArbitrator;
1980
} SDbCfgRsp;
1981

1982
typedef SDbCfgRsp SDbCfgInfo;
1983

1984
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1985
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1986
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1987
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1988
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1989

1990
typedef struct {
1991
  int32_t rowNum;
1992
} SQnodeListReq;
1993

1994
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1995
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1996

1997
typedef struct {
1998
  int32_t rowNum;
1999
} SDnodeListReq;
2000

2001
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2002

2003
typedef struct {
2004
  int32_t useless;  // useless
2005
} SServerVerReq;
2006

2007
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2008
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2009

2010
typedef struct {
2011
  char ver[TSDB_VERSION_LEN];
2012
} SServerVerRsp;
2013

2014
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2015
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2016

2017
typedef struct SQueryNodeAddr {
2018
  int32_t nodeId;  // vgId or qnodeId
2019
  SEpSet  epSet;
2020
} SQueryNodeAddr;
2021

2022
typedef struct {
2023
  SQueryNodeAddr addr;
2024
  uint64_t       load;
2025
} SQueryNodeLoad;
2026

2027
typedef struct {
2028
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2029
} SQnodeListRsp;
2030

2031
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2032
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2033
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2034

2035
typedef struct SDNodeAddr {
2036
  int32_t nodeId;  // dnodeId
2037
  SEpSet  epSet;
2038
} SDNodeAddr;
2039

2040
typedef struct {
2041
  SArray* dnodeList;  // SArray<SDNodeAddr>
2042
} SDnodeListRsp;
2043

2044
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2045
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2046
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2047

2048
typedef struct {
2049
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2050
} STableTSMAInfoRsp;
2051

2052
typedef struct {
2053
  SUseDbRsp*         useDbRsp;
2054
  SDbCfgRsp*         cfgRsp;
2055
  STableTSMAInfoRsp* pTsmaRsp;
2056
  int32_t            dbTsmaVersion;
2057
  char               db[TSDB_DB_FNAME_LEN];
2058
  int64_t            dbId;
2059
} SDbHbRsp;
2060

2061
typedef struct {
2062
  SArray* pArray;  // Array of SDbHbRsp
2063
} SDbHbBatchRsp;
2064

2065
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2066
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2067
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2068

2069
typedef struct {
2070
  SArray* pArray;  // Array of SGetUserAuthRsp
2071
} SUserAuthBatchRsp;
2072

2073
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2074
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2075
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2076

2077
typedef struct {
2078
  char        db[TSDB_DB_FNAME_LEN];
2079
  STimeWindow timeRange;
2080
  int32_t     sqlLen;
2081
  char*       sql;
2082
  SArray*     vgroupIds;
2083
  int32_t     compactId;
2084
  int8_t      metaOnly;
2085
} SCompactDbReq;
2086

2087
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2088
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2089
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2090

2091
typedef struct {
2092
  union {
2093
    int32_t compactId;
2094
    int32_t id;
2095
  };
2096
  int8_t bAccepted;
2097
} SCompactDbRsp;
2098

2099
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2100
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2101

2102
typedef struct {
2103
  union {
2104
    int32_t compactId;
2105
    int32_t id;
2106
  };
2107
  int32_t sqlLen;
2108
  char*   sql;
2109
} SKillCompactReq;
2110

2111
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2112
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2113
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2114

2115
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2116
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2117

2118
typedef struct {
2119
  char    name[TSDB_FUNC_NAME_LEN];
2120
  int8_t  igExists;
2121
  int8_t  funcType;
2122
  int8_t  scriptType;
2123
  int8_t  outputType;
2124
  int32_t outputLen;
2125
  int32_t bufSize;
2126
  int32_t codeLen;
2127
  int64_t signature;
2128
  char*   pComment;
2129
  char*   pCode;
2130
  int8_t  orReplace;
2131
} SCreateFuncReq;
2132

2133
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2134
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2135
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2136

2137
typedef struct {
2138
  char   name[TSDB_FUNC_NAME_LEN];
2139
  int8_t igNotExists;
2140
} SDropFuncReq;
2141

2142
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2143
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2144

2145
typedef struct {
2146
  int32_t numOfFuncs;
2147
  bool    ignoreCodeComment;
2148
  SArray* pFuncNames;
2149
} SRetrieveFuncReq;
2150

2151
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2152
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2153
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2154

2155
typedef struct {
2156
  char    name[TSDB_FUNC_NAME_LEN];
2157
  int8_t  funcType;
2158
  int8_t  scriptType;
2159
  int8_t  outputType;
2160
  int32_t outputLen;
2161
  int32_t bufSize;
2162
  int64_t signature;
2163
  int32_t commentSize;
2164
  int32_t codeSize;
2165
  char*   pComment;
2166
  char*   pCode;
2167
} SFuncInfo;
2168

2169
typedef struct {
2170
  int32_t funcVersion;
2171
  int64_t funcCreatedTime;
2172
} SFuncExtraInfo;
2173

2174
typedef struct {
2175
  int32_t numOfFuncs;
2176
  SArray* pFuncInfos;
2177
  SArray* pFuncExtraInfos;
2178
} SRetrieveFuncRsp;
2179

2180
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2181
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2182
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2183
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2184

2185
typedef struct {
2186
  int32_t       statusInterval;
2187
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2188
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2189
  char          locale[TD_LOCALE_LEN];      // tsLocale
2190
  char          charset[TD_LOCALE_LEN];     // tsCharset
2191
  int8_t        ttlChangeOnWrite;
2192
  int8_t        enableWhiteList;
2193
  int8_t        encryptionKeyStat;
2194
  uint32_t      encryptionKeyChksum;
2195
  SMonitorParas monitorParas;
2196
  int32_t       statusIntervalMs;
2197
} SClusterCfg;
2198

2199
typedef struct {
2200
  int32_t openVnodes;
2201
  int32_t dropVnodes;
2202
  int32_t totalVnodes;
2203
  int32_t masterNum;
2204
  int64_t numOfSelectReqs;
2205
  int64_t numOfInsertReqs;
2206
  int64_t numOfInsertSuccessReqs;
2207
  int64_t numOfBatchInsertReqs;
2208
  int64_t numOfBatchInsertSuccessReqs;
2209
  int64_t errors;
2210
} SVnodesStat;
2211

2212
typedef struct {
2213
  int32_t vgId;
2214
  int8_t  syncState;
2215
  int8_t  syncRestore;
2216
  int64_t syncTerm;
2217
  int64_t roleTimeMs;
2218
  int64_t startTimeMs;
2219
  int8_t  syncCanRead;
2220
  int64_t cacheUsage;
2221
  int64_t numOfTables;
2222
  int64_t numOfTimeSeries;
2223
  int64_t totalStorage;
2224
  int64_t compStorage;
2225
  int64_t pointsWritten;
2226
  int64_t numOfSelectReqs;
2227
  int64_t numOfInsertReqs;
2228
  int64_t numOfInsertSuccessReqs;
2229
  int64_t numOfBatchInsertReqs;
2230
  int64_t numOfBatchInsertSuccessReqs;
2231
  int32_t numOfCachedTables;
2232
  int32_t learnerProgress;  // use one reservered
2233
  int64_t syncAppliedIndex;
2234
  int64_t syncCommitIndex;
2235
  int64_t bufferSegmentUsed;
2236
  int64_t bufferSegmentSize;
2237
} SVnodeLoad;
2238

2239
typedef struct {
2240
  int64_t total_requests;
2241
  int64_t total_rows;
2242
  int64_t total_bytes;
2243
  double  write_size;
2244
  double  cache_hit_ratio;
2245
  int64_t rpc_queue_wait;
2246
  int64_t preprocess_time;
2247

2248
  int64_t memory_table_size;
2249
  int64_t commit_count;
2250
  int64_t merge_count;
2251
  double  commit_time;
2252
  double  merge_time;
2253
  int64_t block_commit_time;
2254
  int64_t memtable_wait_time;
2255
} SVnodeMetrics;
2256

2257
typedef struct {
2258
  int32_t     vgId;
2259
  int64_t     numOfTables;
2260
  int64_t     memSize;
2261
  int64_t     l1Size;
2262
  int64_t     l2Size;
2263
  int64_t     l3Size;
2264
  int64_t     cacheSize;
2265
  int64_t     walSize;
2266
  int64_t     metaSize;
2267
  int64_t     rawDataSize;
2268
  int64_t     ssSize;
2269
  const char* dbname;
2270
  int8_t      estimateRawData;
2271
} SDbSizeStatisInfo;
2272

2273
typedef struct {
2274
  int32_t vgId;
2275
  int64_t nTimeSeries;
2276
} SVnodeLoadLite;
2277

2278
typedef struct {
2279
  int8_t  syncState;
2280
  int64_t syncTerm;
2281
  int8_t  syncRestore;
2282
  int64_t roleTimeMs;
2283
} SMnodeLoad;
2284

2285
typedef struct {
2286
  int32_t dnodeId;
2287
  int64_t numOfProcessedQuery;
2288
  int64_t numOfProcessedCQuery;
2289
  int64_t numOfProcessedFetch;
2290
  int64_t numOfProcessedDrop;
2291
  int64_t numOfProcessedNotify;
2292
  int64_t numOfProcessedHb;
2293
  int64_t numOfProcessedDelete;
2294
  int64_t cacheDataSize;
2295
  int64_t numOfQueryInQueue;
2296
  int64_t numOfFetchInQueue;
2297
  int64_t timeInQueryQueue;
2298
  int64_t timeInFetchQueue;
2299
} SQnodeLoad;
2300

2301
typedef struct {
2302
  int32_t     sver;      // software version
2303
  int64_t     dnodeVer;  // dnode table version in sdb
2304
  int32_t     dnodeId;
2305
  int64_t     clusterId;
2306
  int64_t     rebootTime;
2307
  int64_t     updateTime;
2308
  float       numOfCores;
2309
  int32_t     numOfSupportVnodes;
2310
  int32_t     numOfDiskCfg;
2311
  int64_t     memTotal;
2312
  int64_t     memAvail;
2313
  char        dnodeEp[TSDB_EP_LEN];
2314
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2315
  SMnodeLoad  mload;
2316
  SQnodeLoad  qload;
2317
  SClusterCfg clusterCfg;
2318
  SArray*     pVloads;  // array of SVnodeLoad
2319
  int32_t     statusSeq;
2320
  int64_t     ipWhiteVer;
2321
  int64_t     analVer;
2322
  int64_t     timestamp;
2323
} SStatusReq;
2324

2325
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2326
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2327
void    tFreeSStatusReq(SStatusReq* pReq);
2328

2329
typedef struct {
2330
  int32_t forceReadConfig;
2331
  int32_t cver;
2332
  SArray* array;
2333
} SConfigReq;
2334

2335
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2336
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2337
void    tFreeSConfigReq(SConfigReq* pReq);
2338

2339
typedef struct {
2340
  int32_t dnodeId;
2341
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2342
} SDnodeInfoReq;
2343

2344
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2345
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2346

2347
typedef enum {
2348
  MONITOR_TYPE_COUNTER = 0,
2349
  MONITOR_TYPE_SLOW_LOG = 1,
2350
} MONITOR_TYPE;
2351

2352
typedef struct {
2353
  int32_t      contLen;
2354
  char*        pCont;
2355
  MONITOR_TYPE type;
2356
} SStatisReq;
2357

2358
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2359
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2360
void    tFreeSStatisReq(SStatisReq* pReq);
2361

2362
typedef struct {
2363
  char    db[TSDB_DB_FNAME_LEN];
2364
  char    table[TSDB_TABLE_NAME_LEN];
2365
  char    operation[AUDIT_OPERATION_LEN];
2366
  int32_t sqlLen;
2367
  char*   pSql;
2368
} SAuditReq;
2369
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2370
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2371
void    tFreeSAuditReq(SAuditReq* pReq);
2372

2373
typedef struct {
2374
  int32_t dnodeId;
2375
  int64_t clusterId;
2376
  SArray* pVloads;
2377
} SNotifyReq;
2378

2379
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2380
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2381
void    tFreeSNotifyReq(SNotifyReq* pReq);
2382

2383
typedef struct {
2384
  int32_t dnodeId;
2385
  int64_t clusterId;
2386
} SDnodeCfg;
2387

2388
typedef struct {
2389
  int32_t id;
2390
  int8_t  isMnode;
2391
  SEp     ep;
2392
} SDnodeEp;
2393

2394
typedef struct {
2395
  int32_t id;
2396
  int8_t  isMnode;
2397
  int8_t  offlineReason;
2398
  SEp     ep;
2399
  char    active[TSDB_ACTIVE_KEY_LEN];
2400
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2401
} SDnodeInfo;
2402

2403
typedef struct {
2404
  int64_t   dnodeVer;
2405
  SDnodeCfg dnodeCfg;
2406
  SArray*   pDnodeEps;  // Array of SDnodeEp
2407
  int32_t   statusSeq;
2408
  int64_t   ipWhiteVer;
2409
  int64_t   analVer;
2410
} SStatusRsp;
2411

2412
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2413
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2414
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2415

2416
typedef struct {
2417
  int32_t forceReadConfig;
2418
  int32_t isConifgVerified;
2419
  int32_t isVersionVerified;
2420
  int32_t cver;
2421
  SArray* array;
2422
} SConfigRsp;
2423

2424
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2425
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2426
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2427

2428
typedef struct {
2429
  int32_t reserved;
2430
} SMTimerReq;
2431

2432
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2433
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2434

2435
typedef struct SOrphanTask {
2436
  int64_t streamId;
2437
  int32_t taskId;
2438
  int32_t nodeId;
2439
} SOrphanTask;
2440

2441
typedef struct SMStreamDropOrphanMsg {
2442
  SArray* pList;  // SArray<SOrphanTask>
2443
} SMStreamDropOrphanMsg;
2444

2445
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2446
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2447
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2448

2449
typedef struct {
2450
  int32_t  id;
2451
  uint16_t port;                 // node sync Port
2452
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2453
} SReplica;
2454

2455
typedef struct {
2456
  int32_t  vgId;
2457
  char     db[TSDB_DB_FNAME_LEN];
2458
  int64_t  dbUid;
2459
  int32_t  vgVersion;
2460
  int32_t  numOfStables;
2461
  int32_t  buffer;
2462
  int32_t  pageSize;
2463
  int32_t  pages;
2464
  int32_t  cacheLastSize;
2465
  int32_t  daysPerFile;
2466
  int32_t  daysToKeep0;
2467
  int32_t  daysToKeep1;
2468
  int32_t  daysToKeep2;
2469
  int32_t  keepTimeOffset;
2470
  int32_t  minRows;
2471
  int32_t  maxRows;
2472
  int32_t  walFsyncPeriod;
2473
  uint32_t hashBegin;
2474
  uint32_t hashEnd;
2475
  int8_t   hashMethod;
2476
  int8_t   walLevel;
2477
  int8_t   precision;
2478
  int8_t   compression;
2479
  int8_t   strict;
2480
  int8_t   cacheLast;
2481
  int8_t   isTsma;
2482
  int8_t   replica;
2483
  int8_t   selfIndex;
2484
  SReplica replicas[TSDB_MAX_REPLICA];
2485
  int32_t  numOfRetensions;
2486
  SArray*  pRetensions;  // SRetention
2487
  void*    pTsma;
2488
  int32_t  walRetentionPeriod;
2489
  int64_t  walRetentionSize;
2490
  int32_t  walRollPeriod;
2491
  int64_t  walSegmentSize;
2492
  int16_t  sstTrigger;
2493
  int16_t  hashPrefix;
2494
  int16_t  hashSuffix;
2495
  int32_t  tsdbPageSize;
2496
  int32_t  ssChunkSize;
2497
  int32_t  ssKeepLocal;
2498
  int8_t   ssCompact;
2499
  int64_t  reserved[6];
2500
  int8_t   learnerReplica;
2501
  int8_t   learnerSelfIndex;
2502
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2503
  int32_t  changeVersion;
2504
  int8_t   encryptAlgorithm;
2505
} SCreateVnodeReq;
2506

2507
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2508
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2509
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2510

2511
typedef struct {
2512
  union {
2513
    int32_t compactId;
2514
    int32_t id;
2515
  };
2516
  int32_t vgId;
2517
  int32_t dnodeId;
2518
} SQueryCompactProgressReq;
2519

2520
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2521
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2522

2523
typedef struct {
2524
  union {
2525
    int32_t compactId;
2526
    int32_t id;
2527
  };
2528
  int32_t vgId;
2529
  int32_t dnodeId;
2530
  int32_t numberFileset;
2531
  int32_t finished;
2532
  int32_t progress;
2533
  int64_t remainingTime;
2534
} SQueryCompactProgressRsp;
2535

2536
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2537
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2538

2539
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2540
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2541

2542
typedef struct {
2543
  int32_t vgId;
2544
  int32_t dnodeId;
2545
  int64_t dbUid;
2546
  char    db[TSDB_DB_FNAME_LEN];
2547
  int64_t reserved[8];
2548
} SDropVnodeReq;
2549

2550
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2551
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2552

2553
typedef struct {
2554
  char    colName[TSDB_COL_NAME_LEN];
2555
  char    stb[TSDB_TABLE_FNAME_LEN];
2556
  int64_t stbUid;
2557
  int64_t dbUid;
2558
  int64_t reserved[8];
2559
} SDropIndexReq;
2560

2561
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2562
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2563

2564
typedef struct {
2565
  int64_t dbUid;
2566
  char    db[TSDB_DB_FNAME_LEN];
2567
  union {
2568
    int64_t compactStartTime;
2569
    int64_t startTime;
2570
  };
2571

2572
  STimeWindow tw;
2573
  union {
2574
    int32_t compactId;
2575
    int32_t id;
2576
  };
2577
  int8_t metaOnly;
2578
  union {
2579
    uint16_t flags;
2580
    struct {
2581
      uint16_t optrType : 3;     // ETsdbOpType
2582
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2583
      uint16_t reserved : 12;
2584
    };
2585
  };
2586
} SCompactVnodeReq;
2587

2588
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2589
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2590

2591
typedef struct {
2592
  union {
2593
    int32_t compactId;
2594
    int32_t taskId;
2595
  };
2596
  int32_t vgId;
2597
  int32_t dnodeId;
2598
} SVKillCompactReq;
2599

2600
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2601
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2602

2603
typedef SVKillCompactReq SVKillRetentionReq;
2604

2605
typedef struct {
2606
  char        db[TSDB_DB_FNAME_LEN];
2607
  int32_t     maxSpeed;
2608
  int32_t     sqlLen;
2609
  char*       sql;
2610
  SArray*     vgroupIds;
2611
  STimeWindow tw;  // unit is second
2612
  union {
2613
    uint32_t flags;
2614
    struct {
2615
      uint32_t optrType : 3;     // ETsdbOpType
2616
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2617
      uint32_t reserved : 28;
2618
    };
2619
  };
2620
} STrimDbReq;
2621

2622
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2623
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2624
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2625

2626
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2627

2628
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2629
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2630

2631
typedef struct {
2632
  int32_t vgVersion;
2633
  int32_t buffer;
2634
  int32_t pageSize;
2635
  int32_t pages;
2636
  int32_t cacheLastSize;
2637
  int32_t daysPerFile;
2638
  int32_t daysToKeep0;
2639
  int32_t daysToKeep1;
2640
  int32_t daysToKeep2;
2641
  int32_t keepTimeOffset;
2642
  int32_t walFsyncPeriod;
2643
  int8_t  walLevel;
2644
  int8_t  strict;
2645
  int8_t  cacheLast;
2646
  int64_t reserved[7];
2647
  // 1st modification
2648
  int16_t sttTrigger;
2649
  int32_t minRows;
2650
  // 2nd modification
2651
  int32_t walRetentionPeriod;
2652
  int32_t walRetentionSize;
2653
  int32_t ssKeepLocal;
2654
  int8_t  ssCompact;
2655
} SAlterVnodeConfigReq;
2656

2657
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2658
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2659

2660
typedef struct {
2661
  int32_t  vgId;
2662
  int8_t   strict;
2663
  int8_t   selfIndex;
2664
  int8_t   replica;
2665
  SReplica replicas[TSDB_MAX_REPLICA];
2666
  int64_t  reserved[8];
2667
  int8_t   learnerSelfIndex;
2668
  int8_t   learnerReplica;
2669
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2670
  int32_t  changeVersion;
2671
  int32_t  electBaseLine;
2672
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2673

2674
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2675
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2676

2677
typedef struct {
2678
  int32_t vgId;
2679
  int8_t  disable;
2680
} SDisableVnodeWriteReq;
2681

2682
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2683
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2684

2685
typedef struct {
2686
  int32_t  srcVgId;
2687
  int32_t  dstVgId;
2688
  uint32_t hashBegin;
2689
  uint32_t hashEnd;
2690
  int32_t  changeVersion;
2691
  int32_t  reserved;
2692
} SAlterVnodeHashRangeReq;
2693

2694
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2695
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2696

2697
#define REQ_OPT_TBNAME 0x0
2698
#define REQ_OPT_TBUID  0x01
2699
typedef struct {
2700
  SMsgHead header;
2701
  char     dbFName[TSDB_DB_FNAME_LEN];
2702
  char     tbName[TSDB_TABLE_NAME_LEN];
2703
  uint8_t  option;
2704
  uint8_t  autoCreateCtb;
2705
} STableInfoReq;
2706

2707
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2708
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2709

2710
typedef struct {
2711
  int8_t  metaClone;  // create local clone of the cached table meta
2712
  int32_t numOfVgroups;
2713
  int32_t numOfTables;
2714
  int32_t numOfUdfs;
2715
  char    tableNames[];
2716
} SMultiTableInfoReq;
2717

2718
// todo refactor
2719
typedef struct SVgroupInfo {
2720
  int32_t  vgId;
2721
  uint32_t hashBegin;
2722
  uint32_t hashEnd;
2723
  SEpSet   epSet;
2724
  union {
2725
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2726
    int32_t taskId;      // used in stream
2727
  };
2728
} SVgroupInfo;
2729

2730
typedef struct {
2731
  int32_t     numOfVgroups;
2732
  SVgroupInfo vgroups[];
2733
} SVgroupsInfo;
2734

2735
typedef struct {
2736
  STableMetaRsp* pMeta;
2737
} SMAlterStbRsp;
2738

2739
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2740
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2741
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2742

2743
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2744
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2745
void    tFreeSTableMetaRsp(void* pRsp);
2746
void    tFreeSTableIndexRsp(void* info);
2747

2748
typedef struct {
2749
  SArray* pMetaRsp;   // Array of STableMetaRsp
2750
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2751
} SSTbHbRsp;
2752

2753
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2754
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2755
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2756

2757
typedef struct {
2758
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2759
} SViewHbRsp;
2760

2761
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2762
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2763
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2764

2765
typedef struct {
2766
  int32_t numOfTables;
2767
  int32_t numOfVgroup;
2768
  int32_t numOfUdf;
2769
  int32_t contLen;
2770
  int8_t  compressed;  // denote if compressed or not
2771
  int32_t rawLen;      // size before compress
2772
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2773
  char    meta[];
2774
} SMultiTableMeta;
2775

2776
typedef struct {
2777
  int32_t dataLen;
2778
  char    name[TSDB_TABLE_FNAME_LEN];
2779
  char*   data;
2780
} STagData;
2781

2782
typedef struct {
2783
  int32_t  opType;
2784
  uint32_t valLen;
2785
  char*    val;
2786
} SShowVariablesReq;
2787

2788
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2789
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2790
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2791

2792
typedef struct {
2793
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2794
  char value[TSDB_CONFIG_PATH_LEN + 1];
2795
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2796
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2797
  char info[TSDB_CONFIG_INFO_LEN + 1];
2798
} SVariablesInfo;
2799

2800
typedef struct {
2801
  SArray* variables;  // SArray<SVariablesInfo>
2802
} SShowVariablesRsp;
2803

2804
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2805
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2806

2807
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2808

2809
/*
2810
 * sql: show tables like '%a_%'
2811
 * payload is the query condition, e.g., '%a_%'
2812
 * payloadLen is the length of payload
2813
 */
2814
typedef struct {
2815
  int32_t type;
2816
  char    db[TSDB_DB_FNAME_LEN];
2817
  int32_t payloadLen;
2818
  char*   payload;
2819
} SShowReq;
2820

2821
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2822
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2823
void tFreeSShowReq(SShowReq* pReq);
2824

2825
typedef struct {
2826
  int64_t       showId;
2827
  STableMetaRsp tableMeta;
2828
} SShowRsp, SVShowTablesRsp;
2829

2830
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2831
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2832
// void    tFreeSShowRsp(SShowRsp* pRsp);
2833

2834
typedef struct {
2835
  char    db[TSDB_DB_FNAME_LEN];
2836
  char    tb[TSDB_TABLE_NAME_LEN];
2837
  char    user[TSDB_USER_LEN];
2838
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2839
  int64_t showId;
2840
  int64_t compactId;  // for compact
2841
  bool    withFull;   // for show users full
2842
} SRetrieveTableReq;
2843

2844
typedef struct SSysTableSchema {
2845
  int8_t   type;
2846
  col_id_t colId;
2847
  int32_t  bytes;
2848
} SSysTableSchema;
2849

2850
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2851
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2852

2853
#define RETRIEVE_TABLE_RSP_VERSION         0
2854
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2855
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2856

2857
typedef struct {
2858
  int64_t useconds;
2859
  int8_t  completed;  // all results are returned to client
2860
  int8_t  precision;
2861
  int8_t  compressed;
2862
  int8_t  streamBlockType;
2863
  int32_t payloadLen;
2864
  int32_t compLen;
2865
  int32_t numOfBlocks;
2866
  int64_t numOfRows;  // from int32_t change to int64_t
2867
  int64_t numOfCols;
2868
  int64_t skey;
2869
  int64_t ekey;
2870
  int64_t version;                         // for stream
2871
  TSKEY   watermark;                       // for stream
2872
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2873
  char    data[];
2874
} SRetrieveTableRsp;
2875

2876
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2877

2878
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2879
  do {                                          \
2880
    ((int32_t*)(_p))[0] = (_compLen);           \
2881
    ((int32_t*)(_p))[1] = (_fullLen);           \
2882
  } while (0);
2883

2884
typedef struct {
2885
  int64_t version;
2886
  int64_t numOfRows;
2887
  int8_t  compressed;
2888
  int8_t  precision;
2889
  char    data[];
2890
} SRetrieveTableRspForTmq;
2891

2892
typedef struct {
2893
  int64_t handle;
2894
  int64_t useconds;
2895
  int8_t  completed;  // all results are returned to client
2896
  int8_t  precision;
2897
  int8_t  compressed;
2898
  int32_t compLen;
2899
  int32_t numOfRows;
2900
  int32_t fullLen;
2901
  char    data[];
2902
} SRetrieveMetaTableRsp;
2903

2904
typedef struct SExplainExecInfo {
2905
  double   startupCost;
2906
  double   totalCost;
2907
  uint64_t numOfRows;
2908
  uint32_t verboseLen;
2909
  void*    verboseInfo;
2910
} SExplainExecInfo;
2911

2912
typedef struct {
2913
  int32_t           numOfPlans;
2914
  SExplainExecInfo* subplanInfo;
2915
} SExplainRsp;
2916

2917
typedef struct {
2918
  SExplainRsp rsp;
2919
  uint64_t    qId;
2920
  uint64_t    cId;
2921
  uint64_t    tId;
2922
  int64_t     rId;
2923
  int32_t     eId;
2924
} SExplainLocalRsp;
2925

2926
typedef struct STableScanAnalyzeInfo {
2927
  uint64_t totalRows;
2928
  uint64_t totalCheckedRows;
2929
  uint32_t totalBlocks;
2930
  uint32_t loadBlocks;
2931
  uint32_t loadBlockStatis;
2932
  uint32_t skipBlocks;
2933
  uint32_t filterOutBlocks;
2934
  double   elapsedTime;
2935
  double   filterTime;
2936
} STableScanAnalyzeInfo;
2937

2938
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2939
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2940
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2941

2942
typedef struct {
2943
  char    config[TSDB_DNODE_CONFIG_LEN];
2944
  char    value[TSDB_CLUSTER_VALUE_LEN];
2945
  int32_t sqlLen;
2946
  char*   sql;
2947
} SMCfgClusterReq;
2948

2949
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2950
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2951
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2952

2953
typedef struct {
2954
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2955
  int32_t port;
2956
  int32_t sqlLen;
2957
  char*   sql;
2958
} SCreateDnodeReq;
2959

2960
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2961
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2962
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2963

2964
typedef struct {
2965
  int32_t dnodeId;
2966
  char    fqdn[TSDB_FQDN_LEN];
2967
  int32_t port;
2968
  int8_t  force;
2969
  int8_t  unsafe;
2970
  int32_t sqlLen;
2971
  char*   sql;
2972
} SDropDnodeReq;
2973

2974
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2975
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2976
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2977

2978
enum {
2979
  RESTORE_TYPE__ALL = 1,
2980
  RESTORE_TYPE__MNODE,
2981
  RESTORE_TYPE__VNODE,
2982
  RESTORE_TYPE__QNODE,
2983
};
2984

2985
typedef struct {
2986
  int32_t dnodeId;
2987
  int8_t  restoreType;
2988
  int32_t sqlLen;
2989
  char*   sql;
2990
} SRestoreDnodeReq;
2991

2992
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2993
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2994
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2995

2996
typedef struct {
2997
  int32_t dnodeId;
2998
  char    config[TSDB_DNODE_CONFIG_LEN];
2999
  char    value[TSDB_DNODE_VALUE_LEN];
3000
  int32_t sqlLen;
3001
  char*   sql;
3002
} SMCfgDnodeReq;
3003

3004
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3005
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3006
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3007

3008
typedef struct {
3009
  char    config[TSDB_DNODE_CONFIG_LEN];
3010
  char    value[TSDB_DNODE_VALUE_LEN];
3011
  int32_t version;
3012
} SDCfgDnodeReq;
3013

3014
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3015
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3016

3017
typedef struct {
3018
  int32_t dnodeId;
3019
  int32_t sqlLen;
3020
  char*   sql;
3021
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3022
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
3023

3024

3025
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3026
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3027

3028

3029
typedef struct {
3030
  int32_t nodeId;
3031
  SEpSet  epSet;
3032
} SNodeEpSet;
3033

3034

3035
typedef struct {
3036
  int32_t    snodeId;
3037
  SNodeEpSet leaders[2];
3038
  SNodeEpSet replica;
3039
  int32_t    sqlLen;
3040
  char*      sql;
3041
} SDCreateSnodeReq;
3042

3043
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3044
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3045
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
3046

3047

3048
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3049
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3050
typedef struct {
3051
  int8_t   replica;
3052
  SReplica replicas[TSDB_MAX_REPLICA];
3053
  int8_t   learnerReplica;
3054
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3055
  int64_t  lastIndex;
3056
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3057

3058
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3059
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3060

3061
typedef struct {
3062
  int32_t urlLen;
3063
  int32_t sqlLen;
3064
  char*   url;
3065
  char*   sql;
3066
} SMCreateAnodeReq;
3067

3068
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3069
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3070
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3071

3072
typedef struct {
3073
  int32_t anodeId;
3074
  int32_t sqlLen;
3075
  char*   sql;
3076
} SMDropAnodeReq, SMUpdateAnodeReq;
3077

3078
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3079
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3080
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3081
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3082
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3083
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3084

3085
typedef struct {
3086
  int32_t dnodeId;
3087
  int32_t bnodeProto;
3088
  int32_t sqlLen;
3089
  char*   sql;
3090
} SMCreateBnodeReq, SDCreateBnodeReq;
3091

3092
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3093
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3094
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3095

3096
typedef struct {
3097
  int32_t dnodeId;
3098
  int32_t sqlLen;
3099
  char*   sql;
3100
} SMDropBnodeReq, SDDropBnodeReq;
3101

3102
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3103
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3104
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3105

3106
typedef struct {
3107
  int32_t vgId;
3108
  int32_t hbSeq;
3109
} SVArbHbReqMember;
3110

3111
typedef struct {
3112
  int32_t dnodeId;
3113
  char*   arbToken;
3114
  int64_t arbTerm;
3115
  SArray* hbMembers;  // SVArbHbReqMember
3116
} SVArbHeartBeatReq;
3117

3118
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3119
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3120
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3121

3122
typedef struct {
3123
  int32_t vgId;
3124
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3125
  int32_t hbSeq;
3126
} SVArbHbRspMember;
3127

3128
typedef struct {
3129
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3130
  int32_t dnodeId;
3131
  SArray* hbMembers;  // SVArbHbRspMember
3132
} SVArbHeartBeatRsp;
3133

3134
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3135
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3136
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3137

3138
typedef struct {
3139
  char*   arbToken;
3140
  int64_t arbTerm;
3141
  char*   member0Token;
3142
  char*   member1Token;
3143
} SVArbCheckSyncReq;
3144

3145
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3146
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3147
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3148

3149
typedef struct {
3150
  char*   arbToken;
3151
  char*   member0Token;
3152
  char*   member1Token;
3153
  int32_t vgId;
3154
  int32_t errCode;
3155
} SVArbCheckSyncRsp;
3156

3157
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3158
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3159
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3160

3161
typedef struct {
3162
  char*   arbToken;
3163
  int64_t arbTerm;
3164
  char*   memberToken;
3165
  int8_t  force;
3166
} SVArbSetAssignedLeaderReq;
3167

3168
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3169
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3170
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3171

3172
typedef struct {
3173
  char*   arbToken;
3174
  char*   memberToken;
3175
  int32_t vgId;
3176
} SVArbSetAssignedLeaderRsp;
3177

3178
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3179
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3180
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3181

3182
typedef struct {
3183
  int32_t dnodeId;
3184
  char*   token;
3185
} SMArbUpdateGroupMember;
3186

3187
typedef struct {
3188
  int32_t dnodeId;
3189
  char*   token;
3190
  int8_t  acked;
3191
} SMArbUpdateGroupAssigned;
3192

3193
typedef struct {
3194
  int32_t                  vgId;
3195
  int64_t                  dbUid;
3196
  SMArbUpdateGroupMember   members[2];
3197
  int8_t                   isSync;
3198
  int8_t                   assignedAcked;
3199
  SMArbUpdateGroupAssigned assignedLeader;
3200
  int64_t                  version;
3201
  int32_t                  code;
3202
  int64_t                  updateTimeMs;
3203
} SMArbUpdateGroup;
3204

3205
typedef struct {
3206
  SArray* updateArray;  // SMArbUpdateGroup
3207
} SMArbUpdateGroupBatchReq;
3208

3209
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3210
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3211
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3212

3213
typedef struct {
3214
  char queryStrId[TSDB_QUERY_ID_LEN];
3215
} SKillQueryReq;
3216

3217
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3218
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3219

3220
typedef struct {
3221
  uint32_t connId;
3222
} SKillConnReq;
3223

3224
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3225
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3226

3227
typedef struct {
3228
  int32_t transId;
3229
} SKillTransReq;
3230

3231
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3232
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3233

3234
typedef struct {
3235
  int32_t useless;  // useless
3236
  int32_t sqlLen;
3237
  char*   sql;
3238
} SBalanceVgroupReq;
3239

3240
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3241
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3242
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3243

3244
typedef struct {
3245
  int32_t useless;  // useless
3246
  int32_t sqlLen;
3247
  char*   sql;
3248
} SAssignLeaderReq;
3249

3250
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3251
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3252
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3253
typedef struct {
3254
  int32_t vgId1;
3255
  int32_t vgId2;
3256
} SMergeVgroupReq;
3257

3258
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3259
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3260

3261
typedef struct {
3262
  int32_t vgId;
3263
  int32_t dnodeId1;
3264
  int32_t dnodeId2;
3265
  int32_t dnodeId3;
3266
  int32_t sqlLen;
3267
  char*   sql;
3268
} SRedistributeVgroupReq;
3269

3270
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3271
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3272
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3273

3274
typedef struct {
3275
  int32_t reserved;
3276
  int32_t vgId;
3277
  int32_t sqlLen;
3278
  char*   sql;
3279
  char    db[TSDB_DB_FNAME_LEN];
3280
} SBalanceVgroupLeaderReq;
3281

3282
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3283
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3284
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3285

3286
typedef struct {
3287
  int32_t vgId;
3288
} SForceBecomeFollowerReq;
3289

3290
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3291
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3292

3293
typedef struct {
3294
  int32_t vgId;
3295
  bool    force;
3296
} SSplitVgroupReq;
3297

3298
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3299
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3300

3301
typedef struct {
3302
  char user[TSDB_USER_LEN];
3303
  char spi;
3304
  char encrypt;
3305
  char secret[TSDB_PASSWORD_LEN];
3306
  char ckey[TSDB_PASSWORD_LEN];
3307
} SAuthReq, SAuthRsp;
3308

3309
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3310
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3311

3312
typedef struct {
3313
  int32_t statusCode;
3314
  char    details[1024];
3315
} SServerStatusRsp;
3316

3317
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3318
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3319

3320
/**
3321
 * The layout of the query message payload is as following:
3322
 * +--------------------+---------------------------------+
3323
 * |Sql statement       | Physical plan                   |
3324
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3325
 * +--------------------+---------------------------------+
3326
 */
3327
typedef struct SSubQueryMsg {
3328
  SMsgHead header;
3329
  uint64_t sId;
3330
  uint64_t queryId;
3331
  uint64_t clientId;
3332
  uint64_t taskId;
3333
  int64_t  refId;
3334
  int32_t  execId;
3335
  int32_t  msgMask;
3336
  int8_t   taskType;
3337
  int8_t   explain;
3338
  int8_t   needFetch;
3339
  int8_t   compress;
3340
  uint32_t sqlLen;
3341
  char*    sql;
3342
  uint32_t msgLen;
3343
  char*    msg;
3344
} SSubQueryMsg;
3345

3346
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3347
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3348
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3349

3350
typedef struct {
3351
  SMsgHead header;
3352
  uint64_t sId;
3353
  uint64_t queryId;
3354
  uint64_t taskId;
3355
} SSinkDataReq;
3356

3357
typedef struct {
3358
  SMsgHead header;
3359
  uint64_t sId;
3360
  uint64_t queryId;
3361
  uint64_t clientId;
3362
  uint64_t taskId;
3363
  int32_t  execId;
3364
} SQueryContinueReq;
3365

3366
typedef struct {
3367
  SMsgHead header;
3368
  uint64_t sId;
3369
  uint64_t queryId;
3370
  uint64_t taskId;
3371
} SResReadyReq;
3372

3373
typedef struct {
3374
  int32_t code;
3375
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3376
  int32_t sversion;
3377
  int32_t tversion;
3378
} SResReadyRsp;
3379

3380
typedef struct SOperatorParam {
3381
  int32_t opType;
3382
  int32_t downstreamIdx;
3383
  void*   value;
3384
  SArray* pChildren;  // SArray<SOperatorParam*>
3385
  bool    reUse;
3386
} SOperatorParam;
3387

3388
typedef struct SColIdNameKV {
3389
  col_id_t colId;
3390
  char     colName[TSDB_COL_NAME_LEN];
3391
} SColIdNameKV;
3392

3393
typedef struct SColIdPair {
3394
  col_id_t vtbColId;
3395
  col_id_t orgColId;
3396
} SColIdPair;
3397

3398
typedef struct SOrgTbInfo {
3399
  int32_t vgId;
3400
  char    tbName[TSDB_TABLE_FNAME_LEN];
3401
  SArray* colMap;  // SArray<SColIdNameKV>
3402
} SOrgTbInfo;
3403

3404
typedef struct STableScanOperatorParam {
3405
  bool        tableSeq;
3406
  SArray*     pUidList;
3407
  SOrgTbInfo* pOrgTbInfo;
3408
  STimeWindow window;
3409
} STableScanOperatorParam;
3410

3411
typedef struct STagScanOperatorParam {
3412
  tb_uid_t       vcUid;
3413
} STagScanOperatorParam;
3414

3415
typedef struct SVTableScanOperatorParam {
3416
  uint64_t        uid;
3417
  SOperatorParam* pTagScanOp;
3418
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3419
} SVTableScanOperatorParam;
3420

3421
struct SStreamRuntimeFuncInfo;
3422
typedef struct {
3423
  SMsgHead                       header;
3424
  uint64_t                       sId;
3425
  uint64_t                       queryId;
3426
  uint64_t                       clientId;
3427
  uint64_t                       taskId;
3428
  int32_t                        execId;
3429
  SOperatorParam*                pOpParam;
3430

3431
  // used for new-stream
3432
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3433
  bool                           reset;
3434
  bool                           dynTbname;
3435
  // used for new-stream
3436
} SResFetchReq;
3437

3438
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3439
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3440
void    tDestroySResFetchReq(SResFetchReq* pReq);
3441
typedef struct {
3442
  SMsgHead header;
3443
  uint64_t clientId;
3444
} SSchTasksStatusReq;
3445

3446
typedef struct {
3447
  uint64_t queryId;
3448
  uint64_t clientId;
3449
  uint64_t taskId;
3450
  int64_t  refId;
3451
  int32_t  execId;
3452
  int8_t   status;
3453
} STaskStatus;
3454

3455
typedef struct {
3456
  int64_t refId;
3457
  SArray* taskStatus;  // SArray<STaskStatus>
3458
} SSchedulerStatusRsp;
3459

3460
typedef struct {
3461
  uint64_t queryId;
3462
  uint64_t taskId;
3463
  int8_t   action;
3464
} STaskAction;
3465

3466
typedef struct SQueryNodeEpId {
3467
  int32_t nodeId;  // vgId or qnodeId
3468
  SEp     ep;
3469
} SQueryNodeEpId;
3470

3471
typedef struct {
3472
  SMsgHead       header;
3473
  uint64_t       clientId;
3474
  SQueryNodeEpId epId;
3475
  SArray*        taskAction;  // SArray<STaskAction>
3476
} SSchedulerHbReq;
3477

3478
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3479
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3480
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3481

3482
typedef struct {
3483
  SQueryNodeEpId epId;
3484
  SArray*        taskStatus;  // SArray<STaskStatus>
3485
} SSchedulerHbRsp;
3486

3487
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3488
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3489
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3490

3491
typedef struct {
3492
  SMsgHead header;
3493
  uint64_t sId;
3494
  uint64_t queryId;
3495
  uint64_t clientId;
3496
  uint64_t taskId;
3497
  int64_t  refId;
3498
  int32_t  execId;
3499
} STaskCancelReq;
3500

3501
typedef struct {
3502
  int32_t code;
3503
} STaskCancelRsp;
3504

3505
typedef struct {
3506
  SMsgHead header;
3507
  uint64_t sId;
3508
  uint64_t queryId;
3509
  uint64_t clientId;
3510
  uint64_t taskId;
3511
  int64_t  refId;
3512
  int32_t  execId;
3513
} STaskDropReq;
3514

3515
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3516
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3517

3518
typedef enum {
3519
  TASK_NOTIFY_FINISHED = 1,
3520
} ETaskNotifyType;
3521

3522
typedef struct {
3523
  SMsgHead        header;
3524
  uint64_t        sId;
3525
  uint64_t        queryId;
3526
  uint64_t        clientId;
3527
  uint64_t        taskId;
3528
  int64_t         refId;
3529
  int32_t         execId;
3530
  ETaskNotifyType type;
3531
} STaskNotifyReq;
3532

3533
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3534
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3535

3536
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3537
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3538

3539
typedef struct {
3540
  int32_t code;
3541
} STaskDropRsp;
3542

3543
#define STREAM_TRIGGER_AT_ONCE                 1
3544
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3545
#define STREAM_TRIGGER_MAX_DELAY               3
3546
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3547
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3548

3549
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3550
#define STREAM_FILL_HISTORY_ON        1
3551
#define STREAM_FILL_HISTORY_OFF       0
3552
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3553
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3554
#define STREAM_CREATE_STABLE_TRUE     1
3555
#define STREAM_CREATE_STABLE_FALSE    0
3556

3557
typedef struct SVgroupVer {
3558
  int32_t vgId;
3559
  int64_t ver;
3560
} SVgroupVer;
3561

3562
typedef struct STaskNotifyEventStat {
3563
  int64_t notifyEventAddTimes;     // call times of add function
3564
  int64_t notifyEventAddElems;     // elements added by add function
3565
  double  notifyEventAddCostSec;   // time cost of add function
3566
  int64_t notifyEventPushTimes;    // call times of push function
3567
  int64_t notifyEventPushElems;    // elements pushed by push function
3568
  double  notifyEventPushCostSec;  // time cost of push function
3569
  int64_t notifyEventPackTimes;    // call times of pack function
3570
  int64_t notifyEventPackElems;    // elements packed by pack function
3571
  double  notifyEventPackCostSec;  // time cost of pack function
3572
  int64_t notifyEventSendTimes;    // call times of send function
3573
  int64_t notifyEventSendElems;    // elements sent by send function
3574
  double  notifyEventSendCostSec;  // time cost of send function
3575
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3576
} STaskNotifyEventStat;
3577

3578
enum {
3579
  TOPIC_SUB_TYPE__DB = 1,
3580
  TOPIC_SUB_TYPE__TABLE,
3581
  TOPIC_SUB_TYPE__COLUMN,
3582
};
3583

3584
#define DEFAULT_MAX_POLL_INTERVAL  300000
3585
#define DEFAULT_SESSION_TIMEOUT    12000
3586
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3587
#define DEFAULT_MIN_POLL_ROWS      4096
3588

3589
typedef struct {
3590
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3591
  int8_t igExists;
3592
  int8_t subType;
3593
  int8_t withMeta;
3594
  char*  sql;
3595
  char   subDbName[TSDB_DB_FNAME_LEN];
3596
  char*  ast;
3597
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3598
} SCMCreateTopicReq;
3599

3600
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3601
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3602
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3603

3604
typedef struct {
3605
  int64_t consumerId;
3606
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3607

3608
typedef struct {
3609
  int64_t consumerId;
3610
  char    cgroup[TSDB_CGROUP_LEN];
3611
  char    clientId[TSDB_CLIENT_ID_LEN];
3612
  char    user[TSDB_USER_LEN];
3613
  char    fqdn[TSDB_FQDN_LEN];
3614
  SArray* topicNames;  // SArray<char**>
3615

3616
  int8_t  withTbName;
3617
  int8_t  autoCommit;
3618
  int32_t autoCommitInterval;
3619
  int8_t  resetOffsetCfg;
3620
  int8_t  enableReplay;
3621
  int8_t  enableBatchMeta;
3622
  int32_t sessionTimeoutMs;
3623
  int32_t maxPollIntervalMs;
3624
} SCMSubscribeReq;
3625

3626
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3627
  int32_t tlen = 0;
312✔
3628
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
312!
3629
  tlen += taosEncodeString(buf, pReq->cgroup);
312✔
3630
  tlen += taosEncodeString(buf, pReq->clientId);
312✔
3631

3632
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
312!
3633
  tlen += taosEncodeFixedI32(buf, topicNum);
312✔
3634

3635
  for (int32_t i = 0; i < topicNum; i++) {
472✔
3636
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
320✔
3637
  }
3638

3639
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
312!
3640
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
312!
3641
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
312!
3642
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
312!
3643
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
312!
3644
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
312!
3645
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
312!
3646
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
312!
3647
  tlen += taosEncodeString(buf, pReq->user);
312✔
3648
  tlen += taosEncodeString(buf, pReq->fqdn);
312✔
3649

3650
  return tlen;
312✔
3651
}
3652

3653
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3654
  void* start = buf;
949✔
3655
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
949!
3656
  buf = taosDecodeStringTo(buf, pReq->cgroup);
949✔
3657
  buf = taosDecodeStringTo(buf, pReq->clientId);
949✔
3658

3659
  int32_t topicNum = 0;
949!
3660
  buf = taosDecodeFixedI32(buf, &topicNum);
949✔
3661

3662
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
949✔
3663
  if (pReq->topicNames == NULL) {
949!
3664
    return terrno;
×
3665
  }
3666
  for (int32_t i = 0; i < topicNum; i++) {
1,383✔
3667
    char* name = NULL;
434✔
3668
    buf = taosDecodeString(buf, &name);
434✔
3669
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
868!
3670
      return terrno;
×
3671
    }
3672
  }
3673

3674
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
949✔
3675
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
949✔
3676
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
949!
3677
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
949✔
3678
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
949✔
3679
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
949✔
3680
  if ((char*)buf - (char*)start < len) {
949!
3681
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
949!
3682
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
949!
3683
    buf = taosDecodeStringTo(buf, pReq->user);
949✔
3684
    buf = taosDecodeStringTo(buf, pReq->fqdn);
1,898✔
3685
  } else {
3686
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3687
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3688
  }
3689

3690
  return 0;
949✔
3691
}
3692

3693
typedef struct {
3694
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3695
  SArray* removedConsumers;  // SArray<int64_t>
3696
  SArray* newConsumers;      // SArray<int64_t>
3697
} SMqRebInfo;
3698

3699
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3700
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
949!
3701
  if (pRebInfo == NULL) {
949!
3702
    return NULL;
×
3703
  }
3704
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
949✔
3705
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
949✔
3706
  if (pRebInfo->removedConsumers == NULL) {
949!
3707
    goto _err;
×
3708
  }
3709
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
949✔
3710
  if (pRebInfo->newConsumers == NULL) {
949!
3711
    goto _err;
×
3712
  }
3713
  return pRebInfo;
949✔
3714
_err:
×
3715
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3716
  taosArrayDestroy(pRebInfo->newConsumers);
×
3717
  taosMemoryFreeClear(pRebInfo);
×
3718
  return NULL;
×
3719
}
3720

3721
typedef struct {
3722
  int64_t streamId;
3723
  int64_t checkpointId;
3724
  char    streamName[TSDB_STREAM_FNAME_LEN];
3725
} SMStreamDoCheckpointMsg;
3726

3727
typedef struct {
3728
  int64_t status;
3729
} SMVSubscribeRsp;
3730

3731
typedef struct {
3732
  char    name[TSDB_TOPIC_FNAME_LEN];
3733
  int8_t  igNotExists;
3734
  int32_t sqlLen;
3735
  char*   sql;
3736
  int8_t  force;
3737
} SMDropTopicReq;
3738

3739
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3740
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3741
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3742

3743
typedef struct {
3744
  char   topic[TSDB_TOPIC_FNAME_LEN];
3745
  char   cgroup[TSDB_CGROUP_LEN];
3746
  int8_t igNotExists;
3747
  int8_t force;
3748
} SMDropCgroupReq;
3749

3750
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3751
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3752

3753
typedef struct {
3754
  int8_t reserved;
3755
} SMDropCgroupRsp;
3756

3757
typedef struct {
3758
  char    name[TSDB_TABLE_FNAME_LEN];
3759
  int8_t  alterType;
3760
  SSchema schema;
3761
} SAlterTopicReq;
3762

3763
typedef struct {
3764
  SMsgHead head;
3765
  char     name[TSDB_TABLE_FNAME_LEN];
3766
  int64_t  tuid;
3767
  int32_t  sverson;
3768
  int32_t  execLen;
3769
  char*    executor;
3770
  int32_t  sqlLen;
3771
  char*    sql;
3772
} SDCreateTopicReq;
3773

3774
typedef struct {
3775
  SMsgHead head;
3776
  char     name[TSDB_TABLE_FNAME_LEN];
3777
  int64_t  tuid;
3778
} SDDropTopicReq;
3779

3780
typedef struct {
3781
  char*      name;
3782
  int64_t    uid;
3783
  int64_t    interval[2];
3784
  int8_t     intervalUnit;
3785
  int16_t    nFuncs;
3786
  col_id_t*  funcColIds;  // column ids specified by user
3787
  func_id_t* funcIds;     // function ids specified by user
3788
} SRSmaParam;
3789

3790
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3791
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3792

3793
// TDMT_VND_CREATE_STB ==============
3794
typedef struct SVCreateStbReq {
3795
  char*           name;
3796
  tb_uid_t        suid;
3797
  int8_t          rollup;
3798
  SSchemaWrapper  schemaRow;
3799
  SSchemaWrapper  schemaTag;
3800
  SRSmaParam      rsmaParam;
3801
  int32_t         alterOriDataLen;
3802
  void*           alterOriData;
3803
  int8_t          source;
3804
  int8_t          colCmpred;
3805
  SColCmprWrapper colCmpr;
3806
  int64_t         keep;
3807
  SExtSchema*     pExtSchemas;
3808
  int8_t          virtualStb;
3809
} SVCreateStbReq;
3810

3811
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3812
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3813

3814
// TDMT_VND_DROP_STB ==============
3815
typedef struct SVDropStbReq {
3816
  char*    name;
3817
  tb_uid_t suid;
3818
} SVDropStbReq;
3819

3820
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3821
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3822

3823
// TDMT_VND_CREATE_TABLE ==============
3824
#define TD_CREATE_IF_NOT_EXISTS       0x1
3825
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
3826
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
3827
typedef struct SVCreateTbReq {
3828
  int32_t  flags;
3829
  char*    name;
3830
  tb_uid_t uid;
3831
  int64_t  btime;
3832
  int32_t  ttl;
3833
  int32_t  commentLen;
3834
  char*    comment;
3835
  int8_t   type;
3836
  union {
3837
    struct {
3838
      char*    stbName;  // super table name
3839
      uint8_t  tagNum;
3840
      tb_uid_t suid;
3841
      SArray*  tagName;
3842
      uint8_t* pTag;
3843
    } ctb;
3844
    struct {
3845
      SSchemaWrapper schemaRow;
3846
    } ntb;
3847
  };
3848
  int32_t         sqlLen;
3849
  char*           sql;
3850
  SColCmprWrapper colCmpr;
3851
  SExtSchema*     pExtSchemas;
3852
  SColRefWrapper  colRef;  // col reference for virtual table
3853
} SVCreateTbReq;
3854

3855
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3856
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3857
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3858
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
3859

3860
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3861
  if (NULL == req) {
260,336!
3862
    return;
193,874✔
3863
  }
3864

3865
  taosMemoryFreeClear(req->sql);
66,462!
3866
  taosMemoryFreeClear(req->name);
66,462!
3867
  taosMemoryFreeClear(req->comment);
66,429!
3868
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
66,429!
3869
    taosMemoryFreeClear(req->ctb.pTag);
66,021!
3870
    taosMemoryFreeClear(req->ctb.stbName);
66,076!
3871
    taosArrayDestroy(req->ctb.tagName);
66,051✔
3872
    req->ctb.tagName = NULL;
66,062✔
3873
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
408!
3874
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
408!
3875
  }
3876
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
66,470!
3877
  taosMemoryFreeClear(req->pExtSchemas);
66,470!
3878
  taosMemoryFreeClear(req->colRef.pColRef);
66,470!
3879
}
3880

3881
typedef struct {
3882
  int32_t nReqs;
3883
  union {
3884
    SVCreateTbReq* pReqs;
3885
    SArray*        pArray;
3886
  };
3887
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3888
} SVCreateTbBatchReq;
3889

3890
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3891
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3892
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3893

3894
typedef struct {
3895
  int32_t        code;
3896
  STableMetaRsp* pMeta;
3897
} SVCreateTbRsp, SVUpdateTbRsp;
3898

3899
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3900
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3901
void tFreeSVCreateTbRsp(void* param);
3902

3903
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3904
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3905

3906
typedef struct {
3907
  int32_t nRsps;
3908
  union {
3909
    SVCreateTbRsp* pRsps;
3910
    SArray*        pArray;
3911
  };
3912
} SVCreateTbBatchRsp;
3913

3914
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3915
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3916

3917
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3918
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3919

3920
// TDMT_VND_DROP_TABLE =================
3921
typedef struct {
3922
  char*    name;
3923
  uint64_t suid;  // for tmq in wal format
3924
  int64_t  uid;
3925
  int8_t   igNotExists;
3926
  int8_t   isVirtual;
3927
} SVDropTbReq;
3928

3929
typedef struct {
3930
  int32_t code;
3931
} SVDropTbRsp;
3932

3933
typedef struct {
3934
  int32_t nReqs;
3935
  union {
3936
    SVDropTbReq* pReqs;
3937
    SArray*      pArray;
3938
  };
3939
} SVDropTbBatchReq;
3940

3941
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3942
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3943

3944
typedef struct {
3945
  int32_t nRsps;
3946
  union {
3947
    SVDropTbRsp* pRsps;
3948
    SArray*      pArray;
3949
  };
3950
} SVDropTbBatchRsp;
3951

3952
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3953
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3954

3955
// TDMT_VND_ALTER_TABLE =====================
3956
typedef struct SMultiTagUpateVal {
3957
  char*    tagName;
3958
  int32_t  colId;
3959
  int8_t   tagType;
3960
  int8_t   tagFree;
3961
  uint32_t nTagVal;
3962
  uint8_t* pTagVal;
3963
  int8_t   isNull;
3964
  SArray*  pTagArray;
3965
} SMultiTagUpateVal;
3966
typedef struct SVAlterTbReq {
3967
  char*   tbName;
3968
  int8_t  action;
3969
  char*   colName;
3970
  int32_t colId;
3971
  // TSDB_ALTER_TABLE_ADD_COLUMN
3972
  int8_t  type;
3973
  int8_t  flags;
3974
  int32_t bytes;
3975
  // TSDB_ALTER_TABLE_DROP_COLUMN
3976
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3977
  int8_t   colModType;
3978
  int32_t  colModBytes;
3979
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3980
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3981
  int8_t   isNull;
3982
  int8_t   tagType;
3983
  int8_t   tagFree;
3984
  uint32_t nTagVal;
3985
  uint8_t* pTagVal;
3986
  SArray*  pTagArray;
3987
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3988
  int8_t   updateTTL;
3989
  int32_t  newTTL;
3990
  int32_t  newCommentLen;
3991
  char*    newComment;
3992
  int64_t  ctimeMs;    // fill by vnode
3993
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3994
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3995
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3996
  // for Add column
3997
  STypeMod typeMod;
3998
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3999
  char* refDbName;
4000
  char* refTbName;
4001
  char* refColName;
4002
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4003
} SVAlterTbReq;
4004

4005
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4006
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4007
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4008
void    tfreeMultiTagUpateVal(void* pMultiTag);
4009

4010
typedef struct {
4011
  int32_t        code;
4012
  STableMetaRsp* pMeta;
4013
} SVAlterTbRsp;
4014

4015
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4016
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4017
// ======================
4018

4019
typedef struct {
4020
  SMsgHead head;
4021
  int64_t  uid;
4022
  int32_t  tid;
4023
  int16_t  tversion;
4024
  int16_t  colId;
4025
  int8_t   type;
4026
  int16_t  bytes;
4027
  int32_t  tagValLen;
4028
  int16_t  numOfTags;
4029
  int32_t  schemaLen;
4030
  char     data[];
4031
} SUpdateTagValReq;
4032

4033
typedef struct {
4034
  SMsgHead head;
4035
} SUpdateTagValRsp;
4036

4037
typedef struct {
4038
  SMsgHead head;
4039
} SVShowTablesReq;
4040

4041
typedef struct {
4042
  SMsgHead head;
4043
  int32_t  id;
4044
} SVShowTablesFetchReq;
4045

4046
typedef struct {
4047
  int64_t useconds;
4048
  int8_t  completed;  // all results are returned to client
4049
  int8_t  precision;
4050
  int8_t  compressed;
4051
  int32_t compLen;
4052
  int32_t numOfRows;
4053
  char    data[];
4054
} SVShowTablesFetchRsp;
4055

4056
typedef struct {
4057
  int64_t consumerId;
4058
  int32_t epoch;
4059
  char    cgroup[TSDB_CGROUP_LEN];
4060
} SMqAskEpReq;
4061

4062
typedef struct {
4063
  int32_t key;
4064
  int32_t valueLen;
4065
  void*   value;
4066
} SKv;
4067

4068
typedef struct {
4069
  int64_t tscRid;
4070
  int8_t  connType;
4071
} SClientHbKey;
4072

4073
typedef struct {
4074
  int64_t tid;
4075
  char    status[TSDB_JOB_STATUS_LEN];
4076
} SQuerySubDesc;
4077

4078
typedef struct {
4079
  char     sql[TSDB_SHOW_SQL_LEN];
4080
  uint64_t queryId;
4081
  int64_t  useconds;
4082
  int64_t  stime;  // timestamp precision ms
4083
  int64_t  reqRid;
4084
  bool     stableQuery;
4085
  bool     isSubQuery;
4086
  char     fqdn[TSDB_FQDN_LEN];
4087
  int32_t  subPlanNum;
4088
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4089
} SQueryDesc;
4090

4091
typedef struct {
4092
  uint32_t connId;
4093
  SArray*  queryDesc;  // SArray<SQueryDesc>
4094
} SQueryHbReqBasic;
4095

4096
typedef struct {
4097
  uint32_t connId;
4098
  uint64_t killRid;
4099
  int32_t  totalDnodes;
4100
  int32_t  onlineDnodes;
4101
  int8_t   killConnection;
4102
  int8_t   align[3];
4103
  SEpSet   epSet;
4104
  SArray*  pQnodeList;
4105
} SQueryHbRspBasic;
4106

4107
typedef struct SAppClusterSummary {
4108
  uint64_t numOfInsertsReq;
4109
  uint64_t numOfInsertRows;
4110
  uint64_t insertElapsedTime;
4111
  uint64_t insertBytes;  // submit to tsdb since launched.
4112

4113
  uint64_t fetchBytes;
4114
  uint64_t numOfQueryReq;
4115
  uint64_t queryElapsedTime;
4116
  uint64_t numOfSlowQueries;
4117
  uint64_t totalRequests;
4118
  uint64_t currentRequests;  // the number of SRequestObj
4119
} SAppClusterSummary;
4120

4121
typedef struct {
4122
  int64_t            appId;
4123
  int32_t            pid;
4124
  char               name[TSDB_APP_NAME_LEN];
4125
  int64_t            startTime;
4126
  SAppClusterSummary summary;
4127
} SAppHbReq;
4128

4129
typedef struct {
4130
  SClientHbKey      connKey;
4131
  int64_t           clusterId;
4132
  SAppHbReq         app;
4133
  SQueryHbReqBasic* query;
4134
  SHashObj*         info;  // hash<Skv.key, Skv>
4135
  char              userApp[TSDB_APP_NAME_LEN];
4136
  uint32_t          userIp;
4137
  SIpRange          userDualIp;
4138
} SClientHbReq;
4139

4140
typedef struct {
4141
  int64_t reqId;
4142
  SArray* reqs;  // SArray<SClientHbReq>
4143
  int64_t ipWhiteListVer;
4144
} SClientHbBatchReq;
4145

4146
typedef struct {
4147
  SClientHbKey      connKey;
4148
  int32_t           status;
4149
  SQueryHbRspBasic* query;
4150
  SArray*           info;  // Array<Skv>
4151
} SClientHbRsp;
4152

4153
typedef struct {
4154
  int64_t       reqId;
4155
  int64_t       rspId;
4156
  int32_t       svrTimestamp;
4157
  SArray*       rsps;  // SArray<SClientHbRsp>
4158
  SMonitorParas monitorParas;
4159
  int8_t        enableAuditDelete;
4160
  int8_t        enableStrongPass;
4161
} SClientHbBatchRsp;
4162

4163
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
27,498✔
4164

4165
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4166
  void* pIter = taosHashIterate(info, NULL);
41,395✔
4167
  while (pIter != NULL) {
80,447!
4168
    SKv* kv = (SKv*)pIter;
39,052✔
4169
    taosMemoryFreeClear(kv->value);
39,052!
4170
    pIter = taosHashIterate(info, pIter);
39,052✔
4171
  }
4172
}
41,395✔
4173

4174
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
18,046✔
4175
  SQueryDesc* desc = (SQueryDesc*)pDesc;
18,046✔
4176
  if (desc->subDesc) {
18,046✔
4177
    taosArrayDestroy(desc->subDesc);
18,041✔
4178
    desc->subDesc = NULL;
18,041✔
4179
  }
4180
}
18,046✔
4181

4182
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
46,966✔
4183
  SClientHbReq* req = (SClientHbReq*)pReq;
52,387✔
4184
  if (req->query) {
52,387!
4185
    if (req->query->queryDesc) {
40,686!
4186
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
2,957✔
4187
    }
4188
    taosMemoryFreeClear(req->query);
40,686!
4189
  }
4190

4191
  if (req->info) {
52,387!
4192
    tFreeReqKvHash(req->info);
41,395✔
4193
    taosHashCleanup(req->info);
41,395✔
4194
    req->info = NULL;
41,395✔
4195
  }
4196
}
45,603✔
4197

4198
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4199
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4200

4201
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4202
  if (pReq == NULL) return;
1,394!
4203
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
1,394✔
4204
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
1,394✔
4205
  taosMemoryFree(pReq);
1,394!
4206
}
4207

4208
static FORCE_INLINE void tFreeClientKv(void* pKv) {
15,127✔
4209
  SKv* kv = (SKv*)pKv;
15,127✔
4210
  if (kv) {
15,127!
4211
    taosMemoryFreeClear(kv->value);
15,127!
4212
  }
4213
}
15,127✔
4214

4215
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
46,962✔
4216
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
46,962✔
4217
  if (rsp->query) {
46,962✔
4218
    taosArrayDestroy(rsp->query->pQnodeList);
40,685✔
4219
    taosMemoryFreeClear(rsp->query);
40,686!
4220
  }
4221
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
46,964!
4222
}
6,784✔
4223

4224
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4225
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
35,237✔
4226
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
35,237✔
4227
}
35,238✔
4228

4229
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4230
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4231
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4232

4233
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4234
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
64,664!
4235
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
64,664!
4236
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
64,664!
4237
  return 0;
32,332✔
4238
}
4239

4240
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4241
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
76,034!
4242
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
76,034!
4243
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
38,017!
4244
  if (pKv->value == NULL) {
38,017!
4245
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4246
  }
4247
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
38,017!
4248
  return 0;
38,017✔
4249
}
4250

4251
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4252
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
187,938!
4253
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
187,938!
4254
  return 0;
93,969✔
4255
}
4256

4257
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4258
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
93,966!
4259
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
93,966!
4260
  return 0;
46,983✔
4261
}
4262

4263
typedef struct {
4264
  int32_t vgId;
4265
  // TODO stas
4266
} SMqReportVgInfo;
4267

4268
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4269
  int32_t tlen = 0;
4270
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4271
  return tlen;
4272
}
4273

4274
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4275
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4276
  return buf;
4277
}
4278

4279
typedef struct {
4280
  int32_t epoch;
4281
  int64_t topicUid;
4282
  char    name[TSDB_TOPIC_FNAME_LEN];
4283
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4284
} SMqTopicInfo;
4285

4286
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4287
  int32_t tlen = 0;
4288
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4289
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4290
  tlen += taosEncodeString(buf, pTopicInfo->name);
4291
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4292
  tlen += taosEncodeFixedI32(buf, sz);
4293
  for (int32_t i = 0; i < sz; i++) {
4294
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4295
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4296
  }
4297
  return tlen;
4298
}
4299

4300
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4301
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4302
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4303
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4304
  int32_t sz;
4305
  buf = taosDecodeFixedI32(buf, &sz);
4306
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4307
    return NULL;
4308
  }
4309
  for (int32_t i = 0; i < sz; i++) {
4310
    SMqReportVgInfo vgInfo;
4311
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4312
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4313
      return NULL;
4314
    }
4315
  }
4316
  return buf;
4317
}
4318

4319
typedef struct {
4320
  int32_t status;  // ask hb endpoint
4321
  int32_t epoch;
4322
  int64_t consumerId;
4323
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4324
} SMqReportReq;
4325

4326
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4327
  int32_t tlen = 0;
4328
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4329
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4330
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4331
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4332
  tlen += taosEncodeFixedI32(buf, sz);
4333
  for (int32_t i = 0; i < sz; i++) {
4334
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4335
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4336
  }
4337
  return tlen;
4338
}
4339

4340
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4341
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4342
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4343
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4344
  int32_t sz;
4345
  buf = taosDecodeFixedI32(buf, &sz);
4346
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4347
    return NULL;
4348
  }
4349
  for (int32_t i = 0; i < sz; i++) {
4350
    SMqTopicInfo topicInfo;
4351
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4352
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4353
      return NULL;
4354
    }
4355
  }
4356
  return buf;
4357
}
4358

4359
typedef struct {
4360
  SMsgHead head;
4361
  int64_t  leftForVer;
4362
  int32_t  vgId;
4363
  int64_t  consumerId;
4364
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4365
} SMqVDeleteReq;
4366

4367
typedef struct {
4368
  int8_t reserved;
4369
} SMqVDeleteRsp;
4370

4371
typedef struct {
4372
  char*   name;
4373
  int8_t  igNotExists;
4374
} SMDropStreamReq;
4375

4376
typedef struct {
4377
  int8_t reserved;
4378
} SMDropStreamRsp;
4379

4380
typedef struct {
4381
  SMsgHead head;
4382
  int64_t  resetRelHalt;  // reset related stream task halt status
4383
  int64_t  streamId;
4384
  int32_t  taskId;
4385
} SVDropStreamTaskReq;
4386

4387
typedef struct {
4388
  int8_t reserved;
4389
} SVDropStreamTaskRsp;
4390

4391
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4392
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4393
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4394

4395
typedef struct {
4396
  char*  name;
4397
  int8_t igNotExists;
4398
} SMPauseStreamReq;
4399

4400
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4401
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4402
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4403

4404
typedef struct {
4405
  char*  name;
4406
  int8_t igNotExists;
4407
  int8_t igUntreated;
4408
} SMResumeStreamReq;
4409

4410
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4411
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4412
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4413

4414
typedef struct {
4415
  char*       name;
4416
  int8_t      calcAll;
4417
  STimeWindow timeRange;
4418
} SMRecalcStreamReq;
4419

4420
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4421
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4422
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4423

4424
typedef struct SVUpdateCheckpointInfoReq {
4425
  SMsgHead head;
4426
  int64_t  streamId;
4427
  int32_t  taskId;
4428
  int64_t  checkpointId;
4429
  int64_t  checkpointVer;
4430
  int64_t  checkpointTs;
4431
  int32_t  transId;
4432
  int64_t  hStreamId;  // add encode/decode
4433
  int64_t  hTaskId;
4434
  int8_t   dropRelHTask;
4435
} SVUpdateCheckpointInfoReq;
4436

4437
typedef struct {
4438
  int64_t leftForVer;
4439
  int32_t vgId;
4440
  int64_t oldConsumerId;
4441
  int64_t newConsumerId;
4442
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4443
  int8_t  subType;
4444
  int8_t  withMeta;
4445
  char*   qmsg;  // SubPlanToString
4446
  int64_t suid;
4447
} SMqRebVgReq;
4448

4449
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4450
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4451

4452
typedef struct {
4453
  char    topic[TSDB_TOPIC_FNAME_LEN];
4454
  int64_t ntbUid;
4455
  SArray* colIdList;  // SArray<int16_t>
4456
} STqCheckInfo;
4457

4458
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4459
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4460
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4461

4462
// tqOffset
4463
enum {
4464
  TMQ_OFFSET__RESET_NONE = -3,
4465
  TMQ_OFFSET__RESET_EARLIEST = -2,
4466
  TMQ_OFFSET__RESET_LATEST = -1,
4467
  TMQ_OFFSET__LOG = 1,
4468
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4469
  TMQ_OFFSET__SNAPSHOT_META = 3,
4470
};
4471

4472
enum {
4473
  WITH_DATA = 0,
4474
  WITH_META = 1,
4475
  ONLY_META = 2,
4476
};
4477

4478
#define TQ_OFFSET_VERSION 1
4479

4480
typedef struct {
4481
  int8_t type;
4482
  union {
4483
    // snapshot
4484
    struct {
4485
      int64_t uid;
4486
      int64_t ts;
4487
      SValue  primaryKey;
4488
    };
4489
    // log
4490
    struct {
4491
      int64_t version;
4492
    };
4493
  };
4494
} STqOffsetVal;
4495

4496
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4497
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
24,713✔
4498
  pOffsetVal->uid = uid;
24,713✔
4499
  pOffsetVal->ts = ts;
24,713✔
4500
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
24,713!
4501
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4502
  }
4503
  pOffsetVal->primaryKey = primaryKey;
24,714✔
4504
}
24,714✔
4505

4506
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4507
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
154✔
4508
  pOffsetVal->uid = uid;
154✔
4509
}
154✔
4510

4511
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4512
  pOffsetVal->type = TMQ_OFFSET__LOG;
235,916✔
4513
  pOffsetVal->version = ver;
235,916✔
4514
}
235,916✔
4515

4516
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4517
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4518
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4519
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4520
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4521
void    tOffsetDestroy(void* pVal);
4522

4523
typedef struct {
4524
  STqOffsetVal val;
4525
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4526
} STqOffset;
4527

4528
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4529
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4530
void    tDeleteSTqOffset(void* val);
4531

4532
typedef struct SMqVgOffset {
4533
  int64_t   consumerId;
4534
  STqOffset offset;
4535
} SMqVgOffset;
4536

4537
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4538
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4539

4540
typedef struct {
4541
  char    name[TSDB_TABLE_FNAME_LEN];
4542
  char    stb[TSDB_TABLE_FNAME_LEN];
4543
  int8_t  igExists;
4544
  int8_t  intervalUnit;
4545
  int8_t  slidingUnit;
4546
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4547
  int32_t dstVgId;   // for stream
4548
  int64_t interval;
4549
  int64_t offset;
4550
  int64_t sliding;
4551
  int64_t maxDelay;
4552
  int64_t watermark;
4553
  int32_t exprLen;        // strlen + 1
4554
  int32_t tagsFilterLen;  // strlen + 1
4555
  int32_t sqlLen;         // strlen + 1
4556
  int32_t astLen;         // strlen + 1
4557
  char*   expr;
4558
  char*   tagsFilter;
4559
  char*   sql;
4560
  char*   ast;
4561
  int64_t deleteMark;
4562
  int64_t lastTs;
4563
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4564
  SArray* pVgroupVerList;
4565
  int8_t  recursiveTsma;
4566
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4567
  char*   createStreamReq;
4568
  int32_t streamReqLen;
4569
  char*   dropStreamReq;
4570
  int32_t dropStreamReqLen;
4571
  int64_t uid;
4572
} SMCreateSmaReq;
4573

4574
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4575
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4576
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4577

4578
typedef struct {
4579
  char   name[TSDB_TABLE_FNAME_LEN];
4580
  int8_t igNotExists;
4581
  char*   dropStreamReq;
4582
  int32_t dropStreamReqLen;
4583
} SMDropSmaReq;
4584

4585
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4586
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4587
void tFreeSMDropSmaReq(SMDropSmaReq *pReq);
4588

4589
typedef struct {
4590
  char name[TSDB_TABLE_NAME_LEN];
4591
  union {
4592
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4593
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4594
  };
4595
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4596
  union {
4597
    int8_t igExists;   // used by mnode
4598
    int8_t alterType;  // used by vnode
4599
  };
4600
  int8_t     intervalUnit;
4601
  int16_t    nFuncs;       // number of functions specified by user
4602
  col_id_t*  funcColIds;   // column ids specified by user
4603
  func_id_t* funcIds;      // function ids specified by user
4604
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4605
  int64_t    tbUid;
4606
  int64_t    uid;     // rsma uid
4607
  int32_t    sqlLen;  // strlen + 1
4608
  char*      sql;
4609
} SMCreateRsmaReq;
4610

4611
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4612
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4613
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4614

4615
typedef SMCreateRsmaReq SVCreateRsmaReq;
4616

4617
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4618
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4619
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4620

4621
typedef SMCreateRsmaReq SVAlterRsmaReq;
4622

4623
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4624
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4625
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4626

4627
typedef struct {
4628
  char       name[TSDB_TABLE_NAME_LEN];
4629
  int8_t     alterType;
4630
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4631
  int8_t     igNotExists;
4632
  int16_t    nFuncs;      // number of functions specified by user
4633
  col_id_t*  funcColIds;  // column ids specified by user
4634
  func_id_t* funcIds;     // function ids specified by user
4635
  int32_t    sqlLen;      // strlen + 1
4636
  char*      sql;
4637
} SMAlterRsmaReq;
4638

4639
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4640
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4641
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4642

4643
typedef struct {
4644
  int64_t    id;
4645
  char       name[TSDB_TABLE_NAME_LEN];
4646
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4647
  int32_t    code;
4648
  int32_t    version;
4649
  int8_t     tbType;
4650
  int8_t     intervalUnit;
4651
  col_id_t   nFuncs;
4652
  col_id_t   nColNames;
4653
  int64_t    interval[2];
4654
  col_id_t*  funcColIds;
4655
  func_id_t* funcIds;
4656
  SArray*    colNames;
4657
} SRsmaInfoRsp;
4658

4659
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4660
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4661
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4662

4663
typedef struct {
4664
  char   name[TSDB_TABLE_FNAME_LEN];
4665
  int8_t igNotExists;
4666
} SMDropRsmaReq;
4667

4668
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4669
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4670

4671
typedef struct {
4672
  char    name[TSDB_TABLE_NAME_LEN];
4673
  char    tbName[TSDB_TABLE_NAME_LEN];
4674
  int64_t uid;
4675
  int64_t tbUid;
4676
  int8_t  tbType;
4677
} SVDropRsmaReq;
4678

4679
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4680
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4681

4682
typedef struct {
4683
  char   dbFName[TSDB_DB_FNAME_LEN];
4684
  char   stbName[TSDB_TABLE_NAME_LEN];
4685
  char   colName[TSDB_COL_NAME_LEN];
4686
  char   idxName[TSDB_INDEX_FNAME_LEN];
4687
  int8_t idxType;
4688
} SCreateTagIndexReq;
4689

4690
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4691
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4692

4693
typedef SMDropSmaReq SDropTagIndexReq;
4694

4695
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4696
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4697

4698
typedef struct {
4699
  int8_t         version;       // for compatibility(default 0)
4700
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4701
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4702
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4703
  int32_t        dstVgId;
4704
  char           indexName[TSDB_INDEX_NAME_LEN];
4705
  int32_t        exprLen;
4706
  int32_t        tagsFilterLen;
4707
  int64_t        indexUid;
4708
  tb_uid_t       tableUid;  // super/child/common table uid
4709
  tb_uid_t       dstTbUid;  // for dstVgroup
4710
  int64_t        interval;
4711
  int64_t        offset;  // use unit by precision of DB
4712
  int64_t        sliding;
4713
  char*          dstTbName;  // for dstVgroup
4714
  char*          expr;       // sma expression
4715
  char*          tagsFilter;
4716
  SSchemaWrapper schemaRow;  // for dstVgroup
4717
  SSchemaWrapper schemaTag;  // for dstVgroup
4718
} STSma;                     // Time-range-wise SMA
4719

4720
typedef STSma SVCreateTSmaReq;
4721

4722
typedef struct {
4723
  int8_t  type;  // 0 status report, 1 update data
4724
  int64_t indexUid;
4725
  int64_t skey;  // start TS key of interval/sliding window
4726
} STSmaMsg;
4727

4728
typedef struct {
4729
  int64_t indexUid;
4730
  char    indexName[TSDB_INDEX_NAME_LEN];
4731
} SVDropTSmaReq;
4732

4733
typedef struct {
4734
  int tmp;  // TODO: to avoid compile error
4735
} SVCreateTSmaRsp, SVDropTSmaRsp;
4736

4737
#if 0
4738
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4739
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4740
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4741
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4742
#endif
4743

4744
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4745
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4746
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4747
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4748

4749
typedef struct {
4750
  int32_t number;
4751
  STSma*  tSma;
4752
} STSmaWrapper;
4753

4754
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4755
  if (pSma) {
×
4756
    taosMemoryFreeClear(pSma->dstTbName);
×
4757
    taosMemoryFreeClear(pSma->expr);
×
4758
    taosMemoryFreeClear(pSma->tagsFilter);
×
4759
  }
4760
}
×
4761

4762
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4763
  if (pSW) {
×
4764
    if (pSW->tSma) {
×
4765
      if (deepCopy) {
×
4766
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4767
          tDestroyTSma(pSW->tSma + i);
×
4768
        }
4769
      }
4770
      taosMemoryFreeClear(pSW->tSma);
×
4771
    }
4772
  }
4773
}
×
4774

4775
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4776
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4777
  taosMemoryFreeClear(pSW);
×
4778
  return NULL;
×
4779
}
4780

4781
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4782
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4783

4784
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4785
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4786

4787
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4788
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4789
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4790
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4791
  }
4792
  return 0;
×
4793
}
4794

4795
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4796
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4797
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4798
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4799
  }
4800
  return 0;
×
4801
}
4802

4803
typedef struct {
4804
  int idx;
4805
} SMCreateFullTextReq;
4806

4807
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4808
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4809
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4810

4811
typedef struct {
4812
  char   name[TSDB_TABLE_FNAME_LEN];
4813
  int8_t igNotExists;
4814
} SMDropFullTextReq;
4815

4816
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4817
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4818

4819
typedef struct {
4820
  char indexFName[TSDB_INDEX_FNAME_LEN];
4821
} SUserIndexReq;
4822

4823
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4824
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4825

4826
typedef struct {
4827
  char dbFName[TSDB_DB_FNAME_LEN];
4828
  char tblFName[TSDB_TABLE_FNAME_LEN];
4829
  char colName[TSDB_COL_NAME_LEN];
4830
  char indexType[TSDB_INDEX_TYPE_LEN];
4831
  char indexExts[TSDB_INDEX_EXTS_LEN];
4832
} SUserIndexRsp;
4833

4834
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4835
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4836

4837
typedef struct {
4838
  char tbFName[TSDB_TABLE_FNAME_LEN];
4839
} STableIndexReq;
4840

4841
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4842
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4843

4844
typedef struct {
4845
  int8_t  intervalUnit;
4846
  int8_t  slidingUnit;
4847
  int64_t interval;
4848
  int64_t offset;
4849
  int64_t sliding;
4850
  int64_t dstTbUid;
4851
  int32_t dstVgId;
4852
  SEpSet  epSet;
4853
  char*   expr;
4854
} STableIndexInfo;
4855

4856
typedef struct {
4857
  char     tbName[TSDB_TABLE_NAME_LEN];
4858
  char     dbFName[TSDB_DB_FNAME_LEN];
4859
  uint64_t suid;
4860
  int32_t  version;
4861
  int32_t  indexSize;
4862
  SArray*  pIndex;  // STableIndexInfo
4863
} STableIndexRsp;
4864

4865
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4866
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4867
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4868

4869
void tFreeSTableIndexInfo(void* pInfo);
4870

4871
typedef struct {
4872
  int8_t  mqMsgType;
4873
  int32_t code;
4874
  int32_t epoch;
4875
  int64_t consumerId;
4876
  int64_t walsver;
4877
  int64_t walever;
4878
} SMqRspHead;
4879

4880
typedef struct {
4881
  SMsgHead     head;
4882
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4883
  int8_t       withTbName;
4884
  int8_t       useSnapshot;
4885
  int32_t      epoch;
4886
  uint64_t     reqId;
4887
  int64_t      consumerId;
4888
  int64_t      timeout;
4889
  STqOffsetVal reqOffset;
4890
  int8_t       enableReplay;
4891
  int8_t       sourceExcluded;
4892
  int8_t       rawData;
4893
  int32_t      minPollRows;
4894
  int8_t       enableBatchMeta;
4895
  SHashObj*    uidHash;  // to find if uid is duplicated
4896
} SMqPollReq;
4897

4898
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4899
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4900
void    tDestroySMqPollReq(SMqPollReq* pReq);
4901

4902
typedef struct {
4903
  int32_t vgId;
4904
  int64_t offset;
4905
  SEpSet  epSet;
4906
} SMqSubVgEp;
4907

4908
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4909
  int32_t tlen = 0;
7,536✔
4910
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
7,536✔
4911
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
7,536✔
4912
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
7,536✔
4913
  return tlen;
7,536✔
4914
}
4915

4916
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4917
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
167!
4918
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
167!
4919
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
167✔
4920
  return buf;
167✔
4921
}
4922

4923
typedef struct {
4924
  char           topic[TSDB_TOPIC_FNAME_LEN];
4925
  char           db[TSDB_DB_FNAME_LEN];
4926
  SArray*        vgs;  // SArray<SMqSubVgEp>
4927
  SSchemaWrapper schema;
4928
} SMqSubTopicEp;
4929

4930
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4931
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4932
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4933

4934
typedef struct {
4935
  SMqRspHead   head;
4936
  STqOffsetVal rspOffset;
4937
  int16_t      resMsgType;
4938
  int32_t      metaRspLen;
4939
  void*        metaRsp;
4940
} SMqMetaRsp;
4941

4942
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4943
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4944
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4945

4946
#define MQ_DATA_RSP_VERSION 100
4947

4948
typedef struct {
4949
  SMqRspHead   head;
4950
  STqOffsetVal rspOffset;
4951
  STqOffsetVal reqOffset;
4952
  int32_t      blockNum;
4953
  int8_t       withTbName;
4954
  int8_t       withSchema;
4955
  SArray*      blockDataLen;
4956
  SArray*      blockData;
4957
  SArray*      blockTbName;
4958
  SArray*      blockSchema;
4959

4960
  union {
4961
    struct {
4962
      int64_t sleepTime;
4963
    };
4964
    struct {
4965
      int32_t createTableNum;
4966
      SArray* createTableLen;
4967
      SArray* createTableReq;
4968
    };
4969
    struct {
4970
      int32_t len;
4971
      void*   rawData;
4972
    };
4973
  };
4974
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4975
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4976
} SMqDataRsp;
4977

4978
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4979
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4980
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4981
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4982
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4983

4984
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4985
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4986
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4987

4988
typedef struct SMqBatchMetaRsp {
4989
  SMqRspHead   head;  // not serialize
4990
  STqOffsetVal rspOffset;
4991
  SArray*      batchMetaLen;
4992
  SArray*      batchMetaReq;
4993
  void*        pMetaBuff;    // not serialize
4994
  uint32_t     metaBuffLen;  // not serialize
4995
} SMqBatchMetaRsp;
4996

4997
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4998
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4999
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5000
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5001

5002
typedef struct {
5003
  SMqRspHead head;
5004
  char       cgroup[TSDB_CGROUP_LEN];
5005
  SArray*    topics;  // SArray<SMqSubTopicEp>
5006
} SMqAskEpRsp;
5007

5008
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5009
  int32_t tlen = 0;
16,300✔
5010
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5011
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,300!
5012
  tlen += taosEncodeFixedI32(buf, sz);
16,300✔
5013
  for (int32_t i = 0; i < sz; i++) {
22,578✔
5014
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,278✔
5015
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,278✔
5016
  }
5017
  return tlen;
16,300✔
5018
}
5019

5020
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5021
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5022
  int32_t sz;
5023
  buf = taosDecodeFixedI32(buf, &sz);
302✔
5024
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
302✔
5025
  if (pRsp->topics == NULL) {
302!
5026
    return NULL;
×
5027
  }
5028
  for (int32_t i = 0; i < sz; i++) {
368✔
5029
    SMqSubTopicEp topicEp;
5030
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
66✔
5031
    if (buf == NULL) {
66!
5032
      return NULL;
×
5033
    }
5034
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
132!
5035
      return NULL;
×
5036
    }
5037
  }
5038
  return buf;
302✔
5039
}
5040

5041
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5042
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
10,468✔
5043
}
10,468✔
5044

5045
typedef struct {
5046
  int32_t      vgId;
5047
  STqOffsetVal offset;
5048
  int64_t      rows;
5049
  int64_t      ever;
5050
} OffsetRows;
5051

5052
typedef struct {
5053
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5054
  SArray* offsetRows;
5055
} TopicOffsetRows;
5056

5057
typedef struct {
5058
  int64_t consumerId;
5059
  int32_t epoch;
5060
  SArray* topics;
5061
  int8_t  pollFlag;
5062
} SMqHbReq;
5063

5064
typedef struct {
5065
  char   topic[TSDB_TOPIC_FNAME_LEN];
5066
  int8_t noPrivilege;
5067
} STopicPrivilege;
5068

5069
typedef struct {
5070
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5071
  int32_t debugFlag;
5072
} SMqHbRsp;
5073

5074
typedef struct {
5075
  SMsgHead head;
5076
  int64_t  consumerId;
5077
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5078
} SMqSeekReq;
5079

5080
#define TD_AUTO_CREATE_TABLE 0x1
5081
typedef struct {
5082
  int64_t       suid;
5083
  int64_t       uid;
5084
  int32_t       sver;
5085
  uint32_t      nData;
5086
  uint8_t*      pData;
5087
  SVCreateTbReq cTbReq;
5088
} SVSubmitBlk;
5089

5090
typedef struct {
5091
  SMsgHead header;
5092
  uint64_t sId;
5093
  uint64_t queryId;
5094
  uint64_t clientId;
5095
  uint64_t taskId;
5096
  uint32_t sqlLen;
5097
  uint32_t phyLen;
5098
  char*    sql;
5099
  char*    msg;
5100
  int8_t   source;
5101
} SVDeleteReq;
5102

5103
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5104
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5105

5106
typedef struct {
5107
  int64_t affectedRows;
5108
} SVDeleteRsp;
5109

5110
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5111
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5112

5113
typedef struct SDeleteRes {
5114
  uint64_t suid;
5115
  SArray*  uidList;
5116
  int64_t  skey;
5117
  int64_t  ekey;
5118
  int64_t  affectedRows;
5119
  char     tableFName[TSDB_TABLE_NAME_LEN];
5120
  char     tsColName[TSDB_COL_NAME_LEN];
5121
  int64_t  ctimeMs;  // fill by vnode
5122
  int8_t   source;
5123
} SDeleteRes;
5124

5125
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5126
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5127

5128
typedef struct {
5129
  // int64_t uid;
5130
  char    tbname[TSDB_TABLE_NAME_LEN];
5131
  int64_t startTs;
5132
  int64_t endTs;
5133
} SSingleDeleteReq;
5134

5135
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5136
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5137

5138
typedef struct {
5139
  int64_t suid;
5140
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5141
  int64_t ctimeMs;     // fill by vnode
5142
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5143
} SBatchDeleteReq;
5144

5145
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5146
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5147
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5148

5149
typedef struct {
5150
  int32_t msgIdx;
5151
  int32_t msgType;
5152
  int32_t msgLen;
5153
  void*   msg;
5154
} SBatchMsg;
5155

5156
typedef struct {
5157
  SMsgHead header;
5158
  SArray*  pMsgs;  // SArray<SBatchMsg>
5159
} SBatchReq;
5160

5161
typedef struct {
5162
  int32_t reqType;
5163
  int32_t msgIdx;
5164
  int32_t msgLen;
5165
  int32_t rspCode;
5166
  void*   msg;
5167
} SBatchRspMsg;
5168

5169
typedef struct {
5170
  SArray* pRsps;  // SArray<SBatchRspMsg>
5171
} SBatchRsp;
5172

5173
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5174
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5175
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
244,912✔
5176
  if (NULL == msg) {
244,912!
5177
    return;
×
5178
  }
5179
  SBatchMsg* pMsg = (SBatchMsg*)msg;
244,912✔
5180
  taosMemoryFree(pMsg->msg);
244,912!
5181
}
5182

5183
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5184
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5185

5186
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
121,234✔
5187
  if (NULL == p) {
121,234!
5188
    return;
×
5189
  }
5190

5191
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
121,234✔
5192
  taosMemoryFree(pRsp->msg);
121,234!
5193
}
5194

5195
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5196
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5197
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5198
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5199
void    tDestroySMqHbReq(SMqHbReq* pReq);
5200

5201
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5202
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5203
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5204

5205
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5206
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5207

5208
#define TD_REQ_FROM_APP               0x0
5209
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5210
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5211
#define SUBMIT_REQ_FROM_FILE          0x4
5212
#define TD_REQ_FROM_TAOX              0x8
5213
#define TD_REQ_FROM_SML               0x10
5214
#define SUBMIT_REQUEST_VERSION        (2)
5215
#define SUBMIT_REQ_WITH_BLOB          0x10
5216
#define SUBMIT_REQ_SCHEMA_RES         0x20
5217

5218
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5219

5220
typedef struct {
5221
  int32_t        flags;
5222
  SVCreateTbReq* pCreateTbReq;
5223
  int64_t        suid;
5224
  int64_t        uid;
5225
  int32_t        sver;
5226
  union {
5227
    SArray* aRowP;
5228
    SArray* aCol;
5229
  };
5230
  int64_t    ctimeMs;
5231
  SBlobSet*  pBlobSet;
5232
} SSubmitTbData;
5233

5234
typedef struct {
5235
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5236
  SArray* aSubmitBlobData;
5237
  bool    raw;
5238
} SSubmitReq2;
5239

5240
typedef struct {
5241
  SMsgHead header;
5242
  int64_t  version;
5243
  char     data[];  // SSubmitReq2
5244
} SSubmitReq2Msg;
5245

5246
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5247
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5248
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5249
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5250
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5251

5252
typedef struct {
5253
  int32_t affectedRows;
5254
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5255
} SSubmitRsp2;
5256

5257
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5258
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5259
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5260

5261
#define TSDB_MSG_FLG_ENCODE 0x1
5262
#define TSDB_MSG_FLG_DECODE 0x2
5263
#define TSDB_MSG_FLG_CMPT   0x3
5264

5265
typedef struct {
5266
  union {
5267
    struct {
5268
      void*   msgStr;
5269
      int32_t msgLen;
5270
      int64_t ver;
5271
    };
5272
    void* pDataBlock;
5273
  };
5274
} SPackedData;
5275

5276
typedef struct {
5277
  char     fullname[TSDB_VIEW_FNAME_LEN];
5278
  char     name[TSDB_VIEW_NAME_LEN];
5279
  char     dbFName[TSDB_DB_FNAME_LEN];
5280
  char*    querySql;
5281
  char*    sql;
5282
  int8_t   orReplace;
5283
  int8_t   precision;
5284
  int32_t  numOfCols;
5285
  SSchema* pSchema;
5286
} SCMCreateViewReq;
5287

5288
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5289
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5290
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5291

5292
typedef struct {
5293
  char   fullname[TSDB_VIEW_FNAME_LEN];
5294
  char   name[TSDB_VIEW_NAME_LEN];
5295
  char   dbFName[TSDB_DB_FNAME_LEN];
5296
  char*  sql;
5297
  int8_t igNotExists;
5298
} SCMDropViewReq;
5299

5300
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5301
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5302
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5303

5304
typedef struct {
5305
  char fullname[TSDB_VIEW_FNAME_LEN];
5306
} SViewMetaReq;
5307
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5308
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5309

5310
typedef struct {
5311
  char     name[TSDB_VIEW_NAME_LEN];
5312
  char     dbFName[TSDB_DB_FNAME_LEN];
5313
  char*    user;
5314
  uint64_t dbId;
5315
  uint64_t viewId;
5316
  char*    querySql;
5317
  int8_t   precision;
5318
  int8_t   type;
5319
  int32_t  version;
5320
  int32_t  numOfCols;
5321
  SSchema* pSchema;
5322
} SViewMetaRsp;
5323
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5324
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5325
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5326
typedef struct {
5327
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5328
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5329
} STableTSMAInfoReq;
5330

5331
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5332
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5333

5334
typedef struct {
5335
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5336
  union {
5337
    uint8_t flags;
5338
    struct {
5339
      uint8_t withColName : 1;
5340
      uint8_t reserved : 7;
5341
    };
5342
  };
5343

5344
} SRsmaInfoReq;
5345

5346
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5347
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5348

5349
typedef struct {
5350
  int32_t  funcId;
5351
  col_id_t colId;
5352
} STableTSMAFuncInfo;
5353

5354
typedef struct {
5355
  char     name[TSDB_TABLE_NAME_LEN];
5356
  uint64_t tsmaId;
5357
  char     targetTb[TSDB_TABLE_NAME_LEN];
5358
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5359
  char     tb[TSDB_TABLE_NAME_LEN];
5360
  char     dbFName[TSDB_DB_FNAME_LEN];
5361
  uint64_t suid;
5362
  uint64_t destTbUid;
5363
  uint64_t dbId;
5364
  int32_t  version;
5365
  int64_t  interval;
5366
  int8_t   unit;
5367
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5368
  SArray*  pTags;      // SArray<SSchema>
5369
  SArray*  pUsedCols;  // SArray<SSchema>
5370
  char*    ast;
5371

5372
  int64_t streamUid;
5373
  int64_t reqTs;
5374
  int64_t rspTs;
5375
  int64_t delayDuration;  // ms
5376
  bool    fillHistoryFinished;
5377

5378
  void*   streamAddr;  // for stream task, the address of the stream task
5379
} STableTSMAInfo;
5380

5381
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5382
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5383
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5384
void    tFreeTableTSMAInfo(void* p);
5385
void    tFreeAndClearTableTSMAInfo(void* p);
5386
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5387

5388
#define STSMAHbRsp            STableTSMAInfoRsp
5389
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5390
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5391
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5392

5393
typedef struct SDropCtbWithTsmaSingleVgReq {
5394
  SVgroupInfo vgInfo;
5395
  SArray*     pTbs;  // SVDropTbReq
5396
} SMDropTbReqsOnSingleVg;
5397

5398
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5399
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5400
void    tFreeSMDropTbReqOnSingleVg(void* p);
5401

5402
typedef struct SDropTbsReq {
5403
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5404
} SMDropTbsReq;
5405

5406
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5407
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5408
void    tFreeSMDropTbsReq(void*);
5409

5410
typedef struct SVFetchTtlExpiredTbsRsp {
5411
  SArray* pExpiredTbs;  // SVDropTbReq
5412
  int32_t vgId;
5413
} SVFetchTtlExpiredTbsRsp;
5414

5415
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5416
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5417

5418
void tFreeFetchTtlExpiredTbsRsp(void* p);
5419

5420
void setDefaultOptionsForField(SFieldWithOptions* field);
5421
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5422

5423
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5424
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5425

5426
#ifdef USE_MOUNT
5427
typedef struct {
5428
  char     mountName[TSDB_MOUNT_NAME_LEN];
5429
  int8_t   ignoreExist;
5430
  int16_t  nMounts;
5431
  int32_t* dnodeIds;
5432
  char**   mountPaths;
5433
  int32_t  sqlLen;
5434
  char*    sql;
5435
} SCreateMountReq;
5436

5437
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5438
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5439
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5440

5441
typedef struct {
5442
  char    mountName[TSDB_MOUNT_NAME_LEN];
5443
  int8_t  ignoreNotExists;
5444
  int32_t sqlLen;
5445
  char*   sql;
5446
} SDropMountReq;
5447

5448
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5449
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5450
void    tFreeSDropMountReq(SDropMountReq* pReq);
5451

5452
typedef struct {
5453
  char     mountName[TSDB_MOUNT_NAME_LEN];
5454
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5455
  int64_t  mountUid;
5456
  int32_t  dnodeId;
5457
  uint32_t valLen;
5458
  int8_t   ignoreExist;
5459
  void*    pVal;
5460
} SRetrieveMountPathReq;
5461

5462
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5463
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5464

5465
typedef struct {
5466
  // path
5467
  int32_t diskPrimary;
5468
  // vgInfo
5469
  int32_t  vgId;
5470
  int32_t  cacheLastSize;
5471
  int32_t  szPage;
5472
  int32_t  szCache;
5473
  uint64_t szBuf;
5474
  int8_t   cacheLast;
5475
  int8_t   standby;
5476
  int8_t   hashMethod;
5477
  uint32_t hashBegin;
5478
  uint32_t hashEnd;
5479
  int16_t  hashPrefix;
5480
  int16_t  hashSuffix;
5481
  int16_t  sttTrigger;
5482
  // syncInfo
5483
  int32_t replications;
5484
  // tsdbInfo
5485
  int8_t  precision;
5486
  int8_t  compression;
5487
  int8_t  slLevel;
5488
  int32_t daysPerFile;
5489
  int32_t keep0;
5490
  int32_t keep1;
5491
  int32_t keep2;
5492
  int32_t keepTimeOffset;
5493
  int32_t minRows;
5494
  int32_t maxRows;
5495
  int32_t tsdbPageSize;
5496
  int32_t ssChunkSize;
5497
  int32_t ssKeepLocal;
5498
  int8_t  ssCompact;
5499
  // walInfo
5500
  int32_t walFsyncPeriod;      // millisecond
5501
  int32_t walRetentionPeriod;  // secs
5502
  int32_t walRollPeriod;       // secs
5503
  int64_t walRetentionSize;
5504
  int64_t walSegSize;
5505
  int32_t walLevel;
5506
  // encryptInfo
5507
  int32_t encryptAlgorithm;
5508
  // SVState
5509
  int64_t committed;
5510
  int64_t commitID;
5511
  int64_t commitTerm;
5512
  // stats
5513
  int64_t numOfSTables;
5514
  int64_t numOfCTables;
5515
  int64_t numOfNTables;
5516
  // dbInfo
5517
  uint64_t dbId;
5518
} SMountVgInfo;
5519

5520
typedef struct {
5521
  SMCreateStbReq req;
5522
  SArray*        pColExts;  // element: column id
5523
  SArray*        pTagExts;  // element: tag id
5524
} SMountStbInfo;
5525

5526
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5527
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5528

5529
typedef struct {
5530
  char     dbName[TSDB_DB_FNAME_LEN];
5531
  uint64_t dbId;
5532
  SArray*  pVgs;      // SMountVgInfo
5533
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5534
} SMountDbInfo;
5535

5536
typedef struct {
5537
  // common fields
5538
  char     mountName[TSDB_MOUNT_NAME_LEN];
5539
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5540
  int8_t   ignoreExist;
5541
  int64_t  mountUid;
5542
  int64_t  clusterId;
5543
  int32_t  dnodeId;
5544
  uint32_t valLen;
5545
  void*    pVal;
5546

5547
  // response fields
5548
  SArray* pDbs;  // SMountDbInfo
5549

5550
  // memory fields, no serialized
5551
  SArray*   pDisks[TFS_MAX_TIERS];
5552
  TdFilePtr pFile;
5553
} SMountInfo;
5554

5555
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5556
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5557
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5558

5559
typedef struct {
5560
  SCreateVnodeReq createReq;
5561
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5562
  char            mountName[TSDB_MOUNT_NAME_LEN];
5563
  int64_t         mountId;
5564
  int32_t         diskPrimary;
5565
  int32_t         mountVgId;
5566
  int64_t         committed;
5567
  int64_t         commitID;
5568
  int64_t         commitTerm;
5569
  int64_t         numOfSTables;
5570
  int64_t         numOfCTables;
5571
  int64_t         numOfNTables;
5572
} SMountVnodeReq;
5573

5574
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5575
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5576
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5577

5578
#endif  // USE_MOUNT
5579

5580
#pragma pack(pop)
5581

5582
typedef struct {
5583
  char        db[TSDB_DB_FNAME_LEN];
5584
  STimeWindow timeRange;
5585
  int32_t     sqlLen;
5586
  char*       sql;
5587
  SArray*     vgroupIds;
5588
} SScanDbReq;
5589

5590
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5591
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5592
void    tFreeSScanDbReq(SScanDbReq* pReq);
5593

5594
typedef struct {
5595
  int32_t scanId;
5596
  int8_t  bAccepted;
5597
} SScanDbRsp;
5598

5599
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5600
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5601

5602
typedef struct {
5603
  int32_t scanId;
5604
  int32_t sqlLen;
5605
  char*   sql;
5606
} SKillScanReq;
5607

5608
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5609
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5610
void    tFreeSKillScanReq(SKillScanReq* pReq);
5611

5612
typedef struct {
5613
  int32_t scanId;
5614
  int32_t vgId;
5615
  int32_t dnodeId;
5616
} SVKillScanReq;
5617

5618
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5619
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5620

5621
typedef struct {
5622
  int32_t scanId;
5623
  int32_t vgId;
5624
  int32_t dnodeId;
5625
  int32_t numberFileset;
5626
  int32_t finished;
5627
  int32_t progress;
5628
  int64_t remainingTime;
5629
} SQueryScanProgressRsp;
5630

5631
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5632
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5633

5634
typedef struct {
5635
  int32_t scanId;
5636
  int32_t vgId;
5637
  int32_t dnodeId;
5638
} SQueryScanProgressReq;
5639

5640
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5641
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5642

5643
typedef struct {
5644
  int64_t     dbUid;
5645
  char        db[TSDB_DB_FNAME_LEN];
5646
  int64_t     scanStartTime;
5647
  STimeWindow tw;
5648
  int32_t     scanId;
5649
} SScanVnodeReq;
5650

5651
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5652
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5653

5654
#ifdef __cplusplus
5655
}
5656
#endif
5657

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

© 2026 Coveralls, Inc