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

taosdata / TDengine / #4895

23 Dec 2025 01:08PM UTC coverage: 65.513% (-0.2%) from 65.72%
#4895

push

travis-ci

web-flow
fix: mem leak (#34023)

6 of 9 new or added lines in 1 file covered. (66.67%)

7770 existing lines in 123 files now uncovered.

184705 of 281937 relevant lines covered (65.51%)

112009834.14 hits per line

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

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

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

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

97
static inline bool tmsgIsValid(tmsg_t type) {
2,147,483,647✔
98
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
99
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
2,147,483,647✔
100
  int    segIdx = TMSG_SEG_CODE(type);
2,147,483,647✔
101
  if (segIdx >= 0 && segIdx < maxSegIdx) {
2,147,483,647✔
102
    return type < tMsgRangeDict[segIdx];
2,147,483,647✔
103
  }
104
  return false;
47✔
105
}
106

107
#define TMSG_INFO(type) (tmsgIsValid(type) ? tMsgInfo[TMSG_INDEX(type)] : "unKnown")
108

109
static inline bool vnodeIsMsgBlock(tmsg_t type) {
787,957,470✔
110
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
733,588,772✔
111
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,521,546,242✔
112
         (type == TDMT_SYNC_CONFIG_CHANGE);
113
}
114

115
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,027,610,039✔
116
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,027,610,039✔
117
}
118

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

129
enum {
130
  CONN_TYPE__QUERY = 1,
131
  CONN_TYPE__TMQ,
132
  CONN_TYPE__UDFD,
133
  CONN_TYPE__AUTH_TEST, // only for test authentication
134
  CONN_TYPE__MAX,
135
};
136

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

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

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

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

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

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

249

250
#define TSDB_ALTER_USER_BASIC_INFO             1
251
// these definitions start from 5 is to keep compatible with old versions
252
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
253
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
254

255

256
#define TSDB_ALTER_RSMA_FUNCTION 0x1
257

258
#define TSDB_KILL_MSG_LEN 30
259

260
#define TSDB_TABLE_NUM_UNIT 100000
261

262
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
263
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
264
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
265

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

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

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

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

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

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

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

522
  // logic plan node
523
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
524
  QUERY_NODE_LOGIC_PLAN_JOIN,
525
  QUERY_NODE_LOGIC_PLAN_AGG,
526
  QUERY_NODE_LOGIC_PLAN_PROJECT,
527
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
528
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
529
  QUERY_NODE_LOGIC_PLAN_MERGE,
530
  QUERY_NODE_LOGIC_PLAN_WINDOW,
531
  QUERY_NODE_LOGIC_PLAN_FILL,
532
  QUERY_NODE_LOGIC_PLAN_SORT,
533
  QUERY_NODE_LOGIC_PLAN_PARTITION,
534
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
535
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
536
  QUERY_NODE_LOGIC_SUBPLAN,
537
  QUERY_NODE_LOGIC_PLAN,
538
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
539
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
540
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
541
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
542
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
543

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

615
typedef struct {
616
  int32_t     vgId;
617
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
618
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
619
  const char* dbFName;
620
  const char* tbName;
621
} SBuildTableInput;
622

623
typedef struct {
624
  char    db[TSDB_DB_FNAME_LEN];
625
  int64_t dbId;
626
  int32_t vgVersion;
627
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
628
  int64_t stateTs;
629
} SBuildUseDBInput;
630

631
typedef struct SField {
632
  char    name[TSDB_COL_NAME_LEN];
633
  uint8_t type;
634
  int8_t  flags;
635
  int32_t bytes;
636
} SField;
637

638
typedef struct SFieldWithOptions {
639
  char     name[TSDB_COL_NAME_LEN];
640
  uint8_t  type;
641
  int8_t   flags;
642
  int32_t  bytes;
643
  uint32_t compress;
644
  STypeMod typeMod;
645
} SFieldWithOptions;
646

647
typedef struct SRetention {
648
  int64_t freq;
649
  int64_t keep;
650
  int8_t  freqUnit;
651
  int8_t  keepUnit;
652
} SRetention;
653

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

656
#pragma pack(push, 1)
657
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
658
typedef struct SEp {
659
  char     fqdn[TSDB_FQDN_LEN];
660
  uint16_t port;
661
} SEp;
662

663
typedef struct {
664
  int32_t contLen;
665
  int32_t vgId;
666
} SMsgHead;
667

668
// Submit message for one table
669
typedef struct SSubmitBlk {
670
  int64_t uid;        // table unique id
671
  int64_t suid;       // stable id
672
  int32_t sversion;   // data schema version
673
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
674
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
675
  int32_t numOfRows;  // total number of rows in current submit block
676
  char    data[];
677
} SSubmitBlk;
678

679
// Submit message for this TSDB
680
typedef struct {
681
  SMsgHead header;
682
  int64_t  version;
683
  int32_t  length;
684
  int32_t  numOfBlocks;
685
  char     blocks[];
686
} SSubmitReq;
687

688
typedef struct {
689
  int32_t totalLen;
690
  int32_t len;
691
  STSRow* row;
692
} SSubmitBlkIter;
693

694
typedef struct {
695
  int32_t totalLen;
696
  int32_t len;
697
  // head of SSubmitBlk
698
  int64_t uid;        // table unique id
699
  int64_t suid;       // stable id
700
  int32_t sversion;   // data schema version
701
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
702
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
703
  int32_t numOfRows;  // total number of rows in current submit block
704
  // head of SSubmitBlk
705
  int32_t     numOfBlocks;
706
  const void* pMsg;
707
} SSubmitMsgIter;
708

709
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
710
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
711
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
712
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
713
// for debug
714
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
715

716
typedef struct {
717
  bool     hasRef;
718
  col_id_t id;
719
  char     refDbName[TSDB_DB_NAME_LEN];
720
  char     refTableName[TSDB_TABLE_NAME_LEN];
721
  char     refColName[TSDB_COL_NAME_LEN];
722
} SColRef;
723

724
typedef struct {
725
  int32_t  nCols;
726
  int32_t  version;
727
  SColRef* pColRef;
728
} SColRefWrapper;
729

730
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
731
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
732
typedef struct {
733
  int32_t vgId;
734
  SColRef colRef;
735
} SColRefEx;
736

737
typedef struct {
738
  int16_t colId;
739
  char    refDbName[TSDB_DB_NAME_LEN];
740
  char    refTableName[TSDB_TABLE_NAME_LEN];
741
  char    refColName[TSDB_COL_NAME_LEN];
742
} SRefColInfo;
743

744
typedef struct SVCTableRefCols {
745
  uint64_t     uid;
746
  int32_t      numOfSrcTbls;
747
  int32_t      numOfColRefs;
748
  SRefColInfo* refCols;
749
} SVCTableRefCols;
750

751
typedef struct SVCTableMergeInfo {
752
  uint64_t uid;
753
  int32_t  numOfSrcTbls;
754
} SVCTableMergeInfo;
755

756
typedef struct {
757
  int32_t    nCols;
758
  SColRefEx* pColRefEx;
759
} SColRefExWrapper;
760

761
struct SSchema {
762
  int8_t   type;
763
  int8_t   flags;
764
  col_id_t colId;
765
  int32_t  bytes;
766
  char     name[TSDB_COL_NAME_LEN];
767
};
768
struct SSchemaExt {
769
  col_id_t colId;
770
  uint32_t compress;
771
  STypeMod typeMod;
772
};
773

774
struct SSchemaRsma {
775
  int64_t    interval[2];
776
  int32_t    nFuncs;
777
  int8_t     tbType;
778
  tb_uid_t   tbUid;
779
  func_id_t* funcIds;
780
  char       tbName[TSDB_TABLE_NAME_LEN];
781
};
782

783
struct SSchema2 {
784
  int8_t   type;
785
  int8_t   flags;
786
  col_id_t colId;
787
  int32_t  bytes;
788
  char     name[TSDB_COL_NAME_LEN];
789
  uint32_t compress;
790
};
791

792
typedef struct {
793
  char        tbName[TSDB_TABLE_NAME_LEN];
794
  char        stbName[TSDB_TABLE_NAME_LEN];
795
  char        dbFName[TSDB_DB_FNAME_LEN];
796
  int64_t     dbId;
797
  int32_t     numOfTags;
798
  int32_t     numOfColumns;
799
  int8_t      precision;
800
  int8_t      tableType;
801
  int32_t     sversion;
802
  int32_t     tversion;
803
  int32_t     rversion;
804
  uint64_t    suid;
805
  uint64_t    tuid;
806
  int32_t     vgId;
807
  int8_t      sysInfo;
808
  SSchema*    pSchemas;
809
  SSchemaExt* pSchemaExt;
810
  int8_t      virtualStb;
811
  int32_t     numOfColRefs;
812
  SColRef*    pColRefs;
813
} STableMetaRsp;
814

815
typedef struct {
816
  int32_t        code;
817
  int64_t        uid;
818
  char*          tblFName;
819
  int32_t        numOfRows;
820
  int32_t        affectedRows;
821
  int64_t        sver;
822
  STableMetaRsp* pMeta;
823
} SSubmitBlkRsp;
824

825
typedef struct {
826
  int32_t numOfRows;
827
  int32_t affectedRows;
828
  int32_t nBlocks;
829
  union {
830
    SArray*        pArray;
831
    SSubmitBlkRsp* pBlocks;
832
  };
833
} SSubmitRsp;
834

835
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
836
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
837
// void    tFreeSSubmitBlkRsp(void* param);
838
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
839

840
#define COL_SMA_ON       ((int8_t)0x1)
841
#define COL_IDX_ON       ((int8_t)0x2)
842
#define COL_IS_KEY       ((int8_t)0x4)
843
#define COL_SET_NULL     ((int8_t)0x10)
844
#define COL_SET_VAL      ((int8_t)0x20)
845
#define COL_IS_SYSINFO   ((int8_t)0x40)
846
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
847
#define COL_REF_BY_STM   ((int8_t)0x08)
848

849
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
850
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
851

852
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
853
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
854
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
855

856
#define SSCHMEA_SET_IDX_ON(s) \
857
  do {                        \
858
    (s)->flags |= COL_IDX_ON; \
859
  } while (0)
860

861
#define SSCHMEA_SET_IDX_OFF(s)   \
862
  do {                           \
863
    (s)->flags &= (~COL_IDX_ON); \
864
  } while (0)
865

866
#define SSCHEMA_SET_TYPE_MOD(s)     \
867
  do {                              \
868
    (s)->flags |= COL_HAS_TYPE_MOD; \
869
  } while (0)
870

871
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
872

873
#define SSCHMEA_TYPE(s)  ((s)->type)
874
#define SSCHMEA_FLAGS(s) ((s)->flags)
875
#define SSCHMEA_COLID(s) ((s)->colId)
876
#define SSCHMEA_BYTES(s) ((s)->bytes)
877
#define SSCHMEA_NAME(s)  ((s)->name)
878

879
typedef struct {
880
  bool    tsEnableMonitor;
881
  int32_t tsMonitorInterval;
882
  int32_t tsSlowLogThreshold;
883
  int32_t tsSlowLogMaxLen;
884
  int32_t tsSlowLogScope;
885
  int32_t tsSlowLogThresholdTest;  // Obsolete
886
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
887
} SMonitorParas;
888

889
typedef struct {
890
  STypeMod typeMod;
891
} SExtSchema;
892

893
bool hasExtSchema(const SExtSchema* pExtSchema);
894

895
typedef struct {
896
  int32_t      nCols;
897
  int32_t      version;
898
  SSchema*     pSchema;
899
  SSchemaRsma* pRsma;
900
} SSchemaWrapper;
901

902
typedef struct {
903
  col_id_t id;
904
  uint32_t alg;
905
} SColCmpr;
906

907
typedef struct {
908
  int32_t   nCols;
909
  int32_t   version;
910
  SColCmpr* pColCmpr;
911
} SColCmprWrapper;
912

913
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
914
  if (pRef->pColRef) {
364,490✔
915
    return TSDB_CODE_INVALID_PARA;
×
916
  }
917
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
364,490✔
918
  if (pRef->pColRef == NULL) {
364,490✔
919
    return terrno;
×
920
  }
921
  pRef->nCols = nCols;
364,490✔
922
  for (int32_t i = 0; i < nCols; i++) {
111,819,586✔
923
    pRef->pColRef[i].hasRef = false;
111,455,096✔
924
    pRef->pColRef[i].id = (col_id_t)(i + 1);
111,455,096✔
925
  }
926
  return 0;
364,490✔
927
}
928

929
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
930
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
931
    terrno = TSDB_CODE_INVALID_PARA;
932
    return NULL;
933
  }
934

935
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
936
  if (pDstWrapper == NULL) {
937
    return NULL;
938
  }
939
  pDstWrapper->nCols = pSrcWrapper->nCols;
940
  pDstWrapper->version = pSrcWrapper->version;
941

942
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
943
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
944
  if (pDstWrapper->pColCmpr == NULL) {
945
    taosMemoryFree(pDstWrapper);
946
    return NULL;
947
  }
948
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
949

950
  return pDstWrapper;
951
}
952

953
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
954
  if (!(!pCmpr->pColCmpr)) {
15,703,915✔
955
    return TSDB_CODE_INVALID_PARA;
×
956
  }
957
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
15,703,915✔
958
  if (pCmpr->pColCmpr == NULL) {
15,703,915✔
959
    return terrno;
×
960
  }
961
  pCmpr->nCols = nCols;
15,703,915✔
962
  return 0;
15,703,915✔
963
}
964

965
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
966
  pCmpr->nCols = pSchema->nCols;
967
  if (!(!pCmpr->pColCmpr)) {
968
    return TSDB_CODE_INVALID_PARA;
969
  }
970
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
971
  if (pCmpr->pColCmpr == NULL) {
972
    return terrno;
973
  }
974
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
975
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
976
    SSchema*  pColSchema = &pSchema->pSchema[i];
977
    pColCmpr->id = pColSchema->colId;
978
    pColCmpr->alg = 0;
979
  }
980
  return 0;
981
}
982

983
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
984
  if (pWrapper == NULL) return;
985

986
  taosMemoryFreeClear(pWrapper->pColCmpr);
987
  taosMemoryFreeClear(pWrapper);
988
}
989
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
990
  if (pSchemaWrapper->pSchema == NULL) return NULL;
510,662,948✔
991

992
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
510,596,389✔
993
  if (pSW == NULL) {
510,472,090✔
994
    return NULL;
×
995
  }
996
  pSW->nCols = pSchemaWrapper->nCols;
510,472,090✔
997
  pSW->version = pSchemaWrapper->version;
510,467,204✔
998
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
510,563,908✔
999
  if (pSW->pSchema == NULL) {
510,268,906✔
1000
    taosMemoryFree(pSW);
×
1001
    return NULL;
×
1002
  }
1003

1004
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
510,277,651✔
1005
  return pSW;
510,642,254✔
1006
}
1007

1008
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
117,222,305✔
1009
  if (pSchemaWrapper) {
1,397,108,246✔
1010
    taosMemoryFree(pSchemaWrapper->pSchema);
792,944,291✔
1011
    if (pSchemaWrapper->pRsma) {
792,773,465✔
1012
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
28,404✔
1013
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
28,404✔
1014
    }
1015
    taosMemoryFree(pSchemaWrapper);
792,841,843✔
1016
  }
1017
}
1,382,616,141✔
1018

1019
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1020
  if (pSchemaWrapper) {
1021
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1022
    if (pSchemaWrapper->pRsma) {
1023
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1024
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1025
    }
1026
  }
1027
}
1028

1029
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
956,191✔
1030
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
956,191✔
1031
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
956,191✔
1032
  }
1033
}
956,191✔
1034

1035
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1036
  int32_t tlen = 0;
1,355,372✔
1037
  tlen += taosEncodeFixedI8(buf, pSchema->type);
1,355,444✔
1038
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
1,355,372✔
1039
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
1,355,372✔
1040
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
1,355,372✔
1041
  tlen += taosEncodeString(buf, pSchema->name);
1,355,372✔
1042
  return tlen;
1,355,372✔
1043
}
1044

1045
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1046
  buf = taosDecodeFixedI8(buf, &pSchema->type);
596,588✔
1047
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
596,570✔
1048
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
596,570✔
1049
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
596,570✔
1050
  buf = taosDecodeStringTo(buf, pSchema->name);
596,570✔
1051
  return (void*)buf;
596,570✔
1052
}
1053

1054
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1055
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1056
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1057
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1058
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1059
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1060
  return 0;
2,147,483,647✔
1061
}
1062

1063
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1064
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1065
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1066
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1067
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1068
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1069
  return 0;
2,147,483,647✔
1070
}
1071

1072
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1073
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1074
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1075
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1076
  return 0;
2,147,483,647✔
1077
}
1078

1079
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1080
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1081
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1082
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1083
  return 0;
2,147,483,647✔
1084
}
1085

1086
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1087
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
563,600,312✔
1088
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
563,600,312✔
1089
  if (pColRef->hasRef) {
281,800,156✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
337,014,080✔
1091
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
337,014,080✔
1092
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
337,014,080✔
1093
  }
1094
  return 0;
281,800,156✔
1095
}
1096

1097
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1098
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
283,748,374✔
1099
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
283,748,374✔
1100
  if (pColRef->hasRef) {
141,874,187✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
84,905,152✔
1102
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
84,905,152✔
1103
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
84,905,152✔
1104
  }
1105

1106
  return 0;
141,874,187✔
1107
}
1108

1109
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1110
  int32_t tlen = 0;
177,410✔
1111
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
177,410✔
1112
  tlen += taosEncodeVariantI32(buf, pSW->version);
177,410✔
1113
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,532,782✔
1114
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
2,710,744✔
1115
  }
1116
  return tlen;
177,410✔
1117
}
1118

1119
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1120
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
75,205✔
1121
  buf = taosDecodeVariantI32(buf, &pSW->version);
75,205✔
1122
  if (pSW->nCols > 0) {
75,205✔
1123
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
75,205✔
1124
    if (pSW->pSchema == NULL) {
75,205✔
1125
      return NULL;
×
1126
    }
1127

1128
    for (int32_t i = 0; i < pSW->nCols; i++) {
671,775✔
1129
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
1,193,140✔
1130
    }
1131
  } else {
1132
    pSW->pSchema = NULL;
×
1133
  }
1134
  return (void*)buf;
75,205✔
1135
}
1136

1137
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1138
  if (pSW == NULL) {
373,113,788✔
1139
    return TSDB_CODE_INVALID_PARA;
×
1140
  }
1141
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
746,247,416✔
1142
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
746,240,005✔
1143
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1144
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1145
  }
1146
  return 0;
373,259,429✔
1147
}
1148

1149
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1150
  if (pSW == NULL) {
113,247,966✔
1151
    return TSDB_CODE_INVALID_PARA;
×
1152
  }
1153
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
226,439,729✔
1154
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
226,432,493✔
1155

1156
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
113,240,730✔
1157
  if (pSW->pSchema == NULL) {
113,189,633✔
1158
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1159
  }
1160
  for (int32_t i = 0; i < pSW->nCols; i++) {
895,171,042✔
1161
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,563,735,363✔
1162
  }
1163

1164
  return 0;
113,282,708✔
1165
}
1166

1167
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1168
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1169
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1170

1171
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1172
  if (pSW->pSchema == NULL) {
1,777,237,373✔
1173
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1174
  }
1175
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1176
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1177
  }
1178

1179
  return 0;
1,777,615,932✔
1180
}
1181

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

1215
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1216
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1217
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1218

1219
typedef struct {
1220
  STableMetaRsp* pMeta;
1221
} SMCreateStbRsp;
1222

1223
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1224
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1225
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1226

1227
typedef struct {
1228
  char     name[TSDB_TABLE_FNAME_LEN];
1229
  int8_t   igNotExists;
1230
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1231
  int8_t   reserved[6];
1232
  tb_uid_t suid;
1233
  int32_t  sqlLen;
1234
  char*    sql;
1235
} SMDropStbReq;
1236

1237
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1238
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1239
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1240

1241
typedef struct {
1242
  char    name[TSDB_TABLE_FNAME_LEN];
1243
  int8_t  alterType;
1244
  int32_t numOfFields;
1245
  SArray* pFields;
1246
  int32_t ttl;
1247
  int32_t commentLen;
1248
  char*   comment;
1249
  int32_t sqlLen;
1250
  char*   sql;
1251
  int64_t keep;
1252
  SArray* pTypeMods;
1253
} SMAlterStbReq;
1254

1255
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1256
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1257
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1258

1259
typedef struct SEpSet {
1260
  int8_t inUse;
1261
  int8_t numOfEps;
1262
  SEp    eps[TSDB_MAX_REPLICA];
1263
} SEpSet;
1264

1265
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1266
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1267
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1268
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1269

1270
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1271
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1272

1273
typedef struct {
1274
  int8_t  connType;
1275
  int32_t pid;
1276
  char    app[TSDB_APP_NAME_LEN];
1277
  char    db[TSDB_DB_NAME_LEN];
1278
  char    user[TSDB_USER_LEN];
1279
  char    passwd[TSDB_PASSWORD_LEN];
1280
  int64_t startTime;
1281
  char    sVer[TSDB_VERSION_LEN];
1282
  int32_t totpCode;
1283
} SConnectReq;
1284

1285
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1286
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1287

1288
typedef struct {
1289
  int64_t       clusterId;
1290
  int32_t       acctId;
1291
  uint32_t      connId;
1292
  int32_t       dnodeNum;
1293
  int8_t        superUser;
1294
  int8_t        sysInfo;
1295
  int8_t        connType;
1296
  SEpSet        epSet;
1297
  int32_t       svrTimestamp;
1298
  int32_t       passVer;
1299
  int32_t       authVer;
1300
  char          sVer[TSDB_VERSION_LEN];
1301
  char          sDetailVer[128];
1302
  int64_t       whiteListVer;
1303
  int64_t       timeWhiteListVer;
1304
  SMonitorParas monitorParas;
1305
  int8_t        enableAuditDelete;
1306
  int8_t        enableAuditSelect;
1307
  int8_t        enableAuditInsert;
1308
  int8_t        auditLevel;
1309
} SConnectRsp;
1310

1311
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1312
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1313

1314
typedef struct {
1315
  char    user[TSDB_USER_LEN];
1316
  char    pass[TSDB_PASSWORD_LEN];
1317
  int32_t maxUsers;
1318
  int32_t maxDbs;
1319
  int32_t maxTimeSeries;
1320
  int32_t maxStreams;
1321
  int32_t accessState;  // Configured only by command
1322
  int64_t maxStorage;
1323
} SCreateAcctReq, SAlterAcctReq;
1324

1325
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1326
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1327

1328
typedef struct {
1329
  char    user[TSDB_USER_LEN];
1330
  int32_t sqlLen;
1331
  char*   sql;
1332
} SDropUserReq, SDropAcctReq;
1333

1334
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1335
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1336
void    tFreeSDropUserReq(SDropUserReq* pReq);
1337

1338
typedef struct {
1339
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1340
  int32_t sqlLen;
1341
  char*   sql;
1342
} SDropEncryptAlgrReq;
1343

1344
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1345
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1346
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1347

1348
typedef struct SIpV4Range {
1349
  uint32_t ip;
1350
  uint32_t mask;
1351
} SIpV4Range;
1352

1353
typedef struct SIpv6Range {
1354
  uint64_t addr[2];
1355
  uint32_t mask;
1356
} SIpV6Range;
1357

1358
typedef struct {
1359
  int8_t type;   // 0: IPv4, 1: IPv6
1360
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1361
  union {
1362
    SIpV4Range ipV4;
1363
    SIpV6Range ipV6;
1364
  };
1365
} SIpRange;
1366

1367
typedef struct {
1368
  int32_t    num;
1369
  SIpV4Range pIpRange[];
1370
} SIpWhiteList;
1371

1372
typedef struct {
1373
  int32_t  num;
1374
  SIpRange pIpRanges[];
1375
} SIpWhiteListDual;
1376

1377
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1378
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1379
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1380
int32_t           createDefaultIp6Range(SIpRange* pRange);
1381
int32_t           createDefaultIp4Range(SIpRange* pRange);
1382

1383
typedef struct {
1384
  int32_t sessPerUser;
1385
  int32_t sessConnTime;
1386
  int32_t sessConnIdleTime;
1387
  int32_t sessMaxConcurrency;
1388
  int32_t sessMaxCallVnodeNum;
1389
} SUserSessCfg;
1390

1391
void initUserDefautSessCfg(SUserSessCfg* pCfg);
1392
// copyIpRange ensures that unused bytes are always zeroed, so that [pDst] can be used as a key in hash tables
1393
void copyIpRange(SIpRange* pDst, const SIpRange* pSrc);
1394

1395
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1396
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1397
typedef struct {
1398
  int16_t year;
1399
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1400
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1401
  int8_t hour;
1402
  int8_t minute;
1403
  int8_t neg;   // this is a negative entry
1404
  int32_t duration; // duration in minute
1405
} SDateTimeRange;
1406

1407
bool isValidDateTimeRange(SDateTimeRange* pRange);
1408
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1409
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1410

1411

1412
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1413
typedef struct {
1414
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1415
  bool neg;         // this is a negative entry
1416
  int32_t duration; // duration in seconds
1417
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1418
} SDateTimeWhiteListItem;
1419

1420
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1421
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1422

1423
typedef struct {
1424
  int32_t num;
1425
  SDateTimeWhiteListItem ranges[];
1426
} SDateTimeWhiteList;
1427

1428
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1429
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1430

1431

1432
typedef struct {
1433
  int8_t createType;
1434
  int8_t superUser;  // denote if it is a super user or not
1435
  int8_t ignoreExisting;
1436

1437
  char   user[TSDB_USER_LEN];
1438
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1439
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1440

1441
  int8_t sysInfo;
1442
  int8_t createDb;
1443
  int8_t isImport;
1444
  int8_t changepass;
1445
  int8_t enable;
1446

1447
  int8_t negIpRanges;
1448
  int8_t negTimeRanges;
1449

1450
  int32_t sessionPerUser;
1451
  int32_t connectTime;
1452
  int32_t connectIdleTime;
1453
  int32_t callPerSession;
1454
  int32_t vnodePerCall;
1455
  int32_t failedLoginAttempts;
1456
  int32_t passwordLifeTime;
1457
  int32_t passwordReuseTime;
1458
  int32_t passwordReuseMax;
1459
  int32_t passwordLockTime;
1460
  int32_t passwordGraceTime;
1461
  int32_t inactiveAccountTime;
1462
  int32_t allowTokenNum;
1463

1464
  int32_t         numIpRanges;
1465
  SIpRange*       pIpDualRanges;
1466
  int32_t         numTimeRanges;
1467
  SDateTimeRange* pTimeRanges;
1468

1469
  int32_t sqlLen;
1470
  char*   sql;
1471
} SCreateUserReq;
1472

1473
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1474
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1475
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1476

1477
typedef struct {
1478
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1479
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1480
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1481
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1482
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1483
  int32_t sqlLen;
1484
  char*   sql;
1485
} SCreateEncryptAlgrReq;
1486

1487
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1488
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1489
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1490

1491
typedef struct {
1492
  int32_t dnodeId;
1493
  int64_t analVer;
1494
} SRetrieveAnalyticsAlgoReq;
1495

1496
typedef struct {
1497
  int64_t   ver;
1498
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1499
} SRetrieveAnalyticAlgoRsp;
1500

1501
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1502
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1503
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1504
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1505
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1506

1507
typedef struct {
1508
  int8_t alterType;
1509

1510
  int8_t isView;
1511
  
1512
  int8_t hasPassword;
1513
  int8_t hasTotpseed;
1514
  int8_t hasEnable;
1515
  int8_t hasSysinfo;
1516
  int8_t hasCreatedb;
1517
  int8_t hasChangepass;
1518
  int8_t hasSessionPerUser;
1519
  int8_t hasConnectTime;
1520
  int8_t hasConnectIdleTime;
1521
  int8_t hasCallPerSession;
1522
  int8_t hasVnodePerCall;
1523
  int8_t hasFailedLoginAttempts;
1524
  int8_t hasPasswordLifeTime;
1525
  int8_t hasPasswordReuseTime;
1526
  int8_t hasPasswordReuseMax;
1527
  int8_t hasPasswordLockTime;
1528
  int8_t hasPasswordGraceTime;
1529
  int8_t hasInactiveAccountTime;
1530
  int8_t hasAllowTokenNum;
1531

1532
  int8_t enable;
1533
  int8_t sysinfo;
1534
  int8_t createdb;
1535
  int8_t changepass;
1536

1537
  char   user[TSDB_USER_LEN];
1538
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1539
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1540
  int32_t sessionPerUser;
1541
  int32_t connectTime;
1542
  int32_t connectIdleTime;
1543
  int32_t callPerSession;
1544
  int32_t vnodePerCall;
1545
  int32_t failedLoginAttempts;
1546
  int32_t passwordLifeTime;
1547
  int32_t passwordReuseTime;
1548
  int32_t passwordReuseMax;
1549
  int32_t passwordLockTime;
1550
  int32_t passwordGraceTime;
1551
  int32_t inactiveAccountTime;
1552
  int32_t allowTokenNum;
1553

1554
  int32_t         numIpRanges;
1555
  int32_t         numTimeRanges;
1556
  int32_t         numDropIpRanges;
1557
  int32_t         numDropTimeRanges;
1558
  SIpRange*       pIpRanges;
1559
  SDateTimeRange* pTimeRanges;
1560
  SIpRange*       pDropIpRanges;
1561
  SDateTimeRange* pDropTimeRanges;
1562

1563
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1564
  char        tabName[TSDB_TABLE_NAME_LEN];
1565
  char*       tagCond;
1566
  int32_t     tagCondLen;
1567
  int32_t     sqlLen;
1568
  char*       sql;
1569
  int64_t     privileges;
1570
} SAlterUserReq;
1571

1572
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1573
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1574
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1575

1576
typedef struct {
1577
  char user[TSDB_USER_LEN];
1578
} SGetUserAuthReq;
1579

1580
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1581
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1582

1583
typedef struct {
1584
  char      user[TSDB_USER_LEN];
1585
  int32_t   version;
1586
  int32_t   passVer;
1587
  int8_t    superAuth;
1588
  int8_t    sysInfo;
1589
  int8_t    enable;
1590
  int8_t    dropped;
1591
  SHashObj* createdDbs;
1592
  SHashObj* readDbs;
1593
  SHashObj* writeDbs;
1594
  SHashObj* readTbs;
1595
  SHashObj* writeTbs;
1596
  SHashObj* alterTbs;
1597
  SHashObj* readViews;
1598
  SHashObj* writeViews;
1599
  SHashObj* alterViews;
1600
  SHashObj* useDbs;
1601
  int64_t   whiteListVer;
1602

1603
  SUserSessCfg sessCfg;
1604
  int64_t      timeWhiteListVer;
1605
} SGetUserAuthRsp;
1606

1607
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1608
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1609
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1610

1611
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1612
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1613
typedef struct {
1614
  int64_t ver;
1615
  char    user[TSDB_USER_LEN];
1616
  int32_t numOfRange;
1617
  union {
1618
    SIpV4Range* pIpRanges;
1619
    SIpRange*   pIpDualRanges;
1620
  };
1621
} SUpdateUserIpWhite;
1622

1623
typedef struct {
1624
  int64_t             ver;
1625
  int                 numOfUser;
1626
  SUpdateUserIpWhite* pUserIpWhite;
1627
} SUpdateIpWhite;
1628

1629
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1630
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1631
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1632
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1633

1634
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1635
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1636
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1637

1638

1639
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1640
// corresponding response struct is different.
1641
typedef struct {
1642
  int64_t ver;
1643
} SRetrieveWhiteListReq;
1644

1645
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1646
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1647

1648

1649
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1650
// corresponding response struct is different.
1651
typedef struct {
1652
  char user[TSDB_USER_LEN];
1653
} SGetUserWhiteListReq;
1654

1655
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1656
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1657

1658
typedef struct {
1659
  char    user[TSDB_USER_LEN];
1660
  int32_t numWhiteLists;
1661
  union {
1662
    SIpV4Range* pWhiteLists;
1663
    SIpRange*   pWhiteListsDual;
1664
  };
1665
} SGetUserIpWhiteListRsp;
1666

1667
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1668
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1669
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1670
void    tIpRangeSetDefaultMask(SIpRange* range);
1671

1672
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1673
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1674
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1675

1676
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1677
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1678
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1679

1680
typedef struct {
1681
  int64_t ver;
1682
  char    user[TSDB_USER_LEN];
1683
  int32_t numWhiteLists;
1684
  SDateTimeWhiteListItem* pWhiteLists;
1685
} SUserDateTimeWhiteList;
1686

1687

1688
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1689
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1690
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1691
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1692

1693
typedef struct {
1694
  int64_t             ver;
1695
  int                 numOfUser;
1696
  SUserDateTimeWhiteList *pUsers;
1697
} SRetrieveDateTimeWhiteListRsp;
1698

1699
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1700
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1701
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1702
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1703

1704
/*
1705
 * for client side struct, only column id, type, bytes are necessary
1706
 * But for data in vnode side, we need all the following information.
1707
 */
1708
typedef struct {
1709
  union {
1710
    col_id_t colId;
1711
    int16_t  slotId;
1712
  };
1713

1714
  uint8_t precision;
1715
  uint8_t scale;
1716
  int32_t bytes;
1717
  int8_t  type;
1718
  uint8_t pk;
1719
  bool    noData;
1720
} SColumnInfo;
1721

1722
typedef struct STimeWindow {
1723
  TSKEY skey;
1724
  TSKEY ekey;
1725
} STimeWindow;
1726

1727
typedef struct SQueryHint {
1728
  bool batchScan;
1729
} SQueryHint;
1730

1731
typedef struct {
1732
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1733
  int32_t tsLen;          // total length of ts comp block
1734
  int32_t tsNumOfBlocks;  // ts comp block numbers
1735
  int32_t tsOrder;        // ts comp block order
1736
} STsBufInfo;
1737

1738
typedef struct {
1739
  void*       timezone;
1740
  char        intervalUnit;
1741
  char        slidingUnit;
1742
  char        offsetUnit;
1743
  int8_t      precision;
1744
  int64_t     interval;
1745
  int64_t     sliding;
1746
  int64_t     offset;
1747
  STimeWindow timeRange;
1748
} SInterval;
1749

1750
typedef struct STbVerInfo {
1751
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1752
  int32_t sversion;
1753
  int32_t tversion;
1754
  int32_t rversion;  // virtual table's column ref's version
1755
} STbVerInfo;
1756

1757
typedef struct {
1758
  int32_t code;
1759
  int64_t affectedRows;
1760
  SArray* tbVerInfo;  // STbVerInfo
1761
} SQueryTableRsp;
1762

1763
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1764

1765
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1766

1767
typedef struct {
1768
  SMsgHead header;
1769
  char     dbFName[TSDB_DB_FNAME_LEN];
1770
  char     tbName[TSDB_TABLE_NAME_LEN];
1771
} STableCfgReq;
1772

1773
typedef struct {
1774
  char        tbName[TSDB_TABLE_NAME_LEN];
1775
  char        stbName[TSDB_TABLE_NAME_LEN];
1776
  char        dbFName[TSDB_DB_FNAME_LEN];
1777
  int32_t     numOfTags;
1778
  int32_t     numOfColumns;
1779
  int8_t      tableType;
1780
  int64_t     delay1;
1781
  int64_t     delay2;
1782
  int64_t     watermark1;
1783
  int64_t     watermark2;
1784
  int32_t     ttl;
1785
  int32_t     keep;
1786
  SArray*     pFuncs;
1787
  int32_t     commentLen;
1788
  char*       pComment;
1789
  SSchema*    pSchemas;
1790
  int32_t     tagsLen;
1791
  char*       pTags;
1792
  SSchemaExt* pSchemaExt;
1793
  int8_t      virtualStb;
1794
  SColRef*    pColRefs;
1795
} STableCfg;
1796

1797
typedef STableCfg STableCfgRsp;
1798

1799
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1800
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1801

1802
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1803
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1804
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1805

1806
typedef struct {
1807
  SMsgHead header;
1808
  tb_uid_t suid;
1809
} SVSubTablesReq;
1810

1811
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1812
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1813

1814
typedef struct {
1815
  int32_t vgId;
1816
  SArray* pTables;  // SArray<SVCTableRefCols*>
1817
} SVSubTablesRsp;
1818

1819
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1820
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1821
void    tDestroySVSubTablesRsp(void* rsp);
1822

1823
typedef struct {
1824
  SMsgHead header;
1825
  tb_uid_t suid;
1826
} SVStbRefDbsReq;
1827

1828
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1829
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1830

1831
typedef struct {
1832
  int32_t vgId;
1833
  SArray* pDbs;  // SArray<char* (db name)>
1834
} SVStbRefDbsRsp;
1835

1836
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1837
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1838
void    tDestroySVStbRefDbsRsp(void* rsp);
1839

1840
typedef struct {
1841
  char    db[TSDB_DB_FNAME_LEN];
1842
  int32_t numOfVgroups;
1843
  int32_t numOfStables;  // single_stable
1844
  int32_t buffer;        // MB
1845
  int32_t pageSize;
1846
  int32_t pages;
1847
  int32_t cacheLastSize;
1848
  int32_t daysPerFile;
1849
  int32_t daysToKeep0;
1850
  int32_t daysToKeep1;
1851
  int32_t daysToKeep2;
1852
  int32_t keepTimeOffset;
1853
  int32_t minRows;
1854
  int32_t maxRows;
1855
  int32_t walFsyncPeriod;
1856
  int8_t  walLevel;
1857
  int8_t  precision;  // time resolution
1858
  int8_t  compression;
1859
  int8_t  replications;
1860
  int8_t  strict;
1861
  int8_t  cacheLast;
1862
  int8_t  schemaless;
1863
  int8_t  ignoreExist;
1864
  int32_t numOfRetensions;
1865
  SArray* pRetensions;  // SRetention
1866
  int32_t walRetentionPeriod;
1867
  int64_t walRetentionSize;
1868
  int32_t walRollPeriod;
1869
  int64_t walSegmentSize;
1870
  int32_t sstTrigger;
1871
  int16_t hashPrefix;
1872
  int16_t hashSuffix;
1873
  int32_t ssChunkSize;
1874
  int32_t ssKeepLocal;
1875
  int8_t  ssCompact;
1876
  int32_t tsdbPageSize;
1877
  int32_t sqlLen;
1878
  char*   sql;
1879
  int8_t  withArbitrator;
1880
  int8_t  encryptAlgorithm;
1881
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1882
  // 1. add auto-compact parameters
1883
  int32_t compactInterval;    // minutes
1884
  int32_t compactStartTime;   // minutes
1885
  int32_t compactEndTime;     // minutes
1886
  int8_t  compactTimeOffset;  // hour
1887
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1888
  int8_t  isAudit;
1889
} SCreateDbReq;
1890

1891
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1892
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1893
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1894

1895
typedef struct {
1896
  char    db[TSDB_DB_FNAME_LEN];
1897
  int32_t buffer;
1898
  int32_t pageSize;
1899
  int32_t pages;
1900
  int32_t cacheLastSize;
1901
  int32_t daysPerFile;
1902
  int32_t daysToKeep0;
1903
  int32_t daysToKeep1;
1904
  int32_t daysToKeep2;
1905
  int32_t keepTimeOffset;
1906
  int32_t walFsyncPeriod;
1907
  int8_t  walLevel;
1908
  int8_t  strict;
1909
  int8_t  cacheLast;
1910
  int8_t  replications;
1911
  int32_t sstTrigger;
1912
  int32_t minRows;
1913
  int32_t walRetentionPeriod;
1914
  int32_t walRetentionSize;
1915
  int32_t ssKeepLocal;
1916
  int8_t  ssCompact;
1917
  int32_t sqlLen;
1918
  char*   sql;
1919
  int8_t  withArbitrator;
1920
  // 1. add auto-compact parameters
1921
  int32_t compactInterval;
1922
  int32_t compactStartTime;
1923
  int32_t compactEndTime;
1924
  int8_t  compactTimeOffset;
1925
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1926
  int8_t  isAudit;
1927
} SAlterDbReq;
1928

1929
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1930
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1931
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1932

1933
typedef struct {
1934
  char    db[TSDB_DB_FNAME_LEN];
1935
  int8_t  ignoreNotExists;
1936
  int8_t  force;
1937
  int32_t sqlLen;
1938
  char*   sql;
1939
} SDropDbReq;
1940

1941
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1942
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1943
void    tFreeSDropDbReq(SDropDbReq* pReq);
1944

1945
typedef struct {
1946
  char    db[TSDB_DB_FNAME_LEN];
1947
  int64_t uid;
1948
} SDropDbRsp;
1949

1950
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1951
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1952

1953
typedef struct {
1954
  char    name[TSDB_MOUNT_NAME_LEN];
1955
  int64_t uid;
1956
} SDropMountRsp;
1957

1958
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1959
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1960

1961
typedef struct {
1962
  char    db[TSDB_DB_FNAME_LEN];
1963
  int64_t dbId;
1964
  int32_t vgVersion;
1965
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1966
  int64_t stateTs;     // ms
1967
} SUseDbReq;
1968

1969
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1970
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1971

1972
typedef struct {
1973
  char    db[TSDB_DB_FNAME_LEN];
1974
  int64_t uid;
1975
  int32_t vgVersion;
1976
  int32_t vgNum;
1977
  int16_t hashPrefix;
1978
  int16_t hashSuffix;
1979
  int8_t  hashMethod;
1980
  union {
1981
    uint8_t flags;
1982
    struct {
1983
      uint8_t isMount : 1;  // TS-5868
1984
      uint8_t padding : 7;
1985
    };
1986
  };
1987
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1988
  int32_t errCode;
1989
  int64_t stateTs;  // ms
1990
} SUseDbRsp;
1991

1992
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1993
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1994
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1995
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1996
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1997

1998
typedef struct {
1999
  char db[TSDB_DB_FNAME_LEN];
2000
} SDbCfgReq;
2001

2002
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2003
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2004

2005
typedef struct {
2006
  char db[TSDB_DB_FNAME_LEN];
2007
} SSsMigrateDbReq;
2008

2009
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2010
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2011

2012
typedef struct {
2013
  int32_t ssMigrateId;
2014
  bool    bAccepted;
2015
} SSsMigrateDbRsp;
2016

2017
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2018
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2019

2020
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2021
typedef struct {
2022
  int32_t ssMigrateId;
2023
} SListSsMigrateFileSetsReq;
2024

2025
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2026
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2027

2028
typedef struct {
2029
  int32_t ssMigrateId;
2030
  int32_t vgId;       // vgroup id
2031
  SArray* pFileSets;  // SArray<int32_t>
2032
} SListSsMigrateFileSetsRsp;
2033

2034
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2035
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2036
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2037

2038
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2039
typedef struct {
2040
  int32_t ssMigrateId;
2041
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2042
  int32_t fid;
2043
  int64_t startTimeSec;
2044
} SSsMigrateFileSetReq;
2045

2046
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2047
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2048

2049
typedef struct {
2050
  int32_t ssMigrateId;
2051
  int32_t nodeId;  // node id of the leader vnode
2052
  int32_t vgId;
2053
  int32_t fid;
2054
} SSsMigrateFileSetRsp;
2055

2056
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2057
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2058

2059
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2060
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2061
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2062
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2063
#define SSMIGRATE_FILESET_STATE_FAILED      4
2064

2065
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2066
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2067
// while as a request, the 'state' field is not used.
2068
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2069
typedef struct {
2070
  int32_t ssMigrateId;  // ss migrate id
2071
  int32_t nodeId;       // node id of the leader vnode
2072
  int32_t vgId;         // vgroup id
2073
  int32_t fid;          // file set id
2074
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2075
} SSsMigrateProgress;
2076

2077
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2078
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2079

2080
// Request for TDMT_MND_KILL_SSMIGRATE
2081
typedef struct {
2082
  int32_t ssMigrateId;
2083
  int32_t sqlLen;
2084
  char*   sql;
2085
} SKillSsMigrateReq;
2086

2087
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2088
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2089
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2090

2091
// Request for TDMT_VND_KILL_SSMIGRATE
2092
typedef struct {
2093
  int32_t ssMigrateId;
2094
} SVnodeKillSsMigrateReq;
2095

2096
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2097
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2098

2099
typedef struct {
2100
  int32_t vgId;
2101
  int64_t keepVersion;
2102
} SMndSetVgroupKeepVersionReq;
2103

2104
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2105
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2106

2107
typedef struct {
2108
  int32_t timestampSec;
2109
  int32_t ttlDropMaxCount;
2110
  int32_t nUids;
2111
  SArray* pTbUids;
2112
} SVDropTtlTableReq;
2113

2114
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2115
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2116

2117
typedef struct {
2118
  char    db[TSDB_DB_FNAME_LEN];
2119
  int64_t dbId;
2120
  int32_t cfgVersion;
2121
  int32_t numOfVgroups;
2122
  int32_t numOfStables;
2123
  int32_t buffer;
2124
  int32_t cacheSize;
2125
  int32_t pageSize;
2126
  int32_t pages;
2127
  int32_t daysPerFile;
2128
  int32_t daysToKeep0;
2129
  int32_t daysToKeep1;
2130
  int32_t daysToKeep2;
2131
  int32_t keepTimeOffset;
2132
  int32_t minRows;
2133
  int32_t maxRows;
2134
  int32_t walFsyncPeriod;
2135
  int16_t hashPrefix;
2136
  int16_t hashSuffix;
2137
  int8_t  hashMethod;
2138
  int8_t  walLevel;
2139
  int8_t  precision;
2140
  int8_t  compression;
2141
  int8_t  replications;
2142
  int8_t  strict;
2143
  int8_t  cacheLast;
2144
  int8_t  encryptAlgr;
2145
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2146
  int32_t ssChunkSize;
2147
  int32_t ssKeepLocal;
2148
  int8_t  ssCompact;
2149
  union {
2150
    uint8_t flags;
2151
    struct {
2152
      uint8_t isMount : 1;  // TS-5868
2153
      uint8_t padding : 7;
2154
    };
2155
  };
2156
  int8_t  compactTimeOffset;
2157
  int32_t compactInterval;
2158
  int32_t compactStartTime;
2159
  int32_t compactEndTime;
2160
  int32_t tsdbPageSize;
2161
  int32_t walRetentionPeriod;
2162
  int32_t walRollPeriod;
2163
  int64_t walRetentionSize;
2164
  int64_t walSegmentSize;
2165
  int32_t numOfRetensions;
2166
  SArray* pRetensions;
2167
  int8_t  schemaless;
2168
  int16_t sstTrigger;
2169
  int8_t  withArbitrator;
2170
  int8_t  isAudit;
2171
} SDbCfgRsp;
2172

2173
typedef SDbCfgRsp SDbCfgInfo;
2174

2175
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2176
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2177
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2178
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2179
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2180

2181
typedef struct {
2182
  int32_t rowNum;
2183
} SQnodeListReq;
2184

2185
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2186
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2187

2188
typedef struct {
2189
  int32_t rowNum;
2190
} SDnodeListReq;
2191

2192
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2193

2194
typedef struct {
2195
  int32_t useless;  // useless
2196
} SServerVerReq;
2197

2198
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2199
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2200

2201
typedef struct {
2202
  char ver[TSDB_VERSION_LEN];
2203
} SServerVerRsp;
2204

2205
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2206
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2207

2208
typedef struct SQueryNodeAddr {
2209
  int32_t nodeId;  // vgId or qnodeId
2210
  SEpSet  epSet;
2211
} SQueryNodeAddr;
2212

2213
typedef struct {
2214
  SQueryNodeAddr addr;
2215
  uint64_t       load;
2216
} SQueryNodeLoad;
2217

2218
typedef struct {
2219
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2220
} SQnodeListRsp;
2221

2222
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2223
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2224
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2225

2226

2227
typedef struct SDownstreamSourceNode {
2228
  ENodeType      type;
2229
  SQueryNodeAddr addr;
2230
  uint64_t       clientId;
2231
  uint64_t       taskId;
2232
  uint64_t       sId;
2233
  int32_t        execId;
2234
  int32_t        fetchMsgType;
2235
  bool           localExec;
2236
} SDownstreamSourceNode;
2237

2238

2239

2240
typedef struct SDNodeAddr {
2241
  int32_t nodeId;  // dnodeId
2242
  SEpSet  epSet;
2243
} SDNodeAddr;
2244

2245
typedef struct {
2246
  SArray* dnodeList;  // SArray<SDNodeAddr>
2247
} SDnodeListRsp;
2248

2249
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2250
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2251
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2252

2253
typedef struct {
2254
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2255
} STableTSMAInfoRsp;
2256

2257
typedef struct {
2258
  SUseDbRsp*         useDbRsp;
2259
  SDbCfgRsp*         cfgRsp;
2260
  STableTSMAInfoRsp* pTsmaRsp;
2261
  int32_t            dbTsmaVersion;
2262
  char               db[TSDB_DB_FNAME_LEN];
2263
  int64_t            dbId;
2264
} SDbHbRsp;
2265

2266
typedef struct {
2267
  SArray* pArray;  // Array of SDbHbRsp
2268
} SDbHbBatchRsp;
2269

2270
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2271
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2272
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2273

2274
typedef struct {
2275
  SArray* pArray;  // Array of SGetUserAuthRsp
2276
} SUserAuthBatchRsp;
2277

2278
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2279
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2280
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2281

2282
typedef struct {
2283
  char        db[TSDB_DB_FNAME_LEN];
2284
  STimeWindow timeRange;
2285
  int32_t     sqlLen;
2286
  char*       sql;
2287
  SArray*     vgroupIds;
2288
  int32_t     compactId;
2289
  int8_t      metaOnly;
2290
  int8_t      force;
2291
} SCompactDbReq;
2292

2293
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2294
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2295
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2296

2297
typedef struct {
2298
  union {
2299
    int32_t compactId;
2300
    int32_t id;
2301
  };
2302
  int8_t bAccepted;
2303
} SCompactDbRsp;
2304

2305
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2306
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2307

2308
typedef struct {
2309
  union {
2310
    int32_t compactId;
2311
    int32_t id;
2312
  };
2313
  int32_t sqlLen;
2314
  char*   sql;
2315
} SKillCompactReq;
2316

2317
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2318
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2319
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2320

2321
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2322
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2323

2324
typedef struct {
2325
  char    name[TSDB_FUNC_NAME_LEN];
2326
  int8_t  igExists;
2327
  int8_t  funcType;
2328
  int8_t  scriptType;
2329
  int8_t  outputType;
2330
  int32_t outputLen;
2331
  int32_t bufSize;
2332
  int32_t codeLen;
2333
  int64_t signature;
2334
  char*   pComment;
2335
  char*   pCode;
2336
  int8_t  orReplace;
2337
} SCreateFuncReq;
2338

2339
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2340
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2341
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2342

2343
typedef struct {
2344
  char   name[TSDB_FUNC_NAME_LEN];
2345
  int8_t igNotExists;
2346
} SDropFuncReq;
2347

2348
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2349
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2350

2351
typedef struct {
2352
  int32_t numOfFuncs;
2353
  bool    ignoreCodeComment;
2354
  SArray* pFuncNames;
2355
} SRetrieveFuncReq;
2356

2357
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2358
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2359
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2360

2361
typedef struct {
2362
  char    name[TSDB_FUNC_NAME_LEN];
2363
  int8_t  funcType;
2364
  int8_t  scriptType;
2365
  int8_t  outputType;
2366
  int32_t outputLen;
2367
  int32_t bufSize;
2368
  int64_t signature;
2369
  int32_t commentSize;
2370
  int32_t codeSize;
2371
  char*   pComment;
2372
  char*   pCode;
2373
} SFuncInfo;
2374

2375
typedef struct {
2376
  int32_t funcVersion;
2377
  int64_t funcCreatedTime;
2378
} SFuncExtraInfo;
2379

2380
typedef struct {
2381
  int32_t numOfFuncs;
2382
  SArray* pFuncInfos;
2383
  SArray* pFuncExtraInfos;
2384
} SRetrieveFuncRsp;
2385

2386
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2387
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2388
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2389
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2390

2391
typedef struct {
2392
  int32_t       statusInterval;
2393
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2394
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2395
  char          locale[TD_LOCALE_LEN];      // tsLocale
2396
  char          charset[TD_LOCALE_LEN];     // tsCharset
2397
  int8_t        ttlChangeOnWrite;
2398
  int8_t        enableWhiteList;
2399
  int8_t        encryptionKeyStat;
2400
  uint32_t      encryptionKeyChksum;
2401
  SMonitorParas monitorParas;
2402
  int32_t       statusIntervalMs;
2403
} SClusterCfg;
2404

2405
typedef struct {
2406
  int32_t openVnodes;
2407
  int32_t dropVnodes;
2408
  int32_t totalVnodes;
2409
  int32_t masterNum;
2410
  int64_t numOfSelectReqs;
2411
  int64_t numOfInsertReqs;
2412
  int64_t numOfInsertSuccessReqs;
2413
  int64_t numOfBatchInsertReqs;
2414
  int64_t numOfBatchInsertSuccessReqs;
2415
  int64_t errors;
2416
} SVnodesStat;
2417

2418
typedef struct {
2419
  int32_t vgId;
2420
  int8_t  syncState;
2421
  int8_t  syncRestore;
2422
  int64_t syncTerm;
2423
  int64_t roleTimeMs;
2424
  int64_t startTimeMs;
2425
  int8_t  syncCanRead;
2426
  int64_t cacheUsage;
2427
  int64_t numOfTables;
2428
  int64_t numOfTimeSeries;
2429
  int64_t totalStorage;
2430
  int64_t compStorage;
2431
  int64_t pointsWritten;
2432
  int64_t numOfSelectReqs;
2433
  int64_t numOfInsertReqs;
2434
  int64_t numOfInsertSuccessReqs;
2435
  int64_t numOfBatchInsertReqs;
2436
  int64_t numOfBatchInsertSuccessReqs;
2437
  int32_t numOfCachedTables;
2438
  int32_t learnerProgress;  // use one reservered
2439
  int64_t syncAppliedIndex;
2440
  int64_t syncCommitIndex;
2441
  int64_t bufferSegmentUsed;
2442
  int64_t bufferSegmentSize;
2443
} SVnodeLoad;
2444

2445
typedef struct {
2446
  int64_t total_requests;
2447
  int64_t total_rows;
2448
  int64_t total_bytes;
2449
  double  write_size;
2450
  double  cache_hit_ratio;
2451
  int64_t rpc_queue_wait;
2452
  int64_t preprocess_time;
2453

2454
  int64_t memory_table_size;
2455
  int64_t commit_count;
2456
  int64_t merge_count;
2457
  double  commit_time;
2458
  double  merge_time;
2459
  int64_t block_commit_time;
2460
  int64_t memtable_wait_time;
2461
} SVnodeMetrics;
2462

2463
typedef struct {
2464
  int32_t     vgId;
2465
  int64_t     numOfTables;
2466
  int64_t     memSize;
2467
  int64_t     l1Size;
2468
  int64_t     l2Size;
2469
  int64_t     l3Size;
2470
  int64_t     cacheSize;
2471
  int64_t     walSize;
2472
  int64_t     metaSize;
2473
  int64_t     rawDataSize;
2474
  int64_t     ssSize;
2475
  const char* dbname;
2476
  int8_t      estimateRawData;
2477
} SDbSizeStatisInfo;
2478

2479
typedef struct {
2480
  int32_t vgId;
2481
  int64_t nTimeSeries;
2482
} SVnodeLoadLite;
2483

2484
typedef struct {
2485
  int8_t  syncState;
2486
  int64_t syncTerm;
2487
  int8_t  syncRestore;
2488
  int64_t roleTimeMs;
2489
} SMnodeLoad;
2490

2491
typedef struct {
2492
  int32_t dnodeId;
2493
  int64_t numOfProcessedQuery;
2494
  int64_t numOfProcessedCQuery;
2495
  int64_t numOfProcessedFetch;
2496
  int64_t numOfProcessedDrop;
2497
  int64_t numOfProcessedNotify;
2498
  int64_t numOfProcessedHb;
2499
  int64_t numOfProcessedDelete;
2500
  int64_t cacheDataSize;
2501
  int64_t numOfQueryInQueue;
2502
  int64_t numOfFetchInQueue;
2503
  int64_t timeInQueryQueue;
2504
  int64_t timeInFetchQueue;
2505
} SQnodeLoad;
2506

2507
typedef struct {
2508
  int32_t     sver;      // software version
2509
  int64_t     dnodeVer;  // dnode table version in sdb
2510
  int32_t     dnodeId;
2511
  int64_t     clusterId;
2512
  int64_t     rebootTime;
2513
  int64_t     updateTime;
2514
  float       numOfCores;
2515
  int32_t     numOfSupportVnodes;
2516
  int32_t     numOfDiskCfg;
2517
  int64_t     memTotal;
2518
  int64_t     memAvail;
2519
  char        dnodeEp[TSDB_EP_LEN];
2520
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2521
  SMnodeLoad  mload;
2522
  SQnodeLoad  qload;
2523
  SClusterCfg clusterCfg;
2524
  SArray*     pVloads;  // array of SVnodeLoad
2525
  int32_t     statusSeq;
2526
  int64_t     ipWhiteVer;
2527
  int64_t     timeWhiteVer;
2528
  int64_t     analVer;
2529
  int64_t     timestamp;
2530
  char        auditDB[TSDB_DB_FNAME_LEN];
2531
  char        auditToken[AUDIT_TOKEN_LEN];
2532
} SStatusReq;
2533

2534
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2535
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2536
void    tFreeSStatusReq(SStatusReq* pReq);
2537

2538
typedef struct {
2539
  int32_t forceReadConfig;
2540
  int32_t cver;
2541
  SArray* array;
2542
} SConfigReq;
2543

2544
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2545
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2546
void    tFreeSConfigReq(SConfigReq* pReq);
2547

2548
typedef struct {
2549
  int32_t dnodeId;
2550
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2551
} SDnodeInfoReq;
2552

2553
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2554
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2555

2556
typedef enum {
2557
  MONITOR_TYPE_COUNTER = 0,
2558
  MONITOR_TYPE_SLOW_LOG = 1,
2559
} MONITOR_TYPE;
2560

2561
typedef struct {
2562
  int32_t      contLen;
2563
  char*        pCont;
2564
  MONITOR_TYPE type;
2565
} SStatisReq;
2566

2567
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2568
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2569
void    tFreeSStatisReq(SStatisReq* pReq);
2570

2571
typedef struct {
2572
  char    db[TSDB_DB_FNAME_LEN];
2573
  char    table[TSDB_TABLE_NAME_LEN];
2574
  char    operation[AUDIT_OPERATION_LEN];
2575
  int32_t sqlLen;
2576
  char*   pSql;
2577
  double  duration;
2578
  int64_t affectedRows;
2579
} SAuditReq;
2580
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2581
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2582
void    tFreeSAuditReq(SAuditReq* pReq);
2583

2584
typedef struct {
2585
  SArray* auditArr;
2586
} SBatchAuditReq;
2587
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2588
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2589
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2590

2591
typedef struct {
2592
  int32_t dnodeId;
2593
  int64_t clusterId;
2594
  SArray* pVloads;
2595
} SNotifyReq;
2596

2597
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2598
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2599
void    tFreeSNotifyReq(SNotifyReq* pReq);
2600

2601
typedef struct {
2602
  int32_t dnodeId;
2603
  int64_t clusterId;
2604
} SDnodeCfg;
2605

2606
typedef struct {
2607
  int32_t id;
2608
  int8_t  isMnode;
2609
  SEp     ep;
2610
} SDnodeEp;
2611

2612
typedef struct {
2613
  int32_t id;
2614
  int8_t  isMnode;
2615
  int8_t  offlineReason;
2616
  SEp     ep;
2617
  char    active[TSDB_ACTIVE_KEY_LEN];
2618
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2619
} SDnodeInfo;
2620

2621
typedef struct {
2622
  int64_t   dnodeVer;
2623
  SDnodeCfg dnodeCfg;
2624
  SArray*   pDnodeEps;  // Array of SDnodeEp
2625
  int32_t   statusSeq;
2626
  int64_t   ipWhiteVer;
2627
  int64_t   analVer;
2628
  int64_t   timeWhiteVer;
2629
  char      auditDB[TSDB_DB_FNAME_LEN];
2630
  char      auditToken[AUDIT_TOKEN_LEN];
2631
} SStatusRsp;
2632

2633
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2634
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2635
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2636

2637
typedef struct {
2638
  int32_t forceReadConfig;
2639
  int32_t isConifgVerified;
2640
  int32_t isVersionVerified;
2641
  int32_t cver;
2642
  SArray* array;
2643
} SConfigRsp;
2644

2645
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2646
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2647
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2648

2649
typedef struct {
2650
  int32_t reserved;
2651
} SMTimerReq;
2652

2653
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2654
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2655

2656
typedef struct SOrphanTask {
2657
  int64_t streamId;
2658
  int32_t taskId;
2659
  int32_t nodeId;
2660
} SOrphanTask;
2661

2662
typedef struct SMStreamDropOrphanMsg {
2663
  SArray* pList;  // SArray<SOrphanTask>
2664
} SMStreamDropOrphanMsg;
2665

2666
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2667
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2668
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2669

2670
typedef struct {
2671
  int32_t  id;
2672
  uint16_t port;                 // node sync Port
2673
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2674
} SReplica;
2675

2676
typedef struct {
2677
  int32_t  vgId;
2678
  char     db[TSDB_DB_FNAME_LEN];
2679
  int64_t  dbUid;
2680
  int32_t  vgVersion;
2681
  int32_t  numOfStables;
2682
  int32_t  buffer;
2683
  int32_t  pageSize;
2684
  int32_t  pages;
2685
  int32_t  cacheLastSize;
2686
  int32_t  daysPerFile;
2687
  int32_t  daysToKeep0;
2688
  int32_t  daysToKeep1;
2689
  int32_t  daysToKeep2;
2690
  int32_t  keepTimeOffset;
2691
  int32_t  minRows;
2692
  int32_t  maxRows;
2693
  int32_t  walFsyncPeriod;
2694
  uint32_t hashBegin;
2695
  uint32_t hashEnd;
2696
  int8_t   hashMethod;
2697
  int8_t   walLevel;
2698
  int8_t   precision;
2699
  int8_t   compression;
2700
  int8_t   strict;
2701
  int8_t   cacheLast;
2702
  int8_t   isTsma;
2703
  int8_t   replica;
2704
  int8_t   selfIndex;
2705
  SReplica replicas[TSDB_MAX_REPLICA];
2706
  int32_t  numOfRetensions;
2707
  SArray*  pRetensions;  // SRetention
2708
  void*    pTsma;
2709
  int32_t  walRetentionPeriod;
2710
  int64_t  walRetentionSize;
2711
  int32_t  walRollPeriod;
2712
  int64_t  walSegmentSize;
2713
  int16_t  sstTrigger;
2714
  int16_t  hashPrefix;
2715
  int16_t  hashSuffix;
2716
  int32_t  tsdbPageSize;
2717
  int32_t  ssChunkSize;
2718
  int32_t  ssKeepLocal;
2719
  int8_t   ssCompact;
2720
  int64_t  reserved[6];
2721
  int8_t   learnerReplica;
2722
  int8_t   learnerSelfIndex;
2723
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2724
  int32_t  changeVersion;
2725
  int8_t   encryptAlgorithm;
2726
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2727
} SCreateVnodeReq;
2728

2729
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2730
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2731
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2732

2733
typedef struct {
2734
  union {
2735
    int32_t compactId;
2736
    int32_t id;
2737
  };
2738
  int32_t vgId;
2739
  int32_t dnodeId;
2740
} SQueryCompactProgressReq;
2741

2742
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2743
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2744

2745
typedef struct {
2746
  union {
2747
    int32_t compactId;
2748
    int32_t id;
2749
  };
2750
  int32_t vgId;
2751
  int32_t dnodeId;
2752
  int32_t numberFileset;
2753
  int32_t finished;
2754
  int32_t progress;
2755
  int64_t remainingTime;
2756
} SQueryCompactProgressRsp;
2757

2758
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2759
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2760

2761
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2762
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2763

2764
typedef struct {
2765
  int32_t vgId;
2766
  int32_t dnodeId;
2767
  int64_t dbUid;
2768
  char    db[TSDB_DB_FNAME_LEN];
2769
  int64_t reserved[8];
2770
} SDropVnodeReq;
2771

2772
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2773
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2774

2775
typedef struct {
2776
  char    colName[TSDB_COL_NAME_LEN];
2777
  char    stb[TSDB_TABLE_FNAME_LEN];
2778
  int64_t stbUid;
2779
  int64_t dbUid;
2780
  int64_t reserved[8];
2781
} SDropIndexReq;
2782

2783
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2784
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2785

2786
typedef struct {
2787
  int64_t dbUid;
2788
  char    db[TSDB_DB_FNAME_LEN];
2789
  union {
2790
    int64_t compactStartTime;
2791
    int64_t startTime;
2792
  };
2793

2794
  STimeWindow tw;
2795
  union {
2796
    int32_t compactId;
2797
    int32_t id;
2798
  };
2799
  int8_t metaOnly;
2800
  union {
2801
    uint16_t flags;
2802
    struct {
2803
      uint16_t optrType : 3;     // ETsdbOpType
2804
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2805
      uint16_t reserved : 12;
2806
    };
2807
  };
2808
  int8_t force;  // force compact
2809
} SCompactVnodeReq;
2810

2811
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2812
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2813

2814
typedef struct {
2815
  union {
2816
    int32_t compactId;
2817
    int32_t taskId;
2818
  };
2819
  int32_t vgId;
2820
  int32_t dnodeId;
2821
} SVKillCompactReq;
2822

2823
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2824
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2825

2826
typedef SVKillCompactReq SVKillRetentionReq;
2827

2828
typedef struct {
2829
  char        db[TSDB_DB_FNAME_LEN];
2830
  int32_t     maxSpeed;
2831
  int32_t     sqlLen;
2832
  char*       sql;
2833
  SArray*     vgroupIds;
2834
  STimeWindow tw;  // unit is second
2835
  union {
2836
    uint32_t flags;
2837
    struct {
2838
      uint32_t optrType : 3;     // ETsdbOpType
2839
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2840
      uint32_t reserved : 28;
2841
    };
2842
  };
2843
} STrimDbReq;
2844

2845
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2846
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2847
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2848

2849
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2850

2851
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2852
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2853

2854
typedef struct {
2855
  int32_t vgVersion;
2856
  int32_t buffer;
2857
  int32_t pageSize;
2858
  int32_t pages;
2859
  int32_t cacheLastSize;
2860
  int32_t daysPerFile;
2861
  int32_t daysToKeep0;
2862
  int32_t daysToKeep1;
2863
  int32_t daysToKeep2;
2864
  int32_t keepTimeOffset;
2865
  int32_t walFsyncPeriod;
2866
  int8_t  walLevel;
2867
  int8_t  strict;
2868
  int8_t  cacheLast;
2869
  int64_t reserved[7];
2870
  // 1st modification
2871
  int16_t sttTrigger;
2872
  int32_t minRows;
2873
  // 2nd modification
2874
  int32_t walRetentionPeriod;
2875
  int32_t walRetentionSize;
2876
  int32_t ssKeepLocal;
2877
  int8_t  ssCompact;
2878
} SAlterVnodeConfigReq;
2879

2880
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2881
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2882

2883
typedef struct {
2884
  int32_t  vgId;
2885
  int8_t   strict;
2886
  int8_t   selfIndex;
2887
  int8_t   replica;
2888
  SReplica replicas[TSDB_MAX_REPLICA];
2889
  int64_t  reserved[8];
2890
  int8_t   learnerSelfIndex;
2891
  int8_t   learnerReplica;
2892
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2893
  int32_t  changeVersion;
2894
  int32_t  electBaseLine;
2895
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2896

2897
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2898
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2899

2900
typedef struct {
2901
  int32_t vgId;
2902
  int8_t  disable;
2903
} SDisableVnodeWriteReq;
2904

2905
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2906
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2907

2908
typedef struct {
2909
  int32_t  srcVgId;
2910
  int32_t  dstVgId;
2911
  uint32_t hashBegin;
2912
  uint32_t hashEnd;
2913
  int32_t  changeVersion;
2914
  int32_t  reserved;
2915
} SAlterVnodeHashRangeReq;
2916

2917
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2918
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2919

2920
#define REQ_OPT_TBNAME 0x0
2921
#define REQ_OPT_TBUID  0x01
2922
typedef struct {
2923
  SMsgHead header;
2924
  char     dbFName[TSDB_DB_FNAME_LEN];
2925
  char     tbName[TSDB_TABLE_NAME_LEN];
2926
  uint8_t  option;
2927
  uint8_t  autoCreateCtb;
2928
} STableInfoReq;
2929

2930
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2931
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2932

2933
typedef struct {
2934
  int8_t  metaClone;  // create local clone of the cached table meta
2935
  int32_t numOfVgroups;
2936
  int32_t numOfTables;
2937
  int32_t numOfUdfs;
2938
  char    tableNames[];
2939
} SMultiTableInfoReq;
2940

2941
// todo refactor
2942
typedef struct SVgroupInfo {
2943
  int32_t  vgId;
2944
  uint32_t hashBegin;
2945
  uint32_t hashEnd;
2946
  SEpSet   epSet;
2947
  union {
2948
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2949
    int32_t taskId;      // used in stream
2950
  };
2951
} SVgroupInfo;
2952

2953
typedef struct {
2954
  int32_t     numOfVgroups;
2955
  SVgroupInfo vgroups[];
2956
} SVgroupsInfo;
2957

2958
typedef struct {
2959
  STableMetaRsp* pMeta;
2960
} SMAlterStbRsp;
2961

2962
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2963
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2964
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2965

2966
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2967
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2968
void    tFreeSTableMetaRsp(void* pRsp);
2969
void    tFreeSTableIndexRsp(void* info);
2970

2971
typedef struct {
2972
  SArray* pMetaRsp;   // Array of STableMetaRsp
2973
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2974
} SSTbHbRsp;
2975

2976
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2977
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2978
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2979

2980
typedef struct {
2981
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2982
} SViewHbRsp;
2983

2984
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2985
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2986
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2987

2988
typedef struct {
2989
  int32_t numOfTables;
2990
  int32_t numOfVgroup;
2991
  int32_t numOfUdf;
2992
  int32_t contLen;
2993
  int8_t  compressed;  // denote if compressed or not
2994
  int32_t rawLen;      // size before compress
2995
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2996
  char    meta[];
2997
} SMultiTableMeta;
2998

2999
typedef struct {
3000
  int32_t dataLen;
3001
  char    name[TSDB_TABLE_FNAME_LEN];
3002
  char*   data;
3003
} STagData;
3004

3005
typedef struct {
3006
  int32_t  opType;
3007
  uint32_t valLen;
3008
  char*    val;
3009
} SShowVariablesReq;
3010

3011
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3012
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3013
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3014

3015
typedef struct {
3016
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3017
  char value[TSDB_CONFIG_PATH_LEN + 1];
3018
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3019
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3020
  char info[TSDB_CONFIG_INFO_LEN + 1];
3021
} SVariablesInfo;
3022

3023
typedef struct {
3024
  SArray* variables;  // SArray<SVariablesInfo>
3025
} SShowVariablesRsp;
3026

3027
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3028
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3029

3030
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3031

3032
/*
3033
 * sql: show tables like '%a_%'
3034
 * payload is the query condition, e.g., '%a_%'
3035
 * payloadLen is the length of payload
3036
 */
3037
typedef struct {
3038
  int32_t type;
3039
  char    db[TSDB_DB_FNAME_LEN];
3040
  int32_t payloadLen;
3041
  char*   payload;
3042
} SShowReq;
3043

3044
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3045
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3046
void tFreeSShowReq(SShowReq* pReq);
3047

3048
typedef struct {
3049
  int64_t       showId;
3050
  STableMetaRsp tableMeta;
3051
} SShowRsp, SVShowTablesRsp;
3052

3053
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3054
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3055
// void    tFreeSShowRsp(SShowRsp* pRsp);
3056

3057
typedef struct {
3058
  char    db[TSDB_DB_FNAME_LEN];
3059
  char    tb[TSDB_TABLE_NAME_LEN];
3060
  char    user[TSDB_USER_LEN];
3061
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3062
  int64_t showId;
3063
  int64_t compactId;  // for compact
3064
  bool    withFull;   // for show users full
3065
} SRetrieveTableReq;
3066

3067
typedef struct SSysTableSchema {
3068
  int8_t   type;
3069
  col_id_t colId;
3070
  int32_t  bytes;
3071
} SSysTableSchema;
3072

3073
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3074
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3075

3076
#define RETRIEVE_TABLE_RSP_VERSION         0
3077
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3078
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3079

3080
typedef struct {
3081
  int64_t useconds;
3082
  int8_t  completed;  // all results are returned to client
3083
  int8_t  precision;
3084
  int8_t  compressed;
3085
  int8_t  streamBlockType;
3086
  int32_t payloadLen;
3087
  int32_t compLen;
3088
  int32_t numOfBlocks;
3089
  int64_t numOfRows;  // from int32_t change to int64_t
3090
  int64_t numOfCols;
3091
  int64_t skey;
3092
  int64_t ekey;
3093
  int64_t version;                         // for stream
3094
  TSKEY   watermark;                       // for stream
3095
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3096
  char    data[];
3097
} SRetrieveTableRsp;
3098

3099
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3100

3101
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3102
  do {                                          \
3103
    ((int32_t*)(_p))[0] = (_compLen);           \
3104
    ((int32_t*)(_p))[1] = (_fullLen);           \
3105
  } while (0);
3106

3107
typedef struct {
3108
  int64_t version;
3109
  int64_t numOfRows;
3110
  int8_t  compressed;
3111
  int8_t  precision;
3112
  char    data[];
3113
} SRetrieveTableRspForTmq;
3114

3115
typedef struct {
3116
  int64_t handle;
3117
  int64_t useconds;
3118
  int8_t  completed;  // all results are returned to client
3119
  int8_t  precision;
3120
  int8_t  compressed;
3121
  int32_t compLen;
3122
  int32_t numOfRows;
3123
  int32_t fullLen;
3124
  char    data[];
3125
} SRetrieveMetaTableRsp;
3126

3127
typedef struct SExplainExecInfo {
3128
  double   startupCost;
3129
  double   totalCost;
3130
  uint64_t numOfRows;
3131
  uint32_t verboseLen;
3132
  void*    verboseInfo;
3133
} SExplainExecInfo;
3134

3135
typedef struct {
3136
  int32_t           numOfPlans;
3137
  SExplainExecInfo* subplanInfo;
3138
} SExplainRsp;
3139

3140
typedef struct {
3141
  SExplainRsp rsp;
3142
  uint64_t    qId;
3143
  uint64_t    cId;
3144
  uint64_t    tId;
3145
  int64_t     rId;
3146
  int32_t     eId;
3147
} SExplainLocalRsp;
3148

3149
typedef struct STableScanAnalyzeInfo {
3150
  uint64_t totalRows;
3151
  uint64_t totalCheckedRows;
3152
  uint32_t totalBlocks;
3153
  uint32_t loadBlocks;
3154
  uint32_t loadBlockStatis;
3155
  uint32_t skipBlocks;
3156
  uint32_t filterOutBlocks;
3157
  double   elapsedTime;
3158
  double   filterTime;
3159
} STableScanAnalyzeInfo;
3160

3161
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3162
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3163
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3164

3165
typedef struct {
3166
  char    config[TSDB_DNODE_CONFIG_LEN];
3167
  char    value[TSDB_CLUSTER_VALUE_LEN];
3168
  int32_t sqlLen;
3169
  char*   sql;
3170
} SMCfgClusterReq;
3171

3172
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3173
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3174
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3175

3176
typedef struct {
3177
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3178
  int32_t port;
3179
  int32_t sqlLen;
3180
  char*   sql;
3181
} SCreateDnodeReq;
3182

3183
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3184
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3185
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3186

3187
typedef struct {
3188
  int32_t dnodeId;
3189
  char    fqdn[TSDB_FQDN_LEN];
3190
  int32_t port;
3191
  int8_t  force;
3192
  int8_t  unsafe;
3193
  int32_t sqlLen;
3194
  char*   sql;
3195
} SDropDnodeReq;
3196

3197
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3198
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3199
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3200

3201
enum {
3202
  RESTORE_TYPE__ALL = 1,
3203
  RESTORE_TYPE__MNODE,
3204
  RESTORE_TYPE__VNODE,
3205
  RESTORE_TYPE__QNODE,
3206
};
3207

3208
typedef struct {
3209
  int32_t dnodeId;
3210
  int8_t  restoreType;
3211
  int32_t sqlLen;
3212
  char*   sql;
3213
} SRestoreDnodeReq;
3214

3215
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3216
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3217
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3218

3219
typedef struct {
3220
  int32_t dnodeId;
3221
  char    config[TSDB_DNODE_CONFIG_LEN];
3222
  char    value[TSDB_DNODE_VALUE_LEN];
3223
  int32_t sqlLen;
3224
  char*   sql;
3225
} SMCfgDnodeReq;
3226

3227
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3228
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3229
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3230

3231
typedef struct {
3232
  char    config[TSDB_DNODE_CONFIG_LEN];
3233
  char    value[TSDB_DNODE_VALUE_LEN];
3234
  int32_t version;
3235
} SDCfgDnodeReq;
3236

3237
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3238
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3239

3240
typedef struct {
3241
  int32_t dnodeId;
3242
  int32_t sqlLen;
3243
  char*   sql;
3244
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3245
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3246

3247
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3248
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3249

3250
typedef struct {
3251
  int32_t nodeId;
3252
  SEpSet  epSet;
3253
} SNodeEpSet;
3254

3255
typedef struct {
3256
  int32_t    snodeId;
3257
  SNodeEpSet leaders[2];
3258
  SNodeEpSet replica;
3259
  int32_t    sqlLen;
3260
  char*      sql;
3261
} SDCreateSnodeReq;
3262

3263
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3264
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3265
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3266

3267
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3268
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3269
typedef struct {
3270
  int8_t   replica;
3271
  SReplica replicas[TSDB_MAX_REPLICA];
3272
  int8_t   learnerReplica;
3273
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3274
  int64_t  lastIndex;
3275
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3276

3277
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3278
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3279

3280
typedef struct {
3281
  int32_t urlLen;
3282
  int32_t sqlLen;
3283
  char*   url;
3284
  char*   sql;
3285
} SMCreateAnodeReq;
3286

3287
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3288
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3289
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3290

3291
typedef struct {
3292
  int32_t anodeId;
3293
  int32_t sqlLen;
3294
  char*   sql;
3295
} SMDropAnodeReq, SMUpdateAnodeReq;
3296

3297
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3298
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3299
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3300
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3301
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3302
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3303

3304
typedef struct {
3305
  int32_t dnodeId;
3306
  int32_t bnodeProto;
3307
  int32_t sqlLen;
3308
  char*   sql;
3309
} SMCreateBnodeReq, SDCreateBnodeReq;
3310

3311
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3312
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3313
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3314

3315
typedef struct {
3316
  int32_t dnodeId;
3317
  int32_t sqlLen;
3318
  char*   sql;
3319
} SMDropBnodeReq, SDDropBnodeReq;
3320

3321
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3322
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3323
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3324

3325
typedef struct {
3326
  int32_t vgId;
3327
  int32_t hbSeq;
3328
} SVArbHbReqMember;
3329

3330
typedef struct {
3331
  int32_t dnodeId;
3332
  char*   arbToken;
3333
  int64_t arbTerm;
3334
  SArray* hbMembers;  // SVArbHbReqMember
3335
} SVArbHeartBeatReq;
3336

3337
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3338
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3339
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3340

3341
typedef struct {
3342
  int32_t vgId;
3343
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3344
  int32_t hbSeq;
3345
} SVArbHbRspMember;
3346

3347
typedef struct {
3348
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3349
  int32_t dnodeId;
3350
  SArray* hbMembers;  // SVArbHbRspMember
3351
} SVArbHeartBeatRsp;
3352

3353
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3354
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3355
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3356

3357
typedef struct {
3358
  char*   arbToken;
3359
  int64_t arbTerm;
3360
  char*   member0Token;
3361
  char*   member1Token;
3362
} SVArbCheckSyncReq;
3363

3364
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3365
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3366
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3367

3368
typedef struct {
3369
  char*   arbToken;
3370
  char*   member0Token;
3371
  char*   member1Token;
3372
  int32_t vgId;
3373
  int32_t errCode;
3374
} SVArbCheckSyncRsp;
3375

3376
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3377
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3378
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3379

3380
typedef struct {
3381
  char*   arbToken;
3382
  int64_t arbTerm;
3383
  char*   memberToken;
3384
  int8_t  force;
3385
} SVArbSetAssignedLeaderReq;
3386

3387
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3388
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3389
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3390

3391
typedef struct {
3392
  char*   arbToken;
3393
  char*   memberToken;
3394
  int32_t vgId;
3395
} SVArbSetAssignedLeaderRsp;
3396

3397
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3398
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3399
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3400

3401
typedef struct {
3402
  int32_t dnodeId;
3403
  char*   token;
3404
} SMArbUpdateGroupMember;
3405

3406
typedef struct {
3407
  int32_t dnodeId;
3408
  char*   token;
3409
  int8_t  acked;
3410
} SMArbUpdateGroupAssigned;
3411

3412
typedef struct {
3413
  int32_t                  vgId;
3414
  int64_t                  dbUid;
3415
  SMArbUpdateGroupMember   members[2];
3416
  int8_t                   isSync;
3417
  int8_t                   assignedAcked;
3418
  SMArbUpdateGroupAssigned assignedLeader;
3419
  int64_t                  version;
3420
  int32_t                  code;
3421
  int64_t                  updateTimeMs;
3422
} SMArbUpdateGroup;
3423

3424
typedef struct {
3425
  SArray* updateArray;  // SMArbUpdateGroup
3426
} SMArbUpdateGroupBatchReq;
3427

3428
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3429
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3430
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3431

3432
typedef struct {
3433
  char queryStrId[TSDB_QUERY_ID_LEN];
3434
} SKillQueryReq;
3435

3436
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3437
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3438

3439
typedef struct {
3440
  uint32_t connId;
3441
} SKillConnReq;
3442

3443
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3444
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3445

3446
typedef struct {
3447
  int32_t transId;
3448
} SKillTransReq;
3449

3450
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3451
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3452

3453
typedef struct {
3454
  int32_t useless;  // useless
3455
  int32_t sqlLen;
3456
  char*   sql;
3457
} SBalanceVgroupReq;
3458

3459
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3460
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3461
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3462

3463
typedef struct {
3464
  int32_t useless;  // useless
3465
  int32_t sqlLen;
3466
  char*   sql;
3467
} SAssignLeaderReq;
3468

3469
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3470
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3471
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3472
typedef struct {
3473
  int32_t vgId1;
3474
  int32_t vgId2;
3475
} SMergeVgroupReq;
3476

3477
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3478
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3479

3480
typedef struct {
3481
  int32_t vgId;
3482
  int32_t dnodeId1;
3483
  int32_t dnodeId2;
3484
  int32_t dnodeId3;
3485
  int32_t sqlLen;
3486
  char*   sql;
3487
} SRedistributeVgroupReq;
3488

3489
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3490
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3491
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3492

3493
typedef struct {
3494
  int32_t reserved;
3495
  int32_t vgId;
3496
  int32_t sqlLen;
3497
  char*   sql;
3498
  char    db[TSDB_DB_FNAME_LEN];
3499
} SBalanceVgroupLeaderReq;
3500

3501
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3502
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3503
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3504

3505
typedef struct {
3506
  int32_t vgId;
3507
} SForceBecomeFollowerReq;
3508

3509
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3510
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3511

3512
typedef struct {
3513
  int32_t vgId;
3514
  bool    force;
3515
} SSplitVgroupReq;
3516

3517
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3518
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3519

3520
typedef struct {
3521
  char user[TSDB_USER_LEN];
3522
  char spi;
3523
  char encrypt;
3524
  char secret[TSDB_PASSWORD_LEN];
3525
  char ckey[TSDB_PASSWORD_LEN];
3526
} SAuthReq, SAuthRsp;
3527

3528
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3529
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3530

3531
typedef struct {
3532
  int32_t statusCode;
3533
  char    details[1024];
3534
} SServerStatusRsp;
3535

3536
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3537
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3538

3539
/**
3540
 * The layout of the query message payload is as following:
3541
 * +--------------------+---------------------------------+
3542
 * |Sql statement       | Physical plan                   |
3543
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3544
 * +--------------------+---------------------------------+
3545
 */
3546
typedef struct SSubQueryMsg {
3547
  SMsgHead header;
3548
  uint64_t sId;
3549
  uint64_t queryId;
3550
  uint64_t clientId;
3551
  uint64_t taskId;
3552
  int64_t  refId;
3553
  int32_t  execId;
3554
  int32_t  msgMask;
3555
  int8_t   taskType;
3556
  int8_t   explain;
3557
  int8_t   needFetch;
3558
  int8_t   compress;
3559
  uint32_t sqlLen;
3560
  char*    sql;
3561
  uint32_t msgLen;
3562
  char*    msg;
3563
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
3564
} SSubQueryMsg;
3565

3566
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3567
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3568
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3569

3570
typedef struct {
3571
  SMsgHead header;
3572
  uint64_t sId;
3573
  uint64_t queryId;
3574
  uint64_t taskId;
3575
} SSinkDataReq;
3576

3577
typedef struct {
3578
  SMsgHead header;
3579
  uint64_t sId;
3580
  uint64_t queryId;
3581
  uint64_t clientId;
3582
  uint64_t taskId;
3583
  int32_t  execId;
3584
} SQueryContinueReq;
3585

3586
typedef struct {
3587
  SMsgHead header;
3588
  uint64_t sId;
3589
  uint64_t queryId;
3590
  uint64_t taskId;
3591
} SResReadyReq;
3592

3593
typedef struct {
3594
  int32_t code;
3595
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3596
  int32_t sversion;
3597
  int32_t tversion;
3598
} SResReadyRsp;
3599

3600
typedef struct SOperatorParam {
3601
  int32_t opType;
3602
  int32_t downstreamIdx;
3603
  void*   value;
3604
  SArray* pChildren;  // SArray<SOperatorParam*>
3605
  bool    reUse;
3606
} SOperatorParam;
3607

3608
typedef struct SColIdNameKV {
3609
  col_id_t colId;
3610
  char     colName[TSDB_COL_NAME_LEN];
3611
} SColIdNameKV;
3612

3613
typedef struct SColIdPair {
3614
  col_id_t  vtbColId;
3615
  col_id_t  orgColId;
3616
  SDataType type;
3617
} SColIdPair;
3618

3619
typedef struct SColIdSlotIdPair {
3620
  int32_t  vtbSlotId;
3621
  col_id_t orgColId;
3622
} SColIdSlotIdPair;
3623

3624
typedef struct SOrgTbInfo {
3625
  int32_t vgId;
3626
  char    tbName[TSDB_TABLE_FNAME_LEN];
3627
  SArray* colMap;  // SArray<SColIdNameKV>
3628
} SOrgTbInfo;
3629

3630
void destroySOrgTbInfo(void *info);
3631

3632
typedef enum {
3633
  DYN_TYPE_STB_JOIN = 1,
3634
  DYN_TYPE_VSTB_SINGLE_SCAN,
3635
  DYN_TYPE_VSTB_BATCH_SCAN,
3636
} ETableScanDynType;
3637

3638
typedef struct STableScanOperatorParam {
3639
  bool              tableSeq;
3640
  bool              isNewParam;
3641
  uint64_t          groupid;
3642
  SArray*           pUidList;
3643
  SOrgTbInfo*       pOrgTbInfo;
3644
  SArray*           pBatchTbInfo;  // SArray<SOrgTbInfo>
3645
  SArray*           pTagList;
3646
  STimeWindow       window;
3647
  ETableScanDynType type;
3648
} STableScanOperatorParam;
3649

3650
typedef struct STagScanOperatorParam {
3651
  tb_uid_t vcUid;
3652
} STagScanOperatorParam;
3653

3654
typedef struct SVTableScanOperatorParam {
3655
  uint64_t        uid;
3656
  STimeWindow     window;
3657
  SOperatorParam* pTagScanOp;
3658
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3659
} SVTableScanOperatorParam;
3660

3661
typedef struct SMergeOperatorParam {
3662
  int32_t         winNum;
3663
} SMergeOperatorParam;
3664

3665
typedef struct SAggOperatorParam {
3666
  bool            needCleanRes;
3667
} SAggOperatorParam;
3668

3669
typedef struct SExternalWindowOperatorParam {
3670
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3671
} SExternalWindowOperatorParam;
3672

3673
typedef struct SDynQueryCtrlOperatorParam {
3674
  STimeWindow    window;
3675
} SDynQueryCtrlOperatorParam;
3676

3677
struct SStreamRuntimeFuncInfo;
3678
typedef struct {
3679
  SMsgHead        header;
3680
  uint64_t        sId;
3681
  uint64_t        queryId;
3682
  uint64_t        clientId;
3683
  uint64_t        taskId;
3684
  int32_t         execId;
3685
  SOperatorParam* pOpParam;
3686

3687
  // used for new-stream
3688
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3689
  bool                           reset;
3690
  bool                           dynTbname;
3691
  // used for new-stream
3692
} SResFetchReq;
3693

3694
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3695
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3696
void    tDestroySResFetchReq(SResFetchReq* pReq);
3697
typedef struct {
3698
  SMsgHead header;
3699
  uint64_t clientId;
3700
} SSchTasksStatusReq;
3701

3702
typedef struct {
3703
  uint64_t queryId;
3704
  uint64_t clientId;
3705
  uint64_t taskId;
3706
  int64_t  refId;
3707
  int32_t  subJobId;
3708
  int32_t  execId;
3709
  int8_t   status;
3710
} STaskStatus;
3711

3712
typedef struct {
3713
  int64_t refId;
3714
  SArray* taskStatus;  // SArray<STaskStatus>
3715
} SSchedulerStatusRsp;
3716

3717
typedef struct {
3718
  uint64_t queryId;
3719
  uint64_t taskId;
3720
  int8_t   action;
3721
} STaskAction;
3722

3723
typedef struct SQueryNodeEpId {
3724
  int32_t nodeId;  // vgId or qnodeId
3725
  SEp     ep;
3726
} SQueryNodeEpId;
3727

3728
typedef struct {
3729
  SMsgHead       header;
3730
  uint64_t       clientId;
3731
  SQueryNodeEpId epId;
3732
  SArray*        taskAction;  // SArray<STaskAction>
3733
} SSchedulerHbReq;
3734

3735
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3736
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3737
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3738

3739
typedef struct {
3740
  SQueryNodeEpId epId;
3741
  SArray*        taskStatus;  // SArray<STaskStatus>
3742
} SSchedulerHbRsp;
3743

3744
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3745
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3746
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3747

3748
typedef struct {
3749
  SMsgHead header;
3750
  uint64_t sId;
3751
  uint64_t queryId;
3752
  uint64_t clientId;
3753
  uint64_t taskId;
3754
  int64_t  refId;
3755
  int32_t  execId;
3756
} STaskCancelReq;
3757

3758
typedef struct {
3759
  int32_t code;
3760
} STaskCancelRsp;
3761

3762
typedef struct {
3763
  SMsgHead header;
3764
  uint64_t sId;
3765
  uint64_t queryId;
3766
  uint64_t clientId;
3767
  uint64_t taskId;
3768
  int64_t  refId;
3769
  int32_t  execId;
3770
} STaskDropReq;
3771

3772
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3773
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3774

3775
typedef enum {
3776
  TASK_NOTIFY_FINISHED = 1,
3777
} ETaskNotifyType;
3778

3779
typedef struct {
3780
  SMsgHead        header;
3781
  uint64_t        sId;
3782
  uint64_t        queryId;
3783
  uint64_t        clientId;
3784
  uint64_t        taskId;
3785
  int64_t         refId;
3786
  int32_t         execId;
3787
  ETaskNotifyType type;
3788
} STaskNotifyReq;
3789

3790
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3791
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3792

3793
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3794
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3795

3796
typedef struct {
3797
  int32_t code;
3798
} STaskDropRsp;
3799

3800
#define STREAM_TRIGGER_AT_ONCE                 1
3801
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3802
#define STREAM_TRIGGER_MAX_DELAY               3
3803
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3804
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3805

3806
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3807
#define STREAM_FILL_HISTORY_ON        1
3808
#define STREAM_FILL_HISTORY_OFF       0
3809
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3810
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3811
#define STREAM_CREATE_STABLE_TRUE     1
3812
#define STREAM_CREATE_STABLE_FALSE    0
3813

3814
typedef struct SVgroupVer {
3815
  int32_t vgId;
3816
  int64_t ver;
3817
} SVgroupVer;
3818

3819
typedef struct STaskNotifyEventStat {
3820
  int64_t notifyEventAddTimes;     // call times of add function
3821
  int64_t notifyEventAddElems;     // elements added by add function
3822
  double  notifyEventAddCostSec;   // time cost of add function
3823
  int64_t notifyEventPushTimes;    // call times of push function
3824
  int64_t notifyEventPushElems;    // elements pushed by push function
3825
  double  notifyEventPushCostSec;  // time cost of push function
3826
  int64_t notifyEventPackTimes;    // call times of pack function
3827
  int64_t notifyEventPackElems;    // elements packed by pack function
3828
  double  notifyEventPackCostSec;  // time cost of pack function
3829
  int64_t notifyEventSendTimes;    // call times of send function
3830
  int64_t notifyEventSendElems;    // elements sent by send function
3831
  double  notifyEventSendCostSec;  // time cost of send function
3832
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3833
} STaskNotifyEventStat;
3834

3835
enum {
3836
  TOPIC_SUB_TYPE__DB = 1,
3837
  TOPIC_SUB_TYPE__TABLE,
3838
  TOPIC_SUB_TYPE__COLUMN,
3839
};
3840

3841
#define DEFAULT_MAX_POLL_INTERVAL  300000
3842
#define DEFAULT_SESSION_TIMEOUT    12000
3843
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3844
#define DEFAULT_MIN_POLL_ROWS      4096
3845

3846
typedef struct {
3847
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3848
  int8_t igExists;
3849
  int8_t subType;
3850
  int8_t withMeta;
3851
  char*  sql;
3852
  char   subDbName[TSDB_DB_FNAME_LEN];
3853
  char*  ast;
3854
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3855
  int8_t reload;
3856
} SCMCreateTopicReq;
3857

3858
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3859
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3860
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3861

3862
typedef struct {
3863
  int64_t consumerId;
3864
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3865

3866
typedef struct {
3867
  int64_t consumerId;
3868
  char    cgroup[TSDB_CGROUP_LEN];
3869
  char    clientId[TSDB_CLIENT_ID_LEN];
3870
  char    user[TSDB_USER_LEN];
3871
  char    fqdn[TSDB_FQDN_LEN];
3872
  SArray* topicNames;  // SArray<char**>
3873

3874
  int8_t  withTbName;
3875
  int8_t  autoCommit;
3876
  int32_t autoCommitInterval;
3877
  int8_t  resetOffsetCfg;
3878
  int8_t  enableReplay;
3879
  int8_t  enableBatchMeta;
3880
  int32_t sessionTimeoutMs;
3881
  int32_t maxPollIntervalMs;
3882
} SCMSubscribeReq;
3883

3884
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3885
  int32_t tlen = 0;
292,924✔
3886
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
292,924✔
3887
  tlen += taosEncodeString(buf, pReq->cgroup);
292,924✔
3888
  tlen += taosEncodeString(buf, pReq->clientId);
292,924✔
3889

3890
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
292,924✔
3891
  tlen += taosEncodeFixedI32(buf, topicNum);
292,924✔
3892

3893
  for (int32_t i = 0; i < topicNum; i++) {
406,494✔
3894
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
227,140✔
3895
  }
3896

3897
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
292,924✔
3898
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
292,924✔
3899
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
292,924✔
3900
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
292,924✔
3901
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
292,924✔
3902
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
292,924✔
3903
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
292,924✔
3904
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
292,924✔
3905
  tlen += taosEncodeString(buf, pReq->user);
292,924✔
3906
  tlen += taosEncodeString(buf, pReq->fqdn);
292,924✔
3907

3908
  return tlen;
292,924✔
3909
}
3910

3911
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3912
  void* start = buf;
128,945✔
3913
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
128,945✔
3914
  buf = taosDecodeStringTo(buf, pReq->cgroup);
128,945✔
3915
  buf = taosDecodeStringTo(buf, pReq->clientId);
128,945✔
3916

3917
  int32_t topicNum = 0;
128,945✔
3918
  buf = taosDecodeFixedI32(buf, &topicNum);
128,945✔
3919

3920
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
128,945✔
3921
  if (pReq->topicNames == NULL) {
128,945✔
UNCOV
3922
    return terrno;
×
3923
  }
3924
  for (int32_t i = 0; i < topicNum; i++) {
183,653✔
3925
    char* name = NULL;
54,708✔
3926
    buf = taosDecodeString(buf, &name);
54,708✔
3927
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
109,416✔
3928
      return terrno;
×
3929
    }
3930
  }
3931

3932
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
128,945✔
3933
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
128,945✔
3934
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
128,945✔
3935
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
128,945✔
3936
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
128,945✔
3937
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
128,945✔
3938
  if ((char*)buf - (char*)start < len) {
128,945✔
3939
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
128,945✔
3940
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
128,945✔
3941
    buf = taosDecodeStringTo(buf, pReq->user);
128,945✔
3942
    buf = taosDecodeStringTo(buf, pReq->fqdn);
257,890✔
3943
  } else {
3944
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
3945
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3946
  }
3947

3948
  return 0;
128,945✔
3949
}
3950

3951
typedef struct {
3952
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3953
  SArray* removedConsumers;  // SArray<int64_t>
3954
  SArray* newConsumers;      // SArray<int64_t>
3955
} SMqRebInfo;
3956

3957
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3958
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
95,808✔
3959
  if (pRebInfo == NULL) {
95,808✔
3960
    return NULL;
×
3961
  }
3962
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
95,808✔
3963
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
95,808✔
3964
  if (pRebInfo->removedConsumers == NULL) {
95,808✔
UNCOV
3965
    goto _err;
×
3966
  }
3967
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
95,808✔
3968
  if (pRebInfo->newConsumers == NULL) {
95,808✔
UNCOV
3969
    goto _err;
×
3970
  }
3971
  return pRebInfo;
95,808✔
UNCOV
3972
_err:
×
UNCOV
3973
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
3974
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3975
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
3976
  return NULL;
×
3977
}
3978

3979
typedef struct {
3980
  int64_t streamId;
3981
  int64_t checkpointId;
3982
  char    streamName[TSDB_STREAM_FNAME_LEN];
3983
} SMStreamDoCheckpointMsg;
3984

3985
typedef struct {
3986
  int64_t status;
3987
} SMVSubscribeRsp;
3988

3989
typedef struct {
3990
  char    name[TSDB_TOPIC_FNAME_LEN];
3991
  int8_t  igNotExists;
3992
  int32_t sqlLen;
3993
  char*   sql;
3994
  int8_t  force;
3995
} SMDropTopicReq;
3996

3997
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3998
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3999
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4000

4001
typedef struct {
4002
  char    name[TSDB_TOPIC_FNAME_LEN];
4003
  int8_t  igNotExists;
4004
  int32_t sqlLen;
4005
  char*   sql;
4006
} SMReloadTopicReq;
4007

4008
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4009
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4010
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4011

4012
typedef struct {
4013
  char   topic[TSDB_TOPIC_FNAME_LEN];
4014
  char   cgroup[TSDB_CGROUP_LEN];
4015
  int8_t igNotExists;
4016
  int8_t force;
4017
} SMDropCgroupReq;
4018

4019
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4020
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4021

4022
typedef struct {
4023
  int8_t reserved;
4024
} SMDropCgroupRsp;
4025

4026
typedef struct {
4027
  char    name[TSDB_TABLE_FNAME_LEN];
4028
  int8_t  alterType;
4029
  SSchema schema;
4030
} SAlterTopicReq;
4031

4032
typedef struct {
4033
  SMsgHead head;
4034
  char     name[TSDB_TABLE_FNAME_LEN];
4035
  int64_t  tuid;
4036
  int32_t  sverson;
4037
  int32_t  execLen;
4038
  char*    executor;
4039
  int32_t  sqlLen;
4040
  char*    sql;
4041
} SDCreateTopicReq;
4042

4043
typedef struct {
4044
  SMsgHead head;
4045
  char     name[TSDB_TABLE_FNAME_LEN];
4046
  int64_t  tuid;
4047
} SDDropTopicReq;
4048

4049
typedef struct {
4050
  char*      name;
4051
  int64_t    uid;
4052
  int64_t    interval[2];
4053
  int8_t     intervalUnit;
4054
  int16_t    nFuncs;
4055
  col_id_t*  funcColIds;  // column ids specified by user
4056
  func_id_t* funcIds;     // function ids specified by user
4057
} SRSmaParam;
4058

4059
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4060
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4061

4062
// TDMT_VND_CREATE_STB ==============
4063
typedef struct SVCreateStbReq {
4064
  char*           name;
4065
  tb_uid_t        suid;
4066
  int8_t          rollup;
4067
  SSchemaWrapper  schemaRow;
4068
  SSchemaWrapper  schemaTag;
4069
  SRSmaParam      rsmaParam;
4070
  int32_t         alterOriDataLen;
4071
  void*           alterOriData;
4072
  int8_t          source;
4073
  int8_t          colCmpred;
4074
  SColCmprWrapper colCmpr;
4075
  int64_t         keep;
4076
  SExtSchema*     pExtSchemas;
4077
  int8_t          virtualStb;
4078
} SVCreateStbReq;
4079

4080
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4081
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4082

4083
// TDMT_VND_DROP_STB ==============
4084
typedef struct SVDropStbReq {
4085
  char*    name;
4086
  tb_uid_t suid;
4087
} SVDropStbReq;
4088

4089
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4090
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4091

4092
// TDMT_VND_CREATE_TABLE ==============
4093
#define TD_CREATE_IF_NOT_EXISTS       0x1
4094
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4095
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4096
typedef struct SVCreateTbReq {
4097
  int32_t  flags;
4098
  char*    name;
4099
  tb_uid_t uid;
4100
  int64_t  btime;
4101
  int32_t  ttl;
4102
  int32_t  commentLen;
4103
  char*    comment;
4104
  int8_t   type;
4105
  union {
4106
    struct {
4107
      char*    stbName;  // super table name
4108
      uint8_t  tagNum;
4109
      tb_uid_t suid;
4110
      SArray*  tagName;
4111
      uint8_t* pTag;
4112
    } ctb;
4113
    struct {
4114
      SSchemaWrapper schemaRow;
4115
    } ntb;
4116
  };
4117
  int32_t         sqlLen;
4118
  char*           sql;
4119
  SColCmprWrapper colCmpr;
4120
  SExtSchema*     pExtSchemas;
4121
  SColRefWrapper  colRef;  // col reference for virtual table
4122
} SVCreateTbReq;
4123

4124
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4125
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4126
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4127
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4128

4129
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4130
  if (NULL == req) {
2,147,483,647✔
4131
    return;
2,147,483,647✔
4132
  }
4133

4134
  taosMemoryFreeClear(req->sql);
72,382,723✔
4135
  taosMemoryFreeClear(req->name);
72,387,239✔
4136
  taosMemoryFreeClear(req->comment);
72,412,384✔
4137
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
72,383,907✔
4138
    taosMemoryFreeClear(req->ctb.pTag);
56,429,995✔
4139
    taosMemoryFreeClear(req->ctb.stbName);
56,436,697✔
4140
    taosArrayDestroy(req->ctb.tagName);
56,417,149✔
4141
    req->ctb.tagName = NULL;
56,374,546✔
4142
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
15,969,688✔
4143
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,969,688✔
4144
  }
4145
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
72,358,185✔
4146
  taosMemoryFreeClear(req->pExtSchemas);
72,390,520✔
4147
  taosMemoryFreeClear(req->colRef.pColRef);
72,369,898✔
4148
}
4149

4150
typedef struct {
4151
  int32_t nReqs;
4152
  union {
4153
    SVCreateTbReq* pReqs;
4154
    SArray*        pArray;
4155
  };
4156
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4157
} SVCreateTbBatchReq;
4158

4159
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4160
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4161
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4162

4163
typedef struct {
4164
  int32_t        code;
4165
  STableMetaRsp* pMeta;
4166
} SVCreateTbRsp, SVUpdateTbRsp;
4167

4168
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4169
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4170
void tFreeSVCreateTbRsp(void* param);
4171

4172
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4173
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4174

4175
typedef struct {
4176
  int32_t nRsps;
4177
  union {
4178
    SVCreateTbRsp* pRsps;
4179
    SArray*        pArray;
4180
  };
4181
} SVCreateTbBatchRsp;
4182

4183
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4184
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4185

4186
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4187
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4188

4189
// TDMT_VND_DROP_TABLE =================
4190
typedef struct {
4191
  char*    name;
4192
  uint64_t suid;  // for tmq in wal format
4193
  int64_t  uid;
4194
  int8_t   igNotExists;
4195
  int8_t   isVirtual;
4196
} SVDropTbReq;
4197

4198
typedef struct {
4199
  int32_t code;
4200
} SVDropTbRsp;
4201

4202
typedef struct {
4203
  int32_t nReqs;
4204
  union {
4205
    SVDropTbReq* pReqs;
4206
    SArray*      pArray;
4207
  };
4208
} SVDropTbBatchReq;
4209

4210
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4211
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4212

4213
typedef struct {
4214
  int32_t nRsps;
4215
  union {
4216
    SVDropTbRsp* pRsps;
4217
    SArray*      pArray;
4218
  };
4219
} SVDropTbBatchRsp;
4220

4221
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4222
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4223

4224
// TDMT_VND_ALTER_TABLE =====================
4225
typedef struct SMultiTagUpateVal {
4226
  char*    tagName;
4227
  int32_t  colId;
4228
  int8_t   tagType;
4229
  int8_t   tagFree;
4230
  uint32_t nTagVal;
4231
  uint8_t* pTagVal;
4232
  int8_t   isNull;
4233
  SArray*  pTagArray;
4234
} SMultiTagUpateVal;
4235
typedef struct SVAlterTbReq {
4236
  char*   tbName;
4237
  int8_t  action;
4238
  char*   colName;
4239
  int32_t colId;
4240
  // TSDB_ALTER_TABLE_ADD_COLUMN
4241
  int8_t  type;
4242
  int8_t  flags;
4243
  int32_t bytes;
4244
  // TSDB_ALTER_TABLE_DROP_COLUMN
4245
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4246
  int8_t   colModType;
4247
  int32_t  colModBytes;
4248
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4249
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4250
  int8_t   isNull;
4251
  int8_t   tagType;
4252
  int8_t   tagFree;
4253
  uint32_t nTagVal;
4254
  uint8_t* pTagVal;
4255
  SArray*  pTagArray;
4256
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4257
  int8_t   updateTTL;
4258
  int32_t  newTTL;
4259
  int32_t  newCommentLen;
4260
  char*    newComment;
4261
  int64_t  ctimeMs;    // fill by vnode
4262
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4263
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4264
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4265
  // for Add column
4266
  STypeMod typeMod;
4267
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4268
  char* refDbName;
4269
  char* refTbName;
4270
  char* refColName;
4271
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4272
} SVAlterTbReq;
4273

4274
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4275
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4276
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4277
void    tfreeMultiTagUpateVal(void* pMultiTag);
4278

4279
typedef struct {
4280
  int32_t        code;
4281
  STableMetaRsp* pMeta;
4282
} SVAlterTbRsp;
4283

4284
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4285
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4286
// ======================
4287

4288
typedef struct {
4289
  SMsgHead head;
4290
  int64_t  uid;
4291
  int32_t  tid;
4292
  int16_t  tversion;
4293
  int16_t  colId;
4294
  int8_t   type;
4295
  int16_t  bytes;
4296
  int32_t  tagValLen;
4297
  int16_t  numOfTags;
4298
  int32_t  schemaLen;
4299
  char     data[];
4300
} SUpdateTagValReq;
4301

4302
typedef struct {
4303
  SMsgHead head;
4304
} SUpdateTagValRsp;
4305

4306
typedef struct {
4307
  SMsgHead head;
4308
} SVShowTablesReq;
4309

4310
typedef struct {
4311
  SMsgHead head;
4312
  int32_t  id;
4313
} SVShowTablesFetchReq;
4314

4315
typedef struct {
4316
  int64_t useconds;
4317
  int8_t  completed;  // all results are returned to client
4318
  int8_t  precision;
4319
  int8_t  compressed;
4320
  int32_t compLen;
4321
  int32_t numOfRows;
4322
  char    data[];
4323
} SVShowTablesFetchRsp;
4324

4325
typedef struct {
4326
  int64_t consumerId;
4327
  int32_t epoch;
4328
  char    cgroup[TSDB_CGROUP_LEN];
4329
} SMqAskEpReq;
4330

4331
typedef struct {
4332
  int32_t key;
4333
  int32_t valueLen;
4334
  void*   value;
4335
} SKv;
4336

4337
typedef struct {
4338
  int64_t tscRid;
4339
  int8_t  connType;
4340
} SClientHbKey;
4341

4342
typedef struct {
4343
  int64_t tid;
4344
  char    status[TSDB_JOB_STATUS_LEN];
4345
} SQuerySubDesc;
4346

4347
typedef struct {
4348
  char     sql[TSDB_SHOW_SQL_LEN];
4349
  uint64_t queryId;
4350
  int64_t  useconds;
4351
  int64_t  stime;  // timestamp precision ms
4352
  int64_t  reqRid;
4353
  bool     stableQuery;
4354
  bool     isSubQuery;
4355
  char     fqdn[TSDB_FQDN_LEN];
4356
  int32_t  subPlanNum;
4357
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4358
} SQueryDesc;
4359

4360
typedef struct {
4361
  uint32_t connId;
4362
  SArray*  queryDesc;  // SArray<SQueryDesc>
4363
} SQueryHbReqBasic;
4364

4365
typedef struct {
4366
  uint32_t connId;
4367
  uint64_t killRid;
4368
  int32_t  totalDnodes;
4369
  int32_t  onlineDnodes;
4370
  int8_t   killConnection;
4371
  int8_t   align[3];
4372
  SEpSet   epSet;
4373
  SArray*  pQnodeList;
4374
} SQueryHbRspBasic;
4375

4376
typedef struct SAppClusterSummary {
4377
  uint64_t numOfInsertsReq;
4378
  uint64_t numOfInsertRows;
4379
  uint64_t insertElapsedTime;
4380
  uint64_t insertBytes;  // submit to tsdb since launched.
4381

4382
  uint64_t fetchBytes;
4383
  uint64_t numOfQueryReq;
4384
  uint64_t queryElapsedTime;
4385
  uint64_t numOfSlowQueries;
4386
  uint64_t totalRequests;
4387
  uint64_t currentRequests;  // the number of SRequestObj
4388
} SAppClusterSummary;
4389

4390
typedef struct {
4391
  int64_t            appId;
4392
  int32_t            pid;
4393
  char               name[TSDB_APP_NAME_LEN];
4394
  int64_t            startTime;
4395
  SAppClusterSummary summary;
4396
} SAppHbReq;
4397

4398
typedef struct {
4399
  SClientHbKey      connKey;
4400
  int64_t           clusterId;
4401
  SAppHbReq         app;
4402
  SQueryHbReqBasic* query;
4403
  SHashObj*         info;  // hash<Skv.key, Skv>
4404
  char              userApp[TSDB_APP_NAME_LEN];
4405
  uint32_t          userIp;
4406
  SIpRange          userDualIp;
4407
  char              sVer[TSDB_VERSION_LEN];
4408
  char              cInfo[CONNECTOR_INFO_LEN];
4409
} SClientHbReq;
4410

4411
typedef struct {
4412
  int64_t reqId;
4413
  SArray* reqs;  // SArray<SClientHbReq>
4414
  int64_t ipWhiteListVer;
4415
} SClientHbBatchReq;
4416

4417
typedef struct {
4418
  SClientHbKey      connKey;
4419
  int32_t           status;
4420
  SQueryHbRspBasic* query;
4421
  SArray*           info;  // Array<Skv>
4422
} SClientHbRsp;
4423

4424
typedef struct {
4425
  int64_t       reqId;
4426
  int64_t       rspId;
4427
  int32_t       svrTimestamp;
4428
  SArray*       rsps;  // SArray<SClientHbRsp>
4429
  SMonitorParas monitorParas;
4430
  int8_t        enableAuditDelete;
4431
  int8_t        enableStrongPass;
4432
  int8_t        enableAuditSelect;
4433
  int8_t        enableAuditInsert;
4434
  int8_t        auditLevel;
4435
} SClientHbBatchRsp;
4436

4437
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
63,450,761✔
4438

4439
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4440
  void* pIter = taosHashIterate(info, NULL);
43,688,670✔
4441
  while (pIter != NULL) {
98,552,965✔
4442
    SKv* kv = (SKv*)pIter;
54,863,952✔
4443
    taosMemoryFreeClear(kv->value);
54,863,952✔
4444
    pIter = taosHashIterate(info, pIter);
54,863,952✔
4445
  }
4446
}
43,689,013✔
4447

4448
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
26,399,810✔
4449
  SQueryDesc* desc = (SQueryDesc*)pDesc;
26,399,810✔
4450
  if (desc->subDesc) {
26,399,810✔
4451
    taosArrayDestroy(desc->subDesc);
20,277,321✔
4452
    desc->subDesc = NULL;
20,276,818✔
4453
  }
4454
}
26,400,418✔
4455

4456
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
50,607,975✔
4457
  SClientHbReq* req = (SClientHbReq*)pReq;
53,334,493✔
4458
  if (req->query) {
53,334,493✔
4459
    if (req->query->queryDesc) {
50,607,938✔
4460
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
23,910,589✔
4461
    }
4462
    taosMemoryFreeClear(req->query);
50,607,975✔
4463
  }
4464

4465
  if (req->info) {
53,334,751✔
4466
    tFreeReqKvHash(req->info);
43,689,013✔
4467
    taosHashCleanup(req->info);
43,689,013✔
4468
    req->info = NULL;
43,689,013✔
4469
  }
4470
}
27,471,286✔
4471

4472
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4473
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4474

4475
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4476
  if (pReq == NULL) return;
20,834,466✔
4477
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
20,834,466✔
4478
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
20,834,466✔
4479
  taosMemoryFree(pReq);
20,834,466✔
4480
}
4481

4482
static FORCE_INLINE void tFreeClientKv(void* pKv) {
19,733,134✔
4483
  SKv* kv = (SKv*)pKv;
19,733,134✔
4484
  if (kv) {
19,733,134✔
4485
    taosMemoryFreeClear(kv->value);
19,733,134✔
4486
  }
4487
}
19,733,134✔
4488

4489
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
50,410,567✔
4490
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
50,410,567✔
4491
  if (rsp->query) {
50,410,567✔
4492
    taosArrayDestroy(rsp->query->pQnodeList);
50,407,223✔
4493
    taosMemoryFreeClear(rsp->query);
50,405,764✔
4494
  }
4495
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
50,410,565✔
4496
}
25,667,120✔
4497

4498
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4499
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
40,353,012✔
4500
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
40,353,012✔
4501
}
40,354,847✔
4502

4503
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4504
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4505
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4506

4507
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4508
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
156,502,602✔
4509
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
156,502,544✔
4510
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
156,502,660✔
4511
  return 0;
78,251,388✔
4512
}
4513

4514
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4515
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
75,977,836✔
4516
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
75,977,909✔
4517
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
37,988,991✔
4518
  if (pKv->value == NULL) {
37,988,991✔
UNCOV
4519
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4520
  }
4521
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
37,988,991✔
4522
  return 0;
37,988,991✔
4523
}
4524

4525
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4526
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
209,280,833✔
4527
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
209,278,541✔
4528
  return 0;
104,640,096✔
4529
}
4530

4531
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4532
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
104,236,277✔
4533
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
104,237,118✔
4534
  return 0;
52,120,227✔
4535
}
4536

4537
typedef struct {
4538
  int32_t vgId;
4539
  // TODO stas
4540
} SMqReportVgInfo;
4541

4542
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4543
  int32_t tlen = 0;
4544
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4545
  return tlen;
4546
}
4547

4548
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4549
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4550
  return buf;
4551
}
4552

4553
typedef struct {
4554
  int32_t epoch;
4555
  int64_t topicUid;
4556
  char    name[TSDB_TOPIC_FNAME_LEN];
4557
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4558
} SMqTopicInfo;
4559

4560
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4561
  int32_t tlen = 0;
4562
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4563
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4564
  tlen += taosEncodeString(buf, pTopicInfo->name);
4565
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4566
  tlen += taosEncodeFixedI32(buf, sz);
4567
  for (int32_t i = 0; i < sz; i++) {
4568
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4569
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4570
  }
4571
  return tlen;
4572
}
4573

4574
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4575
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4576
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4577
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4578
  int32_t sz;
4579
  buf = taosDecodeFixedI32(buf, &sz);
4580
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4581
    return NULL;
4582
  }
4583
  for (int32_t i = 0; i < sz; i++) {
4584
    SMqReportVgInfo vgInfo;
4585
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4586
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4587
      return NULL;
4588
    }
4589
  }
4590
  return buf;
4591
}
4592

4593
typedef struct {
4594
  int32_t status;  // ask hb endpoint
4595
  int32_t epoch;
4596
  int64_t consumerId;
4597
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4598
} SMqReportReq;
4599

4600
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4601
  int32_t tlen = 0;
4602
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4603
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4604
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4605
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4606
  tlen += taosEncodeFixedI32(buf, sz);
4607
  for (int32_t i = 0; i < sz; i++) {
4608
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4609
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4610
  }
4611
  return tlen;
4612
}
4613

4614
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4615
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4616
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4617
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4618
  int32_t sz;
4619
  buf = taosDecodeFixedI32(buf, &sz);
4620
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4621
    return NULL;
4622
  }
4623
  for (int32_t i = 0; i < sz; i++) {
4624
    SMqTopicInfo topicInfo;
4625
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4626
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4627
      return NULL;
4628
    }
4629
  }
4630
  return buf;
4631
}
4632

4633
typedef struct {
4634
  SMsgHead head;
4635
  int64_t  leftForVer;
4636
  int32_t  vgId;
4637
  int64_t  consumerId;
4638
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4639
} SMqVDeleteReq;
4640

4641
typedef struct {
4642
  int8_t reserved;
4643
} SMqVDeleteRsp;
4644

4645
typedef struct {
4646
  char*  name;
4647
  int8_t igNotExists;
4648
} SMDropStreamReq;
4649

4650
typedef struct {
4651
  int8_t reserved;
4652
} SMDropStreamRsp;
4653

4654
typedef struct {
4655
  SMsgHead head;
4656
  int64_t  resetRelHalt;  // reset related stream task halt status
4657
  int64_t  streamId;
4658
  int32_t  taskId;
4659
} SVDropStreamTaskReq;
4660

4661
typedef struct {
4662
  int8_t reserved;
4663
} SVDropStreamTaskRsp;
4664

4665
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4666
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4667
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4668

4669
typedef struct {
4670
  char*  name;
4671
  int8_t igNotExists;
4672
} SMPauseStreamReq;
4673

4674
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4675
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4676
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4677

4678
typedef struct {
4679
  char*  name;
4680
  int8_t igNotExists;
4681
  int8_t igUntreated;
4682
} SMResumeStreamReq;
4683

4684
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4685
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4686
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4687

4688
typedef struct {
4689
  char*       name;
4690
  int8_t      calcAll;
4691
  STimeWindow timeRange;
4692
} SMRecalcStreamReq;
4693

4694
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4695
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4696
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4697

4698
typedef struct SVndSetKeepVersionReq {
4699
  int64_t keepVersion;
4700
} SVndSetKeepVersionReq;
4701

4702
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4703
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4704

4705
typedef struct SVUpdateCheckpointInfoReq {
4706
  SMsgHead head;
4707
  int64_t  streamId;
4708
  int32_t  taskId;
4709
  int64_t  checkpointId;
4710
  int64_t  checkpointVer;
4711
  int64_t  checkpointTs;
4712
  int32_t  transId;
4713
  int64_t  hStreamId;  // add encode/decode
4714
  int64_t  hTaskId;
4715
  int8_t   dropRelHTask;
4716
} SVUpdateCheckpointInfoReq;
4717

4718
typedef struct {
4719
  int64_t leftForVer;
4720
  int32_t vgId;
4721
  int64_t oldConsumerId;
4722
  int64_t newConsumerId;
4723
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4724
  int8_t  subType;
4725
  int8_t  withMeta;
4726
  char*   qmsg;  // SubPlanToString
4727
  SSchemaWrapper schema;
4728
  int64_t suid;
4729
} SMqRebVgReq;
4730

4731
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4732
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4733

4734
// tqOffset
4735
enum {
4736
  TMQ_OFFSET__RESET_NONE = -3,
4737
  TMQ_OFFSET__RESET_EARLIEST = -2,
4738
  TMQ_OFFSET__RESET_LATEST = -1,
4739
  TMQ_OFFSET__LOG = 1,
4740
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4741
  TMQ_OFFSET__SNAPSHOT_META = 3,
4742
};
4743

4744
enum {
4745
  WITH_DATA = 0,
4746
  WITH_META = 1,
4747
  ONLY_META = 2,
4748
};
4749

4750
#define TQ_OFFSET_VERSION 1
4751

4752
typedef struct {
4753
  int8_t type;
4754
  union {
4755
    // snapshot
4756
    struct {
4757
      int64_t uid;
4758
      int64_t ts;
4759
      SValue  primaryKey;
4760
    };
4761
    // log
4762
    struct {
4763
      int64_t version;
4764
    };
4765
  };
4766
} STqOffsetVal;
4767

4768
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4769
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,697,770✔
4770
  pOffsetVal->uid = uid;
1,697,809✔
4771
  pOffsetVal->ts = ts;
1,697,764✔
4772
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,697,706✔
4773
    taosMemoryFree(pOffsetVal->primaryKey.pData);
71✔
4774
  }
4775
  pOffsetVal->primaryKey = primaryKey;
1,697,536✔
4776
}
1,697,474✔
4777

4778
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4779
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
7,476✔
4780
  pOffsetVal->uid = uid;
7,476✔
4781
}
7,542✔
4782

4783
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4784
  pOffsetVal->type = TMQ_OFFSET__LOG;
45,742,295✔
4785
  pOffsetVal->version = ver;
45,742,212✔
4786
}
45,741,721✔
4787

4788
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4789
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4790
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4791
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4792
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4793
void    tOffsetDestroy(void* pVal);
4794

4795
typedef struct {
4796
  STqOffsetVal val;
4797
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4798
} STqOffset;
4799

4800
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4801
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4802
void    tDeleteSTqOffset(void* val);
4803

4804
typedef struct SMqVgOffset {
4805
  int64_t   consumerId;
4806
  STqOffset offset;
4807
} SMqVgOffset;
4808

4809
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4810
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4811

4812
typedef struct {
4813
  char    name[TSDB_TABLE_FNAME_LEN];
4814
  char    stb[TSDB_TABLE_FNAME_LEN];
4815
  int8_t  igExists;
4816
  int8_t  intervalUnit;
4817
  int8_t  slidingUnit;
4818
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4819
  int32_t dstVgId;   // for stream
4820
  int64_t interval;
4821
  int64_t offset;
4822
  int64_t sliding;
4823
  int64_t maxDelay;
4824
  int64_t watermark;
4825
  int32_t exprLen;        // strlen + 1
4826
  int32_t tagsFilterLen;  // strlen + 1
4827
  int32_t sqlLen;         // strlen + 1
4828
  int32_t astLen;         // strlen + 1
4829
  char*   expr;
4830
  char*   tagsFilter;
4831
  char*   sql;
4832
  char*   ast;
4833
  int64_t deleteMark;
4834
  int64_t lastTs;
4835
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4836
  SArray* pVgroupVerList;
4837
  int8_t  recursiveTsma;
4838
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4839
  char*   createStreamReq;
4840
  int32_t streamReqLen;
4841
  char*   dropStreamReq;
4842
  int32_t dropStreamReqLen;
4843
  int64_t uid;
4844
} SMCreateSmaReq;
4845

4846
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4847
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4848
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4849

4850
typedef struct {
4851
  char    name[TSDB_TABLE_FNAME_LEN];
4852
  int8_t  igNotExists;
4853
  char*   dropStreamReq;
4854
  int32_t dropStreamReqLen;
4855
} SMDropSmaReq;
4856

4857
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4858
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4859
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
4860

4861
typedef struct {
4862
  char name[TSDB_TABLE_NAME_LEN];
4863
  union {
4864
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4865
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4866
  };
4867
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4868
  union {
4869
    int8_t igExists;   // used by mnode
4870
    int8_t alterType;  // used by vnode
4871
  };
4872
  int8_t     intervalUnit;
4873
  int16_t    nFuncs;       // number of functions specified by user
4874
  col_id_t*  funcColIds;   // column ids specified by user
4875
  func_id_t* funcIds;      // function ids specified by user
4876
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4877
  int64_t    tbUid;
4878
  int64_t    uid;     // rsma uid
4879
  int32_t    sqlLen;  // strlen + 1
4880
  char*      sql;
4881
} SMCreateRsmaReq;
4882

4883
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4884
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4885
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4886

4887
typedef SMCreateRsmaReq SVCreateRsmaReq;
4888

4889
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4890
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4891
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4892

4893
typedef SMCreateRsmaReq SVAlterRsmaReq;
4894

4895
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4896
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4897
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4898

4899
typedef struct {
4900
  char       name[TSDB_TABLE_NAME_LEN];
4901
  int8_t     alterType;
4902
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4903
  int8_t     igNotExists;
4904
  int16_t    nFuncs;      // number of functions specified by user
4905
  col_id_t*  funcColIds;  // column ids specified by user
4906
  func_id_t* funcIds;     // function ids specified by user
4907
  int32_t    sqlLen;      // strlen + 1
4908
  char*      sql;
4909
} SMAlterRsmaReq;
4910

4911
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4912
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4913
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4914

4915
typedef struct {
4916
  int64_t    id;
4917
  char       name[TSDB_TABLE_NAME_LEN];
4918
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4919
  int32_t    code;
4920
  int32_t    version;
4921
  int8_t     tbType;
4922
  int8_t     intervalUnit;
4923
  col_id_t   nFuncs;
4924
  col_id_t   nColNames;
4925
  int64_t    interval[2];
4926
  col_id_t*  funcColIds;
4927
  func_id_t* funcIds;
4928
  SArray*    colNames;
4929
} SRsmaInfoRsp;
4930

4931
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4932
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4933
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4934

4935
typedef struct {
4936
  char   name[TSDB_TABLE_FNAME_LEN];
4937
  int8_t igNotExists;
4938
} SMDropRsmaReq;
4939

4940
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4941
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4942

4943
typedef struct {
4944
  char    name[TSDB_TABLE_NAME_LEN];
4945
  char    tbName[TSDB_TABLE_NAME_LEN];
4946
  int64_t uid;
4947
  int64_t tbUid;
4948
  int8_t  tbType;
4949
} SVDropRsmaReq;
4950

4951
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4952
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4953

4954
typedef struct {
4955
  char   dbFName[TSDB_DB_FNAME_LEN];
4956
  char   stbName[TSDB_TABLE_NAME_LEN];
4957
  char   colName[TSDB_COL_NAME_LEN];
4958
  char   idxName[TSDB_INDEX_FNAME_LEN];
4959
  int8_t idxType;
4960
} SCreateTagIndexReq;
4961

4962
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4963
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4964

4965
typedef SMDropSmaReq SDropTagIndexReq;
4966

4967
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4968
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4969

4970
typedef struct {
4971
  int8_t         version;       // for compatibility(default 0)
4972
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4973
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4974
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4975
  int32_t        dstVgId;
4976
  char           indexName[TSDB_INDEX_NAME_LEN];
4977
  int32_t        exprLen;
4978
  int32_t        tagsFilterLen;
4979
  int64_t        indexUid;
4980
  tb_uid_t       tableUid;  // super/child/common table uid
4981
  tb_uid_t       dstTbUid;  // for dstVgroup
4982
  int64_t        interval;
4983
  int64_t        offset;  // use unit by precision of DB
4984
  int64_t        sliding;
4985
  char*          dstTbName;  // for dstVgroup
4986
  char*          expr;       // sma expression
4987
  char*          tagsFilter;
4988
  SSchemaWrapper schemaRow;  // for dstVgroup
4989
  SSchemaWrapper schemaTag;  // for dstVgroup
4990
} STSma;                     // Time-range-wise SMA
4991

4992
typedef STSma SVCreateTSmaReq;
4993

4994
typedef struct {
4995
  int8_t  type;  // 0 status report, 1 update data
4996
  int64_t indexUid;
4997
  int64_t skey;  // start TS key of interval/sliding window
4998
} STSmaMsg;
4999

5000
typedef struct {
5001
  int64_t indexUid;
5002
  char    indexName[TSDB_INDEX_NAME_LEN];
5003
} SVDropTSmaReq;
5004

5005
typedef struct {
5006
  int tmp;  // TODO: to avoid compile error
5007
} SVCreateTSmaRsp, SVDropTSmaRsp;
5008

5009
#if 0
5010
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5011
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5012
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5013
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5014
#endif
5015

5016
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5017
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5018
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5019
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5020

5021
typedef struct {
5022
  int32_t number;
5023
  STSma*  tSma;
5024
} STSmaWrapper;
5025

5026
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5027
  if (pSma) {
×
UNCOV
5028
    taosMemoryFreeClear(pSma->dstTbName);
×
5029
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5030
    taosMemoryFreeClear(pSma->tagsFilter);
×
5031
  }
5032
}
×
5033

5034
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5035
  if (pSW) {
×
UNCOV
5036
    if (pSW->tSma) {
×
UNCOV
5037
      if (deepCopy) {
×
UNCOV
5038
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5039
          tDestroyTSma(pSW->tSma + i);
×
5040
        }
5041
      }
UNCOV
5042
      taosMemoryFreeClear(pSW->tSma);
×
5043
    }
5044
  }
5045
}
×
5046

5047
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5048
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5049
  taosMemoryFreeClear(pSW);
×
UNCOV
5050
  return NULL;
×
5051
}
5052

5053
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5054
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5055

5056
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5057
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5058

UNCOV
5059
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5060
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5061
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5062
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5063
  }
UNCOV
5064
  return 0;
×
5065
}
5066

UNCOV
5067
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5068
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5069
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5070
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5071
  }
UNCOV
5072
  return 0;
×
5073
}
5074

5075
typedef struct {
5076
  int idx;
5077
} SMCreateFullTextReq;
5078

5079
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5080
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5081
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5082

5083
typedef struct {
5084
  char   name[TSDB_TABLE_FNAME_LEN];
5085
  int8_t igNotExists;
5086
} SMDropFullTextReq;
5087

5088
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5089
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5090

5091
typedef struct {
5092
  char indexFName[TSDB_INDEX_FNAME_LEN];
5093
} SUserIndexReq;
5094

5095
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5096
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5097

5098
typedef struct {
5099
  char dbFName[TSDB_DB_FNAME_LEN];
5100
  char tblFName[TSDB_TABLE_FNAME_LEN];
5101
  char colName[TSDB_COL_NAME_LEN];
5102
  char indexType[TSDB_INDEX_TYPE_LEN];
5103
  char indexExts[TSDB_INDEX_EXTS_LEN];
5104
} SUserIndexRsp;
5105

5106
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5107
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5108

5109
typedef struct {
5110
  char tbFName[TSDB_TABLE_FNAME_LEN];
5111
} STableIndexReq;
5112

5113
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5114
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5115

5116
typedef struct {
5117
  int8_t  intervalUnit;
5118
  int8_t  slidingUnit;
5119
  int64_t interval;
5120
  int64_t offset;
5121
  int64_t sliding;
5122
  int64_t dstTbUid;
5123
  int32_t dstVgId;
5124
  SEpSet  epSet;
5125
  char*   expr;
5126
} STableIndexInfo;
5127

5128
typedef struct {
5129
  char     tbName[TSDB_TABLE_NAME_LEN];
5130
  char     dbFName[TSDB_DB_FNAME_LEN];
5131
  uint64_t suid;
5132
  int32_t  version;
5133
  int32_t  indexSize;
5134
  SArray*  pIndex;  // STableIndexInfo
5135
} STableIndexRsp;
5136

5137
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5138
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5139
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5140

5141
void tFreeSTableIndexInfo(void* pInfo);
5142

5143
typedef struct {
5144
  int8_t  mqMsgType;
5145
  int32_t code;
5146
  int32_t epoch;
5147
  int64_t consumerId;
5148
  int64_t walsver;
5149
  int64_t walever;
5150
} SMqRspHead;
5151

5152
typedef struct {
5153
  SMsgHead     head;
5154
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5155
  int8_t       withTbName;
5156
  int8_t       useSnapshot;
5157
  int32_t      epoch;
5158
  uint64_t     reqId;
5159
  int64_t      consumerId;
5160
  int64_t      timeout;
5161
  STqOffsetVal reqOffset;
5162
  int8_t       enableReplay;
5163
  int8_t       sourceExcluded;
5164
  int8_t       rawData;
5165
  int32_t      minPollRows;
5166
  int8_t       enableBatchMeta;
5167
  SHashObj*    uidHash;  // to find if uid is duplicated
5168
} SMqPollReq;
5169

5170
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5171
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5172
void    tDestroySMqPollReq(SMqPollReq* pReq);
5173

5174
typedef struct {
5175
  int32_t vgId;
5176
  int64_t offset;
5177
  SEpSet  epSet;
5178
} SMqSubVgEp;
5179

5180
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5181
  int32_t tlen = 0;
553,656✔
5182
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
553,656✔
5183
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
553,656✔
5184
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
553,656✔
5185
  return tlen;
553,656✔
5186
}
5187

5188
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5189
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
297,860✔
5190
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
297,860✔
5191
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
297,860✔
5192
  return buf;
297,860✔
5193
}
5194

5195
typedef struct {
5196
  char           topic[TSDB_TOPIC_FNAME_LEN];
5197
  char           db[TSDB_DB_FNAME_LEN];
5198
  SArray*        vgs;  // SArray<SMqSubVgEp>
5199
} SMqSubTopicEp;
5200

5201
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5202
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5203
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5204

5205
typedef struct {
5206
  SMqRspHead   head;
5207
  STqOffsetVal rspOffset;
5208
  int16_t      resMsgType;
5209
  int32_t      metaRspLen;
5210
  void*        metaRsp;
5211
} SMqMetaRsp;
5212

5213
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5214
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5215
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5216

5217
#define MQ_DATA_RSP_VERSION 100
5218

5219
typedef struct {
5220
  SMqRspHead   head;
5221
  STqOffsetVal rspOffset;
5222
  STqOffsetVal reqOffset;
5223
  int32_t      blockNum;
5224
  int8_t       withTbName;
5225
  int8_t       withSchema;
5226
  SArray*      blockDataLen;
5227
  SArray*      blockData;
5228
  SArray*      blockTbName;
5229
  SArray*      blockSchema;
5230

5231
  union {
5232
    struct {
5233
      int64_t sleepTime;
5234
    };
5235
    struct {
5236
      int32_t createTableNum;
5237
      SArray* createTableLen;
5238
      SArray* createTableReq;
5239
    };
5240
    struct {
5241
      int32_t len;
5242
      void*   rawData;
5243
    };
5244
  };
5245
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5246
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5247
} SMqDataRsp;
5248

5249
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5250
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5251
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5252
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5253
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5254

5255
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5256
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5257
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5258

5259
typedef struct SMqBatchMetaRsp {
5260
  SMqRspHead   head;  // not serialize
5261
  STqOffsetVal rspOffset;
5262
  SArray*      batchMetaLen;
5263
  SArray*      batchMetaReq;
5264
  void*        pMetaBuff;    // not serialize
5265
  uint32_t     metaBuffLen;  // not serialize
5266
} SMqBatchMetaRsp;
5267

5268
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5269
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5270
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5271
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5272

5273
typedef struct {
5274
  int32_t    code;
5275
  SArray*    topics;  // SArray<SMqSubTopicEp>
5276
} SMqAskEpRsp;
5277

5278
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5279
  int32_t tlen = 0;
1,987,188✔
5280
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5281
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,987,188✔
5282
  tlen += taosEncodeFixedI32(buf, sz);
1,986,974✔
5283
  for (int32_t i = 0; i < sz; i++) {
2,165,398✔
5284
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
178,210✔
5285
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
178,210✔
5286
  }
5287
  tlen += taosEncodeFixedI32(buf, pRsp->code);
1,987,188✔
5288

5289
  return tlen;
1,987,081✔
5290
}
5291

5292
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5293
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5294
  int32_t sz;
812,926✔
5295
  buf = taosDecodeFixedI32(buf, &sz);
896,912✔
5296
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
896,912✔
5297
  if (pRsp->topics == NULL) {
896,912✔
UNCOV
5298
    return NULL;
×
5299
  }
5300
  for (int32_t i = 0; i < sz; i++) {
1,003,251✔
5301
    SMqSubTopicEp topicEp;
90,670✔
5302
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
106,339✔
5303
    if (buf == NULL) {
106,339✔
UNCOV
5304
      return NULL;
×
5305
    }
5306
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
212,678✔
UNCOV
5307
      return NULL;
×
5308
    }
5309
  }
5310
  buf = taosDecodeFixedI32(buf, &pRsp->code);
896,912✔
5311

5312
  return buf;
896,912✔
5313
}
5314

5315
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5316
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
2,363,723✔
5317
}
2,363,616✔
5318

5319
typedef struct {
5320
  int32_t      vgId;
5321
  STqOffsetVal offset;
5322
  int64_t      rows;
5323
  int64_t      ever;
5324
} OffsetRows;
5325

5326
typedef struct {
5327
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5328
  SArray* offsetRows;
5329
} TopicOffsetRows;
5330

5331
typedef struct {
5332
  int64_t consumerId;
5333
  int32_t epoch;
5334
  SArray* topics;
5335
  int8_t  pollFlag;
5336
} SMqHbReq;
5337

5338
typedef struct {
5339
  char   topic[TSDB_TOPIC_FNAME_LEN];
5340
  int8_t noPrivilege;
5341
} STopicPrivilege;
5342

5343
typedef struct {
5344
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5345
  int32_t debugFlag;
5346
} SMqHbRsp;
5347

5348
typedef struct {
5349
  SMsgHead head;
5350
  int64_t  consumerId;
5351
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5352
} SMqSeekReq;
5353

5354
#define TD_AUTO_CREATE_TABLE 0x1
5355
typedef struct {
5356
  int64_t       suid;
5357
  int64_t       uid;
5358
  int32_t       sver;
5359
  uint32_t      nData;
5360
  uint8_t*      pData;
5361
  SVCreateTbReq cTbReq;
5362
} SVSubmitBlk;
5363

5364
typedef struct {
5365
  SMsgHead header;
5366
  uint64_t sId;
5367
  uint64_t queryId;
5368
  uint64_t clientId;
5369
  uint64_t taskId;
5370
  uint32_t sqlLen;
5371
  uint32_t phyLen;
5372
  char*    sql;
5373
  char*    msg;
5374
  int8_t   source;
5375
} SVDeleteReq;
5376

5377
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5378
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5379

5380
typedef struct {
5381
  int64_t affectedRows;
5382
} SVDeleteRsp;
5383

5384
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5385
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5386

5387
typedef struct SDeleteRes {
5388
  uint64_t suid;
5389
  SArray*  uidList;
5390
  int64_t  skey;
5391
  int64_t  ekey;
5392
  int64_t  affectedRows;
5393
  char     tableFName[TSDB_TABLE_NAME_LEN];
5394
  char     tsColName[TSDB_COL_NAME_LEN];
5395
  int64_t  ctimeMs;  // fill by vnode
5396
  int8_t   source;
5397
} SDeleteRes;
5398

5399
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5400
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5401

5402
typedef struct {
5403
  // int64_t uid;
5404
  char    tbname[TSDB_TABLE_NAME_LEN];
5405
  int64_t startTs;
5406
  int64_t endTs;
5407
} SSingleDeleteReq;
5408

5409
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5410
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5411

5412
typedef struct {
5413
  int64_t suid;
5414
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5415
  int64_t ctimeMs;     // fill by vnode
5416
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5417
} SBatchDeleteReq;
5418

5419
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5420
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5421
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5422

5423
typedef struct {
5424
  int32_t msgIdx;
5425
  int32_t msgType;
5426
  int32_t msgLen;
5427
  void*   msg;
5428
} SBatchMsg;
5429

5430
typedef struct {
5431
  SMsgHead header;
5432
  SArray*  pMsgs;  // SArray<SBatchMsg>
5433
} SBatchReq;
5434

5435
typedef struct {
5436
  int32_t reqType;
5437
  int32_t msgIdx;
5438
  int32_t msgLen;
5439
  int32_t rspCode;
5440
  void*   msg;
5441
} SBatchRspMsg;
5442

5443
typedef struct {
5444
  SArray* pRsps;  // SArray<SBatchRspMsg>
5445
} SBatchRsp;
5446

5447
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5448
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5449
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
90,544,085✔
5450
  if (NULL == msg) {
90,544,085✔
UNCOV
5451
    return;
×
5452
  }
5453
  SBatchMsg* pMsg = (SBatchMsg*)msg;
90,544,085✔
5454
  taosMemoryFree(pMsg->msg);
90,544,085✔
5455
}
5456

5457
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5458
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5459

5460
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
127,555,915✔
5461
  if (NULL == p) {
127,555,915✔
UNCOV
5462
    return;
×
5463
  }
5464

5465
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
127,555,915✔
5466
  taosMemoryFree(pRsp->msg);
127,555,915✔
5467
}
5468

5469
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5470
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5471
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5472
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5473
void    tDestroySMqHbReq(SMqHbReq* pReq);
5474

5475
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5476
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5477
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5478

5479
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5480
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5481

5482
#define TD_REQ_FROM_APP               0x0
5483
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5484
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5485
#define SUBMIT_REQ_FROM_FILE          0x4
5486
#define TD_REQ_FROM_TAOX              0x8
5487
#define TD_REQ_FROM_SML               0x10
5488
#define SUBMIT_REQUEST_VERSION        (2)
5489
#define SUBMIT_REQ_WITH_BLOB          0x10
5490
#define SUBMIT_REQ_SCHEMA_RES         0x20
5491
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5492

5493
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5494

5495
typedef struct {
5496
  int32_t        flags;
5497
  SVCreateTbReq* pCreateTbReq;
5498
  int64_t        suid;
5499
  int64_t        uid;
5500
  int32_t        sver;
5501
  union {
5502
    SArray* aRowP;
5503
    SArray* aCol;
5504
  };
5505
  int64_t   ctimeMs;
5506
  SBlobSet* pBlobSet;
5507
} SSubmitTbData;
5508

5509
typedef struct {
5510
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5511
  SArray* aSubmitBlobData;
5512
  bool    raw;
5513
} SSubmitReq2;
5514

5515
typedef struct {
5516
  SMsgHead header;
5517
  int64_t  version;
5518
  char     data[];  // SSubmitReq2
5519
} SSubmitReq2Msg;
5520

5521
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5522
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5523
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5524
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5525
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5526

5527
typedef struct {
5528
  int32_t affectedRows;
5529
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5530
} SSubmitRsp2;
5531

5532
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5533
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5534
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5535

5536
#define TSDB_MSG_FLG_ENCODE 0x1
5537
#define TSDB_MSG_FLG_DECODE 0x2
5538
#define TSDB_MSG_FLG_CMPT   0x3
5539

5540
typedef struct {
5541
  union {
5542
    struct {
5543
      void*   msgStr;
5544
      int32_t msgLen;
5545
      int64_t ver;
5546
    };
5547
    void* pDataBlock;
5548
  };
5549
} SPackedData;
5550

5551
typedef struct {
5552
  char     fullname[TSDB_VIEW_FNAME_LEN];
5553
  char     name[TSDB_VIEW_NAME_LEN];
5554
  char     dbFName[TSDB_DB_FNAME_LEN];
5555
  char*    querySql;
5556
  char*    sql;
5557
  int8_t   orReplace;
5558
  int8_t   precision;
5559
  int32_t  numOfCols;
5560
  SSchema* pSchema;
5561
} SCMCreateViewReq;
5562

5563
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5564
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5565
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5566

5567
typedef struct {
5568
  char   fullname[TSDB_VIEW_FNAME_LEN];
5569
  char   name[TSDB_VIEW_NAME_LEN];
5570
  char   dbFName[TSDB_DB_FNAME_LEN];
5571
  char*  sql;
5572
  int8_t igNotExists;
5573
} SCMDropViewReq;
5574

5575
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5576
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5577
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5578

5579
typedef struct {
5580
  char fullname[TSDB_VIEW_FNAME_LEN];
5581
} SViewMetaReq;
5582
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5583
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5584

5585
typedef struct {
5586
  char     name[TSDB_VIEW_NAME_LEN];
5587
  char     dbFName[TSDB_DB_FNAME_LEN];
5588
  char*    user;
5589
  uint64_t dbId;
5590
  uint64_t viewId;
5591
  char*    querySql;
5592
  int8_t   precision;
5593
  int8_t   type;
5594
  int32_t  version;
5595
  int32_t  numOfCols;
5596
  SSchema* pSchema;
5597
} SViewMetaRsp;
5598
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5599
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5600
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5601
typedef struct {
5602
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5603
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5604
} STableTSMAInfoReq;
5605

5606
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5607
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5608

5609
typedef struct {
5610
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5611
  union {
5612
    uint8_t flags;
5613
    struct {
5614
      uint8_t withColName : 1;
5615
      uint8_t reserved : 7;
5616
    };
5617
  };
5618

5619
} SRsmaInfoReq;
5620

5621
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5622
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5623

5624
typedef struct {
5625
  int32_t  funcId;
5626
  col_id_t colId;
5627
} STableTSMAFuncInfo;
5628

5629
typedef struct {
5630
  char     name[TSDB_TABLE_NAME_LEN];
5631
  uint64_t tsmaId;
5632
  char     targetTb[TSDB_TABLE_NAME_LEN];
5633
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5634
  char     tb[TSDB_TABLE_NAME_LEN];
5635
  char     dbFName[TSDB_DB_FNAME_LEN];
5636
  uint64_t suid;
5637
  uint64_t destTbUid;
5638
  uint64_t dbId;
5639
  int32_t  version;
5640
  int64_t  interval;
5641
  int8_t   unit;
5642
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5643
  SArray*  pTags;      // SArray<SSchema>
5644
  SArray*  pUsedCols;  // SArray<SSchema>
5645
  char*    ast;
5646

5647
  int64_t streamUid;
5648
  int64_t reqTs;
5649
  int64_t rspTs;
5650
  int64_t delayDuration;  // ms
5651
  bool    fillHistoryFinished;
5652

5653
  void* streamAddr;  // for stream task, the address of the stream task
5654
} STableTSMAInfo;
5655

5656
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5657
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5658
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5659
void    tFreeTableTSMAInfo(void* p);
5660
void    tFreeAndClearTableTSMAInfo(void* p);
5661
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5662

5663
#define STSMAHbRsp            STableTSMAInfoRsp
5664
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5665
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5666
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5667

5668
typedef struct SDropCtbWithTsmaSingleVgReq {
5669
  SVgroupInfo vgInfo;
5670
  SArray*     pTbs;  // SVDropTbReq
5671
} SMDropTbReqsOnSingleVg;
5672

5673
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5674
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5675
void    tFreeSMDropTbReqOnSingleVg(void* p);
5676

5677
typedef struct SDropTbsReq {
5678
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5679
} SMDropTbsReq;
5680

5681
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5682
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5683
void    tFreeSMDropTbsReq(void*);
5684

5685
typedef struct SVFetchTtlExpiredTbsRsp {
5686
  SArray* pExpiredTbs;  // SVDropTbReq
5687
  int32_t vgId;
5688
} SVFetchTtlExpiredTbsRsp;
5689

5690
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5691
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5692

5693
void tFreeFetchTtlExpiredTbsRsp(void* p);
5694

5695
void setDefaultOptionsForField(SFieldWithOptions* field);
5696
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5697

5698
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5699
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5700

5701
typedef struct {
5702
  char    id[TSDB_INSTANCE_ID_LEN];
5703
  char    type[TSDB_INSTANCE_TYPE_LEN];
5704
  char    desc[TSDB_INSTANCE_DESC_LEN];
5705
  int32_t expire;
5706
} SInstanceRegisterReq;
5707

5708
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5709
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5710

5711
typedef struct {
5712
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5713
} SInstanceListReq;
5714

5715
typedef struct {
5716
  int32_t count;
5717
  char**  ids;  // Array of instance IDs
5718
} SInstanceListRsp;
5719

5720
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5721
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5722
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5723
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5724

5725
#ifdef USE_MOUNT
5726
typedef struct {
5727
  char     mountName[TSDB_MOUNT_NAME_LEN];
5728
  int8_t   ignoreExist;
5729
  int16_t  nMounts;
5730
  int32_t* dnodeIds;
5731
  char**   mountPaths;
5732
  int32_t  sqlLen;
5733
  char*    sql;
5734
} SCreateMountReq;
5735

5736
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5737
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5738
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5739

5740
typedef struct {
5741
  char    mountName[TSDB_MOUNT_NAME_LEN];
5742
  int8_t  ignoreNotExists;
5743
  int32_t sqlLen;
5744
  char*   sql;
5745
} SDropMountReq;
5746

5747
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5748
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5749
void    tFreeSDropMountReq(SDropMountReq* pReq);
5750

5751
typedef struct {
5752
  char     mountName[TSDB_MOUNT_NAME_LEN];
5753
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5754
  int64_t  mountUid;
5755
  int32_t  dnodeId;
5756
  uint32_t valLen;
5757
  int8_t   ignoreExist;
5758
  void*    pVal;
5759
} SRetrieveMountPathReq;
5760

5761
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5762
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5763

5764
typedef struct {
5765
  // path
5766
  int32_t diskPrimary;
5767
  // vgInfo
5768
  int32_t  vgId;
5769
  int32_t  cacheLastSize;
5770
  int32_t  szPage;
5771
  int32_t  szCache;
5772
  uint64_t szBuf;
5773
  int8_t   cacheLast;
5774
  int8_t   standby;
5775
  int8_t   hashMethod;
5776
  uint32_t hashBegin;
5777
  uint32_t hashEnd;
5778
  int16_t  hashPrefix;
5779
  int16_t  hashSuffix;
5780
  int16_t  sttTrigger;
5781
  // syncInfo
5782
  int32_t replications;
5783
  // tsdbInfo
5784
  int8_t  precision;
5785
  int8_t  compression;
5786
  int8_t  slLevel;
5787
  int32_t daysPerFile;
5788
  int32_t keep0;
5789
  int32_t keep1;
5790
  int32_t keep2;
5791
  int32_t keepTimeOffset;
5792
  int32_t minRows;
5793
  int32_t maxRows;
5794
  int32_t tsdbPageSize;
5795
  int32_t ssChunkSize;
5796
  int32_t ssKeepLocal;
5797
  int8_t  ssCompact;
5798
  // walInfo
5799
  int32_t walFsyncPeriod;      // millisecond
5800
  int32_t walRetentionPeriod;  // secs
5801
  int32_t walRollPeriod;       // secs
5802
  int64_t walRetentionSize;
5803
  int64_t walSegSize;
5804
  int32_t walLevel;
5805
  // encryptInfo
5806
  int32_t encryptAlgorithm;
5807
  // SVState
5808
  int64_t committed;
5809
  int64_t commitID;
5810
  int64_t commitTerm;
5811
  // stats
5812
  int64_t numOfSTables;
5813
  int64_t numOfCTables;
5814
  int64_t numOfNTables;
5815
  // dbInfo
5816
  uint64_t dbId;
5817
} SMountVgInfo;
5818

5819
typedef struct {
5820
  SMCreateStbReq req;
5821
  SArray*        pColExts;  // element: column id
5822
  SArray*        pTagExts;  // element: tag id
5823
} SMountStbInfo;
5824

5825
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5826
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5827

5828
typedef struct {
5829
  char     dbName[TSDB_DB_FNAME_LEN];
5830
  uint64_t dbId;
5831
  SArray*  pVgs;   // SMountVgInfo
5832
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5833
} SMountDbInfo;
5834

5835
typedef struct {
5836
  // common fields
5837
  char     mountName[TSDB_MOUNT_NAME_LEN];
5838
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5839
  int8_t   ignoreExist;
5840
  int64_t  mountUid;
5841
  int64_t  clusterId;
5842
  int32_t  dnodeId;
5843
  uint32_t valLen;
5844
  void*    pVal;
5845

5846
  // response fields
5847
  SArray* pDbs;  // SMountDbInfo
5848

5849
  // memory fields, no serialized
5850
  SArray*   pDisks[TFS_MAX_TIERS];
5851
  TdFilePtr pFile;
5852
} SMountInfo;
5853

5854
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5855
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5856
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5857

5858
typedef struct {
5859
  SCreateVnodeReq createReq;
5860
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5861
  char            mountName[TSDB_MOUNT_NAME_LEN];
5862
  int64_t         mountId;
5863
  int32_t         diskPrimary;
5864
  int32_t         mountVgId;
5865
  int64_t         committed;
5866
  int64_t         commitID;
5867
  int64_t         commitTerm;
5868
  int64_t         numOfSTables;
5869
  int64_t         numOfCTables;
5870
  int64_t         numOfNTables;
5871
} SMountVnodeReq;
5872

5873
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
5874
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5875
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5876

5877
#endif  // USE_MOUNT
5878

5879
#pragma pack(pop)
5880

5881
typedef struct {
5882
  char        db[TSDB_DB_FNAME_LEN];
5883
  STimeWindow timeRange;
5884
  int32_t     sqlLen;
5885
  char*       sql;
5886
  SArray*     vgroupIds;
5887
} SScanDbReq;
5888

5889
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5890
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5891
void    tFreeSScanDbReq(SScanDbReq* pReq);
5892

5893
typedef struct {
5894
  int32_t scanId;
5895
  int8_t  bAccepted;
5896
} SScanDbRsp;
5897

5898
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5899
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5900

5901
typedef struct {
5902
  int32_t scanId;
5903
  int32_t sqlLen;
5904
  char*   sql;
5905
} SKillScanReq;
5906

5907
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5908
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5909
void    tFreeSKillScanReq(SKillScanReq* pReq);
5910

5911
typedef struct {
5912
  int32_t scanId;
5913
  int32_t vgId;
5914
  int32_t dnodeId;
5915
} SVKillScanReq;
5916

5917
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5918
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5919

5920
typedef struct {
5921
  int32_t scanId;
5922
  int32_t vgId;
5923
  int32_t dnodeId;
5924
  int32_t numberFileset;
5925
  int32_t finished;
5926
  int32_t progress;
5927
  int64_t remainingTime;
5928
} SQueryScanProgressRsp;
5929

5930
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5931
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5932

5933
typedef struct {
5934
  int32_t scanId;
5935
  int32_t vgId;
5936
  int32_t dnodeId;
5937
} SQueryScanProgressReq;
5938

5939
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5940
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5941

5942
typedef struct {
5943
  int64_t     dbUid;
5944
  char        db[TSDB_DB_FNAME_LEN];
5945
  int64_t     scanStartTime;
5946
  STimeWindow tw;
5947
  int32_t     scanId;
5948
} SScanVnodeReq;
5949

5950
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5951
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5952

5953
#ifdef __cplusplus
5954
}
5955
#endif
5956

5957
#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