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

taosdata / TDengine / #5034

24 Apr 2026 11:25AM UTC coverage: 73.058%. Remained the same
#5034

push

travis-ci

web-flow
merge: from main to 3.0 branch #35224

merge: from main to 3.0 branch[manual-only]

1336 of 1975 new or added lines in 48 files covered. (67.65%)

14149 existing lines in 164 files now uncovered.

275896 of 377640 relevant lines covered (73.06%)

132944440.29 hits per line

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

81.99
/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 <stdint.h>
20
#include "taosdef.h"
21
#include "taoserror.h"
22
#include "tarray.h"
23
#include "tcoding.h"
24
#include "tcol.h"
25
#include "tencode.h"
26
#include "thash.h"
27
#include "tlist.h"
28
#include "tname.h"
29
#include "tpriv.h"
30
#include "trow.h"
31
#include "tuuid.h"
32

33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36

37
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
38

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

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

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

63
extern char*   tMsgInfo[];
64
extern int32_t tMsgDict[];
65
extern int32_t tMsgRangeDict[];
66

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,765,365,195✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
1,713,107,251✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,147,483,647✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,147,483,647✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,147,483,647✔
119
}
120

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

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

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

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

223
typedef enum {
224
  TSDB_OPTR_NORMAL = 0,  // default
225
  TSDB_OPTR_SSMIGRATE = 1,
226
  TSDB_OPTR_ROLLUP = 2,
227
} ETsdbOpType;
228

229
typedef enum {
230
  TSDB_TRIGGER_MANUAL = 0,  // default
231
  TSDB_TRIGGER_AUTO = 1,
232
} ETriggerType;
233

234
#define TSDB_ALTER_TABLE_ADD_TAG                         1
235
#define TSDB_ALTER_TABLE_DROP_TAG                        2
236
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
237
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4 // deprecated, kept for wire compatibility
238
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
239
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
240
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
241
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
242
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
243
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
244
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
245
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
246
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
247
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
248
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15 // deprecated, kept for wire compatibility
249
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
250
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
251
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
252
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL      19 // alter multiple tag values of multi tables
253
#define TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL      20 // alter multiple tag values of the child tables of a stable
254

255
#define TSDB_FILL_NONE        0
256
#define TSDB_FILL_NULL        1
257
#define TSDB_FILL_NULL_F      2
258
#define TSDB_FILL_SET_VALUE   3
259
#define TSDB_FILL_SET_VALUE_F 4
260
#define TSDB_FILL_LINEAR      5
261
#define TSDB_FILL_PREV        6
262
#define TSDB_FILL_NEXT        7
263
#define TSDB_FILL_NEAR        8
264

265

266
#define TSDB_ALTER_USER_BASIC_INFO             1
267
// these definitions start from 5 is to keep compatible with old versions
268
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
269
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
270

271

272
#define TSDB_ALTER_ROLE_LOCK            0x1
273
#define TSDB_ALTER_ROLE_ROLE            0x2
274
#define TSDB_ALTER_ROLE_PRIVILEGES      0x3
275
#define TSDB_ALTER_ROLE_MAX             0x4 // increase according to actual use
276

277
#define TSDB_ALTER_RSMA_FUNCTION        0x1
278

279
#define TSDB_KILL_MSG_LEN 30
280

281
#define TSDB_TABLE_NUM_UNIT 100000
282

283
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
284
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
285
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
286

287
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
288
#define TSDB_COL_TAG    0x1u  // the tag column type
289
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
290
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
291
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
292

293
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
294
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
295
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
296
#define TSDB_COL_REQ_NULL(f)      (((f) & TSDB_COL_NULL) != 0)
297

298
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
299
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
300
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
301
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
302
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
303

304
typedef enum ENodeType {
305
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
306
  // VALUE, OPERATOR, FUNCTION and so on.
307
  QUERY_NODE_COLUMN = 1,
308
  QUERY_NODE_VALUE,
309
  QUERY_NODE_OPERATOR,
310
  QUERY_NODE_LOGIC_CONDITION,
311
  QUERY_NODE_FUNCTION,
312
  QUERY_NODE_REAL_TABLE,
313
  QUERY_NODE_TEMP_TABLE,
314
  QUERY_NODE_JOIN_TABLE,
315
  QUERY_NODE_GROUPING_SET,
316
  QUERY_NODE_ORDER_BY_EXPR,
317
  QUERY_NODE_LIMIT,
318
  QUERY_NODE_STATE_WINDOW,
319
  QUERY_NODE_SESSION_WINDOW,
320
  QUERY_NODE_INTERVAL_WINDOW,
321
  QUERY_NODE_NODE_LIST,
322
  QUERY_NODE_FILL,
323
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
324
  QUERY_NODE_TARGET,
325
  QUERY_NODE_DATABLOCK_DESC,
326
  QUERY_NODE_SLOT_DESC,
327
  QUERY_NODE_COLUMN_DEF,
328
  QUERY_NODE_DOWNSTREAM_SOURCE,
329
  QUERY_NODE_DATABASE_OPTIONS,
330
  QUERY_NODE_TABLE_OPTIONS,
331
  QUERY_NODE_INDEX_OPTIONS,
332
  QUERY_NODE_EXPLAIN_OPTIONS,
333
  QUERY_NODE_LEFT_VALUE,
334
  QUERY_NODE_COLUMN_REF,
335
  QUERY_NODE_WHEN_THEN,
336
  QUERY_NODE_CASE_WHEN,
337
  QUERY_NODE_EVENT_WINDOW,
338
  QUERY_NODE_HINT,
339
  QUERY_NODE_VIEW,
340
  QUERY_NODE_WINDOW_OFFSET,
341
  QUERY_NODE_COUNT_WINDOW,
342
  QUERY_NODE_COLUMN_OPTIONS,
343
  QUERY_NODE_TSMA_OPTIONS,
344
  QUERY_NODE_ANOMALY_WINDOW,
345
  QUERY_NODE_RANGE_AROUND,
346
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
347
  QUERY_NODE_VIRTUAL_TABLE,
348
  QUERY_NODE_SLIDING_WINDOW,
349
  QUERY_NODE_PERIOD_WINDOW,
350
  QUERY_NODE_STREAM_TRIGGER,
351
  QUERY_NODE_STREAM,
352
  QUERY_NODE_STREAM_TAG_DEF,
353
  QUERY_NODE_EXTERNAL_WINDOW,
354
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
355
  QUERY_NODE_PLACE_HOLDER_TABLE,
356
  QUERY_NODE_TIME_RANGE,
357
  QUERY_NODE_STREAM_OUT_TABLE,
358
  QUERY_NODE_STREAM_CALC_RANGE,
359
  QUERY_NODE_COUNT_WINDOW_ARGS,
360
  QUERY_NODE_BNODE_OPTIONS,
361
  QUERY_NODE_DATE_TIME_RANGE,
362
  QUERY_NODE_IP_RANGE,
363
  QUERY_NODE_USER_OPTIONS,
364
  QUERY_NODE_REMOTE_VALUE,
365
  QUERY_NODE_TOKEN_OPTIONS,
366
  QUERY_NODE_TRUE_FOR,
367
  QUERY_NODE_REMOTE_VALUE_LIST,
368
  QUERY_NODE_SURROUND,
369
  QUERY_NODE_REMOTE_ROW,
370
  QUERY_NODE_REMOTE_ZERO_ROWS,
371
  QUERY_NODE_UPDATE_TAG_VALUE,
372
  QUERY_NODE_ALTER_TABLE_UPDATE_TAG_VAL_CLAUSE,
373
  QUERY_NODE_REMOTE_TABLE,
374

375
  // Statement nodes are used in parser and planner module.
376
  QUERY_NODE_SET_OPERATOR = 100,
377
  QUERY_NODE_SELECT_STMT,
378
  QUERY_NODE_VNODE_MODIFY_STMT,
379
  QUERY_NODE_CREATE_DATABASE_STMT,
380
  QUERY_NODE_DROP_DATABASE_STMT,
381
  QUERY_NODE_ALTER_DATABASE_STMT,
382
  QUERY_NODE_FLUSH_DATABASE_STMT,
383
  QUERY_NODE_TRIM_DATABASE_STMT,
384
  QUERY_NODE_CREATE_TABLE_STMT,
385
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
386
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
387
  QUERY_NODE_DROP_TABLE_CLAUSE,
388
  QUERY_NODE_DROP_TABLE_STMT,
389
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
390
  QUERY_NODE_ALTER_TABLE_STMT,
391
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
392
  QUERY_NODE_CREATE_USER_STMT,
393
  QUERY_NODE_ALTER_USER_STMT,
394
  QUERY_NODE_DROP_USER_STMT,
395
  QUERY_NODE_USE_DATABASE_STMT,
396
  QUERY_NODE_CREATE_DNODE_STMT,
397
  QUERY_NODE_DROP_DNODE_STMT,
398
  QUERY_NODE_ALTER_DNODE_STMT,
399
  QUERY_NODE_CREATE_INDEX_STMT,
400
  QUERY_NODE_DROP_INDEX_STMT,
401
  QUERY_NODE_CREATE_QNODE_STMT,
402
  QUERY_NODE_DROP_QNODE_STMT,
403
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
404
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
405
  QUERY_NODE_CREATE_SNODE_STMT,
406
  QUERY_NODE_DROP_SNODE_STMT,
407
  QUERY_NODE_CREATE_MNODE_STMT,
408
  QUERY_NODE_DROP_MNODE_STMT,
409
  QUERY_NODE_CREATE_TOPIC_STMT,
410
  QUERY_NODE_DROP_TOPIC_STMT,
411
  QUERY_NODE_DROP_CGROUP_STMT,
412
  QUERY_NODE_ALTER_LOCAL_STMT,
413
  QUERY_NODE_EXPLAIN_STMT,
414
  QUERY_NODE_DESCRIBE_STMT,
415
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
416
  QUERY_NODE_COMPACT_DATABASE_STMT,
417
  QUERY_NODE_COMPACT_VGROUPS_STMT,
418
  QUERY_NODE_CREATE_FUNCTION_STMT,
419
  QUERY_NODE_DROP_FUNCTION_STMT,
420
  QUERY_NODE_CREATE_STREAM_STMT,
421
  QUERY_NODE_DROP_STREAM_STMT,
422
  QUERY_NODE_BALANCE_VGROUP_STMT,
423
  QUERY_NODE_MERGE_VGROUP_STMT,
424
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
425
  QUERY_NODE_SPLIT_VGROUP_STMT,
426
  QUERY_NODE_SYNCDB_STMT,
427
  QUERY_NODE_GRANT_STMT,
428
  QUERY_NODE_REVOKE_STMT,
429
  QUERY_NODE_ALTER_CLUSTER_STMT,
430
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
431
  QUERY_NODE_CREATE_TSMA_STMT,
432
  QUERY_NODE_DROP_TSMA_STMT,
433
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
434
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
435
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
436
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
437
  QUERY_NODE_CREATE_MOUNT_STMT,
438
  QUERY_NODE_DROP_MOUNT_STMT,
439
  QUERY_NODE_SCAN_DATABASE_STMT,
440
  QUERY_NODE_SCAN_VGROUPS_STMT,
441
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
442
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
443
  QUERY_NODE_CREATE_TOKEN_STMT,
444
  QUERY_NODE_ALTER_TOKEN_STMT,
445
  QUERY_NODE_DROP_TOKEN_STMT,
446
  QUERY_NODE_ALTER_ENCRYPT_KEY_STMT,
447
  QUERY_NODE_CREATE_ROLE_STMT,
448
  QUERY_NODE_DROP_ROLE_STMT,
449
  QUERY_NODE_ALTER_ROLE_STMT,
450
  QUERY_NODE_CREATE_TOTP_SECRET_STMT,
451
  QUERY_NODE_DROP_TOTP_SECRET_STMT,
452
  QUERY_NODE_ALTER_KEY_EXPIRATION_STMT,
453

454
  // placeholder for [155, 180]
455
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
456
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
457
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
458
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
459
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
460
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
461
  QUERY_NODE_SHOW_SCORES_STMT,
462
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
463
  QUERY_NODE_KILL_CONNECTION_STMT,
464
  QUERY_NODE_KILL_QUERY_STMT,
465
  QUERY_NODE_KILL_TRANSACTION_STMT,
466
  QUERY_NODE_KILL_COMPACT_STMT,
467
  QUERY_NODE_DELETE_STMT,
468
  QUERY_NODE_INSERT_STMT,
469
  QUERY_NODE_QUERY,
470
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
471
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
472
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
473
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
474
  QUERY_NODE_RESTORE_DNODE_STMT,
475
  QUERY_NODE_RESTORE_QNODE_STMT,
476
  QUERY_NODE_RESTORE_MNODE_STMT,
477
  QUERY_NODE_RESTORE_VNODE_STMT,
478
  QUERY_NODE_PAUSE_STREAM_STMT,
479
  QUERY_NODE_RESUME_STREAM_STMT,
480
  QUERY_NODE_CREATE_VIEW_STMT,
481
  QUERY_NODE_DROP_VIEW_STMT,
482
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
483
  QUERY_NODE_CREATE_ANODE_STMT,
484
  QUERY_NODE_DROP_ANODE_STMT,
485
  QUERY_NODE_UPDATE_ANODE_STMT,
486
  QUERY_NODE_ASSIGN_LEADER_STMT,
487
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
488
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
489
  QUERY_NODE_RECALCULATE_STREAM_STMT,
490
  QUERY_NODE_CREATE_BNODE_STMT,
491
  QUERY_NODE_DROP_BNODE_STMT,
492
  QUERY_NODE_KILL_SSMIGRATE_STMT,
493
  QUERY_NODE_KILL_SCAN_STMT,
494
  QUERY_NODE_CREATE_RSMA_STMT,
495
  QUERY_NODE_DROP_RSMA_STMT,
496
  QUERY_NODE_ALTER_RSMA_STMT,
497
  QUERY_NODE_SHOW_CREATE_RSMA_STMT,
498
  QUERY_NODE_ROLLUP_DATABASE_STMT,
499
  QUERY_NODE_ROLLUP_VGROUPS_STMT,
500
  QUERY_NODE_KILL_RETENTION_STMT,
501
  QUERY_NODE_SET_VGROUP_KEEP_VERSION_STMT,
502
  QUERY_NODE_CREATE_ENCRYPT_ALGORITHMS_STMT,
503
  QUERY_NODE_DROP_ENCRYPT_ALGR_STMT,
504

505
  // show statement nodes
506
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
507
  QUERY_NODE_SHOW_DNODES_STMT = 400,
508
  QUERY_NODE_SHOW_MNODES_STMT,
509
  QUERY_NODE_SHOW_MODULES_STMT,
510
  QUERY_NODE_SHOW_QNODES_STMT,
511
  QUERY_NODE_SHOW_SNODES_STMT,
512
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
513
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
514
  QUERY_NODE_SHOW_CLUSTER_STMT,
515
  QUERY_NODE_SHOW_DATABASES_STMT,
516
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
517
  QUERY_NODE_SHOW_INDEXES_STMT,
518
  QUERY_NODE_SHOW_STABLES_STMT,
519
  QUERY_NODE_SHOW_STREAMS_STMT,
520
  QUERY_NODE_SHOW_TABLES_STMT,
521
  QUERY_NODE_SHOW_TAGS_STMT,
522
  QUERY_NODE_SHOW_USERS_STMT,
523
  QUERY_NODE_SHOW_USERS_FULL_STMT,
524
  QUERY_NODE_SHOW_LICENCES_STMT,
525
  QUERY_NODE_SHOW_VGROUPS_STMT,
526
  QUERY_NODE_SHOW_TOPICS_STMT,
527
  QUERY_NODE_SHOW_CONSUMERS_STMT,
528
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
529
  QUERY_NODE_SHOW_QUERIES_STMT,
530
  QUERY_NODE_SHOW_APPS_STMT,
531
  QUERY_NODE_SHOW_VARIABLES_STMT,
532
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
533
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
534
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
535
  QUERY_NODE_SHOW_VNODES_STMT,
536
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
537
  QUERY_NODE_SHOW_VIEWS_STMT,
538
  QUERY_NODE_SHOW_COMPACTS_STMT,
539
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
540
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
541
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
542
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
543
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
544
  QUERY_NODE_SHOW_TSMAS_STMT,
545
  QUERY_NODE_SHOW_ANODES_STMT,
546
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
547
  QUERY_NODE_SHOW_USAGE_STMT,
548
  QUERY_NODE_SHOW_FILESETS_STMT,
549
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
550
  QUERY_NODE_SHOW_VTABLES_STMT,
551
  QUERY_NODE_SHOW_BNODES_STMT,
552
  QUERY_NODE_SHOW_MOUNTS_STMT,
553
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
554
  QUERY_NODE_SHOW_SCANS_STMT,
555
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
556
  QUERY_NODE_SHOW_RSMAS_STMT,
557
  QUERY_NODE_SHOW_RETENTIONS_STMT,
558
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
559
  QUERY_NODE_SHOW_INSTANCES_STMT,
560
  QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT,
561
  // the order of QUERY_NODE_SHOW_* must be aligned with the order of `sysTableShowAdapter` defines.
562
  QUERY_NODE_SHOW_TOKENS_STMT,
563
  QUERY_NODE_SHOW_ENCRYPT_STATUS_STMT,
564
  QUERY_NODE_SHOW_ROLES_STMT,
565
  QUERY_NODE_SHOW_ROLE_PRIVILEGES_STMT,
566
  QUERY_NODE_SHOW_ROLE_COL_PRIVILEGES_STMT,
567
  QUERY_NODE_SHOW_XNODES_STMT,
568
  QUERY_NODE_SHOW_XNODE_TASKS_STMT,
569
  QUERY_NODE_SHOW_XNODE_AGENTS_STMT,
570
  QUERY_NODE_SHOW_XNODE_JOBS_STMT,
571
  QUERY_NODE_SHOW_VALIDATE_VTABLE_STMT,
572
  QUERY_NODE_SHOW_SECURITY_POLICIES_STMT,
573

574
  // logic plan node
575
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
576
  QUERY_NODE_LOGIC_PLAN_JOIN,
577
  QUERY_NODE_LOGIC_PLAN_AGG,
578
  QUERY_NODE_LOGIC_PLAN_PROJECT,
579
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
580
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
581
  QUERY_NODE_LOGIC_PLAN_MERGE,
582
  QUERY_NODE_LOGIC_PLAN_WINDOW,
583
  QUERY_NODE_LOGIC_PLAN_FILL,
584
  QUERY_NODE_LOGIC_PLAN_SORT,
585
  QUERY_NODE_LOGIC_PLAN_PARTITION,
586
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
587
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
588
  QUERY_NODE_LOGIC_SUBPLAN,
589
  QUERY_NODE_LOGIC_PLAN,
590
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
591
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
592
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
593
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
594
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
595

596
  // physical plan node
597
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
598
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
599
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
600
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
601
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
602
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
603
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
604
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
605
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
606
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
607
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
608
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
609
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
610
  QUERY_NODE_PHYSICAL_PLAN_SORT,
611
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
612
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
613
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
614
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
615
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
616
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
617
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
618
  QUERY_NODE_PHYSICAL_PLAN_FILL,
619
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
620
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
621
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
622
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
623
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
624
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
625
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
626
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
627
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
628
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
629
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
630
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
631
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
632
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
633
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
634
  QUERY_NODE_PHYSICAL_SUBPLAN,
635
  QUERY_NODE_PHYSICAL_PLAN,
636
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
637
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
638
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
639
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
640
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
641
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
642
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
643
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
644
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
645
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
646
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
647
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
648
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
649
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
650
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
651
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
652
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
653
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
654
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
655
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
656
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
657
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
658
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
659
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
660
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
661
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
662
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
663
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
664
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
665
  // xnode
666
  QUERY_NODE_CREATE_XNODE_STMT = 1200,  // Xnode
667
  QUERY_NODE_DROP_XNODE_STMT,
668
  QUERY_NODE_DRAIN_XNODE_STMT,
669
  QUERY_NODE_XNODE_TASK_OPTIONS,              // XNode task options
670
  QUERY_NODE_XNODE_TASK_SOURCE_OPT,           // XNode task source
671
  QUERY_NODE_XNODE_TASK_SINK_OPT,             // XNode task sink
672
  QUERY_NODE_CREATE_XNODE_TASK_STMT,          // XNode task
673
  QUERY_NODE_START_XNODE_TASK_STMT,           // XNode task
674
  QUERY_NODE_STOP_XNODE_TASK_STMT,            // XNode task
675
  QUERY_NODE_UPDATE_XNODE_TASK_STMT,          // XNode task
676
  QUERY_NODE_DROP_XNODE_TASK_STMT,            // XNode task
677
  QUERY_NODE_CREATE_XNODE_JOB_STMT,           // XNode job
678
  QUERY_NODE_ALTER_XNODE_JOB_STMT,            // XNode job
679
  QUERY_NODE_REBALANCE_XNODE_JOB_STMT,        // XNode job
680
  QUERY_NODE_REBALANCE_XNODE_JOB_WHERE_STMT,  // XNode job
681
  QUERY_NODE_DROP_XNODE_JOB_STMT,             // XNode job
682
  QUERY_NODE_CREATE_XNODE_AGENT_STMT,         // XNode agent
683
  QUERY_NODE_DROP_XNODE_AGENT_STMT,           // XNode agent
684
  QUERY_NODE_ALTER_XNODE_AGENT_STMT,          // XNode agent
685
  QUERY_NODE_ALTER_XNODE_STMT,                // Alter xnode
686
} ENodeType;
687

688
typedef struct {
689
  int32_t     vgId;
690
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
691
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
692
  const char* dbFName;
693
  const char* tbName;
694
} SBuildTableInput;
695

696
typedef struct {
697
  char    db[TSDB_DB_FNAME_LEN];
698
  int64_t dbId;
699
  int32_t vgVersion;
700
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
701
  int64_t stateTs;
702
} SBuildUseDBInput;
703

704
typedef struct SField {
705
  char    name[TSDB_COL_NAME_LEN];
706
  uint8_t type;
707
  int8_t  flags;
708
  int32_t bytes;
709
} SField;
710

711
typedef struct SFieldWithOptions {
712
  char     name[TSDB_COL_NAME_LEN];
713
  uint8_t  type;
714
  int8_t   flags;
715
  int32_t  bytes;
716
  uint32_t compress;
717
  STypeMod typeMod;
718
} SFieldWithOptions;
719

720
typedef struct SRetention {
721
  int64_t freq;
722
  int64_t keep;
723
  int8_t  freqUnit;
724
  int8_t  keepUnit;
725
} SRetention;
726

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

729
#pragma pack(push, 1)
730
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
731
typedef struct SEp {
732
  char     fqdn[TSDB_FQDN_LEN];
733
  uint16_t port;
734
} SEp;
735

736
typedef struct {
737
  int32_t contLen;
738
  int32_t vgId;
739
} SMsgHead;
740

741
// Submit message for one table
742
typedef struct SSubmitBlk {
743
  int64_t uid;        // table unique id
744
  int64_t suid;       // stable id
745
  int32_t sversion;   // data schema version
746
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
747
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
748
  int32_t numOfRows;  // total number of rows in current submit block
749
  char    data[];
750
} SSubmitBlk;
751

752
// Submit message for this TSDB
753
typedef struct {
754
  SMsgHead header;
755
  int64_t  version;
756
  int32_t  length;
757
  int32_t  numOfBlocks;
758
  char     blocks[];
759
} SSubmitReq;
760

761
typedef struct {
762
  int32_t totalLen;
763
  int32_t len;
764
  STSRow* row;
765
} SSubmitBlkIter;
766

767
typedef struct {
768
  int32_t totalLen;
769
  int32_t len;
770
  // head of SSubmitBlk
771
  int64_t uid;        // table unique id
772
  int64_t suid;       // stable id
773
  int32_t sversion;   // data schema version
774
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
775
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
776
  int32_t numOfRows;  // total number of rows in current submit block
777
  // head of SSubmitBlk
778
  int32_t     numOfBlocks;
779
  const void* pMsg;
780
} SSubmitMsgIter;
781

782
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
783
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
784
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
785
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
786
// for debug
787
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
788

789
typedef struct {
790
  bool     hasRef;
791
  col_id_t id;
792
  char     refDbName[TSDB_DB_NAME_LEN];
793
  char     refTableName[TSDB_TABLE_NAME_LEN];
794
  char     refColName[TSDB_COL_NAME_LEN];
795
  char     colName[TSDB_COL_NAME_LEN];     // for tmq get json
796
} SColRef;
797

798
typedef struct {
799
  int32_t  nCols;
800
  int32_t  version;
801
  SColRef* pColRef;
802
  int32_t  nTagRefs;
803
  SColRef* pTagRef;
804
} SColRefWrapper;
805

806
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
807
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
808
typedef struct {
809
  int32_t vgId;
810
  SColRef colRef;
811
} SColRefEx;
812

813
typedef struct {
814
  int16_t colId;
815
  char    refDbName[TSDB_DB_NAME_LEN];
816
  char    refTableName[TSDB_TABLE_NAME_LEN];
817
  char    refColName[TSDB_COL_NAME_LEN];
818
} SRefColInfo;
819

820
typedef struct SVCTableRefCols {
821
  uint64_t     uid;
822
  int32_t      numOfSrcTbls;
823
  int32_t      numOfColRefs;
824
  SRefColInfo* refCols;
825
} SVCTableRefCols;
826

827
typedef struct SVCTableMergeInfo {
828
  uint64_t uid;
829
  int32_t  numOfSrcTbls;
830
} SVCTableMergeInfo;
831

832
typedef struct {
833
  int32_t    nCols;
834
  SColRefEx* pColRefEx;
835
} SColRefExWrapper;
836

837
struct SSchema {
838
  int8_t   type;
839
  int8_t   flags;
840
  col_id_t colId;
841
  int32_t  bytes;
842
  char     name[TSDB_COL_NAME_LEN];
843
};
844
struct SSchemaExt {
845
  col_id_t colId;
846
  uint32_t compress;
847
  STypeMod typeMod;
848
};
849

850
struct SSchemaRsma {
851
  int64_t    interval[2];
852
  int32_t    nFuncs;
853
  int8_t     tbType;
854
  tb_uid_t   tbUid;
855
  func_id_t* funcIds;
856
  char       tbName[TSDB_TABLE_NAME_LEN];
857
};
858

859
struct SSchema2 {
860
  int8_t   type;
861
  int8_t   flags;
862
  col_id_t colId;
863
  int32_t  bytes;
864
  char     name[TSDB_COL_NAME_LEN];
865
  uint32_t compress;
866
};
867

868
typedef struct {
869
  char        tbName[TSDB_TABLE_NAME_LEN];
870
  char        stbName[TSDB_TABLE_NAME_LEN];
871
  char        dbFName[TSDB_DB_FNAME_LEN];
872
  int64_t     dbId;
873
  int32_t     numOfTags;
874
  int32_t     numOfColumns;
875
  int8_t      precision;
876
  int8_t      tableType;
877
  int32_t     sversion;
878
  int32_t     tversion;
879
  int32_t     rversion;
880
  uint64_t    suid;
881
  uint64_t    tuid;
882
  int32_t     vgId;
883
  union {
884
    uint8_t flag;
885
    struct {
886
      uint8_t sysInfo : 1;
887
      uint8_t isAudit : 1;
888
      uint8_t privCat : 3;  // ESysTblPrivCat
889
      uint8_t secLvl : 3;
890
    };
891
  };
892
  int64_t     ownerId;
893
  SSchema*    pSchemas;
894
  SSchemaExt* pSchemaExt;
895
  int8_t      virtualStb;
896
  int32_t     numOfColRefs;
897
  SColRef*    pColRefs;
898
  int32_t     numOfTagRefs;
899
  SColRef*    pTagRefs;
900
  int8_t      secureDelete;
901
} STableMetaRsp;
902

903
typedef struct {
904
  int32_t        code;
905
  int64_t        uid;
906
  char*          tblFName;
907
  int32_t        numOfRows;
908
  int32_t        affectedRows;
909
  int64_t        sver;
910
  STableMetaRsp* pMeta;
911
} SSubmitBlkRsp;
912

913
typedef struct {
914
  int32_t numOfRows;
915
  int32_t affectedRows;
916
  int32_t nBlocks;
917
  union {
918
    SArray*        pArray;
919
    SSubmitBlkRsp* pBlocks;
920
  };
921
} SSubmitRsp;
922

923
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
924
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
925
// void    tFreeSSubmitBlkRsp(void* param);
926
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
927

928
#define COL_SMA_ON       ((int8_t)0x1)
929
#define COL_IDX_ON       ((int8_t)0x2)
930
#define COL_IS_KEY       ((int8_t)0x4)
931
#define COL_SET_NULL     ((int8_t)0x10)
932
#define COL_SET_VAL      ((int8_t)0x20)
933
#define COL_IS_SYSINFO   ((int8_t)0x40)
934
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
935
#define COL_REF_BY_STM   ((int8_t)0x08)
936

937
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
938
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
939

940
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
941
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
942
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
943

944
#define SSCHMEA_SET_IDX_ON(s) \
945
  do {                        \
946
    (s)->flags |= COL_IDX_ON; \
947
  } while (0)
948

949
#define SSCHMEA_SET_IDX_OFF(s)   \
950
  do {                           \
951
    (s)->flags &= (~COL_IDX_ON); \
952
  } while (0)
953

954
#define SSCHEMA_SET_TYPE_MOD(s)     \
955
  do {                              \
956
    (s)->flags |= COL_HAS_TYPE_MOD; \
957
  } while (0)
958

959
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
960

961
#define SSCHMEA_TYPE(s)  ((s)->type)
962
#define SSCHMEA_FLAGS(s) ((s)->flags)
963
#define SSCHMEA_COLID(s) ((s)->colId)
964
#define SSCHMEA_BYTES(s) ((s)->bytes)
965
#define SSCHMEA_NAME(s)  ((s)->name)
966

967
typedef struct {
968
  bool    tsEnableMonitor;
969
  int32_t tsMonitorInterval;
970
  int32_t tsSlowLogThreshold;
971
  int32_t tsSlowLogMaxLen;
972
  int32_t tsSlowLogScope;
973
  int32_t tsSlowLogThresholdTest;  // Obsolete
974
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
975
} SMonitorParas;
976

977
typedef struct {
978
  STypeMod typeMod;
979
} SExtSchema;
980

981
bool hasExtSchema(const SExtSchema* pExtSchema);
982

983
typedef struct {
984
  int32_t      nCols;
985
  int32_t      version;
986
  SSchema*     pSchema;
987
  SSchemaRsma* pRsma;
988
} SSchemaWrapper;
989

990
typedef struct {
991
  col_id_t id;
992
  uint32_t alg;
993
} SColCmpr;
994

995
typedef struct {
996
  int32_t   nCols;
997
  int32_t   version;
998
  SColCmpr* pColCmpr;
999
} SColCmprWrapper;
1000

1001
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
1002
  if (pRef->pColRef) {
595,521✔
UNCOV
1003
    return TSDB_CODE_INVALID_PARA;
×
1004
  }
1005
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
595,521✔
1006
  if (pRef->pColRef == NULL) {
595,521✔
UNCOV
1007
    return terrno;
×
1008
  }
1009
  pRef->nCols = nCols;
595,521✔
1010
  for (int32_t i = 0; i < nCols; i++) {
164,472,754✔
1011
    pRef->pColRef[i].hasRef = false;
163,877,233✔
1012
    pRef->pColRef[i].id = (col_id_t)(i + 1);
163,877,233✔
1013
  }
1014
  return 0;
595,521✔
1015
}
1016

1017
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByTags(SColRefWrapper* pRef, int32_t nTags, col_id_t startColId) {
UNCOV
1018
  if (pRef->pTagRef) {
×
UNCOV
1019
    return TSDB_CODE_INVALID_PARA;
×
1020
  }
1021
  pRef->pTagRef = (SColRef*)taosMemoryCalloc(nTags, sizeof(SColRef));
×
UNCOV
1022
  if (pRef->pTagRef == NULL) {
×
1023
    return terrno;
×
1024
  }
1025
  pRef->nTagRefs = nTags;
×
UNCOV
1026
  for (int32_t i = 0; i < nTags; i++) {
×
1027
    pRef->pTagRef[i].hasRef = false;
×
1028
    pRef->pTagRef[i].id = (col_id_t)(startColId + i);
×
1029
  }
1030
  return 0;
×
1031
}
1032

1033
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1034
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1035
    terrno = TSDB_CODE_INVALID_PARA;
1036
    return NULL;
1037
  }
1038

1039
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1040
  if (pDstWrapper == NULL) {
1041
    return NULL;
1042
  }
1043
  pDstWrapper->nCols = pSrcWrapper->nCols;
1044
  pDstWrapper->version = pSrcWrapper->version;
1045

1046
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1047
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1048
  if (pDstWrapper->pColCmpr == NULL) {
1049
    taosMemoryFree(pDstWrapper);
1050
    return NULL;
1051
  }
1052
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1053

1054
  return pDstWrapper;
1055
}
1056

1057
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1058
  if (!(!pCmpr->pColCmpr)) {
7,758,755✔
UNCOV
1059
    return TSDB_CODE_INVALID_PARA;
×
1060
  }
1061
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
7,758,755✔
1062
  if (pCmpr->pColCmpr == NULL) {
7,758,755✔
UNCOV
1063
    return terrno;
×
1064
  }
1065
  pCmpr->nCols = nCols;
7,758,755✔
1066
  return 0;
7,758,755✔
1067
}
1068

1069
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1070
  pCmpr->nCols = pSchema->nCols;
1071
  if (!(!pCmpr->pColCmpr)) {
1072
    return TSDB_CODE_INVALID_PARA;
1073
  }
1074
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1075
  if (pCmpr->pColCmpr == NULL) {
1076
    return terrno;
1077
  }
1078
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1079
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1080
    SSchema*  pColSchema = &pSchema->pSchema[i];
1081
    pColCmpr->id = pColSchema->colId;
1082
    pColCmpr->alg = 0;
1083
  }
1084
  return 0;
1085
}
1086

1087
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1088
  if (pWrapper == NULL) return;
1089

1090
  taosMemoryFreeClear(pWrapper->pColCmpr);
1091
  taosMemoryFreeClear(pWrapper);
1092
}
1093
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1094
  if (pSchemaWrapper->pSchema == NULL) return NULL;
727,917,127✔
1095

1096
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
727,777,765✔
1097
  if (pSW == NULL) {
727,667,014✔
UNCOV
1098
    return NULL;
×
1099
  }
1100
  pSW->nCols = pSchemaWrapper->nCols;
727,667,014✔
1101
  pSW->version = pSchemaWrapper->version;
727,813,770✔
1102
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
727,782,148✔
1103
  if (pSW->pSchema == NULL) {
727,575,415✔
UNCOV
1104
    taosMemoryFree(pSW);
×
UNCOV
1105
    return NULL;
×
1106
  }
1107

1108
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
727,500,867✔
1109
  return pSW;
727,861,269✔
1110
}
1111

1112
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
226,676,792✔
1113
  if (pSchemaWrapper) {
1,665,878,073✔
1114
    taosMemoryFree(pSchemaWrapper->pSchema);
1,159,848,000✔
1115
    if (pSchemaWrapper->pRsma) {
1,159,773,071✔
1116
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
29,119✔
1117
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
29,119✔
1118
    }
1119
    taosMemoryFree(pSchemaWrapper);
1,159,792,694✔
1120
  }
1121
}
1,625,644,018✔
1122

1123
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1124
  if (pSchemaWrapper) {
1125
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1126
    if (pSchemaWrapper->pRsma) {
1127
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1128
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1129
    }
1130
  }
1131
}
1132

1133
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,694,853✔
1134
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,694,853✔
1135
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,696,124✔
1136
  }
1137
}
7,693,642✔
1138

1139
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1140
  int32_t tlen = 0;
3,026,502✔
1141
  tlen += taosEncodeFixedI8(buf, pSchema->type);
3,028,872✔
1142
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
3,026,502✔
1143
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
3,026,502✔
1144
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
3,026,502✔
1145
  tlen += taosEncodeString(buf, pSchema->name);
3,026,502✔
1146
  return tlen;
3,026,502✔
1147
}
1148

1149
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1150
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,348,044✔
1151
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,347,537✔
1152
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,347,537✔
1153
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,347,537✔
1154
  buf = taosDecodeStringTo(buf, pSchema->name);
1,347,537✔
1155
  return (void*)buf;
1,347,537✔
1156
}
1157

1158
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1159
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1160
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1161
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1162
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1163
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1164
  return 0;
2,147,483,647✔
1165
}
1166

1167
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1168
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1169
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1170
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1171
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1172
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1173
  return 0;
2,147,483,647✔
1174
}
1175

1176
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1177
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1178
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1179
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1180
  return 0;
2,147,483,647✔
1181
}
1182

1183
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1184
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1185
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1186
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1187
  return 0;
2,147,483,647✔
1188
}
1189

1190
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1191
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
1,000,049,936✔
1192
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
1,000,049,936✔
1193
  if (pColRef->hasRef) {
500,024,968✔
1194
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
663,437,812✔
1195
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
663,437,812✔
1196
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
663,437,812✔
1197
  }
1198
  return 0;
500,024,968✔
1199
}
1200

1201
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1202
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
500,529,408✔
1203
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
500,529,408✔
1204
  if (pColRef->hasRef) {
250,264,704✔
1205
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
166,071,274✔
1206
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
166,071,274✔
1207
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
166,071,274✔
1208
  }
1209

1210
  return 0;
250,264,704✔
1211
}
1212

1213
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1214
  int32_t tlen = 0;
510,562✔
1215
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
510,562✔
1216
  tlen += taosEncodeVariantI32(buf, pSW->version);
510,562✔
1217
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,537,064✔
1218
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
6,053,004✔
1219
  }
1220
  return tlen;
510,562✔
1221
}
1222

1223
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1224
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
220,086✔
1225
  buf = taosDecodeVariantI32(buf, &pSW->version);
220,086✔
1226
  if (pSW->nCols > 0) {
220,086✔
1227
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
220,086✔
1228
    if (pSW->pSchema == NULL) {
220,086✔
UNCOV
1229
      return NULL;
×
1230
    }
1231

1232
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,567,623✔
1233
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,695,074✔
1234
    }
1235
  } else {
UNCOV
1236
    pSW->pSchema = NULL;
×
1237
  }
1238
  return (void*)buf;
220,086✔
1239
}
1240

1241
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1242
  if (pSW == NULL) {
368,567,983✔
UNCOV
1243
    return TSDB_CODE_INVALID_PARA;
×
1244
  }
1245
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
737,148,435✔
1246
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
737,029,012✔
1247
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1248
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1249
  }
1250
  return 0;
368,780,635✔
1251
}
1252

1253
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1254
  if (pSW == NULL) {
168,804,782✔
UNCOV
1255
    return TSDB_CODE_INVALID_PARA;
×
1256
  }
1257
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
337,593,715✔
1258
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
337,581,221✔
1259

1260
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
168,792,288✔
1261
  if (pSW->pSchema == NULL) {
168,765,318✔
UNCOV
1262
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1263
  }
1264
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,683,560,509✔
1265
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1266
  }
1267

1268
  return 0;
168,815,211✔
1269
}
1270

1271
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1272
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1273
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1274

1275
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1276
  if (pSW->pSchema == NULL) {
2,147,483,647✔
UNCOV
1277
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1278
  }
1279
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1280
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1281
  }
1282

1283
  return 0;
2,147,483,647✔
1284
}
1285

1286
typedef struct {
1287
  char     name[TSDB_TABLE_FNAME_LEN];
1288
  int8_t   igExists;
1289
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1290
  int8_t   reserved[6];
1291
  tb_uid_t suid;
1292
  int64_t  delay1;
1293
  int64_t  delay2;
1294
  int64_t  watermark1;
1295
  int64_t  watermark2;
1296
  int32_t  ttl;
1297
  int32_t  colVer;
1298
  int32_t  tagVer;
1299
  int32_t  numOfColumns;
1300
  int32_t  numOfTags;
1301
  int32_t  numOfFuncs;
1302
  int32_t  commentLen;
1303
  int32_t  ast1Len;
1304
  int32_t  ast2Len;
1305
  SArray*  pColumns;  // array of SFieldWithOptions
1306
  SArray*  pTags;     // array of SField
1307
  SArray*  pFuncs;
1308
  char*    pComment;
1309
  char*    pAst1;
1310
  char*    pAst2;
1311
  int64_t  deleteMark1;
1312
  int64_t  deleteMark2;
1313
  int32_t  sqlLen;
1314
  char*    sql;
1315
  int64_t  keep;
1316
  int8_t   virtualStb;
1317
  int8_t   secureDelete;
1318
  int8_t   securityLevel;
1319
} SMCreateStbReq;
1320

1321
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1322
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1323
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1324

1325
typedef struct {
1326
  STableMetaRsp* pMeta;
1327
} SMCreateStbRsp;
1328

1329
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1330
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1331
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1332

1333
typedef struct {
1334
  char     name[TSDB_TABLE_FNAME_LEN];
1335
  int8_t   igNotExists;
1336
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1337
  int8_t   reserved[6];
1338
  tb_uid_t suid;
1339
  int32_t  sqlLen;
1340
  char*    sql;
1341
} SMDropStbReq;
1342

1343
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1344
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1345
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1346

1347
typedef struct {
1348
  char    name[TSDB_TABLE_FNAME_LEN];
1349
  int8_t  alterType;
1350
  int32_t numOfFields;
1351
  SArray* pFields;
1352
  int32_t ttl;
1353
  int32_t commentLen;
1354
  char*   comment;
1355
  int32_t sqlLen;
1356
  char*   sql;
1357
  int64_t keep;
1358
  SArray* pTypeMods;
1359
  int8_t  secureDelete;
1360
  int8_t  securityLevel;
1361
} SMAlterStbReq;
1362

1363
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1364
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1365
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1366

1367
typedef struct SEpSet {
1368
  int8_t inUse;
1369
  int8_t numOfEps;
1370
  SEp    eps[TSDB_MAX_REPLICA];
1371
} SEpSet;
1372

1373
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1374
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1375
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1376
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1377

1378
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1379
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1380

1381
typedef struct {
1382
  int8_t  connType;
1383
  int32_t pid;
1384
  int32_t totpCode;
1385
  char    app[TSDB_APP_NAME_LEN];
1386
  char    db[TSDB_DB_NAME_LEN];
1387
  char    user[TSDB_USER_LEN];
1388
  char    passwd[TSDB_PASSWORD_LEN];
1389
  char    token[TSDB_TOKEN_LEN];
1390
  int64_t startTime;
1391
  int64_t connectTime;
1392
  char    sVer[TSDB_VERSION_LEN];
1393
  char    signature[20]; // SHA1 produces a 20-byte signature
1394
} SConnectReq;
1395

1396
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1397
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1398
void    tSignConnectReq(SConnectReq* pReq);
1399
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1400

1401
typedef struct {
1402
  int64_t       clusterId;
1403
  int32_t       acctId;
1404
  uint32_t      connId;
1405
  int32_t       dnodeNum;
1406
  int8_t        superUser;
1407
  int8_t        sysInfo;
1408
  int8_t        connType;
1409
  int8_t        enableAuditDelete;
1410
  SEpSet        epSet;
1411
  int32_t       svrTimestamp;
1412
  int32_t       passVer;
1413
  int32_t       authVer;
1414
  char          sVer[TSDB_VERSION_LEN];
1415
  char          sDetailVer[128];
1416
  int64_t       whiteListVer;
1417
  int64_t       timeWhiteListVer;
1418
  int64_t       userId;
1419
  SMonitorParas monitorParas;
1420
  char          user[TSDB_USER_LEN];
1421
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1422
  int8_t        enableAuditSelect;
1423
  int8_t        enableAuditInsert;
1424
  int8_t        auditLevel;
1425
  union {
1426
    uint32_t flags;
1427
    struct {
1428
      uint32_t minSecLevel : 3;  // per-user
1429
      uint32_t maxSecLevel : 3;  // per-user
1430
      uint32_t sodInitial  : 1;  // cluster-wide: 1 = SoD still in initial phase
1431
      uint32_t macActive   : 1;  // cluster-wide: 1 = MAC mandatory mode activated
1432
      uint32_t reserved    : 24;
1433
    };
1434
  };
1435
} SConnectRsp;
1436

1437
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1438
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1439

1440
typedef struct {
1441
  char    user[TSDB_USER_LEN];
1442
  char    pass[TSDB_PASSWORD_LEN];
1443
  int32_t maxUsers;
1444
  int32_t maxDbs;
1445
  int32_t maxTimeSeries;
1446
  int32_t maxStreams;
1447
  int32_t accessState;  // Configured only by command
1448
  int64_t maxStorage;
1449
} SCreateAcctReq, SAlterAcctReq;
1450

1451
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1452
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1453

1454
typedef struct {
1455
  char    user[TSDB_USER_LEN];
1456
  int8_t  ignoreNotExists;
1457
  int32_t sqlLen;
1458
  char*   sql;
1459
} SDropUserReq, SDropAcctReq;
1460

1461
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1462
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1463
void    tFreeSDropUserReq(SDropUserReq* pReq);
1464

1465
typedef struct {
1466
  char name[TSDB_ROLE_LEN];
1467
  union {
1468
    uint8_t flag;
1469
    struct {
1470
      uint8_t ignoreExists : 1;
1471
      uint8_t reserve : 7;
1472
    };
1473
  };
1474
  int32_t sqlLen;
1475
  char*   sql;
1476
} SCreateRoleReq;
1477

1478
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1479
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1480
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1481

1482
typedef struct {
1483
  char name[TSDB_ROLE_LEN];
1484
  union {
1485
    uint8_t flag;
1486
    struct {
1487
      uint8_t ignoreNotExists : 1;
1488
      uint8_t reserve : 7;
1489
    };
1490
  };
1491
  int32_t sqlLen;
1492
  char*   sql;
1493
} SDropRoleReq;
1494

1495
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1496
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1497
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1498

1499
typedef struct {
1500
  SPrivSet privSet;
1501
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1502
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1503
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1504
  // delete can only specify conditions by cond and cannot specify columns
1505
  char*    cond;     // for table privileges
1506
  int32_t  condLen;  // for table privileges
1507
} SPrivSetReqArgs;
1508

1509
typedef struct {
1510
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1511
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1512
  union {
1513
    uint32_t flag;
1514
    struct {
1515
      uint32_t lock : 1;     // lock or unlock role
1516
      uint32_t add : 1;      // add or remove
1517
      uint32_t sysPriv : 1;  // system or object privileges
1518
      uint32_t objLevel : 2;
1519
      uint32_t ignoreNotExists : 1;
1520
      uint32_t reserve : 26;
1521
    };
1522
  };
1523
  union {
1524
    SPrivSetReqArgs privileges;
1525
    char            roleName[TSDB_ROLE_LEN];
1526
  };
1527
  char    principal[TSDB_ROLE_LEN];      // role or user name
1528
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1529
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1530
  int32_t sqlLen;
1531
  char*   sql;
1532
} SAlterRoleReq;
1533

1534
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1535
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1536
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1537

1538
typedef struct {
1539
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1540
  int32_t sqlLen;
1541
  char*   sql;
1542
} SDropEncryptAlgrReq;
1543

1544
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1545
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1546
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1547

1548
typedef struct SIpV4Range {
1549
  uint32_t ip;
1550
  uint32_t mask;
1551
} SIpV4Range;
1552

1553
typedef struct SIpv6Range {
1554
  uint64_t addr[2];
1555
  uint32_t mask;
1556
} SIpV6Range;
1557

1558
typedef struct {
1559
  int8_t type;   // 0: IPv4, 1: IPv6
1560
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1561
  union {
1562
    SIpV4Range ipV4;
1563
    SIpV6Range ipV6;
1564
  };
1565
} SIpRange;
1566

1567
typedef struct {
1568
  int32_t    num;
1569
  SIpV4Range pIpRange[];
1570
} SIpWhiteList;
1571

1572
typedef struct {
1573
  int32_t  num;
1574
  SIpRange pIpRanges[];
1575
} SIpWhiteListDual;
1576

1577
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1578
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1579
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1580
int32_t           createDefaultIp6Range(SIpRange* pRange);
1581
int32_t           createDefaultIp4Range(SIpRange* pRange);
1582

1583
typedef struct {
1584
  int32_t sessPerUser;
1585
  int32_t sessConnTime;
1586
  int32_t sessConnIdleTime;
1587
  int32_t sessMaxConcurrency;
1588
  int32_t sessMaxCallVnodeNum;
1589
} SUserSessCfg;
1590

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

1595
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1596
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1597
typedef struct {
1598
  int16_t year;
1599
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1600
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1601
  int8_t hour;
1602
  int8_t minute;
1603
  int8_t neg;   // this is a negative entry
1604
  int32_t duration; // duration in minute
1605
} SDateTimeRange;
1606

1607
bool isValidDateTimeRange(SDateTimeRange* pRange);
1608
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1609
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1610

1611
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1612
typedef struct {
1613
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1614
  bool neg;         // this is a negative entry
1615
  int32_t duration; // duration in seconds
1616
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1617
} SDateTimeWhiteListItem;
1618

1619
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1620
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1621

1622
typedef struct {
1623
  int32_t num;
1624
  SDateTimeWhiteListItem ranges[];
1625
} SDateTimeWhiteList;
1626

1627
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1628
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1629

1630

1631
typedef struct {
1632
  int8_t createType;
1633

1634
  int8_t hasSessionPerUser;
1635
  int8_t hasConnectTime;
1636
  int8_t hasConnectIdleTime;
1637
  int8_t hasCallPerSession;
1638
  int8_t hasVnodePerCall;
1639
  int8_t hasFailedLoginAttempts;
1640
  int8_t hasPasswordLifeTime;
1641
  int8_t hasPasswordReuseTime;
1642
  int8_t hasPasswordReuseMax;
1643
  int8_t hasPasswordLockTime;
1644
  int8_t hasPasswordGraceTime;
1645
  int8_t hasInactiveAccountTime;
1646
  int8_t hasAllowTokenNum;
1647
  int8_t hasSecurityLevel;
1648

1649
  int8_t superUser;  // denote if it is a super user or not
1650
  int8_t ignoreExists;
1651

1652
  char   user[TSDB_USER_LEN];
1653
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1654
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1655

1656
  int8_t sysInfo;
1657
  int8_t createDb;
1658
  int8_t isImport;
1659
  int8_t changepass;
1660
  int8_t enable;
1661
  int8_t minSecLevel;
1662
  int8_t maxSecLevel;
1663

1664
  int8_t negIpRanges;
1665
  int8_t negTimeRanges;
1666

1667
  int32_t sessionPerUser;
1668
  int32_t connectTime;
1669
  int32_t connectIdleTime;
1670
  int32_t callPerSession;
1671
  int32_t vnodePerCall;
1672
  int32_t failedLoginAttempts;
1673
  int32_t passwordLifeTime;
1674
  int32_t passwordReuseTime;
1675
  int32_t passwordReuseMax;
1676
  int32_t passwordLockTime;
1677
  int32_t passwordGraceTime;
1678
  int32_t inactiveAccountTime;
1679
  int32_t allowTokenNum;
1680

1681
  int32_t         numIpRanges;
1682
  SIpRange*       pIpDualRanges;
1683
  int32_t         numTimeRanges;
1684
  SDateTimeRange* pTimeRanges;
1685

1686
  int32_t sqlLen;
1687
  char*   sql;
1688
} SCreateUserReq;
1689

1690
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1691
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1692
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1693

1694
typedef struct {
1695
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1696
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1697
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1698
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1699
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1700
  int32_t sqlLen;
1701
  char*   sql;
1702
} SCreateEncryptAlgrReq;
1703

1704
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1705
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1706
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1707

1708
typedef struct {
1709
  int32_t dnodeId;
1710
  int64_t analVer;
1711
} SRetrieveAnalyticsAlgoReq;
1712

1713
typedef struct {
1714
  int64_t   ver;
1715
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1716
} SRetrieveAnalyticAlgoRsp;
1717

1718
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1719
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1720
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1721
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1722
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1723

1724
typedef struct {
1725
  int8_t alterType;
1726

1727
  int8_t isView;
1728

1729
  int8_t hasPassword;
1730
  int8_t hasTotpseed;
1731
  int8_t hasEnable;
1732
  int8_t hasSysinfo;
1733
  int8_t hasCreatedb;
1734
  int8_t hasChangepass;
1735
  int8_t hasSessionPerUser;
1736
  int8_t hasConnectTime;
1737
  int8_t hasConnectIdleTime;
1738
  int8_t hasCallPerSession;
1739
  int8_t hasVnodePerCall;
1740
  int8_t hasFailedLoginAttempts;
1741
  int8_t hasPasswordLifeTime;
1742
  int8_t hasPasswordReuseTime;
1743
  int8_t hasPasswordReuseMax;
1744
  int8_t hasPasswordLockTime;
1745
  int8_t hasPasswordGraceTime;
1746
  int8_t hasInactiveAccountTime;
1747
  int8_t hasAllowTokenNum;
1748
  int8_t hasSecurityLevel;
1749

1750
  int8_t enable;
1751
  int8_t sysinfo;
1752
  int8_t createdb;
1753
  int8_t changepass;
1754
  int8_t minSecLevel;
1755
  int8_t maxSecLevel;
1756

1757
  char   user[TSDB_USER_LEN];
1758
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1759
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1760
  int32_t sessionPerUser;
1761
  int32_t connectTime;
1762
  int32_t connectIdleTime;
1763
  int32_t callPerSession;
1764
  int32_t vnodePerCall;
1765
  int32_t failedLoginAttempts;
1766
  int32_t passwordLifeTime;
1767
  int32_t passwordReuseTime;
1768
  int32_t passwordReuseMax;
1769
  int32_t passwordLockTime;
1770
  int32_t passwordGraceTime;
1771
  int32_t inactiveAccountTime;
1772
  int32_t allowTokenNum;
1773

1774
  int32_t         numIpRanges;
1775
  int32_t         numTimeRanges;
1776
  int32_t         numDropIpRanges;
1777
  int32_t         numDropTimeRanges;
1778
  SIpRange*       pIpRanges;
1779
  SDateTimeRange* pTimeRanges;
1780
  SIpRange*       pDropIpRanges;
1781
  SDateTimeRange* pDropTimeRanges;
1782
  SPrivSet        privileges;
1783

1784
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1785
  char        tabName[TSDB_TABLE_NAME_LEN];
1786
  char*       tagCond;
1787
  int32_t     tagCondLen;
1788
  int32_t     sqlLen;
1789
  char*       sql;
1790
} SAlterUserReq;
1791

1792
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1793
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1794
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1795

1796
typedef struct {
1797
  char    name[TSDB_TOKEN_NAME_LEN];
1798
  char    user[TSDB_USER_LEN];
1799
  int8_t  enable;
1800
  int8_t  ignoreExists;
1801
  int32_t ttl;
1802
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1803
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1804

1805
  int32_t sqlLen;
1806
  char*   sql;
1807
} SCreateTokenReq;
1808

1809
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1810
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1811
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1812

1813
typedef struct {
1814
  char name[TSDB_TOKEN_NAME_LEN];
1815
  char user[TSDB_USER_LEN];
1816
  char token[TSDB_TOKEN_LEN];
1817
} SCreateTokenRsp;
1818

1819
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1820
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1821
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1822

1823
typedef struct {
1824
  char    name[TSDB_TOKEN_NAME_LEN];
1825

1826
  int8_t hasEnable;
1827
  int8_t hasTtl;
1828
  int8_t hasProvider;
1829
  int8_t hasExtraInfo;
1830

1831
  int8_t  enable;
1832
  int32_t ttl;
1833
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1834
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1835

1836
  int32_t     sqlLen;
1837
  char*       sql;
1838
} SAlterTokenReq;
1839

1840
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1841
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1842
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1843

1844
typedef struct {
1845
  char    name[TSDB_TOKEN_NAME_LEN];
1846
  int8_t  ignoreNotExists;
1847
  int32_t sqlLen;
1848
  char*   sql;
1849
} SDropTokenReq;
1850

1851
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1852
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1853
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1854

1855
typedef struct {
1856
  char    user[TSDB_USER_LEN];
1857
  int32_t sqlLen;
1858
  char*   sql;
1859
} SCreateTotpSecretReq;
1860

1861
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1862
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1863
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1864

1865
typedef struct {
1866
  char user[TSDB_USER_LEN];
1867
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1868
} SCreateTotpSecretRsp;
1869

1870
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1871
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1872

1873
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1874
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1875
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1876
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1877

1878
typedef struct {
1879
  char user[TSDB_USER_LEN];
1880
} SGetUserAuthReq;
1881

1882
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1883
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1884

1885
typedef struct {
1886
  int8_t  enabled;
1887
  int32_t expireTime;
1888
} STokenStatus;
1889

1890
typedef struct {
1891
  char    user[TSDB_USER_LEN];
1892
  int64_t userId;
1893
  int32_t version;
1894
  int32_t passVer;
1895
  int8_t  superAuth;
1896
  int8_t  sysInfo;
1897
  int8_t  enable;
1898
  int8_t  dropped;
1899
  union {
1900
    uint8_t flags;
1901
    struct {
1902
      uint8_t minSecLevel    : 3;
1903
      uint8_t withInsertCond : 1;
1904
      uint8_t maxSecLevel    : 3;
1905
      uint8_t reserved       : 1;
1906
    };
1907
  };
1908
  SPrivSet  sysPrivs;
1909
  SHashObj* objPrivs;
1910
  SHashObj* selectTbs;
1911
  SHashObj* insertTbs;
1912
  SHashObj* deleteTbs;
1913
  SHashObj* ownedDbs;
1914
  int64_t   whiteListVer;
1915

1916
  SUserSessCfg sessCfg;
1917
  int64_t      timeWhiteListVer;
1918
  SHashObj*    tokens;
1919
} SGetUserAuthRsp;
1920

1921
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1922
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1923
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1924

1925
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1926
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1927
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1928
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1929

1930
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1931
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1932
typedef struct {
1933
  int64_t ver;
1934
  char    user[TSDB_USER_LEN];
1935
  int32_t numOfRange;
1936
  union {
1937
    SIpV4Range* pIpRanges;
1938
    SIpRange*   pIpDualRanges;
1939
  };
1940
} SUpdateUserIpWhite;
1941

1942
typedef struct {
1943
  int64_t             ver;
1944
  int                 numOfUser;
1945
  SUpdateUserIpWhite* pUserIpWhite;
1946
} SUpdateIpWhite;
1947

1948
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1949
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1950
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1951
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1952

1953
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1954
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1955
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1956

1957

1958
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1959
// corresponding response struct is different.
1960
typedef struct {
1961
  int64_t ver;
1962
} SRetrieveWhiteListReq;
1963

1964
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1965
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1966

1967

1968
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1969
// corresponding response struct is different.
1970
typedef struct {
1971
  char user[TSDB_USER_LEN];
1972
} SGetUserWhiteListReq;
1973

1974
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1975
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1976

1977
typedef struct {
1978
  char    user[TSDB_USER_LEN];
1979
  int32_t numWhiteLists;
1980
  union {
1981
    SIpV4Range* pWhiteLists;
1982
    SIpRange*   pWhiteListsDual;
1983
  };
1984
} SGetUserIpWhiteListRsp;
1985

1986
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1987
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1988
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1989
void    tIpRangeSetDefaultMask(SIpRange* range);
1990

1991
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1992
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1993
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1994

1995
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1996
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1997
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1998

1999
typedef struct {
2000
  int64_t ver;
2001
  char    user[TSDB_USER_LEN];
2002
  int32_t numWhiteLists;
2003
  SDateTimeWhiteListItem* pWhiteLists;
2004
} SUserDateTimeWhiteList;
2005

2006

2007
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
2008
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
2009
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
2010
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
2011

2012
typedef struct {
2013
  int64_t             ver;
2014
  int                 numOfUser;
2015
  SUserDateTimeWhiteList *pUsers;
2016
} SRetrieveDateTimeWhiteListRsp;
2017

2018
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
2019
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
2020
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
2021
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
2022

2023
/*
2024
 * for client side struct, only column id, type, bytes are necessary
2025
 * But for data in vnode side, we need all the following information.
2026
 */
2027
typedef struct {
2028
  union {
2029
    col_id_t colId;
2030
    int16_t  slotId;
2031
  };
2032

2033
  uint8_t precision;
2034
  uint8_t scale;
2035
  int32_t bytes;
2036
  int8_t  type;
2037
  uint8_t pk;
2038
  bool    noData;
2039
} SColumnInfo;
2040

2041
typedef struct STimeWindow {
2042
  TSKEY skey;
2043
  TSKEY ekey;
2044
} STimeWindow;
2045

2046
typedef struct SQueryHint {
2047
  bool batchScan;
2048
} SQueryHint;
2049

2050
typedef struct {
2051
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2052
  int32_t tsLen;          // total length of ts comp block
2053
  int32_t tsNumOfBlocks;  // ts comp block numbers
2054
  int32_t tsOrder;        // ts comp block order
2055
} STsBufInfo;
2056

2057
typedef struct {
2058
  void*       timezone;
2059
  char        intervalUnit;
2060
  char        slidingUnit;
2061
  char        offsetUnit;
2062
  int8_t      precision;
2063
  int64_t     interval;
2064
  int64_t     sliding;
2065
  int64_t     offset;
2066
  STimeWindow timeRange;
2067
} SInterval;
2068

2069
typedef struct STbVerInfo {
2070
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2071
  int32_t sversion;
2072
  int32_t tversion;
2073
  int32_t rversion;  // virtual table's column ref's version
2074
} STbVerInfo;
2075

2076
typedef struct {
2077
  int32_t code;
2078
  int64_t affectedRows;
2079
  SArray* tbVerInfo;  // STbVerInfo
2080
} SQueryTableRsp;
2081

2082
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2083

2084
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2085

2086
typedef struct {
2087
  SMsgHead header;
2088
  char     dbFName[TSDB_DB_FNAME_LEN];
2089
  char     tbName[TSDB_TABLE_NAME_LEN];
2090
} STableCfgReq;
2091

2092
typedef struct {
2093
  char        tbName[TSDB_TABLE_NAME_LEN];
2094
  char        stbName[TSDB_TABLE_NAME_LEN];
2095
  char        dbFName[TSDB_DB_FNAME_LEN];
2096
  int32_t     numOfTags;
2097
  int32_t     numOfColumns;
2098
  int8_t      tableType;
2099
  int64_t     delay1;
2100
  int64_t     delay2;
2101
  int64_t     watermark1;
2102
  int64_t     watermark2;
2103
  int32_t     ttl;
2104
  int32_t     keep;
2105
  int64_t     ownerId;
2106
  SArray*     pFuncs;
2107
  int32_t     commentLen;
2108
  char*       pComment;
2109
  SSchema*    pSchemas;
2110
  int32_t     tagsLen;
2111
  char*       pTags;
2112
  SSchemaExt* pSchemaExt;
2113
  union {
2114
    uint8_t flag;
2115
    struct {
2116
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2117
      uint8_t isAudit : 1;
2118
      uint8_t securityLevel : 3;
2119
      uint8_t reserve : 3;
2120
    };
2121
  };
2122
  SColRef* pColRefs;
2123
  int32_t  numOfTagRefs;
2124
  SColRef* pTagRefs;
2125
  int8_t   secureDelete;
2126
} STableCfg;
2127

2128
typedef STableCfg STableCfgRsp;
2129

2130
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2131
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2132

2133
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2134
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2135
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2136

2137
typedef struct {
2138
  SMsgHead header;
2139
  tb_uid_t suid;
2140
} SVSubTablesReq;
2141

2142
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2143
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2144

2145
typedef struct {
2146
  int32_t vgId;
2147
  SArray* pTables;  // SArray<SVCTableRefCols*>
2148
} SVSubTablesRsp;
2149

2150
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2151
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2152
void    tDestroySVSubTablesRsp(void* rsp);
2153

2154
typedef struct {
2155
  SMsgHead header;
2156
  tb_uid_t suid;
2157
} SVStbRefDbsReq;
2158

2159
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2160
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2161

2162
typedef struct {
2163
  int32_t vgId;
2164
  SArray* pDbs;  // SArray<char* (db name)>
2165
} SVStbRefDbsRsp;
2166

2167
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2168
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2169
void    tDestroySVStbRefDbsRsp(void* rsp);
2170

2171
typedef struct {
2172
  char    db[TSDB_DB_FNAME_LEN];
2173
  int32_t numOfVgroups;
2174
  int32_t numOfStables;  // single_stable
2175
  int32_t buffer;        // MB
2176
  int32_t pageSize;
2177
  int32_t pages;
2178
  int32_t cacheLastSize;
2179
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2180
  int32_t daysPerFile;
2181
  int32_t daysToKeep0;
2182
  int32_t daysToKeep1;
2183
  int32_t daysToKeep2;
2184
  int32_t keepTimeOffset;
2185
  int32_t minRows;
2186
  int32_t maxRows;
2187
  int32_t walFsyncPeriod;
2188
  int8_t  walLevel;
2189
  int8_t  precision;  // time resolution
2190
  int8_t  compression;
2191
  int8_t  replications;
2192
  int8_t  strict;
2193
  int8_t  cacheLast;
2194
  int8_t  schemaless;
2195
  int8_t  ignoreExist;
2196
  int32_t numOfRetensions;
2197
  SArray* pRetensions;  // SRetention
2198
  int32_t walRetentionPeriod;
2199
  int64_t walRetentionSize;
2200
  int32_t walRollPeriod;
2201
  int64_t walSegmentSize;
2202
  int32_t sstTrigger;
2203
  int16_t hashPrefix;
2204
  int16_t hashSuffix;
2205
  int32_t ssChunkSize;
2206
  int32_t ssKeepLocal;
2207
  int8_t  ssCompact;
2208
  int32_t tsdbPageSize;
2209
  int32_t sqlLen;
2210
  char*   sql;
2211
  int8_t  withArbitrator;
2212
  int8_t  encryptAlgorithm;
2213
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2214
  // 1. add auto-compact parameters
2215
  int32_t compactInterval;    // minutes
2216
  int32_t compactStartTime;   // minutes
2217
  int32_t compactEndTime;     // minutes
2218
  int8_t  compactTimeOffset;  // hour
2219
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2220
  int8_t  isAudit;
2221
  int8_t  allowDrop;
2222
  int8_t  secureDelete;
2223
  int8_t  securityLevel;
2224
} SCreateDbReq;
2225

2226
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2227
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2228
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2229

2230
typedef struct {
2231
  char    db[TSDB_DB_FNAME_LEN];
2232
  int32_t buffer;
2233
  int32_t pageSize;
2234
  int32_t pages;
2235
  int32_t cacheLastSize;
2236
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2237
  int32_t daysPerFile;
2238
  int32_t daysToKeep0;
2239
  int32_t daysToKeep1;
2240
  int32_t daysToKeep2;
2241
  int32_t keepTimeOffset;
2242
  int32_t walFsyncPeriod;
2243
  int8_t  walLevel;
2244
  int8_t  strict;
2245
  int8_t  cacheLast;
2246
  int8_t  replications;
2247
  int32_t sstTrigger;
2248
  int32_t minRows;
2249
  int32_t walRetentionPeriod;
2250
  int32_t walRetentionSize;
2251
  int32_t ssKeepLocal;
2252
  int8_t  ssCompact;
2253
  int32_t sqlLen;
2254
  char*   sql;
2255
  int8_t  withArbitrator;
2256
  // 1. add auto-compact parameters
2257
  int32_t compactInterval;
2258
  int32_t compactStartTime;
2259
  int32_t compactEndTime;
2260
  int8_t  compactTimeOffset;
2261
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2262
  int8_t  isAudit;
2263
  int8_t  allowDrop;
2264
  int8_t  secureDelete;  
2265
  int8_t  securityLevel;
2266
} SAlterDbReq;
2267

2268
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2269
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2270
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2271

2272
typedef struct {
2273
  char    db[TSDB_DB_FNAME_LEN];
2274
  int8_t  ignoreNotExists;
2275
  int8_t  force;
2276
  int32_t sqlLen;
2277
  char*   sql;
2278
} SDropDbReq;
2279

2280
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2281
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2282
void    tFreeSDropDbReq(SDropDbReq* pReq);
2283

2284
typedef struct {
2285
  char    db[TSDB_DB_FNAME_LEN];
2286
  int64_t uid;
2287
} SDropDbRsp;
2288

2289
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2290
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2291

2292
typedef struct {
2293
  char    name[TSDB_MOUNT_NAME_LEN];
2294
  int64_t uid;
2295
} SDropMountRsp;
2296

2297
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2298
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2299

2300
typedef struct {
2301
  char    db[TSDB_DB_FNAME_LEN];
2302
  int64_t dbId;
2303
  int32_t vgVersion;
2304
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2305
  int64_t stateTs;     // ms
2306
} SUseDbReq;
2307

2308
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2309
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2310

2311
typedef struct {
2312
  char    db[TSDB_DB_FNAME_LEN];
2313
  int64_t uid;
2314
  int32_t vgVersion;
2315
  int32_t vgNum;
2316
  int16_t hashPrefix;
2317
  int16_t hashSuffix;
2318
  int8_t  hashMethod;
2319
  union {
2320
    uint8_t flags;
2321
    struct {
2322
      uint8_t isMount : 1;  // TS-5868
2323
      uint8_t padding : 7;
2324
    };
2325
  };
2326
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2327
  int32_t errCode;
2328
  int64_t stateTs;  // ms
2329
} SUseDbRsp;
2330

2331
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2332
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2333
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2334
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2335
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2336

2337
typedef struct {
2338
  char db[TSDB_DB_FNAME_LEN];
2339
} SDbCfgReq;
2340

2341
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2342
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2343

2344
typedef struct {
2345
  char db[TSDB_DB_FNAME_LEN];
2346
} SSsMigrateDbReq;
2347

2348
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2349
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2350

2351
typedef struct {
2352
  int32_t ssMigrateId;
2353
  bool    bAccepted;
2354
} SSsMigrateDbRsp;
2355

2356
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2357
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2358

2359
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2360
typedef struct {
2361
  int32_t ssMigrateId;
2362
} SListSsMigrateFileSetsReq;
2363

2364
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2365
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2366

2367
typedef struct {
2368
  int32_t ssMigrateId;
2369
  int32_t vgId;       // vgroup id
2370
  SArray* pFileSets;  // SArray<int32_t>
2371
} SListSsMigrateFileSetsRsp;
2372

2373
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2374
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2375
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2376

2377
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2378
typedef struct {
2379
  int32_t ssMigrateId;
2380
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2381
  int32_t fid;
2382
  int64_t startTimeSec;
2383
} SSsMigrateFileSetReq;
2384

2385
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2386
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2387

2388
typedef struct {
2389
  int32_t ssMigrateId;
2390
  int32_t nodeId;  // node id of the leader vnode
2391
  int32_t vgId;
2392
  int32_t fid;
2393
} SSsMigrateFileSetRsp;
2394

2395
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2396
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2397

2398
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2399
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2400
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2401
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2402
#define SSMIGRATE_FILESET_STATE_FAILED      4
2403

2404
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2405
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2406
// while as a request, the 'state' field is not used.
2407
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2408
typedef struct {
2409
  int32_t ssMigrateId;  // ss migrate id
2410
  int32_t nodeId;       // node id of the leader vnode
2411
  int32_t vgId;         // vgroup id
2412
  int32_t fid;          // file set id
2413
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2414
} SSsMigrateProgress;
2415

2416
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2417
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2418

2419
// Request for TDMT_MND_KILL_SSMIGRATE
2420
typedef struct {
2421
  int32_t ssMigrateId;
2422
  int32_t sqlLen;
2423
  char*   sql;
2424
} SKillSsMigrateReq;
2425

2426
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2427
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2428
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2429

2430
// Request for TDMT_VND_KILL_SSMIGRATE
2431
typedef struct {
2432
  int32_t ssMigrateId;
2433
} SVnodeKillSsMigrateReq;
2434

2435
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2436
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2437

2438
typedef struct {
2439
  int32_t vgId;
2440
  int64_t keepVersion;
2441
} SMndSetVgroupKeepVersionReq;
2442

2443
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2444
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2445

2446
typedef struct {
2447
  int32_t timestampSec;
2448
  int32_t ttlDropMaxCount;
2449
  int32_t nUids;
2450
  SArray* pTbUids;
2451
} SVDropTtlTableReq;
2452

2453
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2454
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2455

2456
typedef struct {
2457
  char    db[TSDB_DB_FNAME_LEN];
2458
  int64_t dbId;
2459
  int64_t ownerId;
2460
  int32_t cfgVersion;
2461
  int32_t numOfVgroups;
2462
  int32_t numOfStables;
2463
  int32_t buffer;
2464
  int32_t cacheSize;
2465
  int32_t cacheShardBits;
2466
  int32_t pageSize;
2467
  int32_t pages;
2468
  int32_t daysPerFile;
2469
  int32_t daysToKeep0;
2470
  int32_t daysToKeep1;
2471
  int32_t daysToKeep2;
2472
  int32_t keepTimeOffset;
2473
  int32_t minRows;
2474
  int32_t maxRows;
2475
  int32_t walFsyncPeriod;
2476
  int16_t hashPrefix;
2477
  int16_t hashSuffix;
2478
  int8_t  hashMethod;
2479
  int8_t  walLevel;
2480
  int8_t  precision;
2481
  int8_t  compression;
2482
  int8_t  replications;
2483
  int8_t  strict;
2484
  int8_t  cacheLast;
2485
  int8_t  encryptAlgr;
2486
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2487
  int32_t ssChunkSize;
2488
  int32_t ssKeepLocal;
2489
  int8_t  ssCompact;
2490
  union {
2491
    uint8_t flags;
2492
    struct {
2493
      uint8_t isMount : 1;    // TS-5868
2494
      uint8_t allowDrop : 1;  // TS-7232
2495
      uint8_t securityLevel : 3;   // 6671585124
2496
      uint8_t padding : 3;
2497
    };
2498
  };
2499
  int8_t  compactTimeOffset;
2500
  int32_t compactInterval;
2501
  int32_t compactStartTime;
2502
  int32_t compactEndTime;
2503
  int32_t tsdbPageSize;
2504
  int32_t walRetentionPeriod;
2505
  int32_t walRollPeriod;
2506
  int64_t walRetentionSize;
2507
  int64_t walSegmentSize;
2508
  int32_t numOfRetensions;
2509
  SArray* pRetensions;
2510
  int8_t  schemaless;
2511
  int16_t sstTrigger;
2512
  int8_t  withArbitrator;
2513
  int8_t  isAudit;
2514
  int8_t  secureDelete;
2515
} SDbCfgRsp;
2516

2517
typedef SDbCfgRsp SDbCfgInfo;
2518

2519
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2520
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2521
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2522
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2523
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2524

2525
typedef struct {
2526
  int32_t rowNum;
2527
} SQnodeListReq;
2528

2529
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2530
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2531

2532
typedef struct {
2533
  int32_t rowNum;
2534
} SDnodeListReq;
2535

2536
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2537

2538
typedef struct {
2539
  int32_t useless;  // useless
2540
} SServerVerReq;
2541

2542
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2543
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2544

2545
typedef struct {
2546
  char ver[TSDB_VERSION_LEN];
2547
} SServerVerRsp;
2548

2549
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2550
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2551

2552
typedef struct SQueryNodeAddr {
2553
  int32_t nodeId;  // vgId or qnodeId
2554
  SEpSet  epSet;
2555
} SQueryNodeAddr;
2556

2557
typedef struct {
2558
  SQueryNodeAddr addr;
2559
  uint64_t       load;
2560
} SQueryNodeLoad;
2561

2562
typedef struct {
2563
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2564
} SQnodeListRsp;
2565

2566
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2567
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2568
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2569

2570

2571
typedef struct SDownstreamSourceNode {
2572
  ENodeType      type;
2573
  SQueryNodeAddr addr;
2574
  uint64_t       clientId;
2575
  uint64_t       taskId;
2576
  uint64_t       sId;
2577
  uint64_t       srcTaskId;
2578
  int32_t        execId;
2579
  int32_t        fetchMsgType;
2580
  bool           localExec;
2581
} SDownstreamSourceNode;
2582

2583

2584

2585
typedef struct SDNodeAddr {
2586
  int32_t nodeId;  // dnodeId
2587
  SEpSet  epSet;
2588
} SDNodeAddr;
2589

2590
typedef struct {
2591
  SArray* dnodeList;  // SArray<SDNodeAddr>
2592
} SDnodeListRsp;
2593

2594
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2595
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2596
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2597

2598
typedef struct {
2599
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2600
} STableTSMAInfoRsp;
2601

2602
typedef struct {
2603
  SUseDbRsp*         useDbRsp;
2604
  SDbCfgRsp*         cfgRsp;
2605
  STableTSMAInfoRsp* pTsmaRsp;
2606
  int32_t            dbTsmaVersion;
2607
  char               db[TSDB_DB_FNAME_LEN];
2608
  int64_t            dbId;
2609
} SDbHbRsp;
2610

2611
typedef struct {
2612
  SArray* pArray;  // Array of SDbHbRsp
2613
} SDbHbBatchRsp;
2614

2615
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2616
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2617
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2618

2619
typedef struct {
2620
  SArray* pArray;  // Array of SGetUserAuthRsp
2621
} SUserAuthBatchRsp;
2622

2623
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2624
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2625
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2626

2627
typedef struct {
2628
  char        db[TSDB_DB_FNAME_LEN];
2629
  STimeWindow timeRange;
2630
  int32_t     sqlLen;
2631
  char*       sql;
2632
  SArray*     vgroupIds;
2633
  int32_t     compactId;
2634
  int8_t      metaOnly;
2635
  int8_t      force;
2636
} SCompactDbReq;
2637

2638
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2639
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2640
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2641

2642
typedef struct {
2643
  union {
2644
    int32_t compactId;
2645
    int32_t id;
2646
  };
2647
  int8_t bAccepted;
2648
} SCompactDbRsp;
2649

2650
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2651
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2652

2653
typedef struct {
2654
  union {
2655
    int32_t compactId;
2656
    int32_t id;
2657
  };
2658
  int32_t sqlLen;
2659
  char*   sql;
2660
} SKillCompactReq;
2661

2662
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2663
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2664
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2665

2666
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2667
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2668

2669
typedef struct {
2670
  char    name[TSDB_FUNC_NAME_LEN];
2671
  int8_t  igExists;
2672
  int8_t  funcType;
2673
  int8_t  scriptType;
2674
  int8_t  outputType;
2675
  int32_t outputLen;
2676
  int32_t bufSize;
2677
  int32_t codeLen;
2678
  int64_t signature;
2679
  char*   pComment;
2680
  char*   pCode;
2681
  int8_t  orReplace;
2682
} SCreateFuncReq;
2683

2684
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2685
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2686
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2687

2688
typedef struct {
2689
  char   name[TSDB_FUNC_NAME_LEN];
2690
  int8_t igNotExists;
2691
} SDropFuncReq;
2692

2693
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2694
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2695

2696
typedef struct {
2697
  int32_t numOfFuncs;
2698
  bool    ignoreCodeComment;
2699
  SArray* pFuncNames;
2700
} SRetrieveFuncReq;
2701

2702
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2703
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2704
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2705

2706
typedef struct {
2707
  char    name[TSDB_FUNC_NAME_LEN];
2708
  int8_t  funcType;
2709
  int8_t  scriptType;
2710
  int8_t  outputType;
2711
  int32_t outputLen;
2712
  int32_t bufSize;
2713
  int64_t signature;
2714
  int32_t commentSize;
2715
  int32_t codeSize;
2716
  char*   pComment;
2717
  char*   pCode;
2718
} SFuncInfo;
2719

2720
typedef struct {
2721
  int32_t funcVersion;
2722
  int64_t funcCreatedTime;
2723
} SFuncExtraInfo;
2724

2725
typedef struct {
2726
  int32_t numOfFuncs;
2727
  SArray* pFuncInfos;
2728
  SArray* pFuncExtraInfos;
2729
} SRetrieveFuncRsp;
2730

2731
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2732
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2733
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2734
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2735

2736
typedef struct {
2737
  int32_t       statusInterval;
2738
  /*
2739
    Local timezone UTC offset in seconds (east-positive, e.g. +28800 for
2740
    Asia/Shanghai).  Derived from taosGetLocalTimezoneOffset() on each
2741
    status report.  Paired with the timezone string in
2742
    mndCheckClusterCfgPara: a mismatch is reported only when both the
2743
    timezone string AND this offset differ.
2744
  */
2745
  int64_t       checkTime;
2746
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2747
  char          locale[TD_LOCALE_LEN];      // tsLocale
2748
  char          charset[TD_LOCALE_LEN];     // tsCharset
2749
  int8_t        ttlChangeOnWrite;
2750
  int8_t        enableWhiteList;
2751
  int8_t        encryptionKeyStat;
2752
  uint32_t      encryptionKeyChksum;
2753
  SMonitorParas monitorParas;
2754
  int32_t       statusIntervalMs;
2755
} SClusterCfg;
2756

2757
typedef struct {
2758
  int32_t openVnodes;
2759
  int32_t dropVnodes;
2760
  int32_t totalVnodes;
2761
  int32_t masterNum;
2762
  int64_t numOfSelectReqs;
2763
  int64_t numOfInsertReqs;
2764
  int64_t numOfInsertSuccessReqs;
2765
  int64_t numOfBatchInsertReqs;
2766
  int64_t numOfBatchInsertSuccessReqs;
2767
  int64_t errors;
2768
} SVnodesStat;
2769

2770
typedef struct {
2771
  int32_t vgId;
2772
  int8_t  syncState;
2773
  int8_t  syncRestore;
2774
  int64_t syncTerm;
2775
  int64_t roleTimeMs;
2776
  int64_t startTimeMs;
2777
  int8_t  syncCanRead;
2778
  int64_t cacheUsage;
2779
  int64_t numOfTables;
2780
  int64_t numOfTimeSeries;
2781
  int64_t totalStorage;
2782
  int64_t compStorage;
2783
  int64_t pointsWritten;
2784
  int64_t numOfSelectReqs;
2785
  int64_t numOfInsertReqs;
2786
  int64_t numOfInsertSuccessReqs;
2787
  int64_t numOfBatchInsertReqs;
2788
  int64_t numOfBatchInsertSuccessReqs;
2789
  int32_t numOfCachedTables;
2790
  int32_t learnerProgress;  // use one reservered
2791
  int64_t syncAppliedIndex;
2792
  int64_t syncCommitIndex;
2793
  int64_t bufferSegmentUsed;
2794
  int64_t bufferSegmentSize;
2795
  int32_t snapSeq;
2796
  int64_t syncTotalIndex;
2797
} SVnodeLoad;
2798

2799
typedef struct {
2800
  int64_t total_requests;
2801
  int64_t total_rows;
2802
  int64_t total_bytes;
2803
  double  write_size;
2804
  double  cache_hit_ratio;
2805
  int64_t rpc_queue_wait;
2806
  int64_t preprocess_time;
2807

2808
  int64_t memory_table_size;
2809
  int64_t commit_count;
2810
  int64_t merge_count;
2811
  double  commit_time;
2812
  double  merge_time;
2813
  int64_t block_commit_time;
2814
  int64_t memtable_wait_time;
2815
} SVnodeMetrics;
2816

2817
typedef struct {
2818
  int32_t     vgId;
2819
  int64_t     numOfTables;
2820
  int64_t     memSize;
2821
  int64_t     l1Size;
2822
  int64_t     l2Size;
2823
  int64_t     l3Size;
2824
  int64_t     cacheSize;
2825
  int64_t     walSize;
2826
  int64_t     metaSize;
2827
  int64_t     rawDataSize;
2828
  int64_t     ssSize;
2829
  const char* dbname;
2830
  int8_t      estimateRawData;
2831
} SDbSizeStatisInfo;
2832

2833
typedef struct {
2834
  int32_t vgId;
2835
  int64_t nTimeSeries;
2836
} SVnodeLoadLite;
2837

2838
typedef struct {
2839
  int8_t  syncState;
2840
  int64_t syncTerm;
2841
  int8_t  syncRestore;
2842
  int64_t roleTimeMs;
2843
} SMnodeLoad;
2844

2845
typedef struct {
2846
  int32_t dnodeId;
2847
  int64_t numOfProcessedQuery;
2848
  int64_t numOfProcessedCQuery;
2849
  int64_t numOfProcessedFetch;
2850
  int64_t numOfProcessedDrop;
2851
  int64_t numOfProcessedNotify;
2852
  int64_t numOfProcessedHb;
2853
  int64_t numOfProcessedDelete;
2854
  int64_t cacheDataSize;
2855
  int64_t numOfQueryInQueue;
2856
  int64_t numOfFetchInQueue;
2857
  int64_t timeInQueryQueue;
2858
  int64_t timeInFetchQueue;
2859
} SQnodeLoad;
2860

2861
typedef struct {
2862
  int32_t     sver;      // software version
2863
  int64_t     dnodeVer;  // dnode table version in sdb
2864
  int32_t     dnodeId;
2865
  int64_t     clusterId;
2866
  int64_t     rebootTime;
2867
  int64_t     updateTime;
2868
  float       numOfCores;
2869
  int32_t     numOfSupportVnodes;
2870
  int32_t     numOfDiskCfg;
2871
  int64_t     memTotal;
2872
  int64_t     memAvail;
2873
  char        dnodeEp[TSDB_EP_LEN];
2874
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2875
  SMnodeLoad  mload;
2876
  SQnodeLoad  qload;
2877
  SClusterCfg clusterCfg;
2878
  SArray*     pVloads;  // array of SVnodeLoad
2879
  int32_t     statusSeq;
2880
  int64_t     ipWhiteVer;
2881
  int64_t     timeWhiteVer;
2882
  int64_t     analVer;
2883
  int64_t     timestamp;
2884
  char        auditDB[TSDB_DB_FNAME_LEN];
2885
  char        auditToken[TSDB_TOKEN_LEN];
2886
  SEpSet      auditEpSet;
2887
  int32_t     auditVgId;
2888
} SStatusReq;
2889

2890
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2891
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2892
void    tFreeSStatusReq(SStatusReq* pReq);
2893

2894
typedef struct {
2895
  int32_t forceReadConfig;
2896
  int32_t cver;
2897
  SArray* array;
2898
} SConfigReq;
2899

2900
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2901
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2902
void    tFreeSConfigReq(SConfigReq* pReq);
2903

2904
typedef struct {
2905
  int32_t dnodeId;
2906
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2907
} SDnodeInfoReq;
2908

2909
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2910
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2911

2912
typedef enum {
2913
  MONITOR_TYPE_COUNTER = 0,
2914
  MONITOR_TYPE_SLOW_LOG = 1,
2915
} MONITOR_TYPE;
2916

2917
typedef struct {
2918
  int32_t      contLen;
2919
  char*        pCont;
2920
  MONITOR_TYPE type;
2921
} SStatisReq;
2922

2923
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2924
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2925
void    tFreeSStatisReq(SStatisReq* pReq);
2926

2927
typedef struct {
2928
  char    db[TSDB_DB_FNAME_LEN];
2929
  char    table[TSDB_TABLE_NAME_LEN];
2930
  char    operation[AUDIT_OPERATION_LEN];
2931
  int32_t sqlLen;
2932
  char*   pSql;
2933
  double  duration;
2934
  int64_t affectedRows;
2935
} SAuditReq;
2936
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2937
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2938
void    tFreeSAuditReq(SAuditReq* pReq);
2939

2940
typedef struct {
2941
  SArray* auditArr;
2942
} SBatchAuditReq;
2943
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2944
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2945
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2946

2947
typedef struct {
2948
  int32_t dnodeId;
2949
  int64_t clusterId;
2950
  SArray* pVloads;
2951
} SNotifyReq;
2952

2953
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2954
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2955
void    tFreeSNotifyReq(SNotifyReq* pReq);
2956

2957
typedef struct {
2958
  int32_t dnodeId;
2959
  int64_t clusterId;
2960
} SDnodeCfg;
2961

2962
typedef struct {
2963
  int32_t id;
2964
  int8_t  isMnode;
2965
  SEp     ep;
2966
} SDnodeEp;
2967

2968
typedef struct {
2969
  int32_t id;
2970
  int8_t  isMnode;
2971
  int8_t  offlineReason;
2972
  SEp     ep;
2973
  char    active[TSDB_ACTIVE_KEY_LEN];
2974
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2975
} SDnodeInfo;
2976

2977
typedef struct {
2978
  int64_t   dnodeVer;
2979
  SDnodeCfg dnodeCfg;
2980
  SArray*   pDnodeEps;  // Array of SDnodeEp
2981
  int32_t   statusSeq;
2982
  int64_t   ipWhiteVer;
2983
  int64_t   analVer;
2984
  int64_t   timeWhiteVer;
2985
  char      auditDB[TSDB_DB_FNAME_LEN];
2986
  char      auditToken[TSDB_TOKEN_LEN];
2987
  SEpSet    auditEpSet;
2988
  int32_t   auditVgId;
2989
} SStatusRsp;
2990

2991
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2992
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2993
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2994

2995
typedef struct {
2996
  int32_t forceReadConfig;
2997
  int32_t isConifgVerified;
2998
  int32_t isVersionVerified;
2999
  int32_t cver;
3000
  SArray* array;
3001
} SConfigRsp;
3002

3003
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
3004
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
3005
void    tFreeSConfigRsp(SConfigRsp* pRsp);
3006

3007
typedef struct {
3008
  int32_t dnodeId;
3009
  int32_t keyVersion;  // Local key version
3010
} SKeySyncReq;
3011

3012
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
3013
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
3014

3015
typedef struct {
3016
  int32_t keyVersion;        // mnode's key version
3017
  int8_t  needUpdate;        // 1 if dnode needs to update keys
3018
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
3019
  char    svrKey[129];       // Server key (if needUpdate)
3020
  char    dbKey[129];        // Database key (if needUpdate)
3021
  char    cfgKey[129];       // Config key (if needUpdate)
3022
  char    metaKey[129];      // Metadata key (if needUpdate)
3023
  char    dataKey[129];      // Data key (if needUpdate)
3024
  int32_t algorithm;         // Encryption algorithm for master keys
3025
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
3026
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
3027
  int64_t createTime;        // Key creation time
3028
  int64_t svrKeyUpdateTime;  // Server key update time
3029
  int64_t dbKeyUpdateTime;   // Database key update time
3030
} SKeySyncRsp;
3031

3032
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3033
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3034

3035
typedef struct {
3036
  int32_t reserved;
3037
} SMTimerReq;
3038

3039
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3040
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3041

3042
typedef struct SOrphanTask {
3043
  int64_t streamId;
3044
  int32_t taskId;
3045
  int32_t nodeId;
3046
} SOrphanTask;
3047

3048
typedef struct SMStreamDropOrphanMsg {
3049
  SArray* pList;  // SArray<SOrphanTask>
3050
} SMStreamDropOrphanMsg;
3051

3052
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3053
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3054
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
3055

3056
typedef struct {
3057
  int32_t  id;
3058
  uint16_t port;                 // node sync Port
3059
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3060
} SReplica;
3061

3062
typedef struct {
3063
  int32_t  vgId;
3064
  char     db[TSDB_DB_FNAME_LEN];
3065
  int64_t  dbUid;
3066
  int32_t  vgVersion;
3067
  int32_t  numOfStables;
3068
  int32_t  buffer;
3069
  int32_t  pageSize;
3070
  int32_t  pages;
3071
  int32_t  cacheLastSize;
3072
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3073
  int32_t  daysPerFile;
3074
  int32_t  daysToKeep0;
3075
  int32_t  daysToKeep1;
3076
  int32_t  daysToKeep2;
3077
  int32_t  keepTimeOffset;
3078
  int32_t  minRows;
3079
  int32_t  maxRows;
3080
  int32_t  walFsyncPeriod;
3081
  uint32_t hashBegin;
3082
  uint32_t hashEnd;
3083
  int8_t   hashMethod;
3084
  int8_t   walLevel;
3085
  int8_t   precision;
3086
  int8_t   compression;
3087
  int8_t   strict;
3088
  int8_t   cacheLast;
3089
  int8_t   isTsma;
3090
  int8_t   replica;
3091
  int8_t   selfIndex;
3092
  SReplica replicas[TSDB_MAX_REPLICA];
3093
  int32_t  numOfRetensions;
3094
  SArray*  pRetensions;  // SRetention
3095
  void*    pTsma;
3096
  int32_t  walRetentionPeriod;
3097
  int64_t  walRetentionSize;
3098
  int32_t  walRollPeriod;
3099
  int64_t  walSegmentSize;
3100
  int16_t  sstTrigger;
3101
  int16_t  hashPrefix;
3102
  int16_t  hashSuffix;
3103
  int32_t  tsdbPageSize;
3104
  int32_t  ssChunkSize;
3105
  int32_t  ssKeepLocal;
3106
  int8_t   ssCompact;
3107
  int64_t  reserved[6];
3108
  int8_t   learnerReplica;
3109
  int8_t   learnerSelfIndex;
3110
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3111
  int32_t  changeVersion;
3112
  int8_t   encryptAlgorithm;
3113
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3114
  union {
3115
    uint8_t flags;
3116
    struct {
3117
      uint8_t isAudit : 1;
3118
      uint8_t allowDrop : 1;
3119
      uint8_t securityLevel : 3;   // 6671585124
3120
      uint8_t padding : 3;
3121
    };
3122
  };
3123
  int8_t secureDelete;
3124
} SCreateVnodeReq;
3125

3126
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3127
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3128
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3129

3130
typedef struct {
3131
  union {
3132
    int32_t compactId;
3133
    int32_t id;
3134
  };
3135
  int32_t vgId;
3136
  int32_t dnodeId;
3137
} SQueryCompactProgressReq;
3138

3139
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3140
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3141

3142
typedef struct {
3143
  union {
3144
    int32_t compactId;
3145
    int32_t id;
3146
  };
3147
  int32_t vgId;
3148
  int32_t dnodeId;
3149
  int32_t numberFileset;
3150
  int32_t finished;
3151
  int32_t progress;
3152
  int64_t remainingTime;
3153
} SQueryCompactProgressRsp;
3154

3155
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3156
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3157

3158
typedef struct {
3159
  int32_t compactId;
3160
} SDnodeQueryCompactProgressReq;
3161

3162
int32_t tSerializeSDnodeQueryCompactProgressReq(void *buf, int32_t bufLen, SDnodeQueryCompactProgressReq *pReq);
3163
int32_t tDeserializeSDnodeQueryCompactProgressReq(void *buf, int32_t bufLen, SDnodeQueryCompactProgressReq *pReq);
3164

3165
typedef struct {
3166
  int32_t                   dnodeId;
3167
  int32_t                   numOfVnodes;
3168
  SQueryCompactProgressRsp *vnodeProgress;  // array of numOfVnodes elements
3169
} SDnodeQueryCompactProgressRsp;
3170

3171
int32_t tSerializeSDnodeQueryCompactProgressRsp(void *buf, int32_t bufLen, SDnodeQueryCompactProgressRsp *pRsp);
3172
int32_t tDeserializeSDnodeQueryCompactProgressRsp(void *buf, int32_t bufLen, SDnodeQueryCompactProgressRsp *pRsp);
3173
void    tFreeSDnodeQueryCompactProgressRsp(SDnodeQueryCompactProgressRsp *pRsp);
3174

3175
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3176
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3177

3178
typedef struct {
3179
  int32_t vgId;
3180
  int32_t dnodeId;
3181
  int64_t dbUid;
3182
  char    db[TSDB_DB_FNAME_LEN];
3183
  int64_t reserved[8];
3184
} SDropVnodeReq;
3185

3186
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3187
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3188

3189
typedef struct {
3190
  char    colName[TSDB_COL_NAME_LEN];
3191
  char    stb[TSDB_TABLE_FNAME_LEN];
3192
  int64_t stbUid;
3193
  int64_t dbUid;
3194
  int64_t reserved[8];
3195
} SDropIndexReq;
3196

3197
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3198
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3199

3200
typedef struct {
3201
  int64_t dbUid;
3202
  char    db[TSDB_DB_FNAME_LEN];
3203
  union {
3204
    int64_t compactStartTime;
3205
    int64_t startTime;
3206
  };
3207

3208
  STimeWindow tw;
3209
  union {
3210
    int32_t compactId;
3211
    int32_t id;
3212
  };
3213
  int8_t metaOnly;
3214
  union {
3215
    uint16_t flags;
3216
    struct {
3217
      uint16_t optrType : 3;     // ETsdbOpType
3218
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3219
      uint16_t reserved : 12;
3220
    };
3221
  };
3222
  int8_t force;  // force compact
3223
} SCompactVnodeReq;
3224

3225
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3226
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3227

3228
typedef struct {
3229
  union {
3230
    int32_t compactId;
3231
    int32_t taskId;
3232
  };
3233
  int32_t vgId;
3234
  int32_t dnodeId;
3235
} SVKillCompactReq;
3236

3237
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3238
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3239

3240
typedef SVKillCompactReq SVKillRetentionReq;
3241

3242
typedef struct {
3243
  char        db[TSDB_DB_FNAME_LEN];
3244
  int32_t     maxSpeed;
3245
  int32_t     sqlLen;
3246
  char*       sql;
3247
  SArray*     vgroupIds;
3248
  STimeWindow tw;  // unit is second
3249
  union {
3250
    uint32_t flags;
3251
    struct {
3252
      uint32_t optrType : 3;     // ETsdbOpType
3253
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3254
      uint32_t reserved : 28;
3255
    };
3256
  };
3257
} STrimDbReq;
3258

3259
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3260
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3261
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3262

3263
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3264

3265
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3266
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3267

3268
typedef struct {
3269
  int32_t vgVersion;
3270
  int32_t buffer;
3271
  int32_t pageSize;
3272
  int32_t pages;
3273
  int32_t cacheLastSize;
3274
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3275
  int32_t daysPerFile;
3276
  int32_t daysToKeep0;
3277
  int32_t daysToKeep1;
3278
  int32_t daysToKeep2;
3279
  int32_t keepTimeOffset;
3280
  int32_t walFsyncPeriod;
3281
  int8_t  walLevel;
3282
  int8_t  strict;
3283
  int8_t  cacheLast;
3284
  int64_t reserved[7];
3285
  // 1st modification
3286
  int16_t sttTrigger;
3287
  int32_t minRows;
3288
  // 2nd modification
3289
  int32_t walRetentionPeriod;
3290
  int32_t walRetentionSize;
3291
  int32_t ssKeepLocal;
3292
  int8_t  ssCompact;
3293
  int8_t  allowDrop;
3294
  int8_t  secureDelete;
3295
  int8_t  securityLevel;
3296
} SAlterVnodeConfigReq;
3297

3298
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3299
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3300

3301
typedef struct {
3302
  int32_t  vgId;
3303
  int8_t   strict;
3304
  int8_t   selfIndex;
3305
  int8_t   replica;
3306
  SReplica replicas[TSDB_MAX_REPLICA];
3307
  int64_t  reserved[8];
3308
  int8_t   learnerSelfIndex;
3309
  int8_t   learnerReplica;
3310
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3311
  int32_t  changeVersion;
3312
  int32_t  electBaseLine;
3313
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3314

3315
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3316
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3317

3318
typedef struct {
3319
  int32_t vgId;
3320
  int8_t  disable;
3321
} SDisableVnodeWriteReq;
3322

3323
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3324
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3325

3326
typedef struct {
3327
  int32_t  srcVgId;
3328
  int32_t  dstVgId;
3329
  uint32_t hashBegin;
3330
  uint32_t hashEnd;
3331
  int32_t  changeVersion;
3332
  int32_t  reserved;
3333
} SAlterVnodeHashRangeReq;
3334

3335
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3336
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3337

3338
#define REQ_OPT_TBNAME 0x0
3339
#define REQ_OPT_TBUID  0x01
3340
typedef struct {
3341
  SMsgHead header;
3342
  char     dbFName[TSDB_DB_FNAME_LEN];
3343
  char     tbName[TSDB_TABLE_NAME_LEN];
3344
  uint8_t  option;
3345
  uint8_t  autoCreateCtb;
3346
} STableInfoReq;
3347

3348
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3349
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3350

3351
typedef struct {
3352
  int8_t  metaClone;  // create local clone of the cached table meta
3353
  int32_t numOfVgroups;
3354
  int32_t numOfTables;
3355
  int32_t numOfUdfs;
3356
  char    tableNames[];
3357
} SMultiTableInfoReq;
3358

3359
// todo refactor
3360
typedef struct SVgroupInfo {
3361
  int32_t  vgId;
3362
  uint32_t hashBegin;
3363
  uint32_t hashEnd;
3364
  SEpSet   epSet;
3365
  union {
3366
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3367
    int32_t taskId;      // used in stream
3368
  };
3369
} SVgroupInfo;
3370

3371
typedef struct {
3372
  int32_t     numOfVgroups;
3373
  SVgroupInfo vgroups[];
3374
} SVgroupsInfo;
3375

3376
typedef struct {
3377
  STableMetaRsp* pMeta;
3378
} SMAlterStbRsp;
3379

3380
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3381
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3382
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3383

3384
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3385
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3386
void    tFreeSTableMetaRsp(void* pRsp);
3387
void    tFreeSTableIndexRsp(void* info);
3388

3389
typedef struct {
3390
  SArray* pMetaRsp;   // Array of STableMetaRsp
3391
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3392
} SSTbHbRsp;
3393

3394
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3395
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3396
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3397

3398
typedef struct {
3399
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3400
} SViewHbRsp;
3401

3402
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3403
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3404
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3405

3406
typedef struct {
3407
  int32_t numOfTables;
3408
  int32_t numOfVgroup;
3409
  int32_t numOfUdf;
3410
  int32_t contLen;
3411
  int8_t  compressed;  // denote if compressed or not
3412
  int32_t rawLen;      // size before compress
3413
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3414
  char    meta[];
3415
} SMultiTableMeta;
3416

3417
typedef struct {
3418
  int32_t dataLen;
3419
  char    name[TSDB_TABLE_FNAME_LEN];
3420
  char*   data;
3421
} STagData;
3422

3423
typedef struct {
3424
  int32_t  opType;
3425
  uint32_t valLen;
3426
  char*    val;
3427
} SShowVariablesReq;
3428

3429
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3430
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3431
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3432

3433
typedef struct {
3434
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3435
  char value[TSDB_CONFIG_PATH_LEN + 1];
3436
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3437
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3438
  char info[TSDB_CONFIG_INFO_LEN + 1];
3439
} SVariablesInfo;
3440

3441
typedef struct {
3442
  SArray* variables;  // SArray<SVariablesInfo>
3443
} SShowVariablesRsp;
3444

3445
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3446
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3447

3448
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3449

3450
/*
3451
 * sql: show tables like '%a_%'
3452
 * payload is the query condition, e.g., '%a_%'
3453
 * payloadLen is the length of payload
3454
 */
3455
typedef struct {
3456
  int32_t type;
3457
  char    db[TSDB_DB_FNAME_LEN];
3458
  int32_t payloadLen;
3459
  char*   payload;
3460
} SShowReq;
3461

3462
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3463
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3464
void tFreeSShowReq(SShowReq* pReq);
3465

3466
typedef struct {
3467
  int64_t       showId;
3468
  STableMetaRsp tableMeta;
3469
} SShowRsp, SVShowTablesRsp;
3470

3471
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3472
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3473
// void    tFreeSShowRsp(SShowRsp* pRsp);
3474

3475
typedef struct {
3476
  char    db[TSDB_DB_FNAME_LEN];
3477
  char    tb[TSDB_TABLE_NAME_LEN];
3478
  char    user[TSDB_USER_LEN];
3479
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3480
  int64_t showId;
3481
  int64_t compactId;  // for compact
3482
  bool    withFull;   // for show users full
3483
} SRetrieveTableReq;
3484

3485
typedef struct SSysTableSchema {
3486
  int8_t   type;
3487
  col_id_t colId;
3488
  int32_t  bytes;
3489
} SSysTableSchema;
3490

3491
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3492
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3493

3494
#define RETRIEVE_TABLE_RSP_VERSION         0
3495
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3496
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3497

3498
typedef struct {
3499
  int64_t useconds;
3500
  int8_t  completed;  // all results are returned to client
3501
  int8_t  precision;
3502
  int8_t  compressed;
3503
  int8_t  streamBlockType;
3504
  int32_t payloadLen;
3505
  int32_t compLen;
3506
  int32_t numOfBlocks;
3507
  int64_t numOfRows;  // from int32_t change to int64_t
3508
  int64_t numOfCols;
3509
  int64_t skey;
3510
  int64_t ekey;
3511
  int64_t version;                         // for stream
3512
  TSKEY   watermark;                       // for stream
3513
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3514
  char    data[];
3515
} SRetrieveTableRsp;
3516

3517
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3518

3519
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3520
  do {                                          \
3521
    ((int32_t*)(_p))[0] = (_compLen);           \
3522
    ((int32_t*)(_p))[1] = (_fullLen);           \
3523
  } while (0);
3524

3525
typedef struct {
3526
  int64_t version;
3527
  int64_t numOfRows;
3528
  int8_t  compressed;
3529
  int8_t  precision;
3530
  char    data[];
3531
} SRetrieveTableRspForTmq;
3532

3533
typedef struct {
3534
  int64_t handle;
3535
  int64_t useconds;
3536
  int8_t  completed;  // all results are returned to client
3537
  int8_t  precision;
3538
  int8_t  compressed;
3539
  int32_t compLen;
3540
  int32_t numOfRows;
3541
  int32_t fullLen;
3542
  char    data[];
3543
} SRetrieveMetaTableRsp;
3544

3545
typedef struct SExplainExecInfo {
3546
  /* the number of rows returned */
3547
  uint64_t numOfRows;
3548
  uint32_t verboseLen;
3549
  void*    verboseInfo;
3550

3551
  /* the timestamp when the operator is created */
3552
  TSKEY    execCreate;
3553
  /* the first timestamp when the operator's next interface is called */
3554
  TSKEY    execStart;
3555
  /* the timestamp when the first row is returned */
3556
  TSKEY    execFirstRow;
3557
  /* the timestamp when the last row is returned */
3558
  TSKEY    execLastRow;
3559
  /* the number of times the operator's next interface is called */
3560
  uint32_t execTimes;
3561
  /**
3562
    the time elapsed for executing the operator's next interface,
3563
    not including waiting time for data from downstream
3564
  */
3565
  TSKEY    execElapsed;
3566
  /* the time elapsed for waiting for data from downstream */
3567
  TSKEY    inputWaitElapsed;
3568
  /* the time elapsed for waiting call from upstream */
3569
  TSKEY    outputWaitElapsed;
3570
  /* the number of rows input */
3571
  uint64_t inputRows;
3572

3573
  int32_t  vgId;
3574
} SExplainExecInfo;
3575

3576
typedef struct {
3577
  int32_t           numOfPlans;
3578
  SExplainExecInfo* subplanInfo;
3579
} SExplainRsp;
3580

3581
typedef struct {
3582
  SExplainRsp rsp;
3583
  uint64_t    qId;
3584
  uint64_t    cId;
3585
  uint64_t    tId;
3586
  int64_t     rId;
3587
  int32_t     eId;
3588
} SExplainLocalRsp;
3589

3590
typedef struct STableScanAnalyzeInfo {
3591
  int64_t totalBlocks;
3592
  int64_t fileLoadBlocks;
3593
  double  fileLoadElapsed;
3594
  int64_t sttLoadBlocks;
3595
  double  sttLoadElapsed;
3596
  int64_t memLoadBlocks;
3597
  double  memLoadElapsed;
3598
  int64_t smaLoadBlocks;
3599
  double  smaLoadElapsed;
3600
  int64_t composedBlocks;
3601
  double  composedElapsed;
3602
  
3603
  uint64_t checkRows;
3604

3605
  uint64_t skipBlocks;
3606
  uint64_t filterOutBlocks;
3607
  double   filterTime;
3608
} STableScanAnalyzeInfo;
3609

3610
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3611
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3612
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3613

3614
typedef struct {
3615
  char    config[TSDB_DNODE_CONFIG_LEN];
3616
  char    value[TSDB_CLUSTER_VALUE_LEN];
3617
  int32_t sqlLen;
3618
  char*   sql;
3619
} SMCfgClusterReq;
3620

3621
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3622
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3623
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3624

3625
typedef struct {
3626
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3627
  int32_t port;
3628
  int32_t sqlLen;
3629
  char*   sql;
3630
} SCreateDnodeReq;
3631

3632
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3633
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3634
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3635

3636
typedef struct {
3637
  int32_t dnodeId;
3638
  char    fqdn[TSDB_FQDN_LEN];
3639
  int32_t port;
3640
  int8_t  force;
3641
  int8_t  unsafe;
3642
  int32_t sqlLen;
3643
  char*   sql;
3644
} SDropDnodeReq;
3645

3646
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3647
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3648
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3649

3650
enum {
3651
  RESTORE_TYPE__ALL = 1,
3652
  RESTORE_TYPE__MNODE,
3653
  RESTORE_TYPE__VNODE,
3654
  RESTORE_TYPE__QNODE,
3655
};
3656

3657
typedef struct {
3658
  int32_t dnodeId;
3659
  int8_t  restoreType;
3660
  int32_t sqlLen;
3661
  char*   sql;
3662
  int32_t vgId;
3663
} SRestoreDnodeReq;
3664

3665
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3666
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3667
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3668

3669
typedef struct {
3670
  int32_t dnodeId;
3671
  char    config[TSDB_DNODE_CONFIG_LEN];
3672
  char    value[TSDB_DNODE_VALUE_LEN];
3673
  int32_t sqlLen;
3674
  char*   sql;
3675
} SMCfgDnodeReq;
3676

3677
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3678
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3679
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3680

3681
typedef struct {
3682
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3683
  char    newKey[ENCRYPT_KEY_LEN + 1];
3684
  int32_t sqlLen;
3685
  char*   sql;
3686
} SMAlterEncryptKeyReq;
3687

3688
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3689
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3690
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3691

3692
typedef struct {
3693
  int32_t days;
3694
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3695
  int32_t sqlLen;
3696
  char*   sql;
3697
} SMAlterKeyExpirationReq;
3698

3699
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3700
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3701
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3702

3703
typedef struct {
3704
  char    config[TSDB_DNODE_CONFIG_LEN];
3705
  char    value[TSDB_DNODE_VALUE_LEN];
3706
  int32_t version;
3707
} SDCfgDnodeReq;
3708

3709
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3710
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3711

3712
typedef struct {
3713
  int32_t dnodeId;
3714
  int32_t sqlLen;
3715
  char*   sql;
3716
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3717
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3718

3719
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3720
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3721

3722
typedef struct {
3723
  int32_t nodeId;
3724
  SEpSet  epSet;
3725
} SNodeEpSet;
3726

3727
typedef struct {
3728
  int32_t    snodeId;
3729
  SNodeEpSet leaders[2];
3730
  SNodeEpSet replica;
3731
  int32_t    sqlLen;
3732
  char*      sql;
3733
} SDCreateSnodeReq;
3734

3735
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3736
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3737
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3738

3739
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3740
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3741
typedef struct {
3742
  int8_t   replica;
3743
  SReplica replicas[TSDB_MAX_REPLICA];
3744
  int8_t   learnerReplica;
3745
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3746
  int64_t  lastIndex;
3747
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3748
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3749

3750
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3751
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3752

3753
typedef struct {
3754
  int32_t urlLen;
3755
  int32_t sqlLen;
3756
  char*   url;
3757
  char*   sql;
3758
} SMCreateAnodeReq;
3759

3760
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3761
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3762
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3763

3764
typedef struct {
3765
  int32_t anodeId;
3766
  int32_t sqlLen;
3767
  char*   sql;
3768
} SMDropAnodeReq, SMUpdateAnodeReq;
3769

3770
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3771
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3772
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3773
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3774
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3775
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3776

3777
typedef struct {
3778
  int32_t dnodeId;
3779
  int32_t bnodeProto;
3780
  int32_t sqlLen;
3781
  char*   sql;
3782
} SMCreateBnodeReq, SDCreateBnodeReq;
3783

3784
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3785
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3786
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3787

3788
typedef struct {
3789
  int32_t dnodeId;
3790
  int32_t sqlLen;
3791
  char*   sql;
3792
} SMDropBnodeReq, SDDropBnodeReq;
3793

3794
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3795
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3796
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3797

3798
typedef struct {
3799
  bool        shouldFree;
3800
  int32_t     len;
3801
  const char* ptr;
3802
} CowStr;
3803
/**
3804
 * @brief Create a CowStr object.
3805
 *
3806
 * @param len: length of the string.
3807
 * @param ptr: pointer to the string input.
3808
 * @param shouldClone: whether to clone the string.
3809
 * @return CowStr object.
3810
 */
3811
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3812
/**
3813
 * @brief Set a CowStr object with given string.
3814
 *
3815
 * @param cow: pointer to the CowStr object.
3816
 * @param len: length of the string.
3817
 * @param ptr: pointer to the string input.
3818
 * @param shouldFree: whether to free the string.
3819
 */
3820
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3821
/**
3822
 * @brief Clone a CowStr object without copy the string.
3823
 *
3824
 * @param cow: pointer to the CowStr object.
3825
 * @return CowStr object.
3826
 */
3827
CowStr xCloneRefCowStr(CowStr* cow);
3828
/**
3829
 * @brief Convert a CowStr object to a string.
3830
 *
3831
 * @param cow: pointer to the CowStr object.
3832
 */
3833
char* xCowStrToStr(CowStr* cow);
3834
/**
3835
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3836
 *
3837
 * @param cow: pointer to the CowStr object.
3838
 */
3839
void xFreeCowStr(CowStr* cow);
3840
/**
3841
 * @brief Encode and push a CowStr object into the encoder.
3842
 *
3843
 * @param encoder
3844
 * @param cow
3845
 * @return int32_t
3846
 */
3847
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3848
/**
3849
 * @brief Decode a CowStr from the encoder.
3850
 *
3851
 * @param decoder
3852
 * @param cow
3853
 * @param shouldClone
3854
 * @return int32_t
3855
 */
3856
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3857

3858
typedef struct {
3859
  int32_t sqlLen;
3860
  int32_t urlLen;
3861
  int32_t userLen;
3862
  int32_t passLen;
3863
  int32_t passIsMd5;
3864
  char*   sql;
3865
  char*   url;
3866
  char*   user;
3867
  char*   pass;
3868
  CowStr  token;
3869
} SMCreateXnodeReq, SDCreateXnodeReq;
3870

3871
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3872
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3873
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3874

3875
typedef struct {
3876
  int32_t xnodeId;
3877
  int32_t force;
3878
  int32_t urlLen;
3879
  int32_t sqlLen;
3880
  char*   url;
3881
  char*   sql;
3882
} SMDropXnodeReq, SDDropXnodeReq;
3883

3884
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3885
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3886
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3887

3888
typedef struct {
3889
  int32_t id;
3890
  CowStr  token;
3891
  CowStr  user;
3892
  CowStr  pass;
3893
  int32_t urlLen;
3894
  int32_t sqlLen;
3895
  char*   url;
3896
  char*   sql;
3897
} SMUpdateXnodeReq;
3898
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3899
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3900
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3901

3902
typedef struct {
3903
  int32_t xnodeId;
3904
  int32_t sqlLen;
3905
  char*   sql;
3906
} SMDrainXnodeReq;
3907
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3908
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3909
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3910
typedef enum {
3911
  XNODE_TASK_SOURCE_DSN = 1,
3912
  XNODE_TASK_SOURCE_DATABASE,
3913
  XNODE_TASK_SOURCE_TOPIC,
3914
} ENodeXTaskSourceType;
3915

3916
typedef enum {
3917
  XNODE_TASK_SINK_DSN = 1,
3918
  XNODE_TASK_SINK_DATABASE,
3919
} ENodeXTaskSinkType;
3920

3921
typedef struct {
3922
  ENodeXTaskSourceType type;
3923
  CowStr               cstr;
3924
} xTaskSource;
3925
/**
3926
 * @brief Deallocate a xTaskSource object.
3927
 *
3928
 * @param source ptr
3929
 */
3930
void xFreeTaskSource(xTaskSource* source);
3931
/**
3932
 * @brief Create a xTaskSource object with cloned source string.
3933
 *
3934
 * @param sourceType: source type.
3935
 * @param len: length of source string.
3936
 * @param source: source string ptr.
3937
 * @return xTaskSource object
3938
 */
3939
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3940
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3941
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3942
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3943
const char* xGetTaskSourceStr(xTaskSource* source);
3944
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3945
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3946

3947
typedef struct {
3948
  ENodeXTaskSinkType type;
3949
  CowStr             cstr;
3950
} xTaskSink;
3951
/**
3952
 * @brief Deallocate a xTaskSink object.
3953
 *
3954
 * @param sink ptr
3955
 */
3956
void xFreeTaskSink(xTaskSink* sink);
3957
/**
3958
 * @brief Create a xTaskSink object with cloned name string.
3959
 *
3960
 * @param sinkType: sink type.
3961
 * @param len: length of sink string.
3962
 * @param ptr: sink string ptr.
3963
 * @return xTaskSink object
3964
 */
3965
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3966
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3967
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3968
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3969
const char* xGetTaskSinkStr(xTaskSink* sink);
3970
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3971
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3972

3973
typedef struct {
3974
  int32_t via;
3975
  CowStr  parser;
3976
  // CowStr  reason;
3977
  CowStr  trigger;
3978
  CowStr  health;
3979
  int32_t optionsNum;
3980
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3981
} xTaskOptions;
3982
/**
3983
 * @brief Deallocate a xTaskOptions object.
3984
 *
3985
 * @param options ptr
3986
 */
3987
void    xFreeTaskOptions(xTaskOptions* options);
3988
void    printXnodeTaskOptions(xTaskOptions* options);
3989
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3990
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3991

3992
typedef struct {
3993
  int32_t sqlLen;
3994
  char*   sql;
3995
  int32_t      xnodeId;
3996
  CowStr       name;
3997
  xTaskSource  source;
3998
  xTaskSink    sink;
3999
  xTaskOptions options;
4000
} SMCreateXnodeTaskReq;
4001
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
4002
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
4003
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
4004

4005
typedef struct {
4006
  int32_t     tid;
4007
  CowStr      name;
4008
  int32_t     via;
4009
  int32_t     xnodeId;
4010
  CowStr      status;
4011
  xTaskSource source;
4012
  xTaskSink   sink;
4013
  CowStr      parser;
4014
  CowStr      reason;
4015
  CowStr      updateName;
4016
  CowStr      labels;
4017
  int32_t     sqlLen;
4018
  char*       sql;
4019
} SMUpdateXnodeTaskReq;
4020
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
4021
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
4022
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
4023

4024
typedef struct {
4025
  int32_t id;
4026
  bool    force;
4027
  CowStr  name;
4028
  int32_t sqlLen;
4029
  char*   sql;
4030
} SMDropXnodeTaskReq;
4031
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
4032
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
4033
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
4034

4035
typedef struct {
4036
  int32_t tid;
4037
  CowStr  name;
4038
  int32_t sqlLen;
4039
  char*   sql;
4040
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
4041
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
4042
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
4043
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
4044

4045
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4046
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4047
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
4048

4049
typedef struct {
4050
  int32_t tid;
4051
  int32_t via;
4052
  int32_t xnodeId;
4053
  CowStr  status;
4054
  CowStr  config;
4055
  CowStr  reason;
4056
  int32_t sqlLen;
4057
  char*   sql;
4058
} SMCreateXnodeJobReq;
4059
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4060
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4061
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
4062

4063
typedef struct {
4064
  int32_t jid;
4065
  int32_t via;
4066
  int32_t xnodeId;
4067
  CowStr  status;
4068
  int32_t configLen;
4069
  int32_t reasonLen;
4070
  int32_t sqlLen;
4071
  char*   config;
4072
  char*   reason;
4073
  char*   sql;
4074
} SMUpdateXnodeJobReq;
4075
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4076
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4077
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4078

4079
typedef struct {
4080
  int32_t jid;
4081
  int32_t xnodeId;
4082
  int32_t sqlLen;
4083
  char*   sql;
4084
} SMRebalanceXnodeJobReq;
4085
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4086
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4087
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4088

4089
typedef struct {
4090
  CowStr  ast;
4091
  int32_t sqlLen;
4092
  char*   sql;
4093
} SMRebalanceXnodeJobsWhereReq;
4094
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4095
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4096
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4097

4098
typedef struct {
4099
  int32_t jid;
4100
  CowStr  ast;
4101
  int32_t sqlLen;
4102
  char*   sql;
4103
} SMDropXnodeJobReq;
4104
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4105
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4106
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4107

4108
typedef struct {
4109
  int32_t      sqlLen;
4110
  char*        sql;
4111
  CowStr       name;
4112
  CowStr       status;
4113
  xTaskOptions options;
4114
} SMCreateXnodeAgentReq;
4115
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4116
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4117
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4118

4119
typedef struct {
4120
  int32_t      sqlLen;
4121
  char*        sql;
4122
  int32_t      id;
4123
  CowStr       name;
4124
  xTaskOptions options;
4125
} SMUpdateXnodeAgentReq;
4126
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4127
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4128
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4129

4130
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4131
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4132
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4133
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4134

4135
typedef struct {
4136
  int32_t vgId;
4137
  int32_t hbSeq;
4138
} SVArbHbReqMember;
4139

4140
typedef struct {
4141
  int32_t dnodeId;
4142
  char*   arbToken;
4143
  int64_t arbTerm;
4144
  SArray* hbMembers;  // SVArbHbReqMember
4145
} SVArbHeartBeatReq;
4146

4147
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4148
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4149
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4150

4151
typedef struct {
4152
  int32_t vgId;
4153
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4154
  int32_t hbSeq;
4155
} SVArbHbRspMember;
4156

4157
typedef struct {
4158
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4159
  int32_t dnodeId;
4160
  SArray* hbMembers;  // SVArbHbRspMember
4161
} SVArbHeartBeatRsp;
4162

4163
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4164
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4165
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4166

4167
typedef struct {
4168
  char*   arbToken;
4169
  int64_t arbTerm;
4170
  char*   member0Token;
4171
  char*   member1Token;
4172
} SVArbCheckSyncReq;
4173

4174
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4175
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4176
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4177

4178
typedef struct {
4179
  char*   arbToken;
4180
  char*   member0Token;
4181
  char*   member1Token;
4182
  int32_t vgId;
4183
  int32_t errCode;
4184
} SVArbCheckSyncRsp;
4185

4186
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4187
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4188
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4189

4190
typedef struct {
4191
  char*   arbToken;
4192
  int64_t arbTerm;
4193
  char*   memberToken;
4194
  int8_t  force;
4195
} SVArbSetAssignedLeaderReq;
4196

4197
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4198
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4199
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4200

4201
typedef struct {
4202
  char* data;
4203
} SVAuditRecordReq;
4204
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4205
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4206
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4207

4208
typedef struct {
4209
  char*   arbToken;
4210
  char*   memberToken;
4211
  int32_t vgId;
4212
} SVArbSetAssignedLeaderRsp;
4213

4214
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4215
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4216
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4217

4218
typedef struct {
4219
  int32_t dnodeId;
4220
  char*   token;
4221
} SMArbUpdateGroupMember;
4222

4223
typedef struct {
4224
  int32_t dnodeId;
4225
  char*   token;
4226
  int8_t  acked;
4227
} SMArbUpdateGroupAssigned;
4228

4229
typedef struct {
4230
  int32_t                  vgId;
4231
  int64_t                  dbUid;
4232
  SMArbUpdateGroupMember   members[2];
4233
  int8_t                   isSync;
4234
  int8_t                   assignedAcked;
4235
  SMArbUpdateGroupAssigned assignedLeader;
4236
  int64_t                  version;
4237
  int32_t                  code;
4238
  int64_t                  updateTimeMs;
4239
} SMArbUpdateGroup;
4240

4241
typedef struct {
4242
  SArray* updateArray;  // SMArbUpdateGroup
4243
} SMArbUpdateGroupBatchReq;
4244

4245
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4246
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4247
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4248

4249
typedef struct {
4250
  char queryStrId[TSDB_QUERY_ID_LEN];
4251
} SKillQueryReq;
4252

4253
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4254
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4255

4256
typedef struct {
4257
  uint32_t connId;
4258
} SKillConnReq;
4259

4260
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4261
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4262

4263
typedef struct {
4264
  int32_t transId;
4265
} SKillTransReq;
4266

4267
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4268
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4269

4270
typedef struct {
4271
  int32_t useless;  // useless
4272
  int32_t sqlLen;
4273
  char*   sql;
4274
} SBalanceVgroupReq;
4275

4276
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4277
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4278
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4279

4280
typedef struct {
4281
  int32_t useless;  // useless
4282
  int32_t sqlLen;
4283
  char*   sql;
4284
} SAssignLeaderReq;
4285

4286
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4287
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4288
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4289
typedef struct {
4290
  int32_t vgId1;
4291
  int32_t vgId2;
4292
} SMergeVgroupReq;
4293

4294
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4295
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4296

4297
typedef struct {
4298
  int32_t vgId;
4299
  int32_t dnodeId1;
4300
  int32_t dnodeId2;
4301
  int32_t dnodeId3;
4302
  int32_t sqlLen;
4303
  char*   sql;
4304
} SRedistributeVgroupReq;
4305

4306
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4307
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4308
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4309

4310
typedef struct {
4311
  int32_t reserved;
4312
  int32_t vgId;
4313
  int32_t sqlLen;
4314
  char*   sql;
4315
  char    db[TSDB_DB_FNAME_LEN];
4316
} SBalanceVgroupLeaderReq;
4317

4318
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4319
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4320
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4321

4322
typedef struct {
4323
  int32_t vgId;
4324
} SForceBecomeFollowerReq;
4325

4326
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4327
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4328

4329
typedef struct {
4330
  int32_t vgId;
4331
  bool    force;
4332
} SSplitVgroupReq;
4333

4334
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4335
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4336

4337
typedef struct {
4338
  char user[TSDB_USER_LEN];
4339
  char spi;
4340
  char encrypt;
4341
  char secret[TSDB_PASSWORD_LEN];
4342
  char ckey[TSDB_PASSWORD_LEN];
4343
} SAuthReq, SAuthRsp;
4344

4345
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4346
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4347

4348
typedef struct {
4349
  int32_t statusCode;
4350
  char    details[1024];
4351
} SServerStatusRsp;
4352

4353
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4354
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4355

4356
/**
4357
 * The layout of the query message payload is as following:
4358
 * +--------------------+---------------------------------+
4359
 * |Sql statement       | Physical plan                   |
4360
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4361
 * +--------------------+---------------------------------+
4362
 */
4363
typedef struct SSubQueryMsg {
4364
  SMsgHead header;
4365
  uint64_t sId;
4366
  uint64_t queryId;
4367
  uint64_t clientId;
4368
  uint64_t taskId;
4369
  int64_t  refId;
4370
  int32_t  execId;
4371
  int32_t  msgMask;
4372
  int32_t  subQType;
4373
  int8_t   taskType;
4374
  int8_t   explain;
4375
  int8_t   needFetch;
4376
  int8_t   compress;
4377
  uint32_t sqlLen;
4378
  char*    sql;
4379
  uint32_t msgLen;
4380
  char*    msg;
4381
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4382
} SSubQueryMsg;
4383

4384
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4385
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4386
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4387

4388
typedef struct {
4389
  SMsgHead header;
4390
  uint64_t sId;
4391
  uint64_t queryId;
4392
  uint64_t taskId;
4393
} SSinkDataReq;
4394

4395
typedef struct {
4396
  SMsgHead header;
4397
  uint64_t sId;
4398
  uint64_t queryId;
4399
  uint64_t clientId;
4400
  uint64_t taskId;
4401
  int32_t  execId;
4402
} SQueryContinueReq;
4403

4404
typedef struct {
4405
  SMsgHead header;
4406
  uint64_t sId;
4407
  uint64_t queryId;
4408
  uint64_t taskId;
4409
} SResReadyReq;
4410

4411
typedef struct {
4412
  int32_t code;
4413
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4414
  int32_t sversion;
4415
  int32_t tversion;
4416
} SResReadyRsp;
4417

4418
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4419

4420
typedef struct SOperatorParam {
4421
  int32_t opType;
4422
  int32_t downstreamIdx;
4423
  void*   value;
4424
  SArray* pChildren;  // SArray<SOperatorParam*>
4425
  bool    reUse;
4426
} SOperatorParam;
4427

4428
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4429

4430
// virtual table's colId to origin table's colname
4431
typedef struct SColIdNameKV {
4432
  col_id_t colId;
4433
  char     colName[TSDB_COL_NAME_LEN];
4434
} SColIdNameKV;
4435

4436
#define COL_MASK_ON   ((int8_t)0x1)
4437
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4438
#define COL_SET_MASK_ON(c)     \
4439
  do {                         \
4440
    (c)->flags |= COL_MASK_ON; \
4441
  } while (0)
4442

4443
typedef struct SColNameFlag {
4444
  col_id_t colId;
4445
  char     colName[TSDB_COL_NAME_LEN];
4446
  int8_t   flags;  // 0x01: COL_MASK_ON
4447
} SColNameFlag;
4448

4449
typedef struct SColIdPair {
4450
  col_id_t  vtbColId;
4451
  col_id_t  orgColId;
4452
  SDataType type;
4453
} SColIdPair;
4454

4455
typedef struct SColIdSlotIdPair {
4456
  int32_t  vtbSlotId;
4457
  col_id_t orgColId;
4458
} SColIdSlotIdPair;
4459

4460
typedef struct SOrgTbInfo {
4461
  int32_t vgId;
4462
  char    tbName[TSDB_TABLE_FNAME_LEN];
4463
  SArray* colMap;  // SArray<SColIdNameKV>
4464
} SOrgTbInfo;
4465

4466
void destroySOrgTbInfo(void *info);
4467

4468
typedef enum {
4469
  DYN_TYPE_STB_JOIN = 1,
4470
  DYN_TYPE_VSTB_SINGLE_SCAN,
4471
  DYN_TYPE_VSTB_BATCH_SCAN,
4472
  DYN_TYPE_VSTB_WIN_SCAN,
4473
} ETableScanDynType;
4474

4475
typedef enum {
4476
  DYN_TYPE_SCAN_PARAM = 1,
4477
  NOTIFY_TYPE_SCAN_PARAM,
4478
} ETableScanGetParamType;
4479

4480
typedef struct STableScanOperatorParam {
4481
  ETableScanGetParamType paramType;
4482
  /* for building scan data source */
4483
  bool                   tableSeq;
4484
  bool                   isNewParam;
4485
  uint64_t               groupid;
4486
  SArray*                pUidList;
4487
  SOrgTbInfo*            pOrgTbInfo;
4488
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4489
  SArray*                pTagList;
4490
  STimeWindow            window;
4491
  ETableScanDynType      dynType;
4492
  /* for notifying source step done */
4493
  bool                   notifyToProcess;  // received notify STEP DONE message
4494
  TSKEY                  notifyTs;         // notify timestamp
4495
} STableScanOperatorParam;
4496

4497
typedef struct STagScanOperatorParam {
4498
  tb_uid_t vcUid;
4499
} STagScanOperatorParam;
4500

4501
typedef struct SRefColIdGroup {
4502
  SArray* pSlotIdList;  // SArray<int32_t>
4503
} SRefColIdGroup;
4504

4505
typedef struct SVTableScanOperatorParam {
4506
  uint64_t        uid;
4507
  STimeWindow     window;
4508
  SOperatorParam* pTagScanOp;
4509
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4510
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4511
} SVTableScanOperatorParam;
4512

4513
typedef struct SMergeOperatorParam {
4514
  int32_t         winNum;
4515
} SMergeOperatorParam;
4516

4517
typedef struct SAggOperatorParam {
4518
  bool            needCleanRes;
4519
} SAggOperatorParam;
4520

4521
typedef struct SExternalWindowOperatorParam {
4522
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4523
} SExternalWindowOperatorParam;
4524

4525
typedef struct SDynQueryCtrlOperatorParam {
4526
  STimeWindow    window;
4527
} SDynQueryCtrlOperatorParam;
4528

4529
struct SStreamRuntimeFuncInfo;
4530
typedef struct {
4531
  SMsgHead        header;
4532
  uint64_t        sId;
4533
  uint64_t        queryId;
4534
  uint64_t        clientId;
4535
  uint64_t        taskId;
4536
  uint64_t        srcTaskId;  // used for subQ
4537
  uint64_t        blockIdx;   // used for subQ
4538
  int32_t         execId;
4539
  SOperatorParam* pOpParam;
4540

4541
  // used for new-stream
4542
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4543
  bool                           reset;
4544
  bool                           dynTbname;
4545
  // used for new-stream
4546
} SResFetchReq;
4547

4548
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamRtInfo, bool needStreamGrpInfo);
4549
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4550
void    tDestroySResFetchReq(SResFetchReq* pReq);
4551
typedef struct {
4552
  SMsgHead header;
4553
  uint64_t clientId;
4554
} SSchTasksStatusReq;
4555

4556
typedef struct {
4557
  uint64_t queryId;
4558
  uint64_t clientId;
4559
  uint64_t taskId;
4560
  int64_t  refId;
4561
  int32_t  subJobId;
4562
  int32_t  execId;
4563
  int8_t   status;
4564
} STaskStatus;
4565

4566
typedef struct {
4567
  int64_t refId;
4568
  SArray* taskStatus;  // SArray<STaskStatus>
4569
} SSchedulerStatusRsp;
4570

4571
typedef struct {
4572
  uint64_t queryId;
4573
  uint64_t taskId;
4574
  int8_t   action;
4575
} STaskAction;
4576

4577
typedef struct SQueryNodeEpId {
4578
  int32_t nodeId;  // vgId or qnodeId
4579
  SEp     ep;
4580
} SQueryNodeEpId;
4581

4582
typedef struct {
4583
  SMsgHead       header;
4584
  uint64_t       clientId;
4585
  SQueryNodeEpId epId;
4586
  SArray*        taskAction;  // SArray<STaskAction>
4587
} SSchedulerHbReq;
4588

4589
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4590
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4591
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4592

4593
typedef struct {
4594
  SQueryNodeEpId epId;
4595
  SArray*        taskStatus;  // SArray<STaskStatus>
4596
} SSchedulerHbRsp;
4597

4598
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4599
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4600
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4601

4602
typedef struct {
4603
  SMsgHead header;
4604
  uint64_t sId;
4605
  uint64_t queryId;
4606
  uint64_t clientId;
4607
  uint64_t taskId;
4608
  int64_t  refId;
4609
  int32_t  execId;
4610
} STaskCancelReq;
4611

4612
typedef struct {
4613
  int32_t code;
4614
} STaskCancelRsp;
4615

4616
typedef struct {
4617
  SMsgHead header;
4618
  uint64_t sId;
4619
  uint64_t queryId;
4620
  uint64_t clientId;
4621
  uint64_t taskId;
4622
  int64_t  refId;
4623
  int32_t  execId;
4624
} STaskDropReq;
4625

4626
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4627
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4628

4629
typedef enum {
4630
  TASK_NOTIFY_FINISHED = 1,
4631
} ETaskNotifyType;
4632

4633
typedef struct {
4634
  SMsgHead        header;
4635
  uint64_t        sId;
4636
  uint64_t        queryId;
4637
  uint64_t        clientId;
4638
  uint64_t        taskId;
4639
  int64_t         refId;
4640
  int32_t         execId;
4641
  ETaskNotifyType type;
4642
} STaskNotifyReq;
4643

4644
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4645
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4646

4647
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4648
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4649

4650
typedef struct {
4651
  int32_t code;
4652
} STaskDropRsp;
4653

4654
#define STREAM_TRIGGER_AT_ONCE                 1
4655
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4656
#define STREAM_TRIGGER_MAX_DELAY               3
4657
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4658
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4659

4660
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4661
#define STREAM_FILL_HISTORY_ON        1
4662
#define STREAM_FILL_HISTORY_OFF       0
4663
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4664
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4665
#define STREAM_CREATE_STABLE_TRUE     1
4666
#define STREAM_CREATE_STABLE_FALSE    0
4667

4668
typedef struct SVgroupVer {
4669
  int32_t vgId;
4670
  int64_t ver;
4671
} SVgroupVer;
4672

4673
enum {
4674
  TOPIC_SUB_TYPE__DB = 1,
4675
  TOPIC_SUB_TYPE__TABLE,
4676
  TOPIC_SUB_TYPE__COLUMN,
4677
};
4678

4679
#define DEFAULT_MAX_POLL_INTERVAL  300000
4680
#define DEFAULT_SESSION_TIMEOUT    12000
4681
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4682
#define DEFAULT_MIN_POLL_ROWS      4096
4683

4684
typedef struct {
4685
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4686
  int8_t igExists;
4687
  int8_t subType;
4688
  int8_t withMeta;
4689
  char*  sql;
4690
  char   subDbName[TSDB_DB_FNAME_LEN];
4691
  char*  ast;
4692
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4693
  int8_t reload;
4694
} SCMCreateTopicReq;
4695

4696
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4697
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4698
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4699

4700
typedef struct {
4701
  int64_t consumerId;
4702
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4703

4704
typedef struct {
4705
  int64_t consumerId;
4706
  char    cgroup[TSDB_CGROUP_LEN];
4707
  char    clientId[TSDB_CLIENT_ID_LEN];
4708
  char    user[TSDB_USER_LEN];
4709
  char    fqdn[TSDB_FQDN_LEN];
4710
  SArray* topicNames;  // SArray<char**>
4711

4712
  int8_t  withTbName;
4713
  int8_t  autoCommit;
4714
  int32_t autoCommitInterval;
4715
  int8_t  resetOffsetCfg;
4716
  int8_t  enableReplay;
4717
  int8_t  enableBatchMeta;
4718
  int32_t sessionTimeoutMs;
4719
  int32_t maxPollIntervalMs;
4720
  int64_t ownerId;
4721
} SCMSubscribeReq;
4722

4723
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4724
  int32_t tlen = 0;
766,878✔
4725
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
766,878✔
4726
  tlen += taosEncodeString(buf, pReq->cgroup);
766,878✔
4727
  tlen += taosEncodeString(buf, pReq->clientId);
766,878✔
4728

4729
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
766,878✔
4730
  tlen += taosEncodeFixedI32(buf, topicNum);
766,878✔
4731

4732
  for (int32_t i = 0; i < topicNum; i++) {
1,071,830✔
4733
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
609,904✔
4734
  }
4735

4736
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
766,878✔
4737
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
766,878✔
4738
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
766,878✔
4739
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
766,878✔
4740
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
766,878✔
4741
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
766,878✔
4742
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
766,878✔
4743
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
766,878✔
4744
  tlen += taosEncodeString(buf, pReq->user);
766,878✔
4745
  tlen += taosEncodeString(buf, pReq->fqdn);
766,878✔
4746

4747
  return tlen;
766,878✔
4748
}
4749

4750
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4751
  void* start = buf;
397,918✔
4752
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
397,918✔
4753
  buf = taosDecodeStringTo(buf, pReq->cgroup);
397,918✔
4754
  buf = taosDecodeStringTo(buf, pReq->clientId);
397,918✔
4755

4756
  int32_t topicNum = 0;
397,918✔
4757
  buf = taosDecodeFixedI32(buf, &topicNum);
397,918✔
4758

4759
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
397,918✔
4760
  if (pReq->topicNames == NULL) {
397,918✔
UNCOV
4761
    return terrno;
×
4762
  }
4763
  for (int32_t i = 0; i < topicNum; i++) {
578,610✔
4764
    char* name = NULL;
180,692✔
4765
    buf = taosDecodeString(buf, &name);
180,692✔
4766
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
361,384✔
UNCOV
4767
      return terrno;
×
4768
    }
4769
  }
4770

4771
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
397,918✔
4772
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
397,918✔
4773
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
397,918✔
4774
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
397,918✔
4775
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
397,918✔
4776
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
397,918✔
4777
  if ((char*)buf - (char*)start < len) {
397,918✔
4778
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
397,918✔
4779
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
397,918✔
4780
    buf = taosDecodeStringTo(buf, pReq->user);
397,918✔
4781
    buf = taosDecodeStringTo(buf, pReq->fqdn);
795,836✔
4782
  } else {
UNCOV
4783
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4784
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4785
  }
4786

4787
  return 0;
397,918✔
4788
}
4789

4790
typedef struct {
4791
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4792
  SArray* removedConsumers;  // SArray<int64_t>
4793
  SArray* newConsumers;      // SArray<int64_t>
4794
} SMqRebInfo;
4795

4796
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4797
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
363,942✔
4798
  if (pRebInfo == NULL) {
363,942✔
UNCOV
4799
    return NULL;
×
4800
  }
4801
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
363,942✔
4802
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
363,942✔
4803
  if (pRebInfo->removedConsumers == NULL) {
363,942✔
UNCOV
4804
    goto _err;
×
4805
  }
4806
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
363,942✔
4807
  if (pRebInfo->newConsumers == NULL) {
363,942✔
UNCOV
4808
    goto _err;
×
4809
  }
4810
  return pRebInfo;
363,942✔
4811
_err:
×
UNCOV
4812
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4813
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4814
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4815
  return NULL;
×
4816
}
4817

4818
typedef struct {
4819
  int64_t streamId;
4820
  int64_t checkpointId;
4821
  char    streamName[TSDB_STREAM_FNAME_LEN];
4822
} SMStreamDoCheckpointMsg;
4823

4824
typedef struct {
4825
  int64_t status;
4826
} SMVSubscribeRsp;
4827

4828
typedef struct {
4829
  char    name[TSDB_TOPIC_FNAME_LEN];
4830
  int8_t  igNotExists;
4831
  int32_t sqlLen;
4832
  char*   sql;
4833
  int8_t  force;
4834
} SMDropTopicReq;
4835

4836
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4837
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4838
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4839

4840
typedef struct {
4841
  char    name[TSDB_TOPIC_FNAME_LEN];
4842
  int8_t  igNotExists;
4843
  int32_t sqlLen;
4844
  char*   sql;
4845
} SMReloadTopicReq;
4846

4847
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4848
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4849
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4850

4851
typedef struct {
4852
  char   topic[TSDB_TOPIC_FNAME_LEN];
4853
  char   cgroup[TSDB_CGROUP_LEN];
4854
  int8_t igNotExists;
4855
  int8_t force;
4856
} SMDropCgroupReq;
4857

4858
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4859
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4860

4861
typedef struct {
4862
  int8_t reserved;
4863
} SMDropCgroupRsp;
4864

4865
typedef struct {
4866
  char    name[TSDB_TABLE_FNAME_LEN];
4867
  int8_t  alterType;
4868
  SSchema schema;
4869
} SAlterTopicReq;
4870

4871
typedef struct {
4872
  SMsgHead head;
4873
  char     name[TSDB_TABLE_FNAME_LEN];
4874
  int64_t  tuid;
4875
  int32_t  sverson;
4876
  int32_t  execLen;
4877
  char*    executor;
4878
  int32_t  sqlLen;
4879
  char*    sql;
4880
} SDCreateTopicReq;
4881

4882
typedef struct {
4883
  SMsgHead head;
4884
  char     name[TSDB_TABLE_FNAME_LEN];
4885
  int64_t  tuid;
4886
} SDDropTopicReq;
4887

4888
typedef struct {
4889
  char*      name;
4890
  int64_t    uid;
4891
  int64_t    interval[2];
4892
  int8_t     intervalUnit;
4893
  int16_t    nFuncs;
4894
  col_id_t*  funcColIds;  // column ids specified by user
4895
  func_id_t* funcIds;     // function ids specified by user
4896
} SRSmaParam;
4897

4898
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4899
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4900

4901
// TDMT_VND_CREATE_STB ==============
4902
typedef struct SVCreateStbReq {
4903
  char*           name;
4904
  tb_uid_t        suid;
4905
  int8_t          rollup;
4906
  SSchemaWrapper  schemaRow;
4907
  SSchemaWrapper  schemaTag;
4908
  SRSmaParam      rsmaParam;
4909
  int32_t         alterOriDataLen;
4910
  void*           alterOriData;
4911
  int8_t          source;
4912
  int8_t          colCmpred;
4913
  SColCmprWrapper colCmpr;
4914
  int64_t         keep;
4915
  int64_t         ownerId;
4916
  SExtSchema*     pExtSchemas;
4917
  int8_t          virtualStb;
4918
  int8_t          secureDelete;
4919
  int8_t          securityLevel;
4920
} SVCreateStbReq;
4921

4922
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4923
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4924

4925
// TDMT_VND_DROP_STB ==============
4926
typedef struct SVDropStbReq {
4927
  char*    name;
4928
  tb_uid_t suid;
4929
} SVDropStbReq;
4930

4931
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4932
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4933

4934
// TDMT_VND_CREATE_TABLE ==============
4935
#define TD_CREATE_IF_NOT_EXISTS       0x1
4936
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4937
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4938
typedef struct SVCreateTbReq {
4939
  int32_t  flags;
4940
  char*    name;
4941
  tb_uid_t uid;
4942
  int64_t  btime;
4943
  int32_t  ttl;
4944
  int32_t  commentLen;
4945
  char*    comment;
4946
  int8_t   type;
4947
  union {
4948
    struct {
4949
      char*    stbName;  // super table name
4950
      uint8_t  tagNum;
4951
      tb_uid_t suid;
4952
      SArray*  tagName;
4953
      uint8_t* pTag;
4954
    } ctb;
4955
    struct {
4956
      SSchemaWrapper schemaRow;
4957
      int64_t        userId;
4958
    } ntb;
4959
  };
4960
  int32_t         sqlLen;
4961
  char*           sql;
4962
  SColCmprWrapper colCmpr;
4963
  SExtSchema*     pExtSchemas;
4964
  SColRefWrapper  colRef;  // col reference for virtual table
4965
} SVCreateTbReq;
4966

4967
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4968
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4969
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4970
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4971

4972
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4973
  if (NULL == req) {
2,147,483,647✔
4974
    return;
2,147,483,647✔
4975
  }
4976

4977
  taosMemoryFreeClear(req->sql);
87,267,742✔
4978
  taosMemoryFreeClear(req->name);
87,263,374✔
4979
  taosMemoryFreeClear(req->comment);
87,275,600✔
4980
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
87,248,115✔
4981
    taosMemoryFreeClear(req->ctb.pTag);
79,145,190✔
4982
    taosMemoryFreeClear(req->ctb.stbName);
79,143,654✔
4983
    taosArrayDestroy(req->ctb.tagName);
79,144,465✔
4984
    req->ctb.tagName = NULL;
79,109,904✔
4985
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,114,559✔
4986
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
8,115,393✔
4987
  }
4988
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
87,239,082✔
4989
  taosMemoryFreeClear(req->pExtSchemas);
87,242,299✔
4990
  taosMemoryFreeClear(req->colRef.pColRef);
87,264,552✔
4991
  taosMemoryFreeClear(req->colRef.pTagRef);
87,260,144✔
4992
}
4993

4994
typedef struct {
4995
  int32_t nReqs;
4996
  union {
4997
    SVCreateTbReq* pReqs;
4998
    SArray*        pArray;
4999
  };
5000
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5001
} SVCreateTbBatchReq;
5002

5003
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
5004
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
5005
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
5006

5007
typedef struct {
5008
  int32_t        code;
5009
  int32_t        index;  // index in batch req, start from 0
5010
  STableMetaRsp* pMeta;
5011
} SVCreateTbRsp, SVUpdateTbRsp;
5012

5013
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
5014
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
5015
void tFreeSVCreateTbRsp(void* param);
5016

5017
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
5018
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
5019

5020
typedef struct {
5021
  int32_t nRsps;
5022
  union {
5023
    SVCreateTbRsp* pRsps;
5024
    SArray*        pArray;
5025
  };
5026
} SVCreateTbBatchRsp;
5027

5028
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
5029
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
5030

5031
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
5032
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
5033

5034
// TDMT_VND_DROP_TABLE =================
5035
typedef struct {
5036
  char*    name;
5037
  uint64_t suid;  // for tmq in wal format
5038
  int64_t  uid;
5039
  int8_t   igNotExists;
5040
  int8_t   isVirtual;
5041
} SVDropTbReq;
5042

5043
typedef struct {
5044
  int32_t code;
5045
} SVDropTbRsp;
5046

5047
typedef struct {
5048
  int32_t nReqs;
5049
  union {
5050
    SVDropTbReq* pReqs;
5051
    SArray*      pArray;
5052
  };
5053
} SVDropTbBatchReq;
5054

5055
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
5056
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
5057

5058
typedef struct {
5059
  int32_t nRsps;
5060
  union {
5061
    SVDropTbRsp* pRsps;
5062
    SArray*      pArray;
5063
  };
5064
} SVDropTbBatchRsp;
5065

5066
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
5067
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
5068

5069
// TDMT_VND_ALTER_TABLE =====================
5070
typedef struct SUpdatedTagVal {
5071
  char*    tagName;
5072
  int32_t  colId;
5073
  int8_t   tagType;
5074
  int8_t   tagFree;
5075
  uint32_t nTagVal;
5076
  uint8_t* pTagVal;
5077
  int8_t   isNull;
5078
  SArray*  pTagArray;
5079
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5080
  // they should be replaced by a more generic solution in the future for full expression
5081
  // support
5082
  char*    regexp;
5083
  char*    replacement;
5084
} SUpdatedTagVal;
5085

5086
typedef struct SUpdateTableTagVal {
5087
  char *tbName;
5088
  SArray* tags; // Array of SUpdatedTagVal
5089
} SUpdateTableTagVal;
5090

5091
typedef struct SVAlterTbReq {
5092
  char*   tbName;
5093
  int8_t  action;
5094
  char*   colName;
5095
  int32_t colId;
5096
  // TSDB_ALTER_TABLE_ADD_COLUMN
5097
  int8_t  type;
5098
  int8_t  flags;
5099
  int32_t bytes;
5100
  // TSDB_ALTER_TABLE_DROP_COLUMN
5101
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5102
  int8_t   colModType;
5103
  int32_t  colModBytes;
5104
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5105
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5106
  int8_t   isNull;
5107
  int8_t   tagType;
5108
  int8_t   tagFree;
5109
  uint32_t nTagVal;
5110
  uint8_t* pTagVal;
5111
  SArray*  pTagArray;
5112
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5113
  int8_t   updateTTL;
5114
  int32_t  newTTL;
5115
  int32_t  newCommentLen;
5116
  char*    newComment;
5117
  int64_t  ctimeMs;    // fill by vnode
5118
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5119
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5120
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5121
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5122
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5123
  uint8_t* where;      // [where] is the encode where condition.
5124
  // for Add column
5125
  STypeMod typeMod;
5126
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5127
  char* refDbName;
5128
  char* refTbName;
5129
  char* refColName;
5130
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5131
} SVAlterTbReq;
5132

5133
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5134
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5135
void    destroyAlterTbReq(SVAlterTbReq* pReq);
5136
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5137
void    tfreeMultiTagUpateVal(void* pMultiTag);
5138
void    tfreeUpdateTableTagVal(void* pMultiTable);
5139

5140
typedef struct {
5141
  int32_t        code;
5142
  STableMetaRsp* pMeta;
5143
} SVAlterTbRsp;
5144

5145
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5146
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5147
// ======================
5148

5149
typedef struct {
5150
  SMsgHead head;
5151
  int64_t  uid;
5152
  int32_t  tid;
5153
  int16_t  tversion;
5154
  int16_t  colId;
5155
  int8_t   type;
5156
  int16_t  bytes;
5157
  int32_t  tagValLen;
5158
  int16_t  numOfTags;
5159
  int32_t  schemaLen;
5160
  char     data[];
5161
} SUpdateTagValReq;
5162

5163
typedef struct {
5164
  SMsgHead head;
5165
} SUpdateTagValRsp;
5166

5167
typedef struct {
5168
  SMsgHead head;
5169
} SVShowTablesReq;
5170

5171
typedef struct {
5172
  SMsgHead head;
5173
  int32_t  id;
5174
} SVShowTablesFetchReq;
5175

5176
typedef struct {
5177
  int64_t useconds;
5178
  int8_t  completed;  // all results are returned to client
5179
  int8_t  precision;
5180
  int8_t  compressed;
5181
  int32_t compLen;
5182
  int32_t numOfRows;
5183
  char    data[];
5184
} SVShowTablesFetchRsp;
5185

5186
typedef struct {
5187
  int64_t consumerId;
5188
  int32_t epoch;
5189
  char    cgroup[TSDB_CGROUP_LEN];
5190
} SMqAskEpReq;
5191

5192
typedef struct {
5193
  int32_t key;
5194
  int32_t valueLen;
5195
  void*   value;
5196
} SKv;
5197

5198
typedef struct {
5199
  int64_t tscRid;
5200
  int8_t  connType;
5201
} SClientHbKey;
5202

5203
typedef struct {
5204
  int64_t tid;
5205
  char    status[TSDB_JOB_STATUS_LEN];
5206
  int64_t startTs;  // sub-task first execution start time, us
5207
} SQuerySubDesc;
5208

5209
typedef enum EQueryExecPhase {
5210
  /* Main phases: 0-9 */
5211
  QUERY_PHASE_NONE     = 0,
5212
  QUERY_PHASE_PARSE    = 1,
5213
  QUERY_PHASE_CATALOG  = 2,
5214
  QUERY_PHASE_PLAN     = 3,
5215
  QUERY_PHASE_SCHEDULE = 4,
5216
  QUERY_PHASE_EXECUTE  = 5,
5217
  QUERY_PHASE_FETCH    = 6,
5218
  QUERY_PHASE_DONE     = 7,
5219

5220
  /* SCHEDULE sub-phases: 4x */
5221
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5222
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5223
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5224

5225
  /* EXECUTE sub-phases: 5x */
5226
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5227
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5228
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5229

5230
  /* FETCH sub-phases: 6x */
5231
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5232
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5233
} EQueryExecPhase;
5234

5235
const char* queryPhaseStr(int32_t phase);
5236

5237
typedef struct {
5238
  char     sql[TSDB_SHOW_SQL_LEN];
5239
  uint64_t queryId;
5240
  int64_t  useconds;
5241
  int64_t  stime;  // timestamp precision ms
5242
  int64_t  reqRid;
5243
  bool     stableQuery;
5244
  bool     isSubQuery;
5245
  char     fqdn[TSDB_FQDN_LEN];
5246
  int32_t  subPlanNum;
5247
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5248
  int32_t  execPhase;       // EQueryExecPhase
5249
  int64_t  phaseStartTime;  // when current phase started, ms
5250
} SQueryDesc;
5251

5252
typedef struct {
5253
  uint32_t connId;
5254
  SArray*  queryDesc;  // SArray<SQueryDesc>
5255
} SQueryHbReqBasic;
5256

5257
typedef struct {
5258
  uint32_t connId;
5259
  uint64_t killRid;
5260
  int32_t  totalDnodes;
5261
  int32_t  onlineDnodes;
5262
  int8_t   killConnection;
5263
  int8_t   align[3];
5264
  SEpSet   epSet;
5265
  SArray*  pQnodeList;
5266
} SQueryHbRspBasic;
5267

5268
typedef struct SAppClusterSummary {
5269
  uint64_t numOfInsertsReq;
5270
  uint64_t numOfInsertRows;
5271
  uint64_t insertElapsedTime;
5272
  uint64_t insertBytes;  // submit to tsdb since launched.
5273

5274
  uint64_t fetchBytes;
5275
  uint64_t numOfQueryReq;
5276
  uint64_t queryElapsedTime;
5277
  uint64_t numOfSlowQueries;
5278
  uint64_t totalRequests;
5279
  uint64_t currentRequests;  // the number of SRequestObj
5280
} SAppClusterSummary;
5281

5282
typedef struct {
5283
  int64_t            appId;
5284
  int32_t            pid;
5285
  char               name[TSDB_APP_NAME_LEN];
5286
  int64_t            startTime;
5287
  SAppClusterSummary summary;
5288
} SAppHbReq;
5289

5290
typedef struct {
5291
  SClientHbKey      connKey;
5292
  int64_t           clusterId;
5293
  SAppHbReq         app;
5294
  SQueryHbReqBasic* query;
5295
  SHashObj*         info;  // hash<Skv.key, Skv>
5296
  char              user[TSDB_USER_LEN];
5297
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5298
  char              userApp[TSDB_APP_NAME_LEN];
5299
  uint32_t          userIp;
5300
  SIpRange          userDualIp;
5301
  char              sVer[TSDB_VERSION_LEN];
5302
  char              cInfo[CONNECTOR_INFO_LEN];
5303
} SClientHbReq;
5304

5305
typedef struct {
5306
  int64_t reqId;
5307
  SArray* reqs;  // SArray<SClientHbReq>
5308
  int64_t ipWhiteListVer;
5309
} SClientHbBatchReq;
5310

5311
typedef struct {
5312
  SClientHbKey      connKey;
5313
  int32_t           status;
5314
  SQueryHbRspBasic* query;
5315
  SArray*           info;  // Array<Skv>
5316
} SClientHbRsp;
5317

5318
typedef struct {
5319
  int64_t       reqId;
5320
  int64_t       rspId;
5321
  int32_t       svrTimestamp;
5322
  SArray*       rsps;  // SArray<SClientHbRsp>
5323
  SMonitorParas monitorParas;
5324
  int8_t        enableAuditDelete;
5325
  int8_t        enableStrongPass;
5326
  int8_t        enableAuditSelect;
5327
  int8_t        enableAuditInsert;
5328
  int8_t        auditLevel;
5329
  union {
5330
    uint32_t flags;
5331
    struct {
5332
      uint32_t sodInitial : 1;   // cluster-wide: 1 = SoD still in initial phase
5333
      uint32_t macActive  : 1;   // cluster-wide: 1 = MAC mandatory mode activated
5334
      uint32_t reserved   : 30;
5335
    };
5336
  };
5337
} SClientHbBatchRsp;
5338

5339
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
464,307,565✔
5340

5341
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5342
  void* pIter = taosHashIterate(info, NULL);
66,480,161✔
5343
  while (pIter != NULL) {
155,592,833✔
5344
    SKv* kv = (SKv*)pIter;
89,112,385✔
5345
    taosMemoryFreeClear(kv->value);
89,112,385✔
5346
    pIter = taosHashIterate(info, pIter);
89,112,782✔
5347
  }
5348
}
66,480,448✔
5349

5350
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
45,039,298✔
5351
  SQueryDesc* desc = (SQueryDesc*)pDesc;
45,039,298✔
5352
  if (desc->subDesc) {
45,039,298✔
5353
    taosArrayDestroy(desc->subDesc);
32,069,934✔
5354
    desc->subDesc = NULL;
32,067,376✔
5355
  }
5356
}
45,037,825✔
5357

5358
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
77,140,534✔
5359
  SClientHbReq* req = (SClientHbReq*)pReq;
171,975,850✔
5360
  if (req->query) {
171,975,850✔
5361
    if (req->query->queryDesc) {
77,140,281✔
5362
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
36,273,508✔
5363
    }
5364
    taosMemoryFreeClear(req->query);
77,139,137✔
5365
  }
5366

5367
  if (req->info) {
171,975,087✔
5368
    tFreeReqKvHash(req->info);
66,479,290✔
5369
    taosHashCleanup(req->info);
66,480,448✔
5370
    req->info = NULL;
66,480,498✔
5371
  }
5372
}
131,520,194✔
5373

5374
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5375
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5376

5377
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5378
  if (pReq == NULL) return;
33,443,517✔
5379
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
33,443,517✔
5380
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
33,443,517✔
5381
  taosMemoryFree(pReq);
33,443,517✔
5382
}
5383

5384
static FORCE_INLINE void tFreeClientKv(void* pKv) {
88,793,665✔
5385
  SKv* kv = (SKv*)pKv;
88,793,665✔
5386
  if (kv) {
88,793,665✔
5387
    taosMemoryFreeClear(kv->value);
88,793,665✔
5388
  }
5389
}
88,793,825✔
5390

5391
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
76,802,797✔
5392
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
76,802,797✔
5393
  if (rsp->query) {
76,802,797✔
5394
    taosArrayDestroy(rsp->query->pQnodeList);
76,791,684✔
5395
    taosMemoryFreeClear(rsp->query);
76,793,872✔
5396
  }
5397
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
76,806,435✔
5398
}
40,122,748✔
5399

5400
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5401
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
62,025,686✔
5402
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
62,025,686✔
5403
}
62,021,887✔
5404

5405
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5406
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5407
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5408

5409
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5410
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
366,755,177✔
5411
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
366,755,911✔
5412
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
366,753,969✔
5413
  return 0;
183,376,203✔
5414
}
5415

5416
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5417
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
182,745,228✔
5418
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
182,745,228✔
5419

5420
  if (pKv->valueLen < 0) {
91,372,614✔
UNCOV
5421
    return TSDB_CODE_INVALID_MSG;
×
5422
  }
5423

5424
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
91,372,614✔
5425
  if (pKv->value == NULL) {
91,372,614✔
UNCOV
5426
    return TSDB_CODE_OUT_OF_MEMORY;
×
5427
  }
5428
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
91,372,614✔
5429
  return 0;
91,372,519✔
5430
}
5431

5432
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5433
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
319,344,675✔
5434
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
319,337,690✔
5435
  return 0;
159,666,852✔
5436
}
5437

5438
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5439
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
158,989,700✔
5440
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
158,991,304✔
5441
  return 0;
79,497,422✔
5442
}
5443

5444
typedef struct {
5445
  int32_t vgId;
5446
  // TODO stas
5447
} SMqReportVgInfo;
5448

5449
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5450
  int32_t tlen = 0;
5451
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5452
  return tlen;
5453
}
5454

5455
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5456
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5457
  return buf;
5458
}
5459

5460
typedef struct {
5461
  int32_t epoch;
5462
  int64_t topicUid;
5463
  char    name[TSDB_TOPIC_FNAME_LEN];
5464
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5465
} SMqTopicInfo;
5466

5467
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5468
  int32_t tlen = 0;
5469
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5470
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5471
  tlen += taosEncodeString(buf, pTopicInfo->name);
5472
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5473
  tlen += taosEncodeFixedI32(buf, sz);
5474
  for (int32_t i = 0; i < sz; i++) {
5475
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5476
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5477
  }
5478
  return tlen;
5479
}
5480

5481
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5482
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5483
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5484
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5485
  int32_t sz;
5486
  buf = taosDecodeFixedI32(buf, &sz);
5487
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5488
    return NULL;
5489
  }
5490
  for (int32_t i = 0; i < sz; i++) {
5491
    SMqReportVgInfo vgInfo;
5492
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5493
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5494
      return NULL;
5495
    }
5496
  }
5497
  return buf;
5498
}
5499

5500
typedef struct {
5501
  int32_t status;  // ask hb endpoint
5502
  int32_t epoch;
5503
  int64_t consumerId;
5504
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5505
} SMqReportReq;
5506

5507
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5508
  int32_t tlen = 0;
5509
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5510
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5511
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5512
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5513
  tlen += taosEncodeFixedI32(buf, sz);
5514
  for (int32_t i = 0; i < sz; i++) {
5515
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5516
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5517
  }
5518
  return tlen;
5519
}
5520

5521
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5522
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5523
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5524
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5525
  int32_t sz;
5526
  buf = taosDecodeFixedI32(buf, &sz);
5527
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5528
    return NULL;
5529
  }
5530
  for (int32_t i = 0; i < sz; i++) {
5531
    SMqTopicInfo topicInfo;
5532
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5533
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5534
      return NULL;
5535
    }
5536
  }
5537
  return buf;
5538
}
5539

5540
typedef struct {
5541
  SMsgHead head;
5542
  int64_t  leftForVer;
5543
  int32_t  vgId;
5544
  int64_t  consumerId;
5545
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5546
} SMqVDeleteReq;
5547

5548
typedef struct {
5549
  int8_t reserved;
5550
} SMqVDeleteRsp;
5551

5552
typedef struct {
5553
  char**  name;
5554
  int32_t count;
5555
  int8_t  igNotExists;
5556
} SMDropStreamReq;
5557

5558
typedef struct {
5559
  int8_t reserved;
5560
} SMDropStreamRsp;
5561

5562
typedef struct {
5563
  SMsgHead head;
5564
  int64_t  resetRelHalt;  // reset related stream task halt status
5565
  int64_t  streamId;
5566
  int32_t  taskId;
5567
} SVDropStreamTaskReq;
5568

5569
typedef struct {
5570
  int8_t reserved;
5571
} SVDropStreamTaskRsp;
5572

5573
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5574
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5575
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5576

5577
typedef struct {
5578
  char*  name;
5579
  int8_t igNotExists;
5580
} SMPauseStreamReq;
5581

5582
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5583
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5584
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5585

5586
typedef struct {
5587
  char*  name;
5588
  int8_t igNotExists;
5589
  int8_t igUntreated;
5590
} SMResumeStreamReq;
5591

5592
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5593
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5594
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5595

5596
typedef struct {
5597
  char*       name;
5598
  int8_t      calcAll;
5599
  STimeWindow timeRange;
5600
} SMRecalcStreamReq;
5601

5602
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5603
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5604
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5605

5606
typedef struct SVndSetKeepVersionReq {
5607
  int64_t keepVersion;
5608
} SVndSetKeepVersionReq;
5609

5610
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5611
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5612

5613
typedef struct SVUpdateCheckpointInfoReq {
5614
  SMsgHead head;
5615
  int64_t  streamId;
5616
  int32_t  taskId;
5617
  int64_t  checkpointId;
5618
  int64_t  checkpointVer;
5619
  int64_t  checkpointTs;
5620
  int32_t  transId;
5621
  int64_t  hStreamId;  // add encode/decode
5622
  int64_t  hTaskId;
5623
  int8_t   dropRelHTask;
5624
} SVUpdateCheckpointInfoReq;
5625

5626
typedef struct {
5627
  int64_t        leftForVer;
5628
  int32_t        vgId;
5629
  int64_t        oldConsumerId;
5630
  int64_t        newConsumerId;
5631
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5632
  int8_t         subType;
5633
  int8_t         withMeta;
5634
  char*          qmsg;  // SubPlanToString
5635
  SSchemaWrapper schema;
5636
  int64_t        suid;
5637
} SMqRebVgReq;
5638

5639
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5640
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5641

5642
// tqOffset
5643
enum {
5644
  TMQ_OFFSET__RESET_NONE = -3,
5645
  TMQ_OFFSET__RESET_EARLIEST = -2,
5646
  TMQ_OFFSET__RESET_LATEST = -1,
5647
  TMQ_OFFSET__LOG = 1,
5648
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5649
  TMQ_OFFSET__SNAPSHOT_META = 3,
5650
};
5651

5652
enum {
5653
  ONLY_DATA = 0,
5654
  WITH_META = 1,
5655
  ONLY_META = 2,
5656
};
5657

5658
#define TQ_OFFSET_VERSION 1
5659

5660
typedef struct {
5661
  int8_t type;
5662
  union {
5663
    // snapshot
5664
    struct {
5665
      int64_t uid;
5666
      int64_t ts;
5667
      SValue  primaryKey;
5668
    };
5669
    // log
5670
    struct {
5671
      int64_t version;
5672
    };
5673
  };
5674
} STqOffsetVal;
5675

5676
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5677
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
12,468,135✔
5678
  pOffsetVal->uid = uid;
12,467,822✔
5679
  pOffsetVal->ts = ts;
12,469,490✔
5680
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
12,469,838✔
5681
    taosMemoryFree(pOffsetVal->primaryKey.pData);
337✔
5682
  }
5683
  pOffsetVal->primaryKey = primaryKey;
12,465,435✔
5684
}
12,468,146✔
5685

5686
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5687
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
58,947✔
5688
  pOffsetVal->uid = uid;
58,947✔
5689
}
58,947✔
5690

5691
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5692
  pOffsetVal->type = TMQ_OFFSET__LOG;
314,000,378✔
5693
  pOffsetVal->version = ver;
314,002,109✔
5694
}
314,004,000✔
5695

5696
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5697
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5698
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5699
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5700
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5701
void    tOffsetDestroy(void* pVal);
5702

5703
typedef struct {
5704
  STqOffsetVal val;
5705
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5706
} STqOffset;
5707

5708
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5709
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5710
void    tDeleteSTqOffset(void* val);
5711

5712
typedef struct SMqVgOffset {
5713
  int64_t   consumerId;
5714
  STqOffset offset;
5715
} SMqVgOffset;
5716

5717
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5718
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5719

5720
typedef struct {
5721
  char    name[TSDB_TABLE_FNAME_LEN];
5722
  char    stb[TSDB_TABLE_FNAME_LEN];
5723
  int8_t  igExists;
5724
  int8_t  intervalUnit;
5725
  int8_t  slidingUnit;
5726
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5727
  int32_t dstVgId;   // for stream
5728
  int64_t interval;
5729
  int64_t offset;
5730
  int64_t sliding;
5731
  int64_t maxDelay;
5732
  int64_t watermark;
5733
  int32_t exprLen;        // strlen + 1
5734
  int32_t tagsFilterLen;  // strlen + 1
5735
  int32_t sqlLen;         // strlen + 1
5736
  int32_t astLen;         // strlen + 1
5737
  char*   expr;
5738
  char*   tagsFilter;
5739
  char*   sql;
5740
  char*   ast;
5741
  int64_t deleteMark;
5742
  int64_t lastTs;
5743
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5744
  SArray* pVgroupVerList;
5745
  int8_t  recursiveTsma;
5746
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5747
  char*   createStreamReq;
5748
  int32_t streamReqLen;
5749
  char*   dropStreamReq;
5750
  int32_t dropStreamReqLen;
5751
  int64_t uid;
5752
} SMCreateSmaReq;
5753

5754
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5755
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5756
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5757

5758
typedef struct {
5759
  char    name[TSDB_TABLE_FNAME_LEN];
5760
  int8_t  igNotExists;
5761
  char*   dropStreamReq;
5762
  int32_t dropStreamReqLen;
5763
} SMDropSmaReq;
5764

5765
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5766
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5767
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5768

5769
typedef struct {
5770
  char name[TSDB_TABLE_NAME_LEN];
5771
  union {
5772
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5773
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5774
  };
5775
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5776
  union {
5777
    int8_t igExists;   // used by mnode
5778
    int8_t alterType;  // used by vnode
5779
  };
5780
  int8_t     intervalUnit;
5781
  int16_t    nFuncs;       // number of functions specified by user
5782
  col_id_t*  funcColIds;   // column ids specified by user
5783
  func_id_t* funcIds;      // function ids specified by user
5784
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5785
  int64_t    tbUid;
5786
  int64_t    uid;     // rsma uid
5787
  int32_t    sqlLen;  // strlen + 1
5788
  char*      sql;
5789
} SMCreateRsmaReq;
5790

5791
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5792
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5793
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5794

5795
typedef SMCreateRsmaReq SVCreateRsmaReq;
5796

5797
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5798
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5799
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5800

5801
typedef SMCreateRsmaReq SVAlterRsmaReq;
5802

5803
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5804
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5805
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5806

5807
typedef struct {
5808
  char       name[TSDB_TABLE_NAME_LEN];
5809
  int8_t     alterType;
5810
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5811
  int8_t     igNotExists;
5812
  int16_t    nFuncs;      // number of functions specified by user
5813
  col_id_t*  funcColIds;  // column ids specified by user
5814
  func_id_t* funcIds;     // function ids specified by user
5815
  int32_t    sqlLen;      // strlen + 1
5816
  char*      sql;
5817
} SMAlterRsmaReq;
5818

5819
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5820
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5821
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5822

5823
typedef struct {
5824
  int64_t    id;
5825
  char       name[TSDB_TABLE_NAME_LEN];
5826
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5827
  int64_t    ownerId;
5828
  int32_t    code;
5829
  int32_t    version;
5830
  int8_t     tbType;
5831
  int8_t     intervalUnit;
5832
  col_id_t   nFuncs;
5833
  col_id_t   nColNames;
5834
  int64_t    interval[2];
5835
  col_id_t*  funcColIds;
5836
  func_id_t* funcIds;
5837
  SArray*    colNames;
5838
} SRsmaInfoRsp;
5839

5840
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5841
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5842
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5843

5844
typedef struct {
5845
  char   name[TSDB_TABLE_FNAME_LEN];
5846
  int8_t igNotExists;
5847
} SMDropRsmaReq;
5848

5849
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5850
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5851

5852
typedef struct {
5853
  char    name[TSDB_TABLE_NAME_LEN];
5854
  char    tbName[TSDB_TABLE_NAME_LEN];
5855
  int64_t uid;
5856
  int64_t tbUid;
5857
  int8_t  tbType;
5858
} SVDropRsmaReq;
5859

5860
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5861
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5862

5863
typedef struct {
5864
  char   dbFName[TSDB_DB_FNAME_LEN];
5865
  char   stbName[TSDB_TABLE_NAME_LEN];
5866
  char   colName[TSDB_COL_NAME_LEN];
5867
  char   idxName[TSDB_INDEX_FNAME_LEN];
5868
  int8_t idxType;
5869
} SCreateTagIndexReq;
5870

5871
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5872
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5873

5874
typedef SMDropSmaReq SDropTagIndexReq;
5875

5876
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5877
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5878

5879
typedef struct {
5880
  int8_t         version;       // for compatibility(default 0)
5881
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5882
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5883
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5884
  int32_t        dstVgId;
5885
  char           indexName[TSDB_INDEX_NAME_LEN];
5886
  int32_t        exprLen;
5887
  int32_t        tagsFilterLen;
5888
  int64_t        indexUid;
5889
  tb_uid_t       tableUid;  // super/child/common table uid
5890
  tb_uid_t       dstTbUid;  // for dstVgroup
5891
  int64_t        interval;
5892
  int64_t        offset;  // use unit by precision of DB
5893
  int64_t        sliding;
5894
  char*          dstTbName;  // for dstVgroup
5895
  char*          expr;       // sma expression
5896
  char*          tagsFilter;
5897
  SSchemaWrapper schemaRow;  // for dstVgroup
5898
  SSchemaWrapper schemaTag;  // for dstVgroup
5899
} STSma;                     // Time-range-wise SMA
5900

5901
typedef STSma SVCreateTSmaReq;
5902

5903
typedef struct {
5904
  int8_t  type;  // 0 status report, 1 update data
5905
  int64_t indexUid;
5906
  int64_t skey;  // start TS key of interval/sliding window
5907
} STSmaMsg;
5908

5909
typedef struct {
5910
  int64_t indexUid;
5911
  char    indexName[TSDB_INDEX_NAME_LEN];
5912
} SVDropTSmaReq;
5913

5914
typedef struct {
5915
  int tmp;  // TODO: to avoid compile error
5916
} SVCreateTSmaRsp, SVDropTSmaRsp;
5917

5918
#if 0
5919
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5920
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5921
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5922
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5923
#endif
5924

5925
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5926
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5927
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5928
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5929

5930
typedef struct {
5931
  int32_t number;
5932
  STSma*  tSma;
5933
} STSmaWrapper;
5934

5935
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5936
  if (pSma) {
×
UNCOV
5937
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5938
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5939
    taosMemoryFreeClear(pSma->tagsFilter);
×
5940
  }
UNCOV
5941
}
×
5942

5943
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5944
  if (pSW) {
×
UNCOV
5945
    if (pSW->tSma) {
×
UNCOV
5946
      if (deepCopy) {
×
UNCOV
5947
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5948
          tDestroyTSma(pSW->tSma + i);
×
5949
        }
5950
      }
UNCOV
5951
      taosMemoryFreeClear(pSW->tSma);
×
5952
    }
5953
  }
UNCOV
5954
}
×
5955

5956
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5957
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5958
  taosMemoryFreeClear(pSW);
×
UNCOV
5959
  return NULL;
×
5960
}
5961

5962
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5963
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5964

5965
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5966
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5967

UNCOV
5968
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5969
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5970
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5971
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5972
  }
5973
  return 0;
×
5974
}
5975

UNCOV
5976
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5977
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5978
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5979
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5980
  }
5981
  return 0;
×
5982
}
5983

5984
typedef struct {
5985
  int idx;
5986
} SMCreateFullTextReq;
5987

5988
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5989
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5990
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5991

5992
typedef struct {
5993
  char   name[TSDB_TABLE_FNAME_LEN];
5994
  int8_t igNotExists;
5995
} SMDropFullTextReq;
5996

5997
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5998
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5999

6000
typedef struct {
6001
  char indexFName[TSDB_INDEX_FNAME_LEN];
6002
} SUserIndexReq;
6003

6004
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
6005
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
6006

6007
typedef struct {
6008
  char dbFName[TSDB_DB_FNAME_LEN];
6009
  char tblFName[TSDB_TABLE_FNAME_LEN];
6010
  char colName[TSDB_COL_NAME_LEN];
6011
  char owner[TSDB_USER_LEN];
6012
  char indexType[TSDB_INDEX_TYPE_LEN];
6013
  char indexExts[TSDB_INDEX_EXTS_LEN];
6014
} SUserIndexRsp;
6015

6016
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
6017
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
6018

6019
typedef struct {
6020
  char tbFName[TSDB_TABLE_FNAME_LEN];
6021
} STableIndexReq;
6022

6023
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
6024
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
6025

6026
typedef struct {
6027
  int8_t  intervalUnit;
6028
  int8_t  slidingUnit;
6029
  int64_t interval;
6030
  int64_t offset;
6031
  int64_t sliding;
6032
  int64_t dstTbUid;
6033
  int32_t dstVgId;
6034
  SEpSet  epSet;
6035
  char*   expr;
6036
} STableIndexInfo;
6037

6038
typedef struct {
6039
  char     tbName[TSDB_TABLE_NAME_LEN];
6040
  char     dbFName[TSDB_DB_FNAME_LEN];
6041
  uint64_t suid;
6042
  int32_t  version;
6043
  int32_t  indexSize;
6044
  SArray*  pIndex;  // STableIndexInfo
6045
} STableIndexRsp;
6046

6047
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
6048
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
6049
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
6050

6051
void tFreeSTableIndexInfo(void* pInfo);
6052

6053
typedef struct {
6054
  int8_t  mqMsgType;
6055
  int32_t code;
6056
  int32_t epoch;
6057
  int64_t consumerId;
6058
  int64_t walsver;
6059
  int64_t walever;
6060
} SMqRspHead;
6061

6062
typedef struct {
6063
  SMsgHead     head;
6064
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
6065
  int8_t       withTbName;
6066
  int8_t       useSnapshot;
6067
  int32_t      epoch;
6068
  uint64_t     reqId;
6069
  int64_t      consumerId;
6070
  int64_t      timeout;
6071
  STqOffsetVal reqOffset;
6072
  int8_t       enableReplay;
6073
  int8_t       sourceExcluded;
6074
  int8_t       rawData;
6075
  int32_t      minPollRows;
6076
  int8_t       enableBatchMeta;
6077
  SHashObj*    uidHash;  // to find if uid is duplicated
6078
} SMqPollReq;
6079

6080
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6081
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6082
void    tDestroySMqPollReq(SMqPollReq* pReq);
6083

6084
typedef struct {
6085
  int32_t vgId;
6086
  int64_t offset;
6087
  SEpSet  epSet;
6088
} SMqSubVgEp;
6089

6090
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6091
  int32_t tlen = 0;
2,103,070✔
6092
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,103,070✔
6093
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,103,070✔
6094
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,103,070✔
6095
  return tlen;
2,103,070✔
6096
}
6097

6098
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6099
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,032,452✔
6100
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,032,452✔
6101
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,032,452✔
6102
  return buf;
1,032,452✔
6103
}
6104

6105
typedef struct {
6106
  char    topic[TSDB_TOPIC_FNAME_LEN];
6107
  char    db[TSDB_DB_FNAME_LEN];
6108
  SArray* vgs;  // SArray<SMqSubVgEp>
6109
} SMqSubTopicEp;
6110

6111
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6112
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6113
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6114

6115
typedef struct {
6116
  SMqRspHead   head;
6117
  STqOffsetVal rspOffset;
6118
  int16_t      resMsgType;
6119
  int32_t      metaRspLen;
6120
  void*        metaRsp;
6121
} SMqMetaRsp;
6122

6123
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6124
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6125
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6126

6127
#define MQ_DATA_RSP_VERSION 100
6128

6129
typedef struct {
6130
  SMqRspHead   head;
6131
  STqOffsetVal rspOffset;
6132
  STqOffsetVal reqOffset;
6133
  int32_t      blockNum;
6134
  int8_t       withTbName;
6135
  int8_t       withSchema;
6136
  SArray*      blockDataLen;
6137
  SArray*      blockData;
6138
  SArray*      blockTbName;
6139
  SArray*      blockSchema;
6140

6141
  union {
6142
    struct {
6143
      int64_t sleepTime;
6144
    };
6145
    struct {
6146
      int32_t createTableNum;
6147
      SArray* createTableLen;
6148
      SArray* createTableReq;
6149
    };
6150
    struct {
6151
      int32_t len;
6152
      void*   rawData;
6153
    };
6154
  };
6155
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6156
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6157
  bool  timeout;
6158
} SMqDataRsp;
6159

6160
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6161
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6162
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6163
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6164
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6165

6166
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6167
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6168
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6169

6170
typedef struct SMqBatchMetaRsp {
6171
  SMqRspHead   head;  // not serialize
6172
  STqOffsetVal rspOffset;
6173
  SArray*      batchMetaLen;
6174
  SArray*      batchMetaReq;
6175
  void*        pMetaBuff;    // not serialize
6176
  uint32_t     metaBuffLen;  // not serialize
6177
} SMqBatchMetaRsp;
6178

6179
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6180
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6181
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6182
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6183

6184
typedef struct {
6185
  int32_t code;
6186
  SArray* topics;  // SArray<SMqSubTopicEp>
6187
} SMqAskEpRsp;
6188

6189
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6190
  int32_t tlen = 0;
10,393,440✔
6191
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6192
  int32_t sz = taosArrayGetSize(pRsp->topics);
10,393,440✔
6193
  tlen += taosEncodeFixedI32(buf, sz);
10,393,440✔
6194
  for (int32_t i = 0; i < sz; i++) {
11,833,216✔
6195
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,440,152✔
6196
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,440,152✔
6197
  }
6198
  tlen += taosEncodeFixedI32(buf, pRsp->code);
10,393,064✔
6199

6200
  return tlen;
10,393,440✔
6201
}
6202

6203
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6204
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6205
  int32_t sz;
3,980,212✔
6206
  buf = taosDecodeFixedI32(buf, &sz);
4,060,629✔
6207
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
4,060,629✔
6208
  if (pRsp->topics == NULL) {
4,060,629✔
UNCOV
6209
    return NULL;
×
6210
  }
6211
  for (int32_t i = 0; i < sz; i++) {
4,762,642✔
6212
    SMqSubTopicEp topicEp;
689,542✔
6213
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
702,013✔
6214
    if (buf == NULL) {
702,013✔
UNCOV
6215
      return NULL;
×
6216
    }
6217
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,404,026✔
UNCOV
6218
      return NULL;
×
6219
    }
6220
  }
6221
  buf = taosDecodeFixedI32(buf, &pRsp->code);
4,060,629✔
6222

6223
  return buf;
4,060,629✔
6224
}
6225

6226
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6227
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
31,056,626✔
6228
}
31,056,238✔
6229

6230
typedef struct {
6231
  int32_t      vgId;
6232
  STqOffsetVal offset;
6233
  int64_t      rows;
6234
  int64_t      ever;
6235
} OffsetRows;
6236

6237
typedef struct {
6238
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6239
  SArray* offsetRows;
6240
} TopicOffsetRows;
6241

6242
typedef struct {
6243
  int64_t consumerId;
6244
  int32_t epoch;
6245
  SArray* topics;
6246
  int8_t  pollFlag;
6247
} SMqHbReq;
6248

6249
typedef struct {
6250
  char   topic[TSDB_TOPIC_FNAME_LEN];
6251
  int8_t noPrivilege;
6252
} STopicPrivilege;
6253

6254
typedef struct {
6255
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6256
  int32_t debugFlag;
6257
} SMqHbRsp;
6258

6259
#define TD_AUTO_CREATE_TABLE 0x1
6260
typedef struct {
6261
  int64_t       suid;
6262
  int64_t       uid;
6263
  int32_t       sver;
6264
  uint32_t      nData;
6265
  uint8_t*      pData;
6266
  SVCreateTbReq cTbReq;
6267
} SVSubmitBlk;
6268

6269
typedef struct {
6270
  SMsgHead header;
6271
  uint64_t sId;
6272
  uint64_t queryId;
6273
  uint64_t clientId;
6274
  uint64_t taskId;
6275
  uint32_t sqlLen;
6276
  uint32_t phyLen;
6277
  char*    sql;
6278
  char*    msg;
6279
  int8_t   source;
6280
  int8_t   secureDelete;
6281
} SVDeleteReq;
6282

6283
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6284
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6285

6286
typedef struct {
6287
  int64_t affectedRows;
6288
} SVDeleteRsp;
6289

6290
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6291
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6292

6293
typedef struct SDeleteRes {
6294
  uint64_t suid;
6295
  SArray*  uidList;
6296
  int64_t  skey;
6297
  int64_t  ekey;
6298
  int64_t  affectedRows;
6299
  char     tableFName[TSDB_TABLE_NAME_LEN];
6300
  char     tsColName[TSDB_COL_NAME_LEN];
6301
  int64_t  ctimeMs;  // fill by vnode
6302
  int8_t   source;
6303
  int8_t   secureDelete;  // force physical overwrite
6304
} SDeleteRes;
6305

6306
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6307
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6308

6309
typedef struct {
6310
  // int64_t uid;
6311
  char    tbname[TSDB_TABLE_NAME_LEN];
6312
  int64_t startTs;
6313
  int64_t endTs;
6314
} SSingleDeleteReq;
6315

6316
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6317
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6318

6319
typedef struct {
6320
  int64_t suid;
6321
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6322
  int64_t ctimeMs;     // fill by vnode
6323
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6324
} SBatchDeleteReq;
6325

6326
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6327
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6328
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6329

6330
typedef struct {
6331
  int32_t msgIdx;
6332
  int32_t msgType;
6333
  int32_t msgLen;
6334
  void*   msg;
6335
} SBatchMsg;
6336

6337
typedef struct {
6338
  SMsgHead header;
6339
  SArray*  pMsgs;  // SArray<SBatchMsg>
6340
} SBatchReq;
6341

6342
typedef struct {
6343
  int32_t reqType;
6344
  int32_t msgIdx;
6345
  int32_t msgLen;
6346
  int32_t rspCode;
6347
  void*   msg;
6348
} SBatchRspMsg;
6349

6350
typedef struct {
6351
  SArray* pRsps;  // SArray<SBatchRspMsg>
6352
} SBatchRsp;
6353

6354
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6355
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6356
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
103,391,047✔
6357
  if (NULL == msg) {
103,391,047✔
UNCOV
6358
    return;
×
6359
  }
6360
  SBatchMsg* pMsg = (SBatchMsg*)msg;
103,391,047✔
6361
  taosMemoryFree(pMsg->msg);
103,391,047✔
6362
}
6363

6364
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6365
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6366

6367
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
147,181,074✔
6368
  if (NULL == p) {
147,181,074✔
UNCOV
6369
    return;
×
6370
  }
6371

6372
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
147,181,074✔
6373
  taosMemoryFree(pRsp->msg);
147,181,074✔
6374
}
6375

6376
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6377
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6378
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6379
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6380
void    tDestroySMqHbReq(SMqHbReq* pReq);
6381

6382
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6383
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6384
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6385

6386
#define TD_REQ_FROM_APP               0x0
6387
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6388
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6389
#define SUBMIT_REQ_FROM_FILE          0x4
6390
#define TD_REQ_FROM_TAOX              0x8
6391
#define TD_REQ_FROM_SML               0x10
6392
#define SUBMIT_REQUEST_VERSION        (2)
6393
#define SUBMIT_REQ_WITH_BLOB          0x10
6394
#define SUBMIT_REQ_SCHEMA_RES         0x20
6395
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6396

6397
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6398

6399
typedef struct {
6400
  int32_t        flags;
6401
  SVCreateTbReq* pCreateTbReq;
6402
  int64_t        suid;
6403
  int64_t        uid;
6404
  int32_t        sver;
6405
  union {
6406
    SArray* aRowP;
6407
    SArray* aCol;
6408
  };
6409
  int64_t   ctimeMs;
6410
  SBlobSet* pBlobSet;
6411
} SSubmitTbData;
6412

6413
typedef struct {
6414
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6415
  SArray* aSubmitBlobData;
6416
  bool    raw;
6417
} SSubmitReq2;
6418

6419
typedef struct {
6420
  SMsgHead header;
6421
  int64_t  version;
6422
  char     data[];  // SSubmitReq2
6423
} SSubmitReq2Msg;
6424

6425
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6426
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6427
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6428
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6429
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6430

6431
typedef struct {
6432
  int32_t affectedRows;
6433
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6434
} SSubmitRsp2;
6435

6436
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6437
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6438
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6439

6440
#define TSDB_MSG_FLG_ENCODE 0x1
6441
#define TSDB_MSG_FLG_DECODE 0x2
6442
#define TSDB_MSG_FLG_CMPT   0x3
6443

6444
typedef struct {
6445
  union {
6446
    struct {
6447
      void*   msgStr;
6448
      int32_t msgLen;
6449
      int64_t ver;
6450
    };
6451
    void* pDataBlock;
6452
  };
6453
} SPackedData;
6454

6455
typedef struct {
6456
  char     fullname[TSDB_VIEW_FNAME_LEN];
6457
  char     name[TSDB_VIEW_NAME_LEN];
6458
  char     dbFName[TSDB_DB_FNAME_LEN];
6459
  char*    querySql;
6460
  char*    sql;
6461
  int8_t   orReplace;
6462
  int8_t   precision;
6463
  int32_t  numOfCols;
6464
  SSchema* pSchema;
6465
} SCMCreateViewReq;
6466

6467
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6468
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6469
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6470

6471
typedef struct {
6472
  char   fullname[TSDB_VIEW_FNAME_LEN];
6473
  char   name[TSDB_VIEW_NAME_LEN];
6474
  char   dbFName[TSDB_DB_FNAME_LEN];
6475
  char*  sql;
6476
  int8_t igNotExists;
6477
} SCMDropViewReq;
6478

6479
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6480
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6481
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6482

6483
typedef struct {
6484
  char fullname[TSDB_VIEW_FNAME_LEN];
6485
} SViewMetaReq;
6486
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6487
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6488

6489
typedef struct {
6490
  char     name[TSDB_VIEW_NAME_LEN];
6491
  char     dbFName[TSDB_DB_FNAME_LEN];
6492
  char*    createUser;
6493
  int64_t  ownerId;
6494
  uint64_t dbId;
6495
  uint64_t viewId;
6496
  char*    querySql;
6497
  int8_t   precision;
6498
  int8_t   type;
6499
  int32_t  version;
6500
  int32_t  numOfCols;
6501
  SSchema* pSchema;
6502
} SViewMetaRsp;
6503
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6504
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6505
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6506
typedef struct {
6507
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6508
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6509
} STableTSMAInfoReq;
6510

6511
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6512
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6513

6514
typedef struct {
6515
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6516
  union {
6517
    uint8_t flags;
6518
    struct {
6519
      uint8_t withColName : 1;
6520
      uint8_t reserved : 7;
6521
    };
6522
  };
6523

6524
} SRsmaInfoReq;
6525

6526
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6527
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6528

6529
typedef struct {
6530
  int32_t  funcId;
6531
  col_id_t colId;
6532
} STableTSMAFuncInfo;
6533

6534
typedef struct {
6535
  char     name[TSDB_TABLE_NAME_LEN];
6536
  uint64_t tsmaId;
6537
  char     targetTb[TSDB_TABLE_NAME_LEN];
6538
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6539
  char     tb[TSDB_TABLE_NAME_LEN];
6540
  char     dbFName[TSDB_DB_FNAME_LEN];
6541
  uint64_t suid;
6542
  uint64_t destTbUid;
6543
  uint64_t dbId;
6544
  int32_t  version;
6545
  int64_t  interval;
6546
  int8_t   unit;
6547
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6548
  SArray*  pTags;      // SArray<SSchema>
6549
  SArray*  pUsedCols;  // SArray<SSchema>
6550
  char*    ast;
6551

6552
  int64_t streamUid;
6553
  int64_t reqTs;
6554
  int64_t rspTs;
6555
  int64_t delayDuration;  // ms
6556
  bool    fillHistoryFinished;
6557

6558
  void* streamAddr;  // for stream task, the address of the stream task
6559
} STableTSMAInfo;
6560

6561
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6562
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6563
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6564
void    tFreeTableTSMAInfo(void* p);
6565
void    tFreeAndClearTableTSMAInfo(void* p);
6566
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6567

6568
#define STSMAHbRsp            STableTSMAInfoRsp
6569
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6570
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6571
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6572

6573
typedef struct SDropCtbWithTsmaSingleVgReq {
6574
  SVgroupInfo vgInfo;
6575
  SArray*     pTbs;  // SVDropTbReq
6576
} SMDropTbReqsOnSingleVg;
6577

6578
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6579
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6580
void    tFreeSMDropTbReqOnSingleVg(void* p);
6581

6582
typedef struct SDropTbsReq {
6583
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6584
} SMDropTbsReq;
6585

6586
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6587
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6588
void    tFreeSMDropTbsReq(void*);
6589

6590
typedef struct SVFetchTtlExpiredTbsRsp {
6591
  SArray* pExpiredTbs;  // SVDropTbReq
6592
  int32_t vgId;
6593
} SVFetchTtlExpiredTbsRsp;
6594

6595
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6596
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6597

6598
void tFreeFetchTtlExpiredTbsRsp(void* p);
6599

6600
void setDefaultOptionsForField(SFieldWithOptions* field);
6601
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6602

6603
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6604
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6605

6606
typedef struct {
6607
  char    id[TSDB_INSTANCE_ID_LEN];
6608
  char    type[TSDB_INSTANCE_TYPE_LEN];
6609
  char    desc[TSDB_INSTANCE_DESC_LEN];
6610
  int32_t expire;
6611
} SInstanceRegisterReq;
6612

6613
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6614
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6615

6616
typedef struct {
6617
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6618
} SInstanceListReq;
6619

6620
typedef struct {
6621
  int32_t count;
6622
  char**  ids;  // Array of instance IDs
6623
} SInstanceListRsp;
6624

6625
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6626
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6627
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6628
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6629

6630
#ifdef USE_MOUNT
6631
typedef struct {
6632
  char     mountName[TSDB_MOUNT_NAME_LEN];
6633
  int8_t   ignoreExist;
6634
  int16_t  nMounts;
6635
  int32_t* dnodeIds;
6636
  char**   mountPaths;
6637
  int32_t  sqlLen;
6638
  char*    sql;
6639
} SCreateMountReq;
6640

6641
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6642
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6643
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6644

6645
typedef struct {
6646
  char    mountName[TSDB_MOUNT_NAME_LEN];
6647
  int8_t  ignoreNotExists;
6648
  int32_t sqlLen;
6649
  char*   sql;
6650
} SDropMountReq;
6651

6652
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6653
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6654
void    tFreeSDropMountReq(SDropMountReq* pReq);
6655

6656
typedef struct {
6657
  char     mountName[TSDB_MOUNT_NAME_LEN];
6658
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6659
  int64_t  mountUid;
6660
  int32_t  dnodeId;
6661
  uint32_t valLen;
6662
  int8_t   ignoreExist;
6663
  void*    pVal;
6664
} SRetrieveMountPathReq;
6665

6666
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6667
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6668

6669
typedef struct {
6670
  // path
6671
  int32_t diskPrimary;
6672
  // vgInfo
6673
  int32_t  vgId;
6674
  int32_t  cacheLastSize;
6675
  int32_t  szPage;
6676
  int32_t  szCache;
6677
  uint64_t szBuf;
6678
  int8_t   cacheLast;
6679
  int8_t   standby;
6680
  int8_t   hashMethod;
6681
  uint32_t hashBegin;
6682
  uint32_t hashEnd;
6683
  int16_t  hashPrefix;
6684
  int16_t  hashSuffix;
6685
  int16_t  sttTrigger;
6686
  // syncInfo
6687
  int32_t replications;
6688
  // tsdbInfo
6689
  int8_t  precision;
6690
  int8_t  compression;
6691
  int8_t  slLevel;
6692
  int32_t daysPerFile;
6693
  int32_t keep0;
6694
  int32_t keep1;
6695
  int32_t keep2;
6696
  int32_t keepTimeOffset;
6697
  int32_t minRows;
6698
  int32_t maxRows;
6699
  int32_t tsdbPageSize;
6700
  int32_t ssChunkSize;
6701
  int32_t ssKeepLocal;
6702
  int8_t  ssCompact;
6703
  union {
6704
    uint8_t flags;
6705
    struct {
6706
      uint8_t isAudit : 1;
6707
      uint8_t allowDrop : 1;
6708
      uint8_t securityLevel : 3;
6709
      uint8_t reserved : 3;
6710
    };
6711
  };
6712
  int8_t secureDelete;
6713
  // walInfo
6714
  int32_t walFsyncPeriod;      // millisecond
6715
  int32_t walRetentionPeriod;  // secs
6716
  int32_t walRollPeriod;       // secs
6717
  int64_t walRetentionSize;
6718
  int64_t walSegSize;
6719
  int32_t walLevel;
6720
  // encryptInfo
6721
  int32_t encryptAlgorithm;
6722
  // SVState
6723
  int64_t committed;
6724
  int64_t commitID;
6725
  int64_t commitTerm;
6726
  // stats
6727
  int64_t numOfSTables;
6728
  int64_t numOfCTables;
6729
  int64_t numOfNTables;
6730
  // dbInfo
6731
  uint64_t dbId;
6732
} SMountVgInfo;
6733

6734
typedef struct {
6735
  SMCreateStbReq req;
6736
  SArray*        pColExts;  // element: column id
6737
  SArray*        pTagExts;  // element: tag id
6738
} SMountStbInfo;
6739

6740
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6741
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6742

6743
typedef struct {
6744
  char     dbName[TSDB_DB_FNAME_LEN];
6745
  uint64_t dbId;
6746
  SArray*  pVgs;   // SMountVgInfo
6747
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6748
} SMountDbInfo;
6749

6750
typedef struct {
6751
  // common fields
6752
  char     mountName[TSDB_MOUNT_NAME_LEN];
6753
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6754
  int8_t   ignoreExist;
6755
  int64_t  mountUid;
6756
  int64_t  clusterId;
6757
  int32_t  dnodeId;
6758
  uint32_t valLen;
6759
  void*    pVal;
6760

6761
  // response fields
6762
  SArray* pDbs;  // SMountDbInfo
6763

6764
  // memory fields, no serialized
6765
  SArray*   pDisks[TFS_MAX_TIERS];
6766
  TdFilePtr pFile;
6767
} SMountInfo;
6768

6769
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6770
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6771
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6772

6773
typedef struct {
6774
  SCreateVnodeReq createReq;
6775
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6776
  char            mountName[TSDB_MOUNT_NAME_LEN];
6777
  int64_t         mountId;
6778
  int32_t         diskPrimary;
6779
  int32_t         mountVgId;
6780
  int64_t         committed;
6781
  int64_t         commitID;
6782
  int64_t         commitTerm;
6783
  int64_t         numOfSTables;
6784
  int64_t         numOfCTables;
6785
  int64_t         numOfNTables;
6786
} SMountVnodeReq;
6787

6788
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6789
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6790
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6791

6792
#endif  // USE_MOUNT
6793

6794
#pragma pack(pop)
6795

6796
typedef struct {
6797
  char        db[TSDB_DB_FNAME_LEN];
6798
  STimeWindow timeRange;
6799
  int32_t     sqlLen;
6800
  char*       sql;
6801
  SArray*     vgroupIds;
6802
} SScanDbReq;
6803

6804
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6805
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6806
void    tFreeSScanDbReq(SScanDbReq* pReq);
6807

6808
typedef struct {
6809
  int32_t scanId;
6810
  int8_t  bAccepted;
6811
} SScanDbRsp;
6812

6813
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6814
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6815

6816
typedef struct {
6817
  int32_t scanId;
6818
  int32_t sqlLen;
6819
  char*   sql;
6820
} SKillScanReq;
6821

6822
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6823
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6824
void    tFreeSKillScanReq(SKillScanReq* pReq);
6825

6826
typedef struct {
6827
  int32_t scanId;
6828
  int32_t vgId;
6829
  int32_t dnodeId;
6830
} SVKillScanReq;
6831

6832
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6833
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6834

6835
typedef struct {
6836
  int32_t scanId;
6837
  int32_t vgId;
6838
  int32_t dnodeId;
6839
  int32_t numberFileset;
6840
  int32_t finished;
6841
  int32_t progress;
6842
  int64_t remainingTime;
6843
} SQueryScanProgressRsp;
6844

6845
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6846
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6847

6848
typedef struct {
6849
  int32_t scanId;
6850
  int32_t vgId;
6851
  int32_t dnodeId;
6852
} SQueryScanProgressReq;
6853

6854
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6855
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6856

6857
typedef struct {
6858
  int64_t     dbUid;
6859
  char        db[TSDB_DB_FNAME_LEN];
6860
  int64_t     scanStartTime;
6861
  STimeWindow tw;
6862
  int32_t     scanId;
6863
} SScanVnodeReq;
6864

6865
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6866
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6867

6868
#ifdef __cplusplus
6869
}
6870
#endif
6871

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