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

taosdata / TDengine / #5025

17 Apr 2026 01:15AM UTC coverage: 73.009% (+0.06%) from 72.954%
#5025

push

travis-ci

web-flow
fix: replace \s with [[:space:]] in shell regex for macOS BSD compat (#35162)

6 of 7 new or added lines in 2 files covered. (85.71%)

2432 existing lines in 145 files now uncovered.

273326 of 374375 relevant lines covered (73.01%)

130781443.02 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;
56✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
951,089,974✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
899,660,143✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,850,750,117✔
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_MAX,
220
} EShowType;
221

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

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

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

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

264

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

270

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

276
#define TSDB_ALTER_RSMA_FUNCTION        0x1
277

278
#define TSDB_KILL_MSG_LEN 30
279

280
#define TSDB_TABLE_NUM_UNIT 100000
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

734
typedef struct {
735
  int32_t contLen;
736
  int32_t vgId;
737
} SMsgHead;
738

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

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

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

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

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

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

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

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

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

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

825
typedef struct SVCTableMergeInfo {
826
  uint64_t uid;
827
  int32_t  numOfSrcTbls;
828
} SVCTableMergeInfo;
829

830
typedef struct {
831
  int32_t    nCols;
832
  SColRefEx* pColRefEx;
833
} SColRefExWrapper;
834

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

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

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

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

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

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

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

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

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

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

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

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

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

957
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
958

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

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

975
typedef struct {
976
  STypeMod typeMod;
977
} SExtSchema;
978

979
bool hasExtSchema(const SExtSchema* pExtSchema);
980

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

988
typedef struct {
989
  col_id_t id;
990
  uint32_t alg;
991
} SColCmpr;
992

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

999
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
1000
  if (pRef->pColRef) {
579,988✔
1001
    return TSDB_CODE_INVALID_PARA;
×
1002
  }
1003
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
579,988✔
1004
  if (pRef->pColRef == NULL) {
579,988✔
1005
    return terrno;
×
1006
  }
1007
  pRef->nCols = nCols;
579,988✔
1008
  for (int32_t i = 0; i < nCols; i++) {
161,201,476✔
1009
    pRef->pColRef[i].hasRef = false;
160,621,488✔
1010
    pRef->pColRef[i].id = (col_id_t)(i + 1);
160,621,488✔
1011
  }
1012
  return 0;
579,988✔
1013
}
1014

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

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

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

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

1052
  return pDstWrapper;
1053
}
1054

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

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

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

1088
  taosMemoryFreeClear(pWrapper->pColCmpr);
1089
  taosMemoryFreeClear(pWrapper);
1090
}
1091
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1092
  if (pSchemaWrapper->pSchema == NULL) return NULL;
703,643,869✔
1093

1094
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
703,573,471✔
1095
  if (pSW == NULL) {
703,544,022✔
1096
    return NULL;
×
1097
  }
1098
  pSW->nCols = pSchemaWrapper->nCols;
703,544,022✔
1099
  pSW->version = pSchemaWrapper->version;
703,491,348✔
1100
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
703,697,917✔
1101
  if (pSW->pSchema == NULL) {
703,417,263✔
1102
    taosMemoryFree(pSW);
×
1103
    return NULL;
×
1104
  }
1105

1106
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
703,482,692✔
1107
  return pSW;
703,699,672✔
1108
}
1109

1110
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
187,478,721✔
1111
  if (pSchemaWrapper) {
1,591,445,675✔
1112
    taosMemoryFree(pSchemaWrapper->pSchema);
1,106,439,697✔
1113
    if (pSchemaWrapper->pRsma) {
1,106,356,556✔
1114
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
28,786✔
1115
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
28,786✔
1116
    }
1117
    taosMemoryFree(pSchemaWrapper);
1,106,300,892✔
1118
  }
1119
}
1,551,845,882✔
1120

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

1131
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,610,174✔
1132
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,610,174✔
1133
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,610,789✔
1134
  }
1135
}
7,608,919✔
1136

1137
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1138
  int32_t tlen = 0;
2,994,238✔
1139
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,996,608✔
1140
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,994,238✔
1141
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,994,238✔
1142
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,994,238✔
1143
  tlen += taosEncodeString(buf, pSchema->name);
2,994,238✔
1144
  return tlen;
2,994,238✔
1145
}
1146

1147
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1148
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,325,620✔
1149
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,325,113✔
1150
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,325,113✔
1151
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,325,113✔
1152
  buf = taosDecodeStringTo(buf, pSchema->name);
1,325,113✔
1153
  return (void*)buf;
1,325,113✔
1154
}
1155

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

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

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

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

1188
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1189
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
972,639,828✔
1190
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
972,639,828✔
1191
  if (pColRef->hasRef) {
486,319,914✔
1192
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
645,209,804✔
1193
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
645,209,804✔
1194
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
645,209,804✔
1195
  }
1196
  return 0;
486,319,914✔
1197
}
1198

1199
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1200
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
486,746,808✔
1201
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
486,746,808✔
1202
  if (pColRef->hasRef) {
243,373,404✔
1203
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
161,480,624✔
1204
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
161,480,624✔
1205
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
161,480,624✔
1206
  }
1207

1208
  return 0;
243,373,404✔
1209
}
1210

1211
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1212
  int32_t tlen = 0;
507,078✔
1213
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
507,078✔
1214
  tlen += taosEncodeVariantI32(buf, pSW->version);
507,078✔
1215
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,501,316✔
1216
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,988,476✔
1217
  }
1218
  return tlen;
507,078✔
1219
}
1220

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

1230
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,541,767✔
1231
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,650,226✔
1232
    }
1233
  } else {
1234
    pSW->pSchema = NULL;
×
1235
  }
1236
  return (void*)buf;
216,654✔
1237
}
1238

1239
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1240
  if (pSW == NULL) {
334,951,648✔
1241
    return TSDB_CODE_INVALID_PARA;
×
1242
  }
1243
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
669,895,394✔
1244
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
669,818,853✔
1245
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1246
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1247
  }
1248
  return 0;
335,083,760✔
1249
}
1250

1251
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1252
  if (pSW == NULL) {
145,448,021✔
1253
    return TSDB_CODE_INVALID_PARA;
×
1254
  }
1255
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
290,851,564✔
1256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
290,839,989✔
1257

1258
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
145,436,446✔
1259
  if (pSW->pSchema == NULL) {
145,403,518✔
1260
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1261
  }
1262
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,511,685,627✔
1263
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1264
  }
1265

1266
  return 0;
145,474,128✔
1267
}
1268

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

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

1281
  return 0;
2,147,483,647✔
1282
}
1283

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

1318
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1319
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1320
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1321

1322
typedef struct {
1323
  STableMetaRsp* pMeta;
1324
} SMCreateStbRsp;
1325

1326
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1327
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1328
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1329

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

1340
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1341
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1342
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1343

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

1359
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1360
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1361
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1362

1363
typedef struct SEpSet {
1364
  int8_t inUse;
1365
  int8_t numOfEps;
1366
  SEp    eps[TSDB_MAX_REPLICA];
1367
} SEpSet;
1368

1369
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1370
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1371
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1372
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1373

1374
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1375
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1376

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

1392
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1393
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1394
void    tSignConnectReq(SConnectReq* pReq);
1395
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1396

1397
typedef struct {
1398
  int64_t       clusterId;
1399
  int32_t       acctId;
1400
  uint32_t      connId;
1401
  int32_t       dnodeNum;
1402
  int8_t        superUser;
1403
  int8_t        sysInfo;
1404
  int8_t        connType;
1405
  int8_t        enableAuditDelete;
1406
  SEpSet        epSet;
1407
  int32_t       svrTimestamp;
1408
  int32_t       passVer;
1409
  int32_t       authVer;
1410
  char          sVer[TSDB_VERSION_LEN];
1411
  char          sDetailVer[128];
1412
  int64_t       whiteListVer;
1413
  int64_t       timeWhiteListVer;
1414
  int64_t       userId;
1415
  SMonitorParas monitorParas;
1416
  char          user[TSDB_USER_LEN];
1417
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1418
  int8_t        enableAuditSelect;
1419
  int8_t        enableAuditInsert;
1420
  int8_t        auditLevel;
1421
} SConnectRsp;
1422

1423
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1424
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1425

1426
typedef struct {
1427
  char    user[TSDB_USER_LEN];
1428
  char    pass[TSDB_PASSWORD_LEN];
1429
  int32_t maxUsers;
1430
  int32_t maxDbs;
1431
  int32_t maxTimeSeries;
1432
  int32_t maxStreams;
1433
  int32_t accessState;  // Configured only by command
1434
  int64_t maxStorage;
1435
} SCreateAcctReq, SAlterAcctReq;
1436

1437
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1438
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1439

1440
typedef struct {
1441
  char    user[TSDB_USER_LEN];
1442
  int8_t  ignoreNotExists;
1443
  int32_t sqlLen;
1444
  char*   sql;
1445
} SDropUserReq, SDropAcctReq;
1446

1447
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1448
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1449
void    tFreeSDropUserReq(SDropUserReq* pReq);
1450

1451
typedef struct {
1452
  char name[TSDB_ROLE_LEN];
1453
  union {
1454
    uint8_t flag;
1455
    struct {
1456
      uint8_t ignoreExists : 1;
1457
      uint8_t reserve : 7;
1458
    };
1459
  };
1460
  int32_t sqlLen;
1461
  char*   sql;
1462
} SCreateRoleReq;
1463

1464
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1465
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1466
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1467

1468
typedef struct {
1469
  char name[TSDB_ROLE_LEN];
1470
  union {
1471
    uint8_t flag;
1472
    struct {
1473
      uint8_t ignoreNotExists : 1;
1474
      uint8_t reserve : 7;
1475
    };
1476
  };
1477
  int32_t sqlLen;
1478
  char*   sql;
1479
} SDropRoleReq;
1480

1481
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1482
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1483
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1484

1485
typedef struct {
1486
  SPrivSet privSet;
1487
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1488
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1489
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1490
  // delete can only specify conditions by cond and cannot specify columns
1491
  char*    cond;     // for table privileges
1492
  int32_t  condLen;  // for table privileges
1493
} SPrivSetReqArgs;
1494

1495
typedef struct {
1496
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1497
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1498
  union {
1499
    uint32_t flag;
1500
    struct {
1501
      uint32_t lock : 1;     // lock or unlock role
1502
      uint32_t add : 1;      // add or remove
1503
      uint32_t sysPriv : 1;  // system or object privileges
1504
      uint32_t objLevel : 2;
1505
      uint32_t ignoreNotExists : 1;
1506
      uint32_t reserve : 26;
1507
    };
1508
  };
1509
  union {
1510
    SPrivSetReqArgs privileges;
1511
    char            roleName[TSDB_ROLE_LEN];
1512
  };
1513
  char    principal[TSDB_ROLE_LEN];      // role or user name
1514
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1515
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1516
  int32_t sqlLen;
1517
  char*   sql;
1518
} SAlterRoleReq;
1519

1520
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1521
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1522
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1523

1524
typedef struct {
1525
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1526
  int32_t sqlLen;
1527
  char*   sql;
1528
} SDropEncryptAlgrReq;
1529

1530
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1531
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1532
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1533

1534
typedef struct SIpV4Range {
1535
  uint32_t ip;
1536
  uint32_t mask;
1537
} SIpV4Range;
1538

1539
typedef struct SIpv6Range {
1540
  uint64_t addr[2];
1541
  uint32_t mask;
1542
} SIpV6Range;
1543

1544
typedef struct {
1545
  int8_t type;   // 0: IPv4, 1: IPv6
1546
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1547
  union {
1548
    SIpV4Range ipV4;
1549
    SIpV6Range ipV6;
1550
  };
1551
} SIpRange;
1552

1553
typedef struct {
1554
  int32_t    num;
1555
  SIpV4Range pIpRange[];
1556
} SIpWhiteList;
1557

1558
typedef struct {
1559
  int32_t  num;
1560
  SIpRange pIpRanges[];
1561
} SIpWhiteListDual;
1562

1563
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1564
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1565
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1566
int32_t           createDefaultIp6Range(SIpRange* pRange);
1567
int32_t           createDefaultIp4Range(SIpRange* pRange);
1568

1569
typedef struct {
1570
  int32_t sessPerUser;
1571
  int32_t sessConnTime;
1572
  int32_t sessConnIdleTime;
1573
  int32_t sessMaxConcurrency;
1574
  int32_t sessMaxCallVnodeNum;
1575
} SUserSessCfg;
1576

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

1581
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1582
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1583
typedef struct {
1584
  int16_t year;
1585
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1586
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1587
  int8_t hour;
1588
  int8_t minute;
1589
  int8_t neg;   // this is a negative entry
1590
  int32_t duration; // duration in minute
1591
} SDateTimeRange;
1592

1593
bool isValidDateTimeRange(SDateTimeRange* pRange);
1594
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1595
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1596

1597
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1598
typedef struct {
1599
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1600
  bool neg;         // this is a negative entry
1601
  int32_t duration; // duration in seconds
1602
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1603
} SDateTimeWhiteListItem;
1604

1605
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1606
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1607

1608
typedef struct {
1609
  int32_t num;
1610
  SDateTimeWhiteListItem ranges[];
1611
} SDateTimeWhiteList;
1612

1613
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1614
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1615

1616

1617
typedef struct {
1618
  int8_t createType;
1619

1620
  int8_t hasSessionPerUser;
1621
  int8_t hasConnectTime;
1622
  int8_t hasConnectIdleTime;
1623
  int8_t hasCallPerSession;
1624
  int8_t hasVnodePerCall;
1625
  int8_t hasFailedLoginAttempts;
1626
  int8_t hasPasswordLifeTime;
1627
  int8_t hasPasswordReuseTime;
1628
  int8_t hasPasswordReuseMax;
1629
  int8_t hasPasswordLockTime;
1630
  int8_t hasPasswordGraceTime;
1631
  int8_t hasInactiveAccountTime;
1632
  int8_t hasAllowTokenNum;
1633

1634
  int8_t superUser;  // denote if it is a super user or not
1635
  int8_t ignoreExists;
1636

1637
  char   user[TSDB_USER_LEN];
1638
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1639
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1640

1641
  int8_t sysInfo;
1642
  int8_t createDb;
1643
  int8_t isImport;
1644
  int8_t changepass;
1645
  int8_t enable;
1646

1647
  int8_t negIpRanges;
1648
  int8_t negTimeRanges;
1649

1650
  int32_t sessionPerUser;
1651
  int32_t connectTime;
1652
  int32_t connectIdleTime;
1653
  int32_t callPerSession;
1654
  int32_t vnodePerCall;
1655
  int32_t failedLoginAttempts;
1656
  int32_t passwordLifeTime;
1657
  int32_t passwordReuseTime;
1658
  int32_t passwordReuseMax;
1659
  int32_t passwordLockTime;
1660
  int32_t passwordGraceTime;
1661
  int32_t inactiveAccountTime;
1662
  int32_t allowTokenNum;
1663

1664
  int32_t         numIpRanges;
1665
  SIpRange*       pIpDualRanges;
1666
  int32_t         numTimeRanges;
1667
  SDateTimeRange* pTimeRanges;
1668

1669
  int32_t sqlLen;
1670
  char*   sql;
1671
} SCreateUserReq;
1672

1673
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1674
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1675
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1676

1677
typedef struct {
1678
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1679
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1680
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1681
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1682
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1683
  int32_t sqlLen;
1684
  char*   sql;
1685
} SCreateEncryptAlgrReq;
1686

1687
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1688
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1689
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1690

1691
typedef struct {
1692
  int32_t dnodeId;
1693
  int64_t analVer;
1694
} SRetrieveAnalyticsAlgoReq;
1695

1696
typedef struct {
1697
  int64_t   ver;
1698
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1699
} SRetrieveAnalyticAlgoRsp;
1700

1701
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1702
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1703
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1704
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1705
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1706

1707
typedef struct {
1708
  int8_t alterType;
1709

1710
  int8_t isView;
1711

1712
  int8_t hasPassword;
1713
  int8_t hasTotpseed;
1714
  int8_t hasEnable;
1715
  int8_t hasSysinfo;
1716
  int8_t hasCreatedb;
1717
  int8_t hasChangepass;
1718
  int8_t hasSessionPerUser;
1719
  int8_t hasConnectTime;
1720
  int8_t hasConnectIdleTime;
1721
  int8_t hasCallPerSession;
1722
  int8_t hasVnodePerCall;
1723
  int8_t hasFailedLoginAttempts;
1724
  int8_t hasPasswordLifeTime;
1725
  int8_t hasPasswordReuseTime;
1726
  int8_t hasPasswordReuseMax;
1727
  int8_t hasPasswordLockTime;
1728
  int8_t hasPasswordGraceTime;
1729
  int8_t hasInactiveAccountTime;
1730
  int8_t hasAllowTokenNum;
1731

1732
  int8_t enable;
1733
  int8_t sysinfo;
1734
  int8_t createdb;
1735
  int8_t changepass;
1736

1737
  char   user[TSDB_USER_LEN];
1738
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1739
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1740
  int32_t sessionPerUser;
1741
  int32_t connectTime;
1742
  int32_t connectIdleTime;
1743
  int32_t callPerSession;
1744
  int32_t vnodePerCall;
1745
  int32_t failedLoginAttempts;
1746
  int32_t passwordLifeTime;
1747
  int32_t passwordReuseTime;
1748
  int32_t passwordReuseMax;
1749
  int32_t passwordLockTime;
1750
  int32_t passwordGraceTime;
1751
  int32_t inactiveAccountTime;
1752
  int32_t allowTokenNum;
1753

1754
  int32_t         numIpRanges;
1755
  int32_t         numTimeRanges;
1756
  int32_t         numDropIpRanges;
1757
  int32_t         numDropTimeRanges;
1758
  SIpRange*       pIpRanges;
1759
  SDateTimeRange* pTimeRanges;
1760
  SIpRange*       pDropIpRanges;
1761
  SDateTimeRange* pDropTimeRanges;
1762
  SPrivSet        privileges;
1763

1764
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1765
  char        tabName[TSDB_TABLE_NAME_LEN];
1766
  char*       tagCond;
1767
  int32_t     tagCondLen;
1768
  int32_t     sqlLen;
1769
  char*       sql;
1770
} SAlterUserReq;
1771

1772
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1773
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1774
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1775

1776
typedef struct {
1777
  char    name[TSDB_TOKEN_NAME_LEN];
1778
  char    user[TSDB_USER_LEN];
1779
  int8_t  enable;
1780
  int8_t  ignoreExists;
1781
  int32_t ttl;
1782
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1783
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1784

1785
  int32_t sqlLen;
1786
  char*   sql;
1787
} SCreateTokenReq;
1788

1789
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1790
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1791
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1792

1793
typedef struct {
1794
  char name[TSDB_TOKEN_NAME_LEN];
1795
  char user[TSDB_USER_LEN];
1796
  char token[TSDB_TOKEN_LEN];
1797
} SCreateTokenRsp;
1798

1799
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1800
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1801
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1802

1803
typedef struct {
1804
  char    name[TSDB_TOKEN_NAME_LEN];
1805

1806
  int8_t hasEnable;
1807
  int8_t hasTtl;
1808
  int8_t hasProvider;
1809
  int8_t hasExtraInfo;
1810

1811
  int8_t  enable;
1812
  int32_t ttl;
1813
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1814
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1815

1816
  int32_t     sqlLen;
1817
  char*       sql;
1818
} SAlterTokenReq;
1819

1820
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1821
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1822
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1823

1824
typedef struct {
1825
  char    name[TSDB_TOKEN_NAME_LEN];
1826
  int8_t  ignoreNotExists;
1827
  int32_t sqlLen;
1828
  char*   sql;
1829
} SDropTokenReq;
1830

1831
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1832
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1833
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1834

1835
typedef struct {
1836
  char    user[TSDB_USER_LEN];
1837
  int32_t sqlLen;
1838
  char*   sql;
1839
} SCreateTotpSecretReq;
1840

1841
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1842
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1843
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1844

1845
typedef struct {
1846
  char user[TSDB_USER_LEN];
1847
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1848
} SCreateTotpSecretRsp;
1849

1850
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1851
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1852

1853
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1854
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1855
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1856
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1857

1858
typedef struct {
1859
  char user[TSDB_USER_LEN];
1860
} SGetUserAuthReq;
1861

1862
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1863
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1864

1865
typedef struct {
1866
  int8_t  enabled;
1867
  int32_t expireTime;
1868
} STokenStatus;
1869

1870
typedef struct {
1871
  char    user[TSDB_USER_LEN];
1872
  int64_t userId;
1873
  int32_t version;
1874
  int32_t passVer;
1875
  int8_t  superAuth;
1876
  int8_t  sysInfo;
1877
  int8_t  enable;
1878
  int8_t  dropped;
1879
  union {
1880
    uint8_t flags;
1881
    struct {
1882
      uint8_t privLevel : 3;
1883
      uint8_t withInsertCond : 1;
1884
      uint8_t reserve : 4;
1885
    };
1886
  };
1887
  SPrivSet  sysPrivs;
1888
  SHashObj* objPrivs;
1889
  SHashObj* selectTbs;
1890
  SHashObj* insertTbs;
1891
  SHashObj* deleteTbs;
1892
  SHashObj* ownedDbs;
1893
  int64_t   whiteListVer;
1894

1895
  SUserSessCfg sessCfg;
1896
  int64_t      timeWhiteListVer;
1897
  SHashObj*    tokens;
1898
} SGetUserAuthRsp;
1899

1900
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1901
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1902
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1903

1904
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1905
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1906
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1907
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1908

1909
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1910
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1911
typedef struct {
1912
  int64_t ver;
1913
  char    user[TSDB_USER_LEN];
1914
  int32_t numOfRange;
1915
  union {
1916
    SIpV4Range* pIpRanges;
1917
    SIpRange*   pIpDualRanges;
1918
  };
1919
} SUpdateUserIpWhite;
1920

1921
typedef struct {
1922
  int64_t             ver;
1923
  int                 numOfUser;
1924
  SUpdateUserIpWhite* pUserIpWhite;
1925
} SUpdateIpWhite;
1926

1927
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1928
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1929
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1930
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1931

1932
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1933
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1934
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1935

1936

1937
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1938
// corresponding response struct is different.
1939
typedef struct {
1940
  int64_t ver;
1941
} SRetrieveWhiteListReq;
1942

1943
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1944
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1945

1946

1947
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1948
// corresponding response struct is different.
1949
typedef struct {
1950
  char user[TSDB_USER_LEN];
1951
} SGetUserWhiteListReq;
1952

1953
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1954
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1955

1956
typedef struct {
1957
  char    user[TSDB_USER_LEN];
1958
  int32_t numWhiteLists;
1959
  union {
1960
    SIpV4Range* pWhiteLists;
1961
    SIpRange*   pWhiteListsDual;
1962
  };
1963
} SGetUserIpWhiteListRsp;
1964

1965
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1966
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1967
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1968
void    tIpRangeSetDefaultMask(SIpRange* range);
1969

1970
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1971
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1972
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1973

1974
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1975
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1976
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1977

1978
typedef struct {
1979
  int64_t ver;
1980
  char    user[TSDB_USER_LEN];
1981
  int32_t numWhiteLists;
1982
  SDateTimeWhiteListItem* pWhiteLists;
1983
} SUserDateTimeWhiteList;
1984

1985

1986
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1987
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1988
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1989
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1990

1991
typedef struct {
1992
  int64_t             ver;
1993
  int                 numOfUser;
1994
  SUserDateTimeWhiteList *pUsers;
1995
} SRetrieveDateTimeWhiteListRsp;
1996

1997
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1998
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1999
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
2000
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
2001

2002
/*
2003
 * for client side struct, only column id, type, bytes are necessary
2004
 * But for data in vnode side, we need all the following information.
2005
 */
2006
typedef struct {
2007
  union {
2008
    col_id_t colId;
2009
    int16_t  slotId;
2010
  };
2011

2012
  uint8_t precision;
2013
  uint8_t scale;
2014
  int32_t bytes;
2015
  int8_t  type;
2016
  uint8_t pk;
2017
  bool    noData;
2018
} SColumnInfo;
2019

2020
typedef struct STimeWindow {
2021
  TSKEY skey;
2022
  TSKEY ekey;
2023
} STimeWindow;
2024

2025
typedef struct SQueryHint {
2026
  bool batchScan;
2027
} SQueryHint;
2028

2029
typedef struct {
2030
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2031
  int32_t tsLen;          // total length of ts comp block
2032
  int32_t tsNumOfBlocks;  // ts comp block numbers
2033
  int32_t tsOrder;        // ts comp block order
2034
} STsBufInfo;
2035

2036
typedef struct {
2037
  void*       timezone;
2038
  char        intervalUnit;
2039
  char        slidingUnit;
2040
  char        offsetUnit;
2041
  int8_t      precision;
2042
  int64_t     interval;
2043
  int64_t     sliding;
2044
  int64_t     offset;
2045
  STimeWindow timeRange;
2046
} SInterval;
2047

2048
typedef struct STbVerInfo {
2049
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2050
  int32_t sversion;
2051
  int32_t tversion;
2052
  int32_t rversion;  // virtual table's column ref's version
2053
} STbVerInfo;
2054

2055
typedef struct {
2056
  int32_t code;
2057
  int64_t affectedRows;
2058
  SArray* tbVerInfo;  // STbVerInfo
2059
} SQueryTableRsp;
2060

2061
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2062

2063
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2064

2065
typedef struct {
2066
  SMsgHead header;
2067
  char     dbFName[TSDB_DB_FNAME_LEN];
2068
  char     tbName[TSDB_TABLE_NAME_LEN];
2069
} STableCfgReq;
2070

2071
typedef struct {
2072
  char        tbName[TSDB_TABLE_NAME_LEN];
2073
  char        stbName[TSDB_TABLE_NAME_LEN];
2074
  char        dbFName[TSDB_DB_FNAME_LEN];
2075
  int32_t     numOfTags;
2076
  int32_t     numOfColumns;
2077
  int8_t      tableType;
2078
  int64_t     delay1;
2079
  int64_t     delay2;
2080
  int64_t     watermark1;
2081
  int64_t     watermark2;
2082
  int32_t     ttl;
2083
  int32_t     keep;
2084
  int64_t     ownerId;
2085
  SArray*     pFuncs;
2086
  int32_t     commentLen;
2087
  char*       pComment;
2088
  SSchema*    pSchemas;
2089
  int32_t     tagsLen;
2090
  char*       pTags;
2091
  SSchemaExt* pSchemaExt;
2092
  union {
2093
    uint8_t flag;
2094
    struct {
2095
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2096
      uint8_t isAudit : 1;
2097
      uint8_t reserve : 6;
2098
    };
2099
  };
2100
  SColRef* pColRefs;
2101
  int32_t  numOfTagRefs;
2102
  SColRef* pTagRefs;
2103
  int8_t   secureDelete;
2104
} STableCfg;
2105

2106
typedef STableCfg STableCfgRsp;
2107

2108
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2109
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2110

2111
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2112
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2113
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2114

2115
typedef struct {
2116
  SMsgHead header;
2117
  tb_uid_t suid;
2118
} SVSubTablesReq;
2119

2120
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2121
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2122

2123
typedef struct {
2124
  int32_t vgId;
2125
  SArray* pTables;  // SArray<SVCTableRefCols*>
2126
} SVSubTablesRsp;
2127

2128
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2129
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2130
void    tDestroySVSubTablesRsp(void* rsp);
2131

2132
typedef struct {
2133
  SMsgHead header;
2134
  tb_uid_t suid;
2135
} SVStbRefDbsReq;
2136

2137
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2138
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2139

2140
typedef struct {
2141
  int32_t vgId;
2142
  SArray* pDbs;  // SArray<char* (db name)>
2143
} SVStbRefDbsRsp;
2144

2145
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2146
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2147
void    tDestroySVStbRefDbsRsp(void* rsp);
2148

2149
typedef struct {
2150
  char    db[TSDB_DB_FNAME_LEN];
2151
  int32_t numOfVgroups;
2152
  int32_t numOfStables;  // single_stable
2153
  int32_t buffer;        // MB
2154
  int32_t pageSize;
2155
  int32_t pages;
2156
  int32_t cacheLastSize;
2157
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2158
  int32_t daysPerFile;
2159
  int32_t daysToKeep0;
2160
  int32_t daysToKeep1;
2161
  int32_t daysToKeep2;
2162
  int32_t keepTimeOffset;
2163
  int32_t minRows;
2164
  int32_t maxRows;
2165
  int32_t walFsyncPeriod;
2166
  int8_t  walLevel;
2167
  int8_t  precision;  // time resolution
2168
  int8_t  compression;
2169
  int8_t  replications;
2170
  int8_t  strict;
2171
  int8_t  cacheLast;
2172
  int8_t  schemaless;
2173
  int8_t  ignoreExist;
2174
  int32_t numOfRetensions;
2175
  SArray* pRetensions;  // SRetention
2176
  int32_t walRetentionPeriod;
2177
  int64_t walRetentionSize;
2178
  int32_t walRollPeriod;
2179
  int64_t walSegmentSize;
2180
  int32_t sstTrigger;
2181
  int16_t hashPrefix;
2182
  int16_t hashSuffix;
2183
  int32_t ssChunkSize;
2184
  int32_t ssKeepLocal;
2185
  int8_t  ssCompact;
2186
  int32_t tsdbPageSize;
2187
  int32_t sqlLen;
2188
  char*   sql;
2189
  int8_t  withArbitrator;
2190
  int8_t  encryptAlgorithm;
2191
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2192
  // 1. add auto-compact parameters
2193
  int32_t compactInterval;    // minutes
2194
  int32_t compactStartTime;   // minutes
2195
  int32_t compactEndTime;     // minutes
2196
  int8_t  compactTimeOffset;  // hour
2197
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2198
  int8_t  isAudit;
2199
  int8_t  allowDrop;
2200
  int8_t  secureDelete;
2201
} SCreateDbReq;
2202

2203
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2204
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2205
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2206

2207
typedef struct {
2208
  char    db[TSDB_DB_FNAME_LEN];
2209
  int32_t buffer;
2210
  int32_t pageSize;
2211
  int32_t pages;
2212
  int32_t cacheLastSize;
2213
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2214
  int32_t daysPerFile;
2215
  int32_t daysToKeep0;
2216
  int32_t daysToKeep1;
2217
  int32_t daysToKeep2;
2218
  int32_t keepTimeOffset;
2219
  int32_t walFsyncPeriod;
2220
  int8_t  walLevel;
2221
  int8_t  strict;
2222
  int8_t  cacheLast;
2223
  int8_t  replications;
2224
  int32_t sstTrigger;
2225
  int32_t minRows;
2226
  int32_t walRetentionPeriod;
2227
  int32_t walRetentionSize;
2228
  int32_t ssKeepLocal;
2229
  int8_t  ssCompact;
2230
  int32_t sqlLen;
2231
  char*   sql;
2232
  int8_t  withArbitrator;
2233
  // 1. add auto-compact parameters
2234
  int32_t compactInterval;
2235
  int32_t compactStartTime;
2236
  int32_t compactEndTime;
2237
  int8_t  compactTimeOffset;
2238
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2239
  int8_t  isAudit;
2240
  int8_t  allowDrop;
2241
  int8_t  secureDelete;
2242
} SAlterDbReq;
2243

2244
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2245
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2246
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2247

2248
typedef struct {
2249
  char    db[TSDB_DB_FNAME_LEN];
2250
  int8_t  ignoreNotExists;
2251
  int8_t  force;
2252
  int32_t sqlLen;
2253
  char*   sql;
2254
} SDropDbReq;
2255

2256
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2257
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2258
void    tFreeSDropDbReq(SDropDbReq* pReq);
2259

2260
typedef struct {
2261
  char    db[TSDB_DB_FNAME_LEN];
2262
  int64_t uid;
2263
} SDropDbRsp;
2264

2265
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2266
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2267

2268
typedef struct {
2269
  char    name[TSDB_MOUNT_NAME_LEN];
2270
  int64_t uid;
2271
} SDropMountRsp;
2272

2273
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2274
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2275

2276
typedef struct {
2277
  char    db[TSDB_DB_FNAME_LEN];
2278
  int64_t dbId;
2279
  int32_t vgVersion;
2280
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2281
  int64_t stateTs;     // ms
2282
} SUseDbReq;
2283

2284
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2285
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2286

2287
typedef struct {
2288
  char    db[TSDB_DB_FNAME_LEN];
2289
  int64_t uid;
2290
  int32_t vgVersion;
2291
  int32_t vgNum;
2292
  int16_t hashPrefix;
2293
  int16_t hashSuffix;
2294
  int8_t  hashMethod;
2295
  union {
2296
    uint8_t flags;
2297
    struct {
2298
      uint8_t isMount : 1;  // TS-5868
2299
      uint8_t padding : 7;
2300
    };
2301
  };
2302
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2303
  int32_t errCode;
2304
  int64_t stateTs;  // ms
2305
} SUseDbRsp;
2306

2307
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2308
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2309
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2310
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2311
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2312

2313
typedef struct {
2314
  char db[TSDB_DB_FNAME_LEN];
2315
} SDbCfgReq;
2316

2317
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2318
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2319

2320
typedef struct {
2321
  char db[TSDB_DB_FNAME_LEN];
2322
} SSsMigrateDbReq;
2323

2324
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2325
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2326

2327
typedef struct {
2328
  int32_t ssMigrateId;
2329
  bool    bAccepted;
2330
} SSsMigrateDbRsp;
2331

2332
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2333
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2334

2335
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2336
typedef struct {
2337
  int32_t ssMigrateId;
2338
} SListSsMigrateFileSetsReq;
2339

2340
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2341
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2342

2343
typedef struct {
2344
  int32_t ssMigrateId;
2345
  int32_t vgId;       // vgroup id
2346
  SArray* pFileSets;  // SArray<int32_t>
2347
} SListSsMigrateFileSetsRsp;
2348

2349
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2350
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2351
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2352

2353
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2354
typedef struct {
2355
  int32_t ssMigrateId;
2356
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2357
  int32_t fid;
2358
  int64_t startTimeSec;
2359
} SSsMigrateFileSetReq;
2360

2361
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2362
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2363

2364
typedef struct {
2365
  int32_t ssMigrateId;
2366
  int32_t nodeId;  // node id of the leader vnode
2367
  int32_t vgId;
2368
  int32_t fid;
2369
} SSsMigrateFileSetRsp;
2370

2371
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2372
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2373

2374
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2375
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2376
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2377
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2378
#define SSMIGRATE_FILESET_STATE_FAILED      4
2379

2380
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2381
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2382
// while as a request, the 'state' field is not used.
2383
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2384
typedef struct {
2385
  int32_t ssMigrateId;  // ss migrate id
2386
  int32_t nodeId;       // node id of the leader vnode
2387
  int32_t vgId;         // vgroup id
2388
  int32_t fid;          // file set id
2389
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2390
} SSsMigrateProgress;
2391

2392
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2393
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2394

2395
// Request for TDMT_MND_KILL_SSMIGRATE
2396
typedef struct {
2397
  int32_t ssMigrateId;
2398
  int32_t sqlLen;
2399
  char*   sql;
2400
} SKillSsMigrateReq;
2401

2402
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2403
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2404
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2405

2406
// Request for TDMT_VND_KILL_SSMIGRATE
2407
typedef struct {
2408
  int32_t ssMigrateId;
2409
} SVnodeKillSsMigrateReq;
2410

2411
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2412
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2413

2414
typedef struct {
2415
  int32_t vgId;
2416
  int64_t keepVersion;
2417
} SMndSetVgroupKeepVersionReq;
2418

2419
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2420
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2421

2422
typedef struct {
2423
  int32_t timestampSec;
2424
  int32_t ttlDropMaxCount;
2425
  int32_t nUids;
2426
  SArray* pTbUids;
2427
} SVDropTtlTableReq;
2428

2429
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2430
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2431

2432
typedef struct {
2433
  char    db[TSDB_DB_FNAME_LEN];
2434
  int64_t dbId;
2435
  int64_t ownerId;
2436
  int32_t cfgVersion;
2437
  int32_t numOfVgroups;
2438
  int32_t numOfStables;
2439
  int32_t buffer;
2440
  int32_t cacheSize;
2441
  int32_t cacheShardBits;
2442
  int32_t pageSize;
2443
  int32_t pages;
2444
  int32_t daysPerFile;
2445
  int32_t daysToKeep0;
2446
  int32_t daysToKeep1;
2447
  int32_t daysToKeep2;
2448
  int32_t keepTimeOffset;
2449
  int32_t minRows;
2450
  int32_t maxRows;
2451
  int32_t walFsyncPeriod;
2452
  int16_t hashPrefix;
2453
  int16_t hashSuffix;
2454
  int8_t  hashMethod;
2455
  int8_t  walLevel;
2456
  int8_t  precision;
2457
  int8_t  compression;
2458
  int8_t  replications;
2459
  int8_t  strict;
2460
  int8_t  cacheLast;
2461
  int8_t  encryptAlgr;
2462
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2463
  int32_t ssChunkSize;
2464
  int32_t ssKeepLocal;
2465
  int8_t  ssCompact;
2466
  union {
2467
    uint8_t flags;
2468
    struct {
2469
      uint8_t isMount : 1;    // TS-5868
2470
      uint8_t allowDrop : 1;  // TS-7232
2471
      uint8_t padding : 6;
2472
    };
2473
  };
2474
  int8_t  compactTimeOffset;
2475
  int32_t compactInterval;
2476
  int32_t compactStartTime;
2477
  int32_t compactEndTime;
2478
  int32_t tsdbPageSize;
2479
  int32_t walRetentionPeriod;
2480
  int32_t walRollPeriod;
2481
  int64_t walRetentionSize;
2482
  int64_t walSegmentSize;
2483
  int32_t numOfRetensions;
2484
  SArray* pRetensions;
2485
  int8_t  schemaless;
2486
  int16_t sstTrigger;
2487
  int8_t  withArbitrator;
2488
  int8_t  isAudit;
2489
  int8_t  secureDelete;
2490
} SDbCfgRsp;
2491

2492
typedef SDbCfgRsp SDbCfgInfo;
2493

2494
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2495
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2496
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2497
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2498
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2499

2500
typedef struct {
2501
  int32_t rowNum;
2502
} SQnodeListReq;
2503

2504
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2505
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2506

2507
typedef struct {
2508
  int32_t rowNum;
2509
} SDnodeListReq;
2510

2511
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2512

2513
typedef struct {
2514
  int32_t useless;  // useless
2515
} SServerVerReq;
2516

2517
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2518
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2519

2520
typedef struct {
2521
  char ver[TSDB_VERSION_LEN];
2522
} SServerVerRsp;
2523

2524
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2525
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2526

2527
typedef struct SQueryNodeAddr {
2528
  int32_t nodeId;  // vgId or qnodeId
2529
  SEpSet  epSet;
2530
} SQueryNodeAddr;
2531

2532
typedef struct {
2533
  SQueryNodeAddr addr;
2534
  uint64_t       load;
2535
} SQueryNodeLoad;
2536

2537
typedef struct {
2538
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2539
} SQnodeListRsp;
2540

2541
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2542
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2543
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2544

2545

2546
typedef struct SDownstreamSourceNode {
2547
  ENodeType      type;
2548
  SQueryNodeAddr addr;
2549
  uint64_t       clientId;
2550
  uint64_t       taskId;
2551
  uint64_t       sId;
2552
  uint64_t       srcTaskId;
2553
  int32_t        execId;
2554
  int32_t        fetchMsgType;
2555
  bool           localExec;
2556
} SDownstreamSourceNode;
2557

2558

2559

2560
typedef struct SDNodeAddr {
2561
  int32_t nodeId;  // dnodeId
2562
  SEpSet  epSet;
2563
} SDNodeAddr;
2564

2565
typedef struct {
2566
  SArray* dnodeList;  // SArray<SDNodeAddr>
2567
} SDnodeListRsp;
2568

2569
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2570
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2571
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2572

2573
typedef struct {
2574
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2575
} STableTSMAInfoRsp;
2576

2577
typedef struct {
2578
  SUseDbRsp*         useDbRsp;
2579
  SDbCfgRsp*         cfgRsp;
2580
  STableTSMAInfoRsp* pTsmaRsp;
2581
  int32_t            dbTsmaVersion;
2582
  char               db[TSDB_DB_FNAME_LEN];
2583
  int64_t            dbId;
2584
} SDbHbRsp;
2585

2586
typedef struct {
2587
  SArray* pArray;  // Array of SDbHbRsp
2588
} SDbHbBatchRsp;
2589

2590
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2591
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2592
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2593

2594
typedef struct {
2595
  SArray* pArray;  // Array of SGetUserAuthRsp
2596
} SUserAuthBatchRsp;
2597

2598
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2599
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2600
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2601

2602
typedef struct {
2603
  char        db[TSDB_DB_FNAME_LEN];
2604
  STimeWindow timeRange;
2605
  int32_t     sqlLen;
2606
  char*       sql;
2607
  SArray*     vgroupIds;
2608
  int32_t     compactId;
2609
  int8_t      metaOnly;
2610
  int8_t      force;
2611
} SCompactDbReq;
2612

2613
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2614
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2615
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2616

2617
typedef struct {
2618
  union {
2619
    int32_t compactId;
2620
    int32_t id;
2621
  };
2622
  int8_t bAccepted;
2623
} SCompactDbRsp;
2624

2625
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2626
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2627

2628
typedef struct {
2629
  union {
2630
    int32_t compactId;
2631
    int32_t id;
2632
  };
2633
  int32_t sqlLen;
2634
  char*   sql;
2635
} SKillCompactReq;
2636

2637
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2638
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2639
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2640

2641
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2642
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2643

2644
typedef struct {
2645
  char    name[TSDB_FUNC_NAME_LEN];
2646
  int8_t  igExists;
2647
  int8_t  funcType;
2648
  int8_t  scriptType;
2649
  int8_t  outputType;
2650
  int32_t outputLen;
2651
  int32_t bufSize;
2652
  int32_t codeLen;
2653
  int64_t signature;
2654
  char*   pComment;
2655
  char*   pCode;
2656
  int8_t  orReplace;
2657
} SCreateFuncReq;
2658

2659
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2660
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2661
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2662

2663
typedef struct {
2664
  char   name[TSDB_FUNC_NAME_LEN];
2665
  int8_t igNotExists;
2666
} SDropFuncReq;
2667

2668
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2669
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2670

2671
typedef struct {
2672
  int32_t numOfFuncs;
2673
  bool    ignoreCodeComment;
2674
  SArray* pFuncNames;
2675
} SRetrieveFuncReq;
2676

2677
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2678
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2679
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2680

2681
typedef struct {
2682
  char    name[TSDB_FUNC_NAME_LEN];
2683
  int8_t  funcType;
2684
  int8_t  scriptType;
2685
  int8_t  outputType;
2686
  int32_t outputLen;
2687
  int32_t bufSize;
2688
  int64_t signature;
2689
  int32_t commentSize;
2690
  int32_t codeSize;
2691
  char*   pComment;
2692
  char*   pCode;
2693
} SFuncInfo;
2694

2695
typedef struct {
2696
  int32_t funcVersion;
2697
  int64_t funcCreatedTime;
2698
} SFuncExtraInfo;
2699

2700
typedef struct {
2701
  int32_t numOfFuncs;
2702
  SArray* pFuncInfos;
2703
  SArray* pFuncExtraInfos;
2704
} SRetrieveFuncRsp;
2705

2706
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2707
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2708
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2709
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2710

2711
typedef struct {
2712
  int32_t       statusInterval;
2713
  /*
2714
    Local timezone UTC offset in seconds (east-positive, e.g. +28800 for
2715
    Asia/Shanghai).  Derived from taosGetLocalTimezoneOffset() on each
2716
    status report.  Paired with the timezone string in
2717
    mndCheckClusterCfgPara: a mismatch is reported only when both the
2718
    timezone string AND this offset differ.
2719
  */
2720
  int64_t       checkTime;
2721
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2722
  char          locale[TD_LOCALE_LEN];      // tsLocale
2723
  char          charset[TD_LOCALE_LEN];     // tsCharset
2724
  int8_t        ttlChangeOnWrite;
2725
  int8_t        enableWhiteList;
2726
  int8_t        encryptionKeyStat;
2727
  uint32_t      encryptionKeyChksum;
2728
  SMonitorParas monitorParas;
2729
  int32_t       statusIntervalMs;
2730
} SClusterCfg;
2731

2732
typedef struct {
2733
  int32_t openVnodes;
2734
  int32_t dropVnodes;
2735
  int32_t totalVnodes;
2736
  int32_t masterNum;
2737
  int64_t numOfSelectReqs;
2738
  int64_t numOfInsertReqs;
2739
  int64_t numOfInsertSuccessReqs;
2740
  int64_t numOfBatchInsertReqs;
2741
  int64_t numOfBatchInsertSuccessReqs;
2742
  int64_t errors;
2743
} SVnodesStat;
2744

2745
typedef struct {
2746
  int32_t vgId;
2747
  int8_t  syncState;
2748
  int8_t  syncRestore;
2749
  int64_t syncTerm;
2750
  int64_t roleTimeMs;
2751
  int64_t startTimeMs;
2752
  int8_t  syncCanRead;
2753
  int64_t cacheUsage;
2754
  int64_t numOfTables;
2755
  int64_t numOfTimeSeries;
2756
  int64_t totalStorage;
2757
  int64_t compStorage;
2758
  int64_t pointsWritten;
2759
  int64_t numOfSelectReqs;
2760
  int64_t numOfInsertReqs;
2761
  int64_t numOfInsertSuccessReqs;
2762
  int64_t numOfBatchInsertReqs;
2763
  int64_t numOfBatchInsertSuccessReqs;
2764
  int32_t numOfCachedTables;
2765
  int32_t learnerProgress;  // use one reservered
2766
  int64_t syncAppliedIndex;
2767
  int64_t syncCommitIndex;
2768
  int64_t bufferSegmentUsed;
2769
  int64_t bufferSegmentSize;
2770
  int32_t snapSeq;
2771
  int64_t syncTotalIndex;
2772
} SVnodeLoad;
2773

2774
typedef struct {
2775
  int64_t total_requests;
2776
  int64_t total_rows;
2777
  int64_t total_bytes;
2778
  double  write_size;
2779
  double  cache_hit_ratio;
2780
  int64_t rpc_queue_wait;
2781
  int64_t preprocess_time;
2782

2783
  int64_t memory_table_size;
2784
  int64_t commit_count;
2785
  int64_t merge_count;
2786
  double  commit_time;
2787
  double  merge_time;
2788
  int64_t block_commit_time;
2789
  int64_t memtable_wait_time;
2790
} SVnodeMetrics;
2791

2792
typedef struct {
2793
  int32_t     vgId;
2794
  int64_t     numOfTables;
2795
  int64_t     memSize;
2796
  int64_t     l1Size;
2797
  int64_t     l2Size;
2798
  int64_t     l3Size;
2799
  int64_t     cacheSize;
2800
  int64_t     walSize;
2801
  int64_t     metaSize;
2802
  int64_t     rawDataSize;
2803
  int64_t     ssSize;
2804
  const char* dbname;
2805
  int8_t      estimateRawData;
2806
} SDbSizeStatisInfo;
2807

2808
typedef struct {
2809
  int32_t vgId;
2810
  int64_t nTimeSeries;
2811
} SVnodeLoadLite;
2812

2813
typedef struct {
2814
  int8_t  syncState;
2815
  int64_t syncTerm;
2816
  int8_t  syncRestore;
2817
  int64_t roleTimeMs;
2818
} SMnodeLoad;
2819

2820
typedef struct {
2821
  int32_t dnodeId;
2822
  int64_t numOfProcessedQuery;
2823
  int64_t numOfProcessedCQuery;
2824
  int64_t numOfProcessedFetch;
2825
  int64_t numOfProcessedDrop;
2826
  int64_t numOfProcessedNotify;
2827
  int64_t numOfProcessedHb;
2828
  int64_t numOfProcessedDelete;
2829
  int64_t cacheDataSize;
2830
  int64_t numOfQueryInQueue;
2831
  int64_t numOfFetchInQueue;
2832
  int64_t timeInQueryQueue;
2833
  int64_t timeInFetchQueue;
2834
} SQnodeLoad;
2835

2836
typedef struct {
2837
  int32_t     sver;      // software version
2838
  int64_t     dnodeVer;  // dnode table version in sdb
2839
  int32_t     dnodeId;
2840
  int64_t     clusterId;
2841
  int64_t     rebootTime;
2842
  int64_t     updateTime;
2843
  float       numOfCores;
2844
  int32_t     numOfSupportVnodes;
2845
  int32_t     numOfDiskCfg;
2846
  int64_t     memTotal;
2847
  int64_t     memAvail;
2848
  char        dnodeEp[TSDB_EP_LEN];
2849
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2850
  SMnodeLoad  mload;
2851
  SQnodeLoad  qload;
2852
  SClusterCfg clusterCfg;
2853
  SArray*     pVloads;  // array of SVnodeLoad
2854
  int32_t     statusSeq;
2855
  int64_t     ipWhiteVer;
2856
  int64_t     timeWhiteVer;
2857
  int64_t     analVer;
2858
  int64_t     timestamp;
2859
  char        auditDB[TSDB_DB_FNAME_LEN];
2860
  char        auditToken[TSDB_TOKEN_LEN];
2861
  SEpSet      auditEpSet;
2862
  int32_t     auditVgId;
2863
} SStatusReq;
2864

2865
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2866
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2867
void    tFreeSStatusReq(SStatusReq* pReq);
2868

2869
typedef struct {
2870
  int32_t forceReadConfig;
2871
  int32_t cver;
2872
  SArray* array;
2873
} SConfigReq;
2874

2875
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2876
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2877
void    tFreeSConfigReq(SConfigReq* pReq);
2878

2879
typedef struct {
2880
  int32_t dnodeId;
2881
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2882
} SDnodeInfoReq;
2883

2884
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2885
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2886

2887
typedef enum {
2888
  MONITOR_TYPE_COUNTER = 0,
2889
  MONITOR_TYPE_SLOW_LOG = 1,
2890
} MONITOR_TYPE;
2891

2892
typedef struct {
2893
  int32_t      contLen;
2894
  char*        pCont;
2895
  MONITOR_TYPE type;
2896
} SStatisReq;
2897

2898
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2899
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2900
void    tFreeSStatisReq(SStatisReq* pReq);
2901

2902
typedef struct {
2903
  char    db[TSDB_DB_FNAME_LEN];
2904
  char    table[TSDB_TABLE_NAME_LEN];
2905
  char    operation[AUDIT_OPERATION_LEN];
2906
  int32_t sqlLen;
2907
  char*   pSql;
2908
  double  duration;
2909
  int64_t affectedRows;
2910
} SAuditReq;
2911
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2912
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2913
void    tFreeSAuditReq(SAuditReq* pReq);
2914

2915
typedef struct {
2916
  SArray* auditArr;
2917
} SBatchAuditReq;
2918
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2919
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2920
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2921

2922
typedef struct {
2923
  int32_t dnodeId;
2924
  int64_t clusterId;
2925
  SArray* pVloads;
2926
} SNotifyReq;
2927

2928
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2929
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2930
void    tFreeSNotifyReq(SNotifyReq* pReq);
2931

2932
typedef struct {
2933
  int32_t dnodeId;
2934
  int64_t clusterId;
2935
} SDnodeCfg;
2936

2937
typedef struct {
2938
  int32_t id;
2939
  int8_t  isMnode;
2940
  SEp     ep;
2941
} SDnodeEp;
2942

2943
typedef struct {
2944
  int32_t id;
2945
  int8_t  isMnode;
2946
  int8_t  offlineReason;
2947
  SEp     ep;
2948
  char    active[TSDB_ACTIVE_KEY_LEN];
2949
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2950
} SDnodeInfo;
2951

2952
typedef struct {
2953
  int64_t   dnodeVer;
2954
  SDnodeCfg dnodeCfg;
2955
  SArray*   pDnodeEps;  // Array of SDnodeEp
2956
  int32_t   statusSeq;
2957
  int64_t   ipWhiteVer;
2958
  int64_t   analVer;
2959
  int64_t   timeWhiteVer;
2960
  char      auditDB[TSDB_DB_FNAME_LEN];
2961
  char      auditToken[TSDB_TOKEN_LEN];
2962
  SEpSet    auditEpSet;
2963
  int32_t   auditVgId;
2964
} SStatusRsp;
2965

2966
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2967
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2968
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2969

2970
typedef struct {
2971
  int32_t forceReadConfig;
2972
  int32_t isConifgVerified;
2973
  int32_t isVersionVerified;
2974
  int32_t cver;
2975
  SArray* array;
2976
} SConfigRsp;
2977

2978
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2979
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2980
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2981

2982
typedef struct {
2983
  int32_t dnodeId;
2984
  int32_t keyVersion;  // Local key version
2985
} SKeySyncReq;
2986

2987
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2988
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2989

2990
typedef struct {
2991
  int32_t keyVersion;        // mnode's key version
2992
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2993
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2994
  char    svrKey[129];       // Server key (if needUpdate)
2995
  char    dbKey[129];        // Database key (if needUpdate)
2996
  char    cfgKey[129];       // Config key (if needUpdate)
2997
  char    metaKey[129];      // Metadata key (if needUpdate)
2998
  char    dataKey[129];      // Data key (if needUpdate)
2999
  int32_t algorithm;         // Encryption algorithm for master keys
3000
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
3001
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
3002
  int64_t createTime;        // Key creation time
3003
  int64_t svrKeyUpdateTime;  // Server key update time
3004
  int64_t dbKeyUpdateTime;   // Database key update time
3005
} SKeySyncRsp;
3006

3007
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3008
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3009

3010
typedef struct {
3011
  int32_t reserved;
3012
} SMTimerReq;
3013

3014
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3015
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3016

3017
typedef struct SOrphanTask {
3018
  int64_t streamId;
3019
  int32_t taskId;
3020
  int32_t nodeId;
3021
} SOrphanTask;
3022

3023
typedef struct SMStreamDropOrphanMsg {
3024
  SArray* pList;  // SArray<SOrphanTask>
3025
} SMStreamDropOrphanMsg;
3026

3027
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3028
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3029
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
3030

3031
typedef struct {
3032
  int32_t  id;
3033
  uint16_t port;                 // node sync Port
3034
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3035
} SReplica;
3036

3037
typedef struct {
3038
  int32_t  vgId;
3039
  char     db[TSDB_DB_FNAME_LEN];
3040
  int64_t  dbUid;
3041
  int32_t  vgVersion;
3042
  int32_t  numOfStables;
3043
  int32_t  buffer;
3044
  int32_t  pageSize;
3045
  int32_t  pages;
3046
  int32_t  cacheLastSize;
3047
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3048
  int32_t  daysPerFile;
3049
  int32_t  daysToKeep0;
3050
  int32_t  daysToKeep1;
3051
  int32_t  daysToKeep2;
3052
  int32_t  keepTimeOffset;
3053
  int32_t  minRows;
3054
  int32_t  maxRows;
3055
  int32_t  walFsyncPeriod;
3056
  uint32_t hashBegin;
3057
  uint32_t hashEnd;
3058
  int8_t   hashMethod;
3059
  int8_t   walLevel;
3060
  int8_t   precision;
3061
  int8_t   compression;
3062
  int8_t   strict;
3063
  int8_t   cacheLast;
3064
  int8_t   isTsma;
3065
  int8_t   replica;
3066
  int8_t   selfIndex;
3067
  SReplica replicas[TSDB_MAX_REPLICA];
3068
  int32_t  numOfRetensions;
3069
  SArray*  pRetensions;  // SRetention
3070
  void*    pTsma;
3071
  int32_t  walRetentionPeriod;
3072
  int64_t  walRetentionSize;
3073
  int32_t  walRollPeriod;
3074
  int64_t  walSegmentSize;
3075
  int16_t  sstTrigger;
3076
  int16_t  hashPrefix;
3077
  int16_t  hashSuffix;
3078
  int32_t  tsdbPageSize;
3079
  int32_t  ssChunkSize;
3080
  int32_t  ssKeepLocal;
3081
  int8_t   ssCompact;
3082
  int64_t  reserved[6];
3083
  int8_t   learnerReplica;
3084
  int8_t   learnerSelfIndex;
3085
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3086
  int32_t  changeVersion;
3087
  int8_t   encryptAlgorithm;
3088
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3089
  union {
3090
    uint8_t flags;
3091
    struct {
3092
      uint8_t isAudit : 1;
3093
      uint8_t allowDrop : 1;
3094
      uint8_t padding : 6;
3095
    };
3096
  };
3097
  int8_t secureDelete;
3098
} SCreateVnodeReq;
3099

3100
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3101
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3102
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3103

3104
typedef struct {
3105
  union {
3106
    int32_t compactId;
3107
    int32_t id;
3108
  };
3109
  int32_t vgId;
3110
  int32_t dnodeId;
3111
} SQueryCompactProgressReq;
3112

3113
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3114
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3115

3116
typedef struct {
3117
  union {
3118
    int32_t compactId;
3119
    int32_t id;
3120
  };
3121
  int32_t vgId;
3122
  int32_t dnodeId;
3123
  int32_t numberFileset;
3124
  int32_t finished;
3125
  int32_t progress;
3126
  int64_t remainingTime;
3127
} SQueryCompactProgressRsp;
3128

3129
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3130
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3131

3132
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3133
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3134

3135
typedef struct {
3136
  int32_t vgId;
3137
  int32_t dnodeId;
3138
  int64_t dbUid;
3139
  char    db[TSDB_DB_FNAME_LEN];
3140
  int64_t reserved[8];
3141
} SDropVnodeReq;
3142

3143
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3144
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3145

3146
typedef struct {
3147
  char    colName[TSDB_COL_NAME_LEN];
3148
  char    stb[TSDB_TABLE_FNAME_LEN];
3149
  int64_t stbUid;
3150
  int64_t dbUid;
3151
  int64_t reserved[8];
3152
} SDropIndexReq;
3153

3154
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3155
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3156

3157
typedef struct {
3158
  int64_t dbUid;
3159
  char    db[TSDB_DB_FNAME_LEN];
3160
  union {
3161
    int64_t compactStartTime;
3162
    int64_t startTime;
3163
  };
3164

3165
  STimeWindow tw;
3166
  union {
3167
    int32_t compactId;
3168
    int32_t id;
3169
  };
3170
  int8_t metaOnly;
3171
  union {
3172
    uint16_t flags;
3173
    struct {
3174
      uint16_t optrType : 3;     // ETsdbOpType
3175
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3176
      uint16_t reserved : 12;
3177
    };
3178
  };
3179
  int8_t force;  // force compact
3180
} SCompactVnodeReq;
3181

3182
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3183
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3184

3185
typedef struct {
3186
  union {
3187
    int32_t compactId;
3188
    int32_t taskId;
3189
  };
3190
  int32_t vgId;
3191
  int32_t dnodeId;
3192
} SVKillCompactReq;
3193

3194
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3195
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3196

3197
typedef SVKillCompactReq SVKillRetentionReq;
3198

3199
typedef struct {
3200
  char        db[TSDB_DB_FNAME_LEN];
3201
  int32_t     maxSpeed;
3202
  int32_t     sqlLen;
3203
  char*       sql;
3204
  SArray*     vgroupIds;
3205
  STimeWindow tw;  // unit is second
3206
  union {
3207
    uint32_t flags;
3208
    struct {
3209
      uint32_t optrType : 3;     // ETsdbOpType
3210
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3211
      uint32_t reserved : 28;
3212
    };
3213
  };
3214
} STrimDbReq;
3215

3216
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3217
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3218
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3219

3220
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3221

3222
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3223
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3224

3225
typedef struct {
3226
  int32_t vgVersion;
3227
  int32_t buffer;
3228
  int32_t pageSize;
3229
  int32_t pages;
3230
  int32_t cacheLastSize;
3231
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3232
  int32_t daysPerFile;
3233
  int32_t daysToKeep0;
3234
  int32_t daysToKeep1;
3235
  int32_t daysToKeep2;
3236
  int32_t keepTimeOffset;
3237
  int32_t walFsyncPeriod;
3238
  int8_t  walLevel;
3239
  int8_t  strict;
3240
  int8_t  cacheLast;
3241
  int64_t reserved[7];
3242
  // 1st modification
3243
  int16_t sttTrigger;
3244
  int32_t minRows;
3245
  // 2nd modification
3246
  int32_t walRetentionPeriod;
3247
  int32_t walRetentionSize;
3248
  int32_t ssKeepLocal;
3249
  int8_t  ssCompact;
3250
  int8_t  allowDrop;
3251
  int8_t  secureDelete;
3252
} SAlterVnodeConfigReq;
3253

3254
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3255
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3256

3257
typedef struct {
3258
  int32_t  vgId;
3259
  int8_t   strict;
3260
  int8_t   selfIndex;
3261
  int8_t   replica;
3262
  SReplica replicas[TSDB_MAX_REPLICA];
3263
  int64_t  reserved[8];
3264
  int8_t   learnerSelfIndex;
3265
  int8_t   learnerReplica;
3266
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3267
  int32_t  changeVersion;
3268
  int32_t  electBaseLine;
3269
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3270

3271
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3272
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3273

3274
typedef struct {
3275
  int32_t vgId;
3276
  int8_t  disable;
3277
} SDisableVnodeWriteReq;
3278

3279
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3280
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3281

3282
typedef struct {
3283
  int32_t  srcVgId;
3284
  int32_t  dstVgId;
3285
  uint32_t hashBegin;
3286
  uint32_t hashEnd;
3287
  int32_t  changeVersion;
3288
  int32_t  reserved;
3289
} SAlterVnodeHashRangeReq;
3290

3291
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3292
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3293

3294
#define REQ_OPT_TBNAME 0x0
3295
#define REQ_OPT_TBUID  0x01
3296
typedef struct {
3297
  SMsgHead header;
3298
  char     dbFName[TSDB_DB_FNAME_LEN];
3299
  char     tbName[TSDB_TABLE_NAME_LEN];
3300
  uint8_t  option;
3301
  uint8_t  autoCreateCtb;
3302
} STableInfoReq;
3303

3304
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3305
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3306

3307
typedef struct {
3308
  int8_t  metaClone;  // create local clone of the cached table meta
3309
  int32_t numOfVgroups;
3310
  int32_t numOfTables;
3311
  int32_t numOfUdfs;
3312
  char    tableNames[];
3313
} SMultiTableInfoReq;
3314

3315
// todo refactor
3316
typedef struct SVgroupInfo {
3317
  int32_t  vgId;
3318
  uint32_t hashBegin;
3319
  uint32_t hashEnd;
3320
  SEpSet   epSet;
3321
  union {
3322
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3323
    int32_t taskId;      // used in stream
3324
  };
3325
} SVgroupInfo;
3326

3327
typedef struct {
3328
  int32_t     numOfVgroups;
3329
  SVgroupInfo vgroups[];
3330
} SVgroupsInfo;
3331

3332
typedef struct {
3333
  STableMetaRsp* pMeta;
3334
} SMAlterStbRsp;
3335

3336
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3337
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3338
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3339

3340
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3341
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3342
void    tFreeSTableMetaRsp(void* pRsp);
3343
void    tFreeSTableIndexRsp(void* info);
3344

3345
typedef struct {
3346
  SArray* pMetaRsp;   // Array of STableMetaRsp
3347
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3348
} SSTbHbRsp;
3349

3350
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3351
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3352
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3353

3354
typedef struct {
3355
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3356
} SViewHbRsp;
3357

3358
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3359
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3360
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3361

3362
typedef struct {
3363
  int32_t numOfTables;
3364
  int32_t numOfVgroup;
3365
  int32_t numOfUdf;
3366
  int32_t contLen;
3367
  int8_t  compressed;  // denote if compressed or not
3368
  int32_t rawLen;      // size before compress
3369
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3370
  char    meta[];
3371
} SMultiTableMeta;
3372

3373
typedef struct {
3374
  int32_t dataLen;
3375
  char    name[TSDB_TABLE_FNAME_LEN];
3376
  char*   data;
3377
} STagData;
3378

3379
typedef struct {
3380
  int32_t  opType;
3381
  uint32_t valLen;
3382
  char*    val;
3383
} SShowVariablesReq;
3384

3385
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3386
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3387
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3388

3389
typedef struct {
3390
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3391
  char value[TSDB_CONFIG_PATH_LEN + 1];
3392
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3393
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3394
  char info[TSDB_CONFIG_INFO_LEN + 1];
3395
} SVariablesInfo;
3396

3397
typedef struct {
3398
  SArray* variables;  // SArray<SVariablesInfo>
3399
} SShowVariablesRsp;
3400

3401
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3402
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3403

3404
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3405

3406
/*
3407
 * sql: show tables like '%a_%'
3408
 * payload is the query condition, e.g., '%a_%'
3409
 * payloadLen is the length of payload
3410
 */
3411
typedef struct {
3412
  int32_t type;
3413
  char    db[TSDB_DB_FNAME_LEN];
3414
  int32_t payloadLen;
3415
  char*   payload;
3416
} SShowReq;
3417

3418
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3419
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3420
void tFreeSShowReq(SShowReq* pReq);
3421

3422
typedef struct {
3423
  int64_t       showId;
3424
  STableMetaRsp tableMeta;
3425
} SShowRsp, SVShowTablesRsp;
3426

3427
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3428
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3429
// void    tFreeSShowRsp(SShowRsp* pRsp);
3430

3431
typedef struct {
3432
  char    db[TSDB_DB_FNAME_LEN];
3433
  char    tb[TSDB_TABLE_NAME_LEN];
3434
  char    user[TSDB_USER_LEN];
3435
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3436
  int64_t showId;
3437
  int64_t compactId;  // for compact
3438
  bool    withFull;   // for show users full
3439
} SRetrieveTableReq;
3440

3441
typedef struct SSysTableSchema {
3442
  int8_t   type;
3443
  col_id_t colId;
3444
  int32_t  bytes;
3445
} SSysTableSchema;
3446

3447
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3448
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3449

3450
#define RETRIEVE_TABLE_RSP_VERSION         0
3451
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3452
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3453

3454
typedef struct {
3455
  int64_t useconds;
3456
  int8_t  completed;  // all results are returned to client
3457
  int8_t  precision;
3458
  int8_t  compressed;
3459
  int8_t  streamBlockType;
3460
  int32_t payloadLen;
3461
  int32_t compLen;
3462
  int32_t numOfBlocks;
3463
  int64_t numOfRows;  // from int32_t change to int64_t
3464
  int64_t numOfCols;
3465
  int64_t skey;
3466
  int64_t ekey;
3467
  int64_t version;                         // for stream
3468
  TSKEY   watermark;                       // for stream
3469
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3470
  char    data[];
3471
} SRetrieveTableRsp;
3472

3473
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3474

3475
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3476
  do {                                          \
3477
    ((int32_t*)(_p))[0] = (_compLen);           \
3478
    ((int32_t*)(_p))[1] = (_fullLen);           \
3479
  } while (0);
3480

3481
typedef struct {
3482
  int64_t version;
3483
  int64_t numOfRows;
3484
  int8_t  compressed;
3485
  int8_t  precision;
3486
  char    data[];
3487
} SRetrieveTableRspForTmq;
3488

3489
typedef struct {
3490
  int64_t handle;
3491
  int64_t useconds;
3492
  int8_t  completed;  // all results are returned to client
3493
  int8_t  precision;
3494
  int8_t  compressed;
3495
  int32_t compLen;
3496
  int32_t numOfRows;
3497
  int32_t fullLen;
3498
  char    data[];
3499
} SRetrieveMetaTableRsp;
3500

3501
typedef struct SExplainExecInfo {
3502
  /* the number of rows returned */
3503
  uint64_t numOfRows;
3504
  uint32_t verboseLen;
3505
  void*    verboseInfo;
3506

3507
  /* the timestamp when the operator is created */
3508
  TSKEY    execCreate;
3509
  /* the first timestamp when the operator's next interface is called */
3510
  TSKEY    execStart;
3511
  /* the timestamp when the first row is returned */
3512
  TSKEY    execFirstRow;
3513
  /* the timestamp when the last row is returned */
3514
  TSKEY    execLastRow;
3515
  /* the number of times the operator's next interface is called */
3516
  uint32_t execTimes;
3517
  /**
3518
    the time elapsed for executing the operator's next interface,
3519
    not including waiting time for data from downstream
3520
  */
3521
  TSKEY    execElapsed;
3522
  /* the time elapsed for waiting for data from downstream */
3523
  TSKEY    inputWaitElapsed;
3524
  /* the time elapsed for waiting call from upstream */
3525
  TSKEY    outputWaitElapsed;
3526
  /* the number of rows input */
3527
  uint64_t inputRows;
3528

3529
  int32_t  vgId;
3530
} SExplainExecInfo;
3531

3532
typedef struct {
3533
  int32_t           numOfPlans;
3534
  SExplainExecInfo* subplanInfo;
3535
} SExplainRsp;
3536

3537
typedef struct {
3538
  SExplainRsp rsp;
3539
  uint64_t    qId;
3540
  uint64_t    cId;
3541
  uint64_t    tId;
3542
  int64_t     rId;
3543
  int32_t     eId;
3544
} SExplainLocalRsp;
3545

3546
typedef struct STableScanAnalyzeInfo {
3547
  int64_t totalBlocks;
3548
  int64_t fileLoadBlocks;
3549
  double  fileLoadElapsed;
3550
  int64_t sttLoadBlocks;
3551
  double  sttLoadElapsed;
3552
  int64_t memLoadBlocks;
3553
  double  memLoadElapsed;
3554
  int64_t smaLoadBlocks;
3555
  double  smaLoadElapsed;
3556
  int64_t composedBlocks;
3557
  double  composedElapsed;
3558
  
3559
  uint64_t checkRows;
3560

3561
  uint64_t skipBlocks;
3562
  uint64_t filterOutBlocks;
3563
  double   filterTime;
3564
} STableScanAnalyzeInfo;
3565

3566
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3567
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3568
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3569

3570
typedef struct {
3571
  char    config[TSDB_DNODE_CONFIG_LEN];
3572
  char    value[TSDB_CLUSTER_VALUE_LEN];
3573
  int32_t sqlLen;
3574
  char*   sql;
3575
} SMCfgClusterReq;
3576

3577
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3578
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3579
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3580

3581
typedef struct {
3582
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3583
  int32_t port;
3584
  int32_t sqlLen;
3585
  char*   sql;
3586
} SCreateDnodeReq;
3587

3588
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3589
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3590
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3591

3592
typedef struct {
3593
  int32_t dnodeId;
3594
  char    fqdn[TSDB_FQDN_LEN];
3595
  int32_t port;
3596
  int8_t  force;
3597
  int8_t  unsafe;
3598
  int32_t sqlLen;
3599
  char*   sql;
3600
} SDropDnodeReq;
3601

3602
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3603
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3604
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3605

3606
enum {
3607
  RESTORE_TYPE__ALL = 1,
3608
  RESTORE_TYPE__MNODE,
3609
  RESTORE_TYPE__VNODE,
3610
  RESTORE_TYPE__QNODE,
3611
};
3612

3613
typedef struct {
3614
  int32_t dnodeId;
3615
  int8_t  restoreType;
3616
  int32_t sqlLen;
3617
  char*   sql;
3618
  int32_t vgId;
3619
} SRestoreDnodeReq;
3620

3621
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3622
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3623
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3624

3625
typedef struct {
3626
  int32_t dnodeId;
3627
  char    config[TSDB_DNODE_CONFIG_LEN];
3628
  char    value[TSDB_DNODE_VALUE_LEN];
3629
  int32_t sqlLen;
3630
  char*   sql;
3631
} SMCfgDnodeReq;
3632

3633
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3634
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3635
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3636

3637
typedef struct {
3638
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3639
  char    newKey[ENCRYPT_KEY_LEN + 1];
3640
  int32_t sqlLen;
3641
  char*   sql;
3642
} SMAlterEncryptKeyReq;
3643

3644
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3645
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3646
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3647

3648
typedef struct {
3649
  int32_t days;
3650
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3651
  int32_t sqlLen;
3652
  char*   sql;
3653
} SMAlterKeyExpirationReq;
3654

3655
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3656
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3657
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3658

3659
typedef struct {
3660
  char    config[TSDB_DNODE_CONFIG_LEN];
3661
  char    value[TSDB_DNODE_VALUE_LEN];
3662
  int32_t version;
3663
} SDCfgDnodeReq;
3664

3665
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3666
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3667

3668
typedef struct {
3669
  int32_t dnodeId;
3670
  int32_t sqlLen;
3671
  char*   sql;
3672
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3673
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3674

3675
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3676
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3677

3678
typedef struct {
3679
  int32_t nodeId;
3680
  SEpSet  epSet;
3681
} SNodeEpSet;
3682

3683
typedef struct {
3684
  int32_t    snodeId;
3685
  SNodeEpSet leaders[2];
3686
  SNodeEpSet replica;
3687
  int32_t    sqlLen;
3688
  char*      sql;
3689
} SDCreateSnodeReq;
3690

3691
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3692
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3693
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3694

3695
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3696
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3697
typedef struct {
3698
  int8_t   replica;
3699
  SReplica replicas[TSDB_MAX_REPLICA];
3700
  int8_t   learnerReplica;
3701
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3702
  int64_t  lastIndex;
3703
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3704
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3705

3706
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3707
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3708

3709
typedef struct {
3710
  int32_t urlLen;
3711
  int32_t sqlLen;
3712
  char*   url;
3713
  char*   sql;
3714
} SMCreateAnodeReq;
3715

3716
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3717
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3718
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3719

3720
typedef struct {
3721
  int32_t anodeId;
3722
  int32_t sqlLen;
3723
  char*   sql;
3724
} SMDropAnodeReq, SMUpdateAnodeReq;
3725

3726
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3727
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3728
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3729
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3730
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3731
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3732

3733
typedef struct {
3734
  int32_t dnodeId;
3735
  int32_t bnodeProto;
3736
  int32_t sqlLen;
3737
  char*   sql;
3738
} SMCreateBnodeReq, SDCreateBnodeReq;
3739

3740
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3741
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3742
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3743

3744
typedef struct {
3745
  int32_t dnodeId;
3746
  int32_t sqlLen;
3747
  char*   sql;
3748
} SMDropBnodeReq, SDDropBnodeReq;
3749

3750
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3751
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3752
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3753

3754
typedef struct {
3755
  bool        shouldFree;
3756
  int32_t     len;
3757
  const char* ptr;
3758
} CowStr;
3759
/**
3760
 * @brief Create a CowStr object.
3761
 *
3762
 * @param len: length of the string.
3763
 * @param ptr: pointer to the string input.
3764
 * @param shouldClone: whether to clone the string.
3765
 * @return CowStr object.
3766
 */
3767
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3768
/**
3769
 * @brief Set a CowStr object with given string.
3770
 *
3771
 * @param cow: pointer to the CowStr object.
3772
 * @param len: length of the string.
3773
 * @param ptr: pointer to the string input.
3774
 * @param shouldFree: whether to free the string.
3775
 */
3776
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3777
/**
3778
 * @brief Clone a CowStr object without copy the string.
3779
 *
3780
 * @param cow: pointer to the CowStr object.
3781
 * @return CowStr object.
3782
 */
3783
CowStr xCloneRefCowStr(CowStr* cow);
3784
/**
3785
 * @brief Convert a CowStr object to a string.
3786
 *
3787
 * @param cow: pointer to the CowStr object.
3788
 */
3789
char* xCowStrToStr(CowStr* cow);
3790
/**
3791
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3792
 *
3793
 * @param cow: pointer to the CowStr object.
3794
 */
3795
void xFreeCowStr(CowStr* cow);
3796
/**
3797
 * @brief Encode and push a CowStr object into the encoder.
3798
 *
3799
 * @param encoder
3800
 * @param cow
3801
 * @return int32_t
3802
 */
3803
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3804
/**
3805
 * @brief Decode a CowStr from the encoder.
3806
 *
3807
 * @param decoder
3808
 * @param cow
3809
 * @param shouldClone
3810
 * @return int32_t
3811
 */
3812
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3813

3814
typedef struct {
3815
  int32_t sqlLen;
3816
  int32_t urlLen;
3817
  int32_t userLen;
3818
  int32_t passLen;
3819
  int32_t passIsMd5;
3820
  char*   sql;
3821
  char*   url;
3822
  char*   user;
3823
  char*   pass;
3824
  CowStr  token;
3825
} SMCreateXnodeReq, SDCreateXnodeReq;
3826

3827
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3828
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3829
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3830

3831
typedef struct {
3832
  int32_t xnodeId;
3833
  int32_t force;
3834
  int32_t urlLen;
3835
  int32_t sqlLen;
3836
  char*   url;
3837
  char*   sql;
3838
} SMDropXnodeReq, SDDropXnodeReq;
3839

3840
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3841
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3842
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3843

3844
typedef struct {
3845
  int32_t id;
3846
  CowStr  token;
3847
  CowStr  user;
3848
  CowStr  pass;
3849
  int32_t urlLen;
3850
  int32_t sqlLen;
3851
  char*   url;
3852
  char*   sql;
3853
} SMUpdateXnodeReq;
3854
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3855
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3856
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3857

3858
typedef struct {
3859
  int32_t xnodeId;
3860
  int32_t sqlLen;
3861
  char*   sql;
3862
} SMDrainXnodeReq;
3863
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3864
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3865
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3866
typedef enum {
3867
  XNODE_TASK_SOURCE_DSN = 1,
3868
  XNODE_TASK_SOURCE_DATABASE,
3869
  XNODE_TASK_SOURCE_TOPIC,
3870
} ENodeXTaskSourceType;
3871

3872
typedef enum {
3873
  XNODE_TASK_SINK_DSN = 1,
3874
  XNODE_TASK_SINK_DATABASE,
3875
} ENodeXTaskSinkType;
3876

3877
typedef struct {
3878
  ENodeXTaskSourceType type;
3879
  CowStr               cstr;
3880
} xTaskSource;
3881
/**
3882
 * @brief Deallocate a xTaskSource object.
3883
 *
3884
 * @param source ptr
3885
 */
3886
void xFreeTaskSource(xTaskSource* source);
3887
/**
3888
 * @brief Create a xTaskSource object with cloned source string.
3889
 *
3890
 * @param sourceType: source type.
3891
 * @param len: length of source string.
3892
 * @param source: source string ptr.
3893
 * @return xTaskSource object
3894
 */
3895
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3896
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3897
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3898
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3899
const char* xGetTaskSourceStr(xTaskSource* source);
3900
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3901
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3902

3903
typedef struct {
3904
  ENodeXTaskSinkType type;
3905
  CowStr             cstr;
3906
} xTaskSink;
3907
/**
3908
 * @brief Deallocate a xTaskSink object.
3909
 *
3910
 * @param sink ptr
3911
 */
3912
void xFreeTaskSink(xTaskSink* sink);
3913
/**
3914
 * @brief Create a xTaskSink object with cloned name string.
3915
 *
3916
 * @param sinkType: sink type.
3917
 * @param len: length of sink string.
3918
 * @param ptr: sink string ptr.
3919
 * @return xTaskSink object
3920
 */
3921
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3922
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3923
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3924
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3925
const char* xGetTaskSinkStr(xTaskSink* sink);
3926
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3927
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3928

3929
typedef struct {
3930
  int32_t via;
3931
  CowStr  parser;
3932
  // CowStr  reason;
3933
  CowStr  trigger;
3934
  CowStr  health;
3935
  int32_t optionsNum;
3936
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3937
} xTaskOptions;
3938
/**
3939
 * @brief Deallocate a xTaskOptions object.
3940
 *
3941
 * @param options ptr
3942
 */
3943
void    xFreeTaskOptions(xTaskOptions* options);
3944
void    printXnodeTaskOptions(xTaskOptions* options);
3945
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3946
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3947

3948
typedef struct {
3949
  int32_t sqlLen;
3950
  char*   sql;
3951
  int32_t      xnodeId;
3952
  CowStr       name;
3953
  xTaskSource  source;
3954
  xTaskSink    sink;
3955
  xTaskOptions options;
3956
} SMCreateXnodeTaskReq;
3957
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3958
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3959
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3960

3961
typedef struct {
3962
  int32_t     tid;
3963
  CowStr      name;
3964
  int32_t     via;
3965
  int32_t     xnodeId;
3966
  CowStr      status;
3967
  xTaskSource source;
3968
  xTaskSink   sink;
3969
  CowStr      parser;
3970
  CowStr      reason;
3971
  CowStr      updateName;
3972
  CowStr      labels;
3973
  int32_t     sqlLen;
3974
  char*       sql;
3975
} SMUpdateXnodeTaskReq;
3976
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3977
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3978
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3979

3980
typedef struct {
3981
  int32_t id;
3982
  bool    force;
3983
  CowStr  name;
3984
  int32_t sqlLen;
3985
  char*   sql;
3986
} SMDropXnodeTaskReq;
3987
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3988
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3989
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3990

3991
typedef struct {
3992
  int32_t tid;
3993
  CowStr  name;
3994
  int32_t sqlLen;
3995
  char*   sql;
3996
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3997
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3998
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3999
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
4000

4001
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4002
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4003
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
4004

4005
typedef struct {
4006
  int32_t tid;
4007
  int32_t via;
4008
  int32_t xnodeId;
4009
  CowStr  status;
4010
  CowStr  config;
4011
  CowStr  reason;
4012
  int32_t sqlLen;
4013
  char*   sql;
4014
} SMCreateXnodeJobReq;
4015
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4016
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4017
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
4018

4019
typedef struct {
4020
  int32_t jid;
4021
  int32_t via;
4022
  int32_t xnodeId;
4023
  CowStr  status;
4024
  int32_t configLen;
4025
  int32_t reasonLen;
4026
  int32_t sqlLen;
4027
  char*   config;
4028
  char*   reason;
4029
  char*   sql;
4030
} SMUpdateXnodeJobReq;
4031
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4032
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4033
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4034

4035
typedef struct {
4036
  int32_t jid;
4037
  int32_t xnodeId;
4038
  int32_t sqlLen;
4039
  char*   sql;
4040
} SMRebalanceXnodeJobReq;
4041
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4042
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4043
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4044

4045
typedef struct {
4046
  CowStr  ast;
4047
  int32_t sqlLen;
4048
  char*   sql;
4049
} SMRebalanceXnodeJobsWhereReq;
4050
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4051
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4052
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4053

4054
typedef struct {
4055
  int32_t jid;
4056
  CowStr  ast;
4057
  int32_t sqlLen;
4058
  char*   sql;
4059
} SMDropXnodeJobReq;
4060
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4061
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4062
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4063

4064
typedef struct {
4065
  int32_t      sqlLen;
4066
  char*        sql;
4067
  CowStr       name;
4068
  CowStr       status;
4069
  xTaskOptions options;
4070
} SMCreateXnodeAgentReq;
4071
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4072
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4073
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4074

4075
typedef struct {
4076
  int32_t      sqlLen;
4077
  char*        sql;
4078
  int32_t      id;
4079
  CowStr       name;
4080
  xTaskOptions options;
4081
} SMUpdateXnodeAgentReq;
4082
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4083
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4084
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4085

4086
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4087
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4088
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4089
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4090

4091
typedef struct {
4092
  int32_t vgId;
4093
  int32_t hbSeq;
4094
} SVArbHbReqMember;
4095

4096
typedef struct {
4097
  int32_t dnodeId;
4098
  char*   arbToken;
4099
  int64_t arbTerm;
4100
  SArray* hbMembers;  // SVArbHbReqMember
4101
} SVArbHeartBeatReq;
4102

4103
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4104
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4105
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4106

4107
typedef struct {
4108
  int32_t vgId;
4109
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4110
  int32_t hbSeq;
4111
} SVArbHbRspMember;
4112

4113
typedef struct {
4114
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4115
  int32_t dnodeId;
4116
  SArray* hbMembers;  // SVArbHbRspMember
4117
} SVArbHeartBeatRsp;
4118

4119
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4120
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4121
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4122

4123
typedef struct {
4124
  char*   arbToken;
4125
  int64_t arbTerm;
4126
  char*   member0Token;
4127
  char*   member1Token;
4128
} SVArbCheckSyncReq;
4129

4130
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4131
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4132
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4133

4134
typedef struct {
4135
  char*   arbToken;
4136
  char*   member0Token;
4137
  char*   member1Token;
4138
  int32_t vgId;
4139
  int32_t errCode;
4140
} SVArbCheckSyncRsp;
4141

4142
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4143
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4144
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4145

4146
typedef struct {
4147
  char*   arbToken;
4148
  int64_t arbTerm;
4149
  char*   memberToken;
4150
  int8_t  force;
4151
} SVArbSetAssignedLeaderReq;
4152

4153
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4154
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4155
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4156

4157
typedef struct {
4158
  char* data;
4159
} SVAuditRecordReq;
4160
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4161
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4162
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4163

4164
typedef struct {
4165
  char*   arbToken;
4166
  char*   memberToken;
4167
  int32_t vgId;
4168
} SVArbSetAssignedLeaderRsp;
4169

4170
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4171
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4172
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4173

4174
typedef struct {
4175
  int32_t dnodeId;
4176
  char*   token;
4177
} SMArbUpdateGroupMember;
4178

4179
typedef struct {
4180
  int32_t dnodeId;
4181
  char*   token;
4182
  int8_t  acked;
4183
} SMArbUpdateGroupAssigned;
4184

4185
typedef struct {
4186
  int32_t                  vgId;
4187
  int64_t                  dbUid;
4188
  SMArbUpdateGroupMember   members[2];
4189
  int8_t                   isSync;
4190
  int8_t                   assignedAcked;
4191
  SMArbUpdateGroupAssigned assignedLeader;
4192
  int64_t                  version;
4193
  int32_t                  code;
4194
  int64_t                  updateTimeMs;
4195
} SMArbUpdateGroup;
4196

4197
typedef struct {
4198
  SArray* updateArray;  // SMArbUpdateGroup
4199
} SMArbUpdateGroupBatchReq;
4200

4201
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4202
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4203
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4204

4205
typedef struct {
4206
  char queryStrId[TSDB_QUERY_ID_LEN];
4207
} SKillQueryReq;
4208

4209
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4210
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4211

4212
typedef struct {
4213
  uint32_t connId;
4214
} SKillConnReq;
4215

4216
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4217
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4218

4219
typedef struct {
4220
  int32_t transId;
4221
} SKillTransReq;
4222

4223
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4224
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4225

4226
typedef struct {
4227
  int32_t useless;  // useless
4228
  int32_t sqlLen;
4229
  char*   sql;
4230
} SBalanceVgroupReq;
4231

4232
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4233
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4234
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4235

4236
typedef struct {
4237
  int32_t useless;  // useless
4238
  int32_t sqlLen;
4239
  char*   sql;
4240
} SAssignLeaderReq;
4241

4242
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4243
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4244
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4245
typedef struct {
4246
  int32_t vgId1;
4247
  int32_t vgId2;
4248
} SMergeVgroupReq;
4249

4250
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4251
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4252

4253
typedef struct {
4254
  int32_t vgId;
4255
  int32_t dnodeId1;
4256
  int32_t dnodeId2;
4257
  int32_t dnodeId3;
4258
  int32_t sqlLen;
4259
  char*   sql;
4260
} SRedistributeVgroupReq;
4261

4262
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4263
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4264
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4265

4266
typedef struct {
4267
  int32_t reserved;
4268
  int32_t vgId;
4269
  int32_t sqlLen;
4270
  char*   sql;
4271
  char    db[TSDB_DB_FNAME_LEN];
4272
} SBalanceVgroupLeaderReq;
4273

4274
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4275
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4276
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4277

4278
typedef struct {
4279
  int32_t vgId;
4280
} SForceBecomeFollowerReq;
4281

4282
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4283
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4284

4285
typedef struct {
4286
  int32_t vgId;
4287
  bool    force;
4288
} SSplitVgroupReq;
4289

4290
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4291
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4292

4293
typedef struct {
4294
  char user[TSDB_USER_LEN];
4295
  char spi;
4296
  char encrypt;
4297
  char secret[TSDB_PASSWORD_LEN];
4298
  char ckey[TSDB_PASSWORD_LEN];
4299
} SAuthReq, SAuthRsp;
4300

4301
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4302
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4303

4304
typedef struct {
4305
  int32_t statusCode;
4306
  char    details[1024];
4307
} SServerStatusRsp;
4308

4309
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4310
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4311

4312
/**
4313
 * The layout of the query message payload is as following:
4314
 * +--------------------+---------------------------------+
4315
 * |Sql statement       | Physical plan                   |
4316
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4317
 * +--------------------+---------------------------------+
4318
 */
4319
typedef struct SSubQueryMsg {
4320
  SMsgHead header;
4321
  uint64_t sId;
4322
  uint64_t queryId;
4323
  uint64_t clientId;
4324
  uint64_t taskId;
4325
  int64_t  refId;
4326
  int32_t  execId;
4327
  int32_t  msgMask;
4328
  int32_t  subQType;
4329
  int8_t   taskType;
4330
  int8_t   explain;
4331
  int8_t   needFetch;
4332
  int8_t   compress;
4333
  uint32_t sqlLen;
4334
  char*    sql;
4335
  uint32_t msgLen;
4336
  char*    msg;
4337
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4338
} SSubQueryMsg;
4339

4340
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4341
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4342
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4343

4344
typedef struct {
4345
  SMsgHead header;
4346
  uint64_t sId;
4347
  uint64_t queryId;
4348
  uint64_t taskId;
4349
} SSinkDataReq;
4350

4351
typedef struct {
4352
  SMsgHead header;
4353
  uint64_t sId;
4354
  uint64_t queryId;
4355
  uint64_t clientId;
4356
  uint64_t taskId;
4357
  int32_t  execId;
4358
} SQueryContinueReq;
4359

4360
typedef struct {
4361
  SMsgHead header;
4362
  uint64_t sId;
4363
  uint64_t queryId;
4364
  uint64_t taskId;
4365
} SResReadyReq;
4366

4367
typedef struct {
4368
  int32_t code;
4369
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4370
  int32_t sversion;
4371
  int32_t tversion;
4372
} SResReadyRsp;
4373

4374
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4375

4376
typedef struct SOperatorParam {
4377
  int32_t opType;
4378
  int32_t downstreamIdx;
4379
  void*   value;
4380
  SArray* pChildren;  // SArray<SOperatorParam*>
4381
  bool    reUse;
4382
} SOperatorParam;
4383

4384
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4385

4386
// virtual table's colId to origin table's colname
4387
typedef struct SColIdNameKV {
4388
  col_id_t colId;
4389
  char     colName[TSDB_COL_NAME_LEN];
4390
} SColIdNameKV;
4391

4392
#define COL_MASK_ON   ((int8_t)0x1)
4393
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4394
#define COL_SET_MASK_ON(c)     \
4395
  do {                         \
4396
    (c)->flags |= COL_MASK_ON; \
4397
  } while (0)
4398

4399
typedef struct SColNameFlag {
4400
  col_id_t colId;
4401
  char     colName[TSDB_COL_NAME_LEN];
4402
  int8_t   flags;  // 0x01: COL_MASK_ON
4403
} SColNameFlag;
4404

4405
typedef struct SColIdPair {
4406
  col_id_t  vtbColId;
4407
  col_id_t  orgColId;
4408
  SDataType type;
4409
} SColIdPair;
4410

4411
typedef struct SColIdSlotIdPair {
4412
  int32_t  vtbSlotId;
4413
  col_id_t orgColId;
4414
} SColIdSlotIdPair;
4415

4416
typedef struct SOrgTbInfo {
4417
  int32_t vgId;
4418
  char    tbName[TSDB_TABLE_FNAME_LEN];
4419
  SArray* colMap;  // SArray<SColIdNameKV>
4420
} SOrgTbInfo;
4421

4422
void destroySOrgTbInfo(void *info);
4423

4424
typedef enum {
4425
  DYN_TYPE_STB_JOIN = 1,
4426
  DYN_TYPE_VSTB_SINGLE_SCAN,
4427
  DYN_TYPE_VSTB_BATCH_SCAN,
4428
  DYN_TYPE_VSTB_WIN_SCAN,
4429
} ETableScanDynType;
4430

4431
typedef enum {
4432
  DYN_TYPE_SCAN_PARAM = 1,
4433
  NOTIFY_TYPE_SCAN_PARAM,
4434
} ETableScanGetParamType;
4435

4436
typedef struct STableScanOperatorParam {
4437
  ETableScanGetParamType paramType;
4438
  /* for building scan data source */
4439
  bool                   tableSeq;
4440
  bool                   isNewParam;
4441
  uint64_t               groupid;
4442
  SArray*                pUidList;
4443
  SOrgTbInfo*            pOrgTbInfo;
4444
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4445
  SArray*                pTagList;
4446
  STimeWindow            window;
4447
  ETableScanDynType      dynType;
4448
  /* for notifying source step done */
4449
  bool                   notifyToProcess;  // received notify STEP DONE message
4450
  TSKEY                  notifyTs;         // notify timestamp
4451
} STableScanOperatorParam;
4452

4453
typedef struct STagScanOperatorParam {
4454
  tb_uid_t vcUid;
4455
} STagScanOperatorParam;
4456

4457
typedef struct SRefColIdGroup {
4458
  SArray* pSlotIdList;  // SArray<int32_t>
4459
} SRefColIdGroup;
4460

4461
typedef struct SVTableScanOperatorParam {
4462
  uint64_t        uid;
4463
  STimeWindow     window;
4464
  SOperatorParam* pTagScanOp;
4465
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4466
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4467
} SVTableScanOperatorParam;
4468

4469
typedef struct SMergeOperatorParam {
4470
  int32_t         winNum;
4471
} SMergeOperatorParam;
4472

4473
typedef struct SAggOperatorParam {
4474
  bool            needCleanRes;
4475
} SAggOperatorParam;
4476

4477
typedef struct SExternalWindowOperatorParam {
4478
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4479
} SExternalWindowOperatorParam;
4480

4481
typedef struct SDynQueryCtrlOperatorParam {
4482
  STimeWindow    window;
4483
} SDynQueryCtrlOperatorParam;
4484

4485
struct SStreamRuntimeFuncInfo;
4486
typedef struct {
4487
  SMsgHead        header;
4488
  uint64_t        sId;
4489
  uint64_t        queryId;
4490
  uint64_t        clientId;
4491
  uint64_t        taskId;
4492
  uint64_t        srcTaskId;  // used for subQ
4493
  uint64_t        blockIdx;   // used for subQ
4494
  int32_t         execId;
4495
  SOperatorParam* pOpParam;
4496

4497
  // used for new-stream
4498
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4499
  bool                           reset;
4500
  bool                           dynTbname;
4501
  // used for new-stream
4502
} SResFetchReq;
4503

4504
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamRtInfo, bool needStreamGrpInfo);
4505
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4506
void    tDestroySResFetchReq(SResFetchReq* pReq);
4507
typedef struct {
4508
  SMsgHead header;
4509
  uint64_t clientId;
4510
} SSchTasksStatusReq;
4511

4512
typedef struct {
4513
  uint64_t queryId;
4514
  uint64_t clientId;
4515
  uint64_t taskId;
4516
  int64_t  refId;
4517
  int32_t  subJobId;
4518
  int32_t  execId;
4519
  int8_t   status;
4520
} STaskStatus;
4521

4522
typedef struct {
4523
  int64_t refId;
4524
  SArray* taskStatus;  // SArray<STaskStatus>
4525
} SSchedulerStatusRsp;
4526

4527
typedef struct {
4528
  uint64_t queryId;
4529
  uint64_t taskId;
4530
  int8_t   action;
4531
} STaskAction;
4532

4533
typedef struct SQueryNodeEpId {
4534
  int32_t nodeId;  // vgId or qnodeId
4535
  SEp     ep;
4536
} SQueryNodeEpId;
4537

4538
typedef struct {
4539
  SMsgHead       header;
4540
  uint64_t       clientId;
4541
  SQueryNodeEpId epId;
4542
  SArray*        taskAction;  // SArray<STaskAction>
4543
} SSchedulerHbReq;
4544

4545
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4546
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4547
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4548

4549
typedef struct {
4550
  SQueryNodeEpId epId;
4551
  SArray*        taskStatus;  // SArray<STaskStatus>
4552
} SSchedulerHbRsp;
4553

4554
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4555
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4556
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4557

4558
typedef struct {
4559
  SMsgHead header;
4560
  uint64_t sId;
4561
  uint64_t queryId;
4562
  uint64_t clientId;
4563
  uint64_t taskId;
4564
  int64_t  refId;
4565
  int32_t  execId;
4566
} STaskCancelReq;
4567

4568
typedef struct {
4569
  int32_t code;
4570
} STaskCancelRsp;
4571

4572
typedef struct {
4573
  SMsgHead header;
4574
  uint64_t sId;
4575
  uint64_t queryId;
4576
  uint64_t clientId;
4577
  uint64_t taskId;
4578
  int64_t  refId;
4579
  int32_t  execId;
4580
} STaskDropReq;
4581

4582
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4583
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4584

4585
typedef enum {
4586
  TASK_NOTIFY_FINISHED = 1,
4587
} ETaskNotifyType;
4588

4589
typedef struct {
4590
  SMsgHead        header;
4591
  uint64_t        sId;
4592
  uint64_t        queryId;
4593
  uint64_t        clientId;
4594
  uint64_t        taskId;
4595
  int64_t         refId;
4596
  int32_t         execId;
4597
  ETaskNotifyType type;
4598
} STaskNotifyReq;
4599

4600
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4601
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4602

4603
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4604
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4605

4606
typedef struct {
4607
  int32_t code;
4608
} STaskDropRsp;
4609

4610
#define STREAM_TRIGGER_AT_ONCE                 1
4611
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4612
#define STREAM_TRIGGER_MAX_DELAY               3
4613
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4614
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4615

4616
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4617
#define STREAM_FILL_HISTORY_ON        1
4618
#define STREAM_FILL_HISTORY_OFF       0
4619
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4620
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4621
#define STREAM_CREATE_STABLE_TRUE     1
4622
#define STREAM_CREATE_STABLE_FALSE    0
4623

4624
typedef struct SVgroupVer {
4625
  int32_t vgId;
4626
  int64_t ver;
4627
} SVgroupVer;
4628

4629
enum {
4630
  TOPIC_SUB_TYPE__DB = 1,
4631
  TOPIC_SUB_TYPE__TABLE,
4632
  TOPIC_SUB_TYPE__COLUMN,
4633
};
4634

4635
#define DEFAULT_MAX_POLL_INTERVAL  300000
4636
#define DEFAULT_SESSION_TIMEOUT    12000
4637
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4638
#define DEFAULT_MIN_POLL_ROWS      4096
4639

4640
typedef struct {
4641
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4642
  int8_t igExists;
4643
  int8_t subType;
4644
  int8_t withMeta;
4645
  char*  sql;
4646
  char   subDbName[TSDB_DB_FNAME_LEN];
4647
  char*  ast;
4648
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4649
  int8_t reload;
4650
} SCMCreateTopicReq;
4651

4652
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4653
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4654
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4655

4656
typedef struct {
4657
  int64_t consumerId;
4658
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4659

4660
typedef struct {
4661
  int64_t consumerId;
4662
  char    cgroup[TSDB_CGROUP_LEN];
4663
  char    clientId[TSDB_CLIENT_ID_LEN];
4664
  char    user[TSDB_USER_LEN];
4665
  char    fqdn[TSDB_FQDN_LEN];
4666
  SArray* topicNames;  // SArray<char**>
4667

4668
  int8_t  withTbName;
4669
  int8_t  autoCommit;
4670
  int32_t autoCommitInterval;
4671
  int8_t  resetOffsetCfg;
4672
  int8_t  enableReplay;
4673
  int8_t  enableBatchMeta;
4674
  int32_t sessionTimeoutMs;
4675
  int32_t maxPollIntervalMs;
4676
  int64_t ownerId;
4677
} SCMSubscribeReq;
4678

4679
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4680
  int32_t tlen = 0;
783,078✔
4681
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
783,078✔
4682
  tlen += taosEncodeString(buf, pReq->cgroup);
783,078✔
4683
  tlen += taosEncodeString(buf, pReq->clientId);
783,078✔
4684

4685
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
783,078✔
4686
  tlen += taosEncodeFixedI32(buf, topicNum);
783,078✔
4687

4688
  for (int32_t i = 0; i < topicNum; i++) {
1,100,796✔
4689
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
635,381✔
4690
  }
4691

4692
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
783,133✔
4693
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
783,133✔
4694
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
783,133✔
4695
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
783,133✔
4696
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
783,133✔
4697
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
783,133✔
4698
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
783,133✔
4699
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
783,133✔
4700
  tlen += taosEncodeString(buf, pReq->user);
783,133✔
4701
  tlen += taosEncodeString(buf, pReq->fqdn);
783,133✔
4702

4703
  return tlen;
783,133✔
4704
}
4705

4706
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4707
  void* start = buf;
404,228✔
4708
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
404,228✔
4709
  buf = taosDecodeStringTo(buf, pReq->cgroup);
404,228✔
4710
  buf = taosDecodeStringTo(buf, pReq->clientId);
404,228✔
4711

4712
  int32_t topicNum = 0;
404,228✔
4713
  buf = taosDecodeFixedI32(buf, &topicNum);
404,228✔
4714

4715
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
404,228✔
4716
  if (pReq->topicNames == NULL) {
404,228✔
4717
    return terrno;
×
4718
  }
4719
  for (int32_t i = 0; i < topicNum; i++) {
589,979✔
4720
    char* name = NULL;
185,751✔
4721
    buf = taosDecodeString(buf, &name);
185,751✔
4722
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
371,502✔
4723
      return terrno;
×
4724
    }
4725
  }
4726

4727
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
404,228✔
4728
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
404,228✔
4729
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
404,228✔
4730
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
404,228✔
4731
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
404,228✔
4732
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
404,228✔
4733
  if ((char*)buf - (char*)start < len) {
404,228✔
4734
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
404,228✔
4735
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
404,228✔
4736
    buf = taosDecodeStringTo(buf, pReq->user);
404,228✔
4737
    buf = taosDecodeStringTo(buf, pReq->fqdn);
808,456✔
4738
  } else {
4739
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4740
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4741
  }
4742

4743
  return 0;
404,228✔
4744
}
4745

4746
typedef struct {
4747
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4748
  SArray* removedConsumers;  // SArray<int64_t>
4749
  SArray* newConsumers;      // SArray<int64_t>
4750
} SMqRebInfo;
4751

4752
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4753
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
352,848✔
4754
  if (pRebInfo == NULL) {
352,848✔
4755
    return NULL;
×
4756
  }
4757
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
352,848✔
4758
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
352,848✔
4759
  if (pRebInfo->removedConsumers == NULL) {
352,848✔
4760
    goto _err;
×
4761
  }
4762
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
352,848✔
4763
  if (pRebInfo->newConsumers == NULL) {
352,848✔
4764
    goto _err;
×
4765
  }
4766
  return pRebInfo;
352,848✔
4767
_err:
×
4768
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4769
  taosArrayDestroy(pRebInfo->newConsumers);
×
4770
  taosMemoryFreeClear(pRebInfo);
×
4771
  return NULL;
×
4772
}
4773

4774
typedef struct {
4775
  int64_t streamId;
4776
  int64_t checkpointId;
4777
  char    streamName[TSDB_STREAM_FNAME_LEN];
4778
} SMStreamDoCheckpointMsg;
4779

4780
typedef struct {
4781
  int64_t status;
4782
} SMVSubscribeRsp;
4783

4784
typedef struct {
4785
  char    name[TSDB_TOPIC_FNAME_LEN];
4786
  int8_t  igNotExists;
4787
  int32_t sqlLen;
4788
  char*   sql;
4789
  int8_t  force;
4790
} SMDropTopicReq;
4791

4792
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4793
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4794
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4795

4796
typedef struct {
4797
  char    name[TSDB_TOPIC_FNAME_LEN];
4798
  int8_t  igNotExists;
4799
  int32_t sqlLen;
4800
  char*   sql;
4801
} SMReloadTopicReq;
4802

4803
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4804
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4805
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4806

4807
typedef struct {
4808
  char   topic[TSDB_TOPIC_FNAME_LEN];
4809
  char   cgroup[TSDB_CGROUP_LEN];
4810
  int8_t igNotExists;
4811
  int8_t force;
4812
} SMDropCgroupReq;
4813

4814
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4815
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4816

4817
typedef struct {
4818
  int8_t reserved;
4819
} SMDropCgroupRsp;
4820

4821
typedef struct {
4822
  char    name[TSDB_TABLE_FNAME_LEN];
4823
  int8_t  alterType;
4824
  SSchema schema;
4825
} SAlterTopicReq;
4826

4827
typedef struct {
4828
  SMsgHead head;
4829
  char     name[TSDB_TABLE_FNAME_LEN];
4830
  int64_t  tuid;
4831
  int32_t  sverson;
4832
  int32_t  execLen;
4833
  char*    executor;
4834
  int32_t  sqlLen;
4835
  char*    sql;
4836
} SDCreateTopicReq;
4837

4838
typedef struct {
4839
  SMsgHead head;
4840
  char     name[TSDB_TABLE_FNAME_LEN];
4841
  int64_t  tuid;
4842
} SDDropTopicReq;
4843

4844
typedef struct {
4845
  char*      name;
4846
  int64_t    uid;
4847
  int64_t    interval[2];
4848
  int8_t     intervalUnit;
4849
  int16_t    nFuncs;
4850
  col_id_t*  funcColIds;  // column ids specified by user
4851
  func_id_t* funcIds;     // function ids specified by user
4852
} SRSmaParam;
4853

4854
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4855
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4856

4857
// TDMT_VND_CREATE_STB ==============
4858
typedef struct SVCreateStbReq {
4859
  char*           name;
4860
  tb_uid_t        suid;
4861
  int8_t          rollup;
4862
  SSchemaWrapper  schemaRow;
4863
  SSchemaWrapper  schemaTag;
4864
  SRSmaParam      rsmaParam;
4865
  int32_t         alterOriDataLen;
4866
  void*           alterOriData;
4867
  int8_t          source;
4868
  int8_t          colCmpred;
4869
  SColCmprWrapper colCmpr;
4870
  int64_t         keep;
4871
  int64_t         ownerId;
4872
  SExtSchema*     pExtSchemas;
4873
  int8_t          virtualStb;
4874
  int8_t          secureDelete;
4875
} SVCreateStbReq;
4876

4877
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4878
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4879

4880
// TDMT_VND_DROP_STB ==============
4881
typedef struct SVDropStbReq {
4882
  char*    name;
4883
  tb_uid_t suid;
4884
} SVDropStbReq;
4885

4886
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4887
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4888

4889
// TDMT_VND_CREATE_TABLE ==============
4890
#define TD_CREATE_IF_NOT_EXISTS       0x1
4891
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4892
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4893
typedef struct SVCreateTbReq {
4894
  int32_t  flags;
4895
  char*    name;
4896
  tb_uid_t uid;
4897
  int64_t  btime;
4898
  int32_t  ttl;
4899
  int32_t  commentLen;
4900
  char*    comment;
4901
  int8_t   type;
4902
  union {
4903
    struct {
4904
      char*    stbName;  // super table name
4905
      uint8_t  tagNum;
4906
      tb_uid_t suid;
4907
      SArray*  tagName;
4908
      uint8_t* pTag;
4909
    } ctb;
4910
    struct {
4911
      SSchemaWrapper schemaRow;
4912
      int64_t        userId;
4913
    } ntb;
4914
  };
4915
  int32_t         sqlLen;
4916
  char*           sql;
4917
  SColCmprWrapper colCmpr;
4918
  SExtSchema*     pExtSchemas;
4919
  SColRefWrapper  colRef;  // col reference for virtual table
4920
} SVCreateTbReq;
4921

4922
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4923
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4924
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4925
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4926

4927
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4928
  if (NULL == req) {
2,147,483,647✔
4929
    return;
2,147,483,647✔
4930
  }
4931

4932
  taosMemoryFreeClear(req->sql);
86,876,560✔
4933
  taosMemoryFreeClear(req->name);
86,878,655✔
4934
  taosMemoryFreeClear(req->comment);
86,894,675✔
4935
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
86,876,731✔
4936
    taosMemoryFreeClear(req->ctb.pTag);
78,916,947✔
4937
    taosMemoryFreeClear(req->ctb.stbName);
78,883,953✔
4938
    taosArrayDestroy(req->ctb.tagName);
78,908,408✔
4939
    req->ctb.tagName = NULL;
78,862,806✔
4940
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,963,471✔
4941
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,963,471✔
4942
  }
4943
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
86,845,295✔
4944
  taosMemoryFreeClear(req->pExtSchemas);
86,876,374✔
4945
  taosMemoryFreeClear(req->colRef.pColRef);
86,874,363✔
4946
  taosMemoryFreeClear(req->colRef.pTagRef);
86,876,865✔
4947
}
4948

4949
typedef struct {
4950
  int32_t nReqs;
4951
  union {
4952
    SVCreateTbReq* pReqs;
4953
    SArray*        pArray;
4954
  };
4955
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4956
} SVCreateTbBatchReq;
4957

4958
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4959
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4960
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4961

4962
typedef struct {
4963
  int32_t        code;
4964
  int32_t        index;  // index in batch req, start from 0
4965
  STableMetaRsp* pMeta;
4966
} SVCreateTbRsp, SVUpdateTbRsp;
4967

4968
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4969
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4970
void tFreeSVCreateTbRsp(void* param);
4971

4972
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4973
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4974

4975
typedef struct {
4976
  int32_t nRsps;
4977
  union {
4978
    SVCreateTbRsp* pRsps;
4979
    SArray*        pArray;
4980
  };
4981
} SVCreateTbBatchRsp;
4982

4983
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4984
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4985

4986
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4987
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4988

4989
// TDMT_VND_DROP_TABLE =================
4990
typedef struct {
4991
  char*    name;
4992
  uint64_t suid;  // for tmq in wal format
4993
  int64_t  uid;
4994
  int8_t   igNotExists;
4995
  int8_t   isVirtual;
4996
} SVDropTbReq;
4997

4998
typedef struct {
4999
  int32_t code;
5000
} SVDropTbRsp;
5001

5002
typedef struct {
5003
  int32_t nReqs;
5004
  union {
5005
    SVDropTbReq* pReqs;
5006
    SArray*      pArray;
5007
  };
5008
} SVDropTbBatchReq;
5009

5010
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
5011
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
5012

5013
typedef struct {
5014
  int32_t nRsps;
5015
  union {
5016
    SVDropTbRsp* pRsps;
5017
    SArray*      pArray;
5018
  };
5019
} SVDropTbBatchRsp;
5020

5021
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
5022
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
5023

5024
// TDMT_VND_ALTER_TABLE =====================
5025
typedef struct SUpdatedTagVal {
5026
  char*    tagName;
5027
  int32_t  colId;
5028
  int8_t   tagType;
5029
  int8_t   tagFree;
5030
  uint32_t nTagVal;
5031
  uint8_t* pTagVal;
5032
  int8_t   isNull;
5033
  SArray*  pTagArray;
5034
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5035
  // they should be replaced by a more generic solution in the future for full expression
5036
  // support
5037
  char*    regexp;
5038
  char*    replacement;
5039
} SUpdatedTagVal;
5040

5041
typedef struct SUpdateTableTagVal {
5042
  char *tbName;
5043
  SArray* tags; // Array of SUpdatedTagVal
5044
} SUpdateTableTagVal;
5045

5046
typedef struct SVAlterTbReq {
5047
  char*   tbName;
5048
  int8_t  action;
5049
  char*   colName;
5050
  int32_t colId;
5051
  // TSDB_ALTER_TABLE_ADD_COLUMN
5052
  int8_t  type;
5053
  int8_t  flags;
5054
  int32_t bytes;
5055
  // TSDB_ALTER_TABLE_DROP_COLUMN
5056
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5057
  int8_t   colModType;
5058
  int32_t  colModBytes;
5059
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5060
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5061
  int8_t   isNull;
5062
  int8_t   tagType;
5063
  int8_t   tagFree;
5064
  uint32_t nTagVal;
5065
  uint8_t* pTagVal;
5066
  SArray*  pTagArray;
5067
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5068
  int8_t   updateTTL;
5069
  int32_t  newTTL;
5070
  int32_t  newCommentLen;
5071
  char*    newComment;
5072
  int64_t  ctimeMs;    // fill by vnode
5073
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5074
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5075
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5076
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5077
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5078
  uint8_t* where;      // [where] is the encode where condition.
5079
  // for Add column
5080
  STypeMod typeMod;
5081
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5082
  char* refDbName;
5083
  char* refTbName;
5084
  char* refColName;
5085
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5086
} SVAlterTbReq;
5087

5088
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5089
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5090
void    destroyAlterTbReq(SVAlterTbReq* pReq);
5091
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5092
void    tfreeMultiTagUpateVal(void* pMultiTag);
5093
void    tfreeUpdateTableTagVal(void* pMultiTable);
5094

5095
typedef struct {
5096
  int32_t        code;
5097
  STableMetaRsp* pMeta;
5098
} SVAlterTbRsp;
5099

5100
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5101
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5102
// ======================
5103

5104
typedef struct {
5105
  SMsgHead head;
5106
  int64_t  uid;
5107
  int32_t  tid;
5108
  int16_t  tversion;
5109
  int16_t  colId;
5110
  int8_t   type;
5111
  int16_t  bytes;
5112
  int32_t  tagValLen;
5113
  int16_t  numOfTags;
5114
  int32_t  schemaLen;
5115
  char     data[];
5116
} SUpdateTagValReq;
5117

5118
typedef struct {
5119
  SMsgHead head;
5120
} SUpdateTagValRsp;
5121

5122
typedef struct {
5123
  SMsgHead head;
5124
} SVShowTablesReq;
5125

5126
typedef struct {
5127
  SMsgHead head;
5128
  int32_t  id;
5129
} SVShowTablesFetchReq;
5130

5131
typedef struct {
5132
  int64_t useconds;
5133
  int8_t  completed;  // all results are returned to client
5134
  int8_t  precision;
5135
  int8_t  compressed;
5136
  int32_t compLen;
5137
  int32_t numOfRows;
5138
  char    data[];
5139
} SVShowTablesFetchRsp;
5140

5141
typedef struct {
5142
  int64_t consumerId;
5143
  int32_t epoch;
5144
  char    cgroup[TSDB_CGROUP_LEN];
5145
} SMqAskEpReq;
5146

5147
typedef struct {
5148
  int32_t key;
5149
  int32_t valueLen;
5150
  void*   value;
5151
} SKv;
5152

5153
typedef struct {
5154
  int64_t tscRid;
5155
  int8_t  connType;
5156
} SClientHbKey;
5157

5158
typedef struct {
5159
  int64_t tid;
5160
  char    status[TSDB_JOB_STATUS_LEN];
5161
  int64_t startTs;  // sub-task first execution start time, us
5162
} SQuerySubDesc;
5163

5164
typedef enum EQueryExecPhase {
5165
  /* Main phases: 0-9 */
5166
  QUERY_PHASE_NONE     = 0,
5167
  QUERY_PHASE_PARSE    = 1,
5168
  QUERY_PHASE_CATALOG  = 2,
5169
  QUERY_PHASE_PLAN     = 3,
5170
  QUERY_PHASE_SCHEDULE = 4,
5171
  QUERY_PHASE_EXECUTE  = 5,
5172
  QUERY_PHASE_FETCH    = 6,
5173
  QUERY_PHASE_DONE     = 7,
5174

5175
  /* SCHEDULE sub-phases: 4x */
5176
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5177
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5178
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5179

5180
  /* EXECUTE sub-phases: 5x */
5181
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5182
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5183
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5184

5185
  /* FETCH sub-phases: 6x */
5186
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5187
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5188
} EQueryExecPhase;
5189

5190
const char* queryPhaseStr(int32_t phase);
5191

5192
typedef struct {
5193
  char     sql[TSDB_SHOW_SQL_LEN];
5194
  uint64_t queryId;
5195
  int64_t  useconds;
5196
  int64_t  stime;  // timestamp precision ms
5197
  int64_t  reqRid;
5198
  bool     stableQuery;
5199
  bool     isSubQuery;
5200
  char     fqdn[TSDB_FQDN_LEN];
5201
  int32_t  subPlanNum;
5202
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5203
  int32_t  execPhase;       // EQueryExecPhase
5204
  int64_t  phaseStartTime;  // when current phase started, ms
5205
} SQueryDesc;
5206

5207
typedef struct {
5208
  uint32_t connId;
5209
  SArray*  queryDesc;  // SArray<SQueryDesc>
5210
} SQueryHbReqBasic;
5211

5212
typedef struct {
5213
  uint32_t connId;
5214
  uint64_t killRid;
5215
  int32_t  totalDnodes;
5216
  int32_t  onlineDnodes;
5217
  int8_t   killConnection;
5218
  int8_t   align[3];
5219
  SEpSet   epSet;
5220
  SArray*  pQnodeList;
5221
} SQueryHbRspBasic;
5222

5223
typedef struct SAppClusterSummary {
5224
  uint64_t numOfInsertsReq;
5225
  uint64_t numOfInsertRows;
5226
  uint64_t insertElapsedTime;
5227
  uint64_t insertBytes;  // submit to tsdb since launched.
5228

5229
  uint64_t fetchBytes;
5230
  uint64_t numOfQueryReq;
5231
  uint64_t queryElapsedTime;
5232
  uint64_t numOfSlowQueries;
5233
  uint64_t totalRequests;
5234
  uint64_t currentRequests;  // the number of SRequestObj
5235
} SAppClusterSummary;
5236

5237
typedef struct {
5238
  int64_t            appId;
5239
  int32_t            pid;
5240
  char               name[TSDB_APP_NAME_LEN];
5241
  int64_t            startTime;
5242
  SAppClusterSummary summary;
5243
} SAppHbReq;
5244

5245
typedef struct {
5246
  SClientHbKey      connKey;
5247
  int64_t           clusterId;
5248
  SAppHbReq         app;
5249
  SQueryHbReqBasic* query;
5250
  SHashObj*         info;  // hash<Skv.key, Skv>
5251
  char              user[TSDB_USER_LEN];
5252
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5253
  char              userApp[TSDB_APP_NAME_LEN];
5254
  uint32_t          userIp;
5255
  SIpRange          userDualIp;
5256
  char              sVer[TSDB_VERSION_LEN];
5257
  char              cInfo[CONNECTOR_INFO_LEN];
5258
} SClientHbReq;
5259

5260
typedef struct {
5261
  int64_t reqId;
5262
  SArray* reqs;  // SArray<SClientHbReq>
5263
  int64_t ipWhiteListVer;
5264
} SClientHbBatchReq;
5265

5266
typedef struct {
5267
  SClientHbKey      connKey;
5268
  int32_t           status;
5269
  SQueryHbRspBasic* query;
5270
  SArray*           info;  // Array<Skv>
5271
} SClientHbRsp;
5272

5273
typedef struct {
5274
  int64_t       reqId;
5275
  int64_t       rspId;
5276
  int32_t       svrTimestamp;
5277
  SArray*       rsps;  // SArray<SClientHbRsp>
5278
  SMonitorParas monitorParas;
5279
  int8_t        enableAuditDelete;
5280
  int8_t        enableStrongPass;
5281
  int8_t        enableAuditSelect;
5282
  int8_t        enableAuditInsert;
5283
  int8_t        auditLevel;
5284
} SClientHbBatchRsp;
5285

5286
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
457,385,281✔
5287

5288
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5289
  void* pIter = taosHashIterate(info, NULL);
64,273,770✔
5290
  while (pIter != NULL) {
153,039,676✔
5291
    SKv* kv = (SKv*)pIter;
88,762,291✔
5292
    taosMemoryFreeClear(kv->value);
88,762,291✔
5293
    pIter = taosHashIterate(info, pIter);
88,760,218✔
5294
  }
5295
}
64,277,385✔
5296

5297
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
41,695,900✔
5298
  SQueryDesc* desc = (SQueryDesc*)pDesc;
41,695,900✔
5299
  if (desc->subDesc) {
41,695,900✔
5300
    taosArrayDestroy(desc->subDesc);
29,372,093✔
5301
    desc->subDesc = NULL;
29,371,018✔
5302
  }
5303
}
41,696,910✔
5304

5305
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
73,509,008✔
5306
  SClientHbReq* req = (SClientHbReq*)pReq;
167,355,366✔
5307
  if (req->query) {
167,355,366✔
5308
    if (req->query->queryDesc) {
73,506,050✔
5309
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
34,574,033✔
5310
    }
5311
    taosMemoryFreeClear(req->query);
73,505,705✔
5312
  }
5313

5314
  if (req->info) {
167,360,037✔
5315
    tFreeReqKvHash(req->info);
64,276,229✔
5316
    taosHashCleanup(req->info);
64,277,385✔
5317
    req->info = NULL;
64,276,553✔
5318
  }
5319
}
128,963,735✔
5320

5321
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5322
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5323

5324
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5325
  if (pReq == NULL) return;
31,628,682✔
5326
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
31,628,682✔
5327
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
31,628,682✔
5328
  taosMemoryFree(pReq);
31,628,682✔
5329
}
5330

5331
static FORCE_INLINE void tFreeClientKv(void* pKv) {
88,443,545✔
5332
  SKv* kv = (SKv*)pKv;
88,443,545✔
5333
  if (kv) {
88,443,545✔
5334
    taosMemoryFreeClear(kv->value);
88,443,569✔
5335
  }
5336
}
88,442,076✔
5337

5338
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
73,195,133✔
5339
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
73,195,133✔
5340
  if (rsp->query) {
73,195,133✔
5341
    taosArrayDestroy(rsp->query->pQnodeList);
73,185,966✔
5342
    taosMemoryFreeClear(rsp->query);
73,177,344✔
5343
  }
5344
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
73,210,519✔
5345
}
38,080,259✔
5346

5347
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5348
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
60,578,698✔
5349
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
60,578,698✔
5350
}
60,581,199✔
5351

5352
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5353
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5354
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5355

5356
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5357
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
365,016,926✔
5358
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
365,015,089✔
5359
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
365,012,154✔
5360
  return 0;
182,506,682✔
5361
}
5362

5363
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5364
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
181,878,147✔
5365
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
181,877,349✔
5366

5367
  if (pKv->valueLen < 0) {
90,938,442✔
5368
    return TSDB_CODE_INVALID_MSG;
×
5369
  }
5370

5371
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
90,938,747✔
5372
  if (pKv->value == NULL) {
90,936,470✔
5373
    return TSDB_CODE_OUT_OF_MEMORY;
×
5374
  }
5375
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
90,936,139✔
5376
  return 0;
90,939,240✔
5377
}
5378

5379
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5380
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
303,633,326✔
5381
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
303,623,899✔
5382
  return 0;
151,809,960✔
5383
}
5384

5385
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5386
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
151,183,598✔
5387
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
151,185,041✔
5388
  return 0;
75,594,734✔
5389
}
5390

5391
typedef struct {
5392
  int32_t vgId;
5393
  // TODO stas
5394
} SMqReportVgInfo;
5395

5396
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5397
  int32_t tlen = 0;
5398
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5399
  return tlen;
5400
}
5401

5402
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5403
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5404
  return buf;
5405
}
5406

5407
typedef struct {
5408
  int32_t epoch;
5409
  int64_t topicUid;
5410
  char    name[TSDB_TOPIC_FNAME_LEN];
5411
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5412
} SMqTopicInfo;
5413

5414
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5415
  int32_t tlen = 0;
5416
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5417
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5418
  tlen += taosEncodeString(buf, pTopicInfo->name);
5419
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5420
  tlen += taosEncodeFixedI32(buf, sz);
5421
  for (int32_t i = 0; i < sz; i++) {
5422
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5423
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5424
  }
5425
  return tlen;
5426
}
5427

5428
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5429
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5430
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5431
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5432
  int32_t sz;
5433
  buf = taosDecodeFixedI32(buf, &sz);
5434
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5435
    return NULL;
5436
  }
5437
  for (int32_t i = 0; i < sz; i++) {
5438
    SMqReportVgInfo vgInfo;
5439
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5440
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5441
      return NULL;
5442
    }
5443
  }
5444
  return buf;
5445
}
5446

5447
typedef struct {
5448
  int32_t status;  // ask hb endpoint
5449
  int32_t epoch;
5450
  int64_t consumerId;
5451
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5452
} SMqReportReq;
5453

5454
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5455
  int32_t tlen = 0;
5456
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5457
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5458
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5459
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5460
  tlen += taosEncodeFixedI32(buf, sz);
5461
  for (int32_t i = 0; i < sz; i++) {
5462
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5463
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5464
  }
5465
  return tlen;
5466
}
5467

5468
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5469
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5470
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5471
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5472
  int32_t sz;
5473
  buf = taosDecodeFixedI32(buf, &sz);
5474
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5475
    return NULL;
5476
  }
5477
  for (int32_t i = 0; i < sz; i++) {
5478
    SMqTopicInfo topicInfo;
5479
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5480
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5481
      return NULL;
5482
    }
5483
  }
5484
  return buf;
5485
}
5486

5487
typedef struct {
5488
  SMsgHead head;
5489
  int64_t  leftForVer;
5490
  int32_t  vgId;
5491
  int64_t  consumerId;
5492
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5493
} SMqVDeleteReq;
5494

5495
typedef struct {
5496
  int8_t reserved;
5497
} SMqVDeleteRsp;
5498

5499
typedef struct {
5500
  char**  name;
5501
  int32_t count;
5502
  int8_t  igNotExists;
5503
} SMDropStreamReq;
5504

5505
typedef struct {
5506
  int8_t reserved;
5507
} SMDropStreamRsp;
5508

5509
typedef struct {
5510
  SMsgHead head;
5511
  int64_t  resetRelHalt;  // reset related stream task halt status
5512
  int64_t  streamId;
5513
  int32_t  taskId;
5514
} SVDropStreamTaskReq;
5515

5516
typedef struct {
5517
  int8_t reserved;
5518
} SVDropStreamTaskRsp;
5519

5520
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5521
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5522
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5523

5524
typedef struct {
5525
  char*  name;
5526
  int8_t igNotExists;
5527
} SMPauseStreamReq;
5528

5529
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5530
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5531
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5532

5533
typedef struct {
5534
  char*  name;
5535
  int8_t igNotExists;
5536
  int8_t igUntreated;
5537
} SMResumeStreamReq;
5538

5539
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5540
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5541
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5542

5543
typedef struct {
5544
  char*       name;
5545
  int8_t      calcAll;
5546
  STimeWindow timeRange;
5547
} SMRecalcStreamReq;
5548

5549
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5550
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5551
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5552

5553
typedef struct SVndSetKeepVersionReq {
5554
  int64_t keepVersion;
5555
} SVndSetKeepVersionReq;
5556

5557
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5558
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5559

5560
typedef struct SVUpdateCheckpointInfoReq {
5561
  SMsgHead head;
5562
  int64_t  streamId;
5563
  int32_t  taskId;
5564
  int64_t  checkpointId;
5565
  int64_t  checkpointVer;
5566
  int64_t  checkpointTs;
5567
  int32_t  transId;
5568
  int64_t  hStreamId;  // add encode/decode
5569
  int64_t  hTaskId;
5570
  int8_t   dropRelHTask;
5571
} SVUpdateCheckpointInfoReq;
5572

5573
typedef struct {
5574
  int64_t        leftForVer;
5575
  int32_t        vgId;
5576
  int64_t        oldConsumerId;
5577
  int64_t        newConsumerId;
5578
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5579
  int8_t         subType;
5580
  int8_t         withMeta;
5581
  char*          qmsg;  // SubPlanToString
5582
  SSchemaWrapper schema;
5583
  int64_t        suid;
5584
} SMqRebVgReq;
5585

5586
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5587
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5588

5589
// tqOffset
5590
enum {
5591
  TMQ_OFFSET__RESET_NONE = -3,
5592
  TMQ_OFFSET__RESET_EARLIEST = -2,
5593
  TMQ_OFFSET__RESET_LATEST = -1,
5594
  TMQ_OFFSET__LOG = 1,
5595
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5596
  TMQ_OFFSET__SNAPSHOT_META = 3,
5597
};
5598

5599
enum {
5600
  ONLY_DATA = 0,
5601
  WITH_META = 1,
5602
  ONLY_META = 2,
5603
};
5604

5605
#define TQ_OFFSET_VERSION 1
5606

5607
typedef struct {
5608
  int8_t type;
5609
  union {
5610
    // snapshot
5611
    struct {
5612
      int64_t uid;
5613
      int64_t ts;
5614
      SValue  primaryKey;
5615
    };
5616
    // log
5617
    struct {
5618
      int64_t version;
5619
    };
5620
  };
5621
} STqOffsetVal;
5622

5623
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5624
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
12,392,407✔
5625
  pOffsetVal->uid = uid;
12,389,067✔
5626
  pOffsetVal->ts = ts;
12,392,407✔
5627
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
12,393,073✔
5628
    taosMemoryFree(pOffsetVal->primaryKey.pData);
333✔
5629
  }
5630
  pOffsetVal->primaryKey = primaryKey;
12,391,086✔
5631
}
12,388,411✔
5632

5633
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5634
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
57,419✔
5635
  pOffsetVal->uid = uid;
57,419✔
5636
}
57,419✔
5637

5638
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5639
  pOffsetVal->type = TMQ_OFFSET__LOG;
286,368,618✔
5640
  pOffsetVal->version = ver;
286,366,475✔
5641
}
286,366,643✔
5642

5643
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5644
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5645
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5646
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5647
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5648
void    tOffsetDestroy(void* pVal);
5649

5650
typedef struct {
5651
  STqOffsetVal val;
5652
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5653
} STqOffset;
5654

5655
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5656
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5657
void    tDeleteSTqOffset(void* val);
5658

5659
typedef struct SMqVgOffset {
5660
  int64_t   consumerId;
5661
  STqOffset offset;
5662
} SMqVgOffset;
5663

5664
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5665
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5666

5667
typedef struct {
5668
  char    name[TSDB_TABLE_FNAME_LEN];
5669
  char    stb[TSDB_TABLE_FNAME_LEN];
5670
  int8_t  igExists;
5671
  int8_t  intervalUnit;
5672
  int8_t  slidingUnit;
5673
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5674
  int32_t dstVgId;   // for stream
5675
  int64_t interval;
5676
  int64_t offset;
5677
  int64_t sliding;
5678
  int64_t maxDelay;
5679
  int64_t watermark;
5680
  int32_t exprLen;        // strlen + 1
5681
  int32_t tagsFilterLen;  // strlen + 1
5682
  int32_t sqlLen;         // strlen + 1
5683
  int32_t astLen;         // strlen + 1
5684
  char*   expr;
5685
  char*   tagsFilter;
5686
  char*   sql;
5687
  char*   ast;
5688
  int64_t deleteMark;
5689
  int64_t lastTs;
5690
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5691
  SArray* pVgroupVerList;
5692
  int8_t  recursiveTsma;
5693
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5694
  char*   createStreamReq;
5695
  int32_t streamReqLen;
5696
  char*   dropStreamReq;
5697
  int32_t dropStreamReqLen;
5698
  int64_t uid;
5699
} SMCreateSmaReq;
5700

5701
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5702
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5703
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5704

5705
typedef struct {
5706
  char    name[TSDB_TABLE_FNAME_LEN];
5707
  int8_t  igNotExists;
5708
  char*   dropStreamReq;
5709
  int32_t dropStreamReqLen;
5710
} SMDropSmaReq;
5711

5712
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5713
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5714
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5715

5716
typedef struct {
5717
  char name[TSDB_TABLE_NAME_LEN];
5718
  union {
5719
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5720
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5721
  };
5722
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5723
  union {
5724
    int8_t igExists;   // used by mnode
5725
    int8_t alterType;  // used by vnode
5726
  };
5727
  int8_t     intervalUnit;
5728
  int16_t    nFuncs;       // number of functions specified by user
5729
  col_id_t*  funcColIds;   // column ids specified by user
5730
  func_id_t* funcIds;      // function ids specified by user
5731
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5732
  int64_t    tbUid;
5733
  int64_t    uid;     // rsma uid
5734
  int32_t    sqlLen;  // strlen + 1
5735
  char*      sql;
5736
} SMCreateRsmaReq;
5737

5738
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5739
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5740
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5741

5742
typedef SMCreateRsmaReq SVCreateRsmaReq;
5743

5744
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5745
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5746
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5747

5748
typedef SMCreateRsmaReq SVAlterRsmaReq;
5749

5750
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5751
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5752
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5753

5754
typedef struct {
5755
  char       name[TSDB_TABLE_NAME_LEN];
5756
  int8_t     alterType;
5757
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5758
  int8_t     igNotExists;
5759
  int16_t    nFuncs;      // number of functions specified by user
5760
  col_id_t*  funcColIds;  // column ids specified by user
5761
  func_id_t* funcIds;     // function ids specified by user
5762
  int32_t    sqlLen;      // strlen + 1
5763
  char*      sql;
5764
} SMAlterRsmaReq;
5765

5766
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5767
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5768
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5769

5770
typedef struct {
5771
  int64_t    id;
5772
  char       name[TSDB_TABLE_NAME_LEN];
5773
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5774
  int64_t    ownerId;
5775
  int32_t    code;
5776
  int32_t    version;
5777
  int8_t     tbType;
5778
  int8_t     intervalUnit;
5779
  col_id_t   nFuncs;
5780
  col_id_t   nColNames;
5781
  int64_t    interval[2];
5782
  col_id_t*  funcColIds;
5783
  func_id_t* funcIds;
5784
  SArray*    colNames;
5785
} SRsmaInfoRsp;
5786

5787
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5788
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5789
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5790

5791
typedef struct {
5792
  char   name[TSDB_TABLE_FNAME_LEN];
5793
  int8_t igNotExists;
5794
} SMDropRsmaReq;
5795

5796
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5797
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5798

5799
typedef struct {
5800
  char    name[TSDB_TABLE_NAME_LEN];
5801
  char    tbName[TSDB_TABLE_NAME_LEN];
5802
  int64_t uid;
5803
  int64_t tbUid;
5804
  int8_t  tbType;
5805
} SVDropRsmaReq;
5806

5807
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5808
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5809

5810
typedef struct {
5811
  char   dbFName[TSDB_DB_FNAME_LEN];
5812
  char   stbName[TSDB_TABLE_NAME_LEN];
5813
  char   colName[TSDB_COL_NAME_LEN];
5814
  char   idxName[TSDB_INDEX_FNAME_LEN];
5815
  int8_t idxType;
5816
} SCreateTagIndexReq;
5817

5818
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5819
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5820

5821
typedef SMDropSmaReq SDropTagIndexReq;
5822

5823
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5824
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5825

5826
typedef struct {
5827
  int8_t         version;       // for compatibility(default 0)
5828
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5829
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5830
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5831
  int32_t        dstVgId;
5832
  char           indexName[TSDB_INDEX_NAME_LEN];
5833
  int32_t        exprLen;
5834
  int32_t        tagsFilterLen;
5835
  int64_t        indexUid;
5836
  tb_uid_t       tableUid;  // super/child/common table uid
5837
  tb_uid_t       dstTbUid;  // for dstVgroup
5838
  int64_t        interval;
5839
  int64_t        offset;  // use unit by precision of DB
5840
  int64_t        sliding;
5841
  char*          dstTbName;  // for dstVgroup
5842
  char*          expr;       // sma expression
5843
  char*          tagsFilter;
5844
  SSchemaWrapper schemaRow;  // for dstVgroup
5845
  SSchemaWrapper schemaTag;  // for dstVgroup
5846
} STSma;                     // Time-range-wise SMA
5847

5848
typedef STSma SVCreateTSmaReq;
5849

5850
typedef struct {
5851
  int8_t  type;  // 0 status report, 1 update data
5852
  int64_t indexUid;
5853
  int64_t skey;  // start TS key of interval/sliding window
5854
} STSmaMsg;
5855

5856
typedef struct {
5857
  int64_t indexUid;
5858
  char    indexName[TSDB_INDEX_NAME_LEN];
5859
} SVDropTSmaReq;
5860

5861
typedef struct {
5862
  int tmp;  // TODO: to avoid compile error
5863
} SVCreateTSmaRsp, SVDropTSmaRsp;
5864

5865
#if 0
5866
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5867
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5868
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5869
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5870
#endif
5871

5872
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5873
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5874
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5875
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5876

5877
typedef struct {
5878
  int32_t number;
5879
  STSma*  tSma;
5880
} STSmaWrapper;
5881

5882
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5883
  if (pSma) {
×
5884
    taosMemoryFreeClear(pSma->dstTbName);
×
5885
    taosMemoryFreeClear(pSma->expr);
×
5886
    taosMemoryFreeClear(pSma->tagsFilter);
×
5887
  }
5888
}
×
5889

5890
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5891
  if (pSW) {
×
5892
    if (pSW->tSma) {
×
5893
      if (deepCopy) {
×
5894
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5895
          tDestroyTSma(pSW->tSma + i);
×
5896
        }
5897
      }
5898
      taosMemoryFreeClear(pSW->tSma);
×
5899
    }
5900
  }
5901
}
×
5902

5903
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5904
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5905
  taosMemoryFreeClear(pSW);
×
5906
  return NULL;
×
5907
}
5908

5909
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5910
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5911

5912
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5913
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5914

5915
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5916
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5917
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5918
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5919
  }
5920
  return 0;
×
5921
}
5922

5923
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5924
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5925
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5926
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5927
  }
5928
  return 0;
×
5929
}
5930

5931
typedef struct {
5932
  int idx;
5933
} SMCreateFullTextReq;
5934

5935
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5936
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5937
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5938

5939
typedef struct {
5940
  char   name[TSDB_TABLE_FNAME_LEN];
5941
  int8_t igNotExists;
5942
} SMDropFullTextReq;
5943

5944
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5945
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5946

5947
typedef struct {
5948
  char indexFName[TSDB_INDEX_FNAME_LEN];
5949
} SUserIndexReq;
5950

5951
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5952
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5953

5954
typedef struct {
5955
  char dbFName[TSDB_DB_FNAME_LEN];
5956
  char tblFName[TSDB_TABLE_FNAME_LEN];
5957
  char colName[TSDB_COL_NAME_LEN];
5958
  char owner[TSDB_USER_LEN];
5959
  char indexType[TSDB_INDEX_TYPE_LEN];
5960
  char indexExts[TSDB_INDEX_EXTS_LEN];
5961
} SUserIndexRsp;
5962

5963
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5964
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5965

5966
typedef struct {
5967
  char tbFName[TSDB_TABLE_FNAME_LEN];
5968
} STableIndexReq;
5969

5970
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5971
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5972

5973
typedef struct {
5974
  int8_t  intervalUnit;
5975
  int8_t  slidingUnit;
5976
  int64_t interval;
5977
  int64_t offset;
5978
  int64_t sliding;
5979
  int64_t dstTbUid;
5980
  int32_t dstVgId;
5981
  SEpSet  epSet;
5982
  char*   expr;
5983
} STableIndexInfo;
5984

5985
typedef struct {
5986
  char     tbName[TSDB_TABLE_NAME_LEN];
5987
  char     dbFName[TSDB_DB_FNAME_LEN];
5988
  uint64_t suid;
5989
  int32_t  version;
5990
  int32_t  indexSize;
5991
  SArray*  pIndex;  // STableIndexInfo
5992
} STableIndexRsp;
5993

5994
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5995
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5996
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5997

5998
void tFreeSTableIndexInfo(void* pInfo);
5999

6000
typedef struct {
6001
  int8_t  mqMsgType;
6002
  int32_t code;
6003
  int32_t epoch;
6004
  int64_t consumerId;
6005
  int64_t walsver;
6006
  int64_t walever;
6007
} SMqRspHead;
6008

6009
typedef struct {
6010
  SMsgHead     head;
6011
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
6012
  int8_t       withTbName;
6013
  int8_t       useSnapshot;
6014
  int32_t      epoch;
6015
  uint64_t     reqId;
6016
  int64_t      consumerId;
6017
  int64_t      timeout;
6018
  STqOffsetVal reqOffset;
6019
  int8_t       enableReplay;
6020
  int8_t       sourceExcluded;
6021
  int8_t       rawData;
6022
  int32_t      minPollRows;
6023
  int8_t       enableBatchMeta;
6024
  SHashObj*    uidHash;  // to find if uid is duplicated
6025
} SMqPollReq;
6026

6027
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6028
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6029
void    tDestroySMqPollReq(SMqPollReq* pReq);
6030

6031
typedef struct {
6032
  int32_t vgId;
6033
  int64_t offset;
6034
  SEpSet  epSet;
6035
} SMqSubVgEp;
6036

6037
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6038
  int32_t tlen = 0;
2,184,552✔
6039
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,184,552✔
6040
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,184,552✔
6041
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,184,552✔
6042
  return tlen;
2,184,552✔
6043
}
6044

6045
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6046
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,076,325✔
6047
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,076,325✔
6048
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,076,325✔
6049
  return buf;
1,076,325✔
6050
}
6051

6052
typedef struct {
6053
  char    topic[TSDB_TOPIC_FNAME_LEN];
6054
  char    db[TSDB_DB_FNAME_LEN];
6055
  SArray* vgs;  // SArray<SMqSubVgEp>
6056
} SMqSubTopicEp;
6057

6058
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6059
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6060
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6061

6062
typedef struct {
6063
  SMqRspHead   head;
6064
  STqOffsetVal rspOffset;
6065
  int16_t      resMsgType;
6066
  int32_t      metaRspLen;
6067
  void*        metaRsp;
6068
} SMqMetaRsp;
6069

6070
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6071
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6072
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6073

6074
#define MQ_DATA_RSP_VERSION 100
6075

6076
typedef struct {
6077
  SMqRspHead   head;
6078
  STqOffsetVal rspOffset;
6079
  STqOffsetVal reqOffset;
6080
  int32_t      blockNum;
6081
  int8_t       withTbName;
6082
  int8_t       withSchema;
6083
  SArray*      blockDataLen;
6084
  SArray*      blockData;
6085
  SArray*      blockTbName;
6086
  SArray*      blockSchema;
6087

6088
  union {
6089
    struct {
6090
      int64_t sleepTime;
6091
    };
6092
    struct {
6093
      int32_t createTableNum;
6094
      SArray* createTableLen;
6095
      SArray* createTableReq;
6096
    };
6097
    struct {
6098
      int32_t len;
6099
      void*   rawData;
6100
    };
6101
  };
6102
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6103
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6104
  bool  timeout;
6105
} SMqDataRsp;
6106

6107
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6108
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6109
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6110
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6111
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6112

6113
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6114
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6115
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6116

6117
typedef struct SMqBatchMetaRsp {
6118
  SMqRspHead   head;  // not serialize
6119
  STqOffsetVal rspOffset;
6120
  SArray*      batchMetaLen;
6121
  SArray*      batchMetaReq;
6122
  void*        pMetaBuff;    // not serialize
6123
  uint32_t     metaBuffLen;  // not serialize
6124
} SMqBatchMetaRsp;
6125

6126
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6127
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6128
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6129
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6130

6131
typedef struct {
6132
  int32_t code;
6133
  SArray* topics;  // SArray<SMqSubTopicEp>
6134
} SMqAskEpRsp;
6135

6136
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6137
  int32_t tlen = 0;
8,649,568✔
6138
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6139
  int32_t sz = taosArrayGetSize(pRsp->topics);
8,649,568✔
6140
  tlen += taosEncodeFixedI32(buf, sz);
8,649,568✔
6141
  for (int32_t i = 0; i < sz; i++) {
10,151,406✔
6142
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,501,838✔
6143
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,501,838✔
6144
  }
6145
  tlen += taosEncodeFixedI32(buf, pRsp->code);
8,649,568✔
6146

6147
  return tlen;
8,649,197✔
6148
}
6149

6150
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6151
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6152
  int32_t sz;
3,482,806✔
6153
  buf = taosDecodeFixedI32(buf, &sz);
3,563,693✔
6154
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,563,693✔
6155
  if (pRsp->topics == NULL) {
3,563,693✔
6156
    return NULL;
×
6157
  }
6158
  for (int32_t i = 0; i < sz; i++) {
4,298,309✔
6159
    SMqSubTopicEp topicEp;
722,104✔
6160
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
734,616✔
6161
    if (buf == NULL) {
734,616✔
6162
      return NULL;
×
6163
    }
6164
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,469,232✔
6165
      return NULL;
×
6166
    }
6167
  }
6168
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,563,693✔
6169

6170
  return buf;
3,563,693✔
6171
}
6172

6173
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6174
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
27,195,325✔
6175
}
27,194,954✔
6176

6177
typedef struct {
6178
  int32_t      vgId;
6179
  STqOffsetVal offset;
6180
  int64_t      rows;
6181
  int64_t      ever;
6182
} OffsetRows;
6183

6184
typedef struct {
6185
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6186
  SArray* offsetRows;
6187
} TopicOffsetRows;
6188

6189
typedef struct {
6190
  int64_t consumerId;
6191
  int32_t epoch;
6192
  SArray* topics;
6193
  int8_t  pollFlag;
6194
} SMqHbReq;
6195

6196
typedef struct {
6197
  char   topic[TSDB_TOPIC_FNAME_LEN];
6198
  int8_t noPrivilege;
6199
} STopicPrivilege;
6200

6201
typedef struct {
6202
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6203
  int32_t debugFlag;
6204
} SMqHbRsp;
6205

6206
#define TD_AUTO_CREATE_TABLE 0x1
6207
typedef struct {
6208
  int64_t       suid;
6209
  int64_t       uid;
6210
  int32_t       sver;
6211
  uint32_t      nData;
6212
  uint8_t*      pData;
6213
  SVCreateTbReq cTbReq;
6214
} SVSubmitBlk;
6215

6216
typedef struct {
6217
  SMsgHead header;
6218
  uint64_t sId;
6219
  uint64_t queryId;
6220
  uint64_t clientId;
6221
  uint64_t taskId;
6222
  uint32_t sqlLen;
6223
  uint32_t phyLen;
6224
  char*    sql;
6225
  char*    msg;
6226
  int8_t   source;
6227
  int8_t   secureDelete;
6228
} SVDeleteReq;
6229

6230
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6231
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6232

6233
typedef struct {
6234
  int64_t affectedRows;
6235
} SVDeleteRsp;
6236

6237
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6238
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6239

6240
typedef struct SDeleteRes {
6241
  uint64_t suid;
6242
  SArray*  uidList;
6243
  int64_t  skey;
6244
  int64_t  ekey;
6245
  int64_t  affectedRows;
6246
  char     tableFName[TSDB_TABLE_NAME_LEN];
6247
  char     tsColName[TSDB_COL_NAME_LEN];
6248
  int64_t  ctimeMs;  // fill by vnode
6249
  int8_t   source;
6250
  int8_t   secureDelete;  // force physical overwrite
6251
} SDeleteRes;
6252

6253
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6254
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6255

6256
typedef struct {
6257
  // int64_t uid;
6258
  char    tbname[TSDB_TABLE_NAME_LEN];
6259
  int64_t startTs;
6260
  int64_t endTs;
6261
} SSingleDeleteReq;
6262

6263
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6264
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6265

6266
typedef struct {
6267
  int64_t suid;
6268
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6269
  int64_t ctimeMs;     // fill by vnode
6270
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6271
} SBatchDeleteReq;
6272

6273
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6274
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6275
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6276

6277
typedef struct {
6278
  int32_t msgIdx;
6279
  int32_t msgType;
6280
  int32_t msgLen;
6281
  void*   msg;
6282
} SBatchMsg;
6283

6284
typedef struct {
6285
  SMsgHead header;
6286
  SArray*  pMsgs;  // SArray<SBatchMsg>
6287
} SBatchReq;
6288

6289
typedef struct {
6290
  int32_t reqType;
6291
  int32_t msgIdx;
6292
  int32_t msgLen;
6293
  int32_t rspCode;
6294
  void*   msg;
6295
} SBatchRspMsg;
6296

6297
typedef struct {
6298
  SArray* pRsps;  // SArray<SBatchRspMsg>
6299
} SBatchRsp;
6300

6301
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6302
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6303
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
104,855,265✔
6304
  if (NULL == msg) {
104,855,265✔
UNCOV
6305
    return;
×
6306
  }
6307
  SBatchMsg* pMsg = (SBatchMsg*)msg;
104,855,265✔
6308
  taosMemoryFree(pMsg->msg);
104,855,265✔
6309
}
6310

6311
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6312
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6313

6314
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
148,071,138✔
6315
  if (NULL == p) {
148,071,138✔
UNCOV
6316
    return;
×
6317
  }
6318

6319
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
148,071,138✔
6320
  taosMemoryFree(pRsp->msg);
148,071,138✔
6321
}
6322

6323
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6324
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6325
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6326
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6327
void    tDestroySMqHbReq(SMqHbReq* pReq);
6328

6329
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6330
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6331
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6332

6333
#define TD_REQ_FROM_APP               0x0
6334
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6335
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6336
#define SUBMIT_REQ_FROM_FILE          0x4
6337
#define TD_REQ_FROM_TAOX              0x8
6338
#define TD_REQ_FROM_SML               0x10
6339
#define SUBMIT_REQUEST_VERSION        (2)
6340
#define SUBMIT_REQ_WITH_BLOB          0x10
6341
#define SUBMIT_REQ_SCHEMA_RES         0x20
6342
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6343

6344
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6345

6346
typedef struct {
6347
  int32_t        flags;
6348
  SVCreateTbReq* pCreateTbReq;
6349
  int64_t        suid;
6350
  int64_t        uid;
6351
  int32_t        sver;
6352
  union {
6353
    SArray* aRowP;
6354
    SArray* aCol;
6355
  };
6356
  int64_t   ctimeMs;
6357
  SBlobSet* pBlobSet;
6358
} SSubmitTbData;
6359

6360
typedef struct {
6361
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6362
  SArray* aSubmitBlobData;
6363
  bool    raw;
6364
} SSubmitReq2;
6365

6366
typedef struct {
6367
  SMsgHead header;
6368
  int64_t  version;
6369
  char     data[];  // SSubmitReq2
6370
} SSubmitReq2Msg;
6371

6372
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6373
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6374
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6375
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6376
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6377

6378
typedef struct {
6379
  int32_t affectedRows;
6380
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6381
} SSubmitRsp2;
6382

6383
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6384
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6385
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6386

6387
#define TSDB_MSG_FLG_ENCODE 0x1
6388
#define TSDB_MSG_FLG_DECODE 0x2
6389
#define TSDB_MSG_FLG_CMPT   0x3
6390

6391
typedef struct {
6392
  union {
6393
    struct {
6394
      void*   msgStr;
6395
      int32_t msgLen;
6396
      int64_t ver;
6397
    };
6398
    void* pDataBlock;
6399
  };
6400
} SPackedData;
6401

6402
typedef struct {
6403
  char     fullname[TSDB_VIEW_FNAME_LEN];
6404
  char     name[TSDB_VIEW_NAME_LEN];
6405
  char     dbFName[TSDB_DB_FNAME_LEN];
6406
  char*    querySql;
6407
  char*    sql;
6408
  int8_t   orReplace;
6409
  int8_t   precision;
6410
  int32_t  numOfCols;
6411
  SSchema* pSchema;
6412
} SCMCreateViewReq;
6413

6414
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6415
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6416
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6417

6418
typedef struct {
6419
  char   fullname[TSDB_VIEW_FNAME_LEN];
6420
  char   name[TSDB_VIEW_NAME_LEN];
6421
  char   dbFName[TSDB_DB_FNAME_LEN];
6422
  char*  sql;
6423
  int8_t igNotExists;
6424
} SCMDropViewReq;
6425

6426
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6427
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6428
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6429

6430
typedef struct {
6431
  char fullname[TSDB_VIEW_FNAME_LEN];
6432
} SViewMetaReq;
6433
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6434
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6435

6436
typedef struct {
6437
  char     name[TSDB_VIEW_NAME_LEN];
6438
  char     dbFName[TSDB_DB_FNAME_LEN];
6439
  char*    createUser;
6440
  int64_t  ownerId;
6441
  uint64_t dbId;
6442
  uint64_t viewId;
6443
  char*    querySql;
6444
  int8_t   precision;
6445
  int8_t   type;
6446
  int32_t  version;
6447
  int32_t  numOfCols;
6448
  SSchema* pSchema;
6449
} SViewMetaRsp;
6450
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6451
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6452
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6453
typedef struct {
6454
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6455
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6456
} STableTSMAInfoReq;
6457

6458
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6459
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6460

6461
typedef struct {
6462
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6463
  union {
6464
    uint8_t flags;
6465
    struct {
6466
      uint8_t withColName : 1;
6467
      uint8_t reserved : 7;
6468
    };
6469
  };
6470

6471
} SRsmaInfoReq;
6472

6473
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6474
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6475

6476
typedef struct {
6477
  int32_t  funcId;
6478
  col_id_t colId;
6479
} STableTSMAFuncInfo;
6480

6481
typedef struct {
6482
  char     name[TSDB_TABLE_NAME_LEN];
6483
  uint64_t tsmaId;
6484
  char     targetTb[TSDB_TABLE_NAME_LEN];
6485
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6486
  char     tb[TSDB_TABLE_NAME_LEN];
6487
  char     dbFName[TSDB_DB_FNAME_LEN];
6488
  uint64_t suid;
6489
  uint64_t destTbUid;
6490
  uint64_t dbId;
6491
  int32_t  version;
6492
  int64_t  interval;
6493
  int8_t   unit;
6494
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6495
  SArray*  pTags;      // SArray<SSchema>
6496
  SArray*  pUsedCols;  // SArray<SSchema>
6497
  char*    ast;
6498

6499
  int64_t streamUid;
6500
  int64_t reqTs;
6501
  int64_t rspTs;
6502
  int64_t delayDuration;  // ms
6503
  bool    fillHistoryFinished;
6504

6505
  void* streamAddr;  // for stream task, the address of the stream task
6506
} STableTSMAInfo;
6507

6508
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6509
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6510
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6511
void    tFreeTableTSMAInfo(void* p);
6512
void    tFreeAndClearTableTSMAInfo(void* p);
6513
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6514

6515
#define STSMAHbRsp            STableTSMAInfoRsp
6516
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6517
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6518
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6519

6520
typedef struct SDropCtbWithTsmaSingleVgReq {
6521
  SVgroupInfo vgInfo;
6522
  SArray*     pTbs;  // SVDropTbReq
6523
} SMDropTbReqsOnSingleVg;
6524

6525
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6526
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6527
void    tFreeSMDropTbReqOnSingleVg(void* p);
6528

6529
typedef struct SDropTbsReq {
6530
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6531
} SMDropTbsReq;
6532

6533
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6534
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6535
void    tFreeSMDropTbsReq(void*);
6536

6537
typedef struct SVFetchTtlExpiredTbsRsp {
6538
  SArray* pExpiredTbs;  // SVDropTbReq
6539
  int32_t vgId;
6540
} SVFetchTtlExpiredTbsRsp;
6541

6542
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6543
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6544

6545
void tFreeFetchTtlExpiredTbsRsp(void* p);
6546

6547
void setDefaultOptionsForField(SFieldWithOptions* field);
6548
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6549

6550
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6551
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6552

6553
typedef struct {
6554
  char    id[TSDB_INSTANCE_ID_LEN];
6555
  char    type[TSDB_INSTANCE_TYPE_LEN];
6556
  char    desc[TSDB_INSTANCE_DESC_LEN];
6557
  int32_t expire;
6558
} SInstanceRegisterReq;
6559

6560
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6561
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6562

6563
typedef struct {
6564
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6565
} SInstanceListReq;
6566

6567
typedef struct {
6568
  int32_t count;
6569
  char**  ids;  // Array of instance IDs
6570
} SInstanceListRsp;
6571

6572
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6573
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6574
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6575
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6576

6577
#ifdef USE_MOUNT
6578
typedef struct {
6579
  char     mountName[TSDB_MOUNT_NAME_LEN];
6580
  int8_t   ignoreExist;
6581
  int16_t  nMounts;
6582
  int32_t* dnodeIds;
6583
  char**   mountPaths;
6584
  int32_t  sqlLen;
6585
  char*    sql;
6586
} SCreateMountReq;
6587

6588
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6589
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6590
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6591

6592
typedef struct {
6593
  char    mountName[TSDB_MOUNT_NAME_LEN];
6594
  int8_t  ignoreNotExists;
6595
  int32_t sqlLen;
6596
  char*   sql;
6597
} SDropMountReq;
6598

6599
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6600
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6601
void    tFreeSDropMountReq(SDropMountReq* pReq);
6602

6603
typedef struct {
6604
  char     mountName[TSDB_MOUNT_NAME_LEN];
6605
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6606
  int64_t  mountUid;
6607
  int32_t  dnodeId;
6608
  uint32_t valLen;
6609
  int8_t   ignoreExist;
6610
  void*    pVal;
6611
} SRetrieveMountPathReq;
6612

6613
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6614
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6615

6616
typedef struct {
6617
  // path
6618
  int32_t diskPrimary;
6619
  // vgInfo
6620
  int32_t  vgId;
6621
  int32_t  cacheLastSize;
6622
  int32_t  szPage;
6623
  int32_t  szCache;
6624
  uint64_t szBuf;
6625
  int8_t   cacheLast;
6626
  int8_t   standby;
6627
  int8_t   hashMethod;
6628
  uint32_t hashBegin;
6629
  uint32_t hashEnd;
6630
  int16_t  hashPrefix;
6631
  int16_t  hashSuffix;
6632
  int16_t  sttTrigger;
6633
  // syncInfo
6634
  int32_t replications;
6635
  // tsdbInfo
6636
  int8_t  precision;
6637
  int8_t  compression;
6638
  int8_t  slLevel;
6639
  int32_t daysPerFile;
6640
  int32_t keep0;
6641
  int32_t keep1;
6642
  int32_t keep2;
6643
  int32_t keepTimeOffset;
6644
  int32_t minRows;
6645
  int32_t maxRows;
6646
  int32_t tsdbPageSize;
6647
  int32_t ssChunkSize;
6648
  int32_t ssKeepLocal;
6649
  int8_t  ssCompact;
6650
  union {
6651
    uint8_t flags;
6652
    struct {
6653
      uint8_t isAudit : 1;
6654
      uint8_t allowDrop : 1;
6655
      uint8_t reserved : 6;
6656
    };
6657
  };
6658
  int8_t secureDelete;
6659
  // walInfo
6660
  int32_t walFsyncPeriod;      // millisecond
6661
  int32_t walRetentionPeriod;  // secs
6662
  int32_t walRollPeriod;       // secs
6663
  int64_t walRetentionSize;
6664
  int64_t walSegSize;
6665
  int32_t walLevel;
6666
  // encryptInfo
6667
  int32_t encryptAlgorithm;
6668
  // SVState
6669
  int64_t committed;
6670
  int64_t commitID;
6671
  int64_t commitTerm;
6672
  // stats
6673
  int64_t numOfSTables;
6674
  int64_t numOfCTables;
6675
  int64_t numOfNTables;
6676
  // dbInfo
6677
  uint64_t dbId;
6678
} SMountVgInfo;
6679

6680
typedef struct {
6681
  SMCreateStbReq req;
6682
  SArray*        pColExts;  // element: column id
6683
  SArray*        pTagExts;  // element: tag id
6684
} SMountStbInfo;
6685

6686
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6687
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6688

6689
typedef struct {
6690
  char     dbName[TSDB_DB_FNAME_LEN];
6691
  uint64_t dbId;
6692
  SArray*  pVgs;   // SMountVgInfo
6693
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6694
} SMountDbInfo;
6695

6696
typedef struct {
6697
  // common fields
6698
  char     mountName[TSDB_MOUNT_NAME_LEN];
6699
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6700
  int8_t   ignoreExist;
6701
  int64_t  mountUid;
6702
  int64_t  clusterId;
6703
  int32_t  dnodeId;
6704
  uint32_t valLen;
6705
  void*    pVal;
6706

6707
  // response fields
6708
  SArray* pDbs;  // SMountDbInfo
6709

6710
  // memory fields, no serialized
6711
  SArray*   pDisks[TFS_MAX_TIERS];
6712
  TdFilePtr pFile;
6713
} SMountInfo;
6714

6715
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6716
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6717
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6718

6719
typedef struct {
6720
  SCreateVnodeReq createReq;
6721
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6722
  char            mountName[TSDB_MOUNT_NAME_LEN];
6723
  int64_t         mountId;
6724
  int32_t         diskPrimary;
6725
  int32_t         mountVgId;
6726
  int64_t         committed;
6727
  int64_t         commitID;
6728
  int64_t         commitTerm;
6729
  int64_t         numOfSTables;
6730
  int64_t         numOfCTables;
6731
  int64_t         numOfNTables;
6732
} SMountVnodeReq;
6733

6734
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6735
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6736
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6737

6738
#endif  // USE_MOUNT
6739

6740
#pragma pack(pop)
6741

6742
typedef struct {
6743
  char        db[TSDB_DB_FNAME_LEN];
6744
  STimeWindow timeRange;
6745
  int32_t     sqlLen;
6746
  char*       sql;
6747
  SArray*     vgroupIds;
6748
} SScanDbReq;
6749

6750
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6751
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6752
void    tFreeSScanDbReq(SScanDbReq* pReq);
6753

6754
typedef struct {
6755
  int32_t scanId;
6756
  int8_t  bAccepted;
6757
} SScanDbRsp;
6758

6759
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6760
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6761

6762
typedef struct {
6763
  int32_t scanId;
6764
  int32_t sqlLen;
6765
  char*   sql;
6766
} SKillScanReq;
6767

6768
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6769
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6770
void    tFreeSKillScanReq(SKillScanReq* pReq);
6771

6772
typedef struct {
6773
  int32_t scanId;
6774
  int32_t vgId;
6775
  int32_t dnodeId;
6776
} SVKillScanReq;
6777

6778
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6779
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6780

6781
typedef struct {
6782
  int32_t scanId;
6783
  int32_t vgId;
6784
  int32_t dnodeId;
6785
  int32_t numberFileset;
6786
  int32_t finished;
6787
  int32_t progress;
6788
  int64_t remainingTime;
6789
} SQueryScanProgressRsp;
6790

6791
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6792
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6793

6794
typedef struct {
6795
  int32_t scanId;
6796
  int32_t vgId;
6797
  int32_t dnodeId;
6798
} SQueryScanProgressReq;
6799

6800
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6801
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6802

6803
typedef struct {
6804
  int64_t     dbUid;
6805
  char        db[TSDB_DB_FNAME_LEN];
6806
  int64_t     scanStartTime;
6807
  STimeWindow tw;
6808
  int32_t     scanId;
6809
} SScanVnodeReq;
6810

6811
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6812
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6813

6814
#ifdef __cplusplus
6815
}
6816
#endif
6817

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