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

taosdata / TDengine / #4982

12 Mar 2026 05:32AM UTC coverage: 68.587% (+0.1%) from 68.488%
#4982

push

travis-ci

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

merge: from main to 3.0 branch

279 of 443 new or added lines in 34 files covered. (62.98%)

2352 existing lines in 132 files now uncovered.

212163 of 309332 relevant lines covered (68.59%)

135254549.82 hits per line

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

84.4
/include/common/tmsg.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include <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;
34✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,038,227,725✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
986,776,576✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,025,004,301✔
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_MAX,
219
} EShowType;
220

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

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

232
#define TSDB_ALTER_TABLE_ADD_TAG                         1
233
#define TSDB_ALTER_TABLE_DROP_TAG                        2
234
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
235
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
236
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
237
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
238
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
239
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
240
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
241
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
242
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
243
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
244
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
245
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
246
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
247
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
248
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
249
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
250

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

261

262
#define TSDB_ALTER_USER_BASIC_INFO             1
263
// these definitions start from 5 is to keep compatible with old versions
264
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
265
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
266

267

268
#define TSDB_ALTER_ROLE_LOCK            0x1
269
#define TSDB_ALTER_ROLE_ROLE            0x2
270
#define TSDB_ALTER_ROLE_PRIVILEGES      0x3
271
#define TSDB_ALTER_ROLE_MAX             0x4 // increase according to actual use
272

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

279
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
280
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
281
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
282

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

289
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
290
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
291
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
292
#define TSDB_COL_REQ_NULL(f)      (((f) & TSDB_COL_NULL) != 0)
293

294
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
295
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
296
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
297
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
298
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
299

300
typedef enum ENodeType {
301
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
302
  // VALUE, OPERATOR, FUNCTION and so on.
303
  QUERY_NODE_COLUMN = 1,
304
  QUERY_NODE_VALUE,
305
  QUERY_NODE_OPERATOR,
306
  QUERY_NODE_LOGIC_CONDITION,
307
  QUERY_NODE_FUNCTION,
308
  QUERY_NODE_REAL_TABLE,
309
  QUERY_NODE_TEMP_TABLE,
310
  QUERY_NODE_JOIN_TABLE,
311
  QUERY_NODE_GROUPING_SET,
312
  QUERY_NODE_ORDER_BY_EXPR,
313
  QUERY_NODE_LIMIT,
314
  QUERY_NODE_STATE_WINDOW,
315
  QUERY_NODE_SESSION_WINDOW,
316
  QUERY_NODE_INTERVAL_WINDOW,
317
  QUERY_NODE_NODE_LIST,
318
  QUERY_NODE_FILL,
319
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
320
  QUERY_NODE_TARGET,
321
  QUERY_NODE_DATABLOCK_DESC,
322
  QUERY_NODE_SLOT_DESC,
323
  QUERY_NODE_COLUMN_DEF,
324
  QUERY_NODE_DOWNSTREAM_SOURCE,
325
  QUERY_NODE_DATABASE_OPTIONS,
326
  QUERY_NODE_TABLE_OPTIONS,
327
  QUERY_NODE_INDEX_OPTIONS,
328
  QUERY_NODE_EXPLAIN_OPTIONS,
329
  QUERY_NODE_LEFT_VALUE,
330
  QUERY_NODE_COLUMN_REF,
331
  QUERY_NODE_WHEN_THEN,
332
  QUERY_NODE_CASE_WHEN,
333
  QUERY_NODE_EVENT_WINDOW,
334
  QUERY_NODE_HINT,
335
  QUERY_NODE_VIEW,
336
  QUERY_NODE_WINDOW_OFFSET,
337
  QUERY_NODE_COUNT_WINDOW,
338
  QUERY_NODE_COLUMN_OPTIONS,
339
  QUERY_NODE_TSMA_OPTIONS,
340
  QUERY_NODE_ANOMALY_WINDOW,
341
  QUERY_NODE_RANGE_AROUND,
342
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
343
  QUERY_NODE_VIRTUAL_TABLE,
344
  QUERY_NODE_SLIDING_WINDOW,
345
  QUERY_NODE_PERIOD_WINDOW,
346
  QUERY_NODE_STREAM_TRIGGER,
347
  QUERY_NODE_STREAM,
348
  QUERY_NODE_STREAM_TAG_DEF,
349
  QUERY_NODE_EXTERNAL_WINDOW,
350
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
351
  QUERY_NODE_PLACE_HOLDER_TABLE,
352
  QUERY_NODE_TIME_RANGE,
353
  QUERY_NODE_STREAM_OUT_TABLE,
354
  QUERY_NODE_STREAM_CALC_RANGE,
355
  QUERY_NODE_COUNT_WINDOW_ARGS,
356
  QUERY_NODE_BNODE_OPTIONS,
357
  QUERY_NODE_DATE_TIME_RANGE,
358
  QUERY_NODE_IP_RANGE,
359
  QUERY_NODE_USER_OPTIONS,
360
  QUERY_NODE_REMOTE_VALUE,
361
  QUERY_NODE_TOKEN_OPTIONS,
362
  QUERY_NODE_TRUE_FOR,
363
  QUERY_NODE_REMOTE_VALUE_LIST,
364
  QUERY_NODE_SURROUND,
365
  QUERY_NODE_REMOTE_ROW,
366
  QUERY_NODE_REMOTE_ZERO_ROWS,
367
  
368
  // Statement nodes are used in parser and planner module.
369
  QUERY_NODE_SET_OPERATOR = 100,
370
  QUERY_NODE_SELECT_STMT,
371
  QUERY_NODE_VNODE_MODIFY_STMT,
372
  QUERY_NODE_CREATE_DATABASE_STMT,
373
  QUERY_NODE_DROP_DATABASE_STMT,
374
  QUERY_NODE_ALTER_DATABASE_STMT,
375
  QUERY_NODE_FLUSH_DATABASE_STMT,
376
  QUERY_NODE_TRIM_DATABASE_STMT,
377
  QUERY_NODE_CREATE_TABLE_STMT,
378
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
379
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
380
  QUERY_NODE_DROP_TABLE_CLAUSE,
381
  QUERY_NODE_DROP_TABLE_STMT,
382
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
383
  QUERY_NODE_ALTER_TABLE_STMT,
384
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
385
  QUERY_NODE_CREATE_USER_STMT,
386
  QUERY_NODE_ALTER_USER_STMT,
387
  QUERY_NODE_DROP_USER_STMT,
388
  QUERY_NODE_USE_DATABASE_STMT,
389
  QUERY_NODE_CREATE_DNODE_STMT,
390
  QUERY_NODE_DROP_DNODE_STMT,
391
  QUERY_NODE_ALTER_DNODE_STMT,
392
  QUERY_NODE_CREATE_INDEX_STMT,
393
  QUERY_NODE_DROP_INDEX_STMT,
394
  QUERY_NODE_CREATE_QNODE_STMT,
395
  QUERY_NODE_DROP_QNODE_STMT,
396
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
397
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
398
  QUERY_NODE_CREATE_SNODE_STMT,
399
  QUERY_NODE_DROP_SNODE_STMT,
400
  QUERY_NODE_CREATE_MNODE_STMT,
401
  QUERY_NODE_DROP_MNODE_STMT,
402
  QUERY_NODE_CREATE_TOPIC_STMT,
403
  QUERY_NODE_DROP_TOPIC_STMT,
404
  QUERY_NODE_DROP_CGROUP_STMT,
405
  QUERY_NODE_ALTER_LOCAL_STMT,
406
  QUERY_NODE_EXPLAIN_STMT,
407
  QUERY_NODE_DESCRIBE_STMT,
408
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
409
  QUERY_NODE_COMPACT_DATABASE_STMT,
410
  QUERY_NODE_COMPACT_VGROUPS_STMT,
411
  QUERY_NODE_CREATE_FUNCTION_STMT,
412
  QUERY_NODE_DROP_FUNCTION_STMT,
413
  QUERY_NODE_CREATE_STREAM_STMT,
414
  QUERY_NODE_DROP_STREAM_STMT,
415
  QUERY_NODE_BALANCE_VGROUP_STMT,
416
  QUERY_NODE_MERGE_VGROUP_STMT,
417
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
418
  QUERY_NODE_SPLIT_VGROUP_STMT,
419
  QUERY_NODE_SYNCDB_STMT,
420
  QUERY_NODE_GRANT_STMT,
421
  QUERY_NODE_REVOKE_STMT,
422
  QUERY_NODE_ALTER_CLUSTER_STMT,
423
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
424
  QUERY_NODE_CREATE_TSMA_STMT,
425
  QUERY_NODE_DROP_TSMA_STMT,
426
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
427
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
428
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
429
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
430
  QUERY_NODE_CREATE_MOUNT_STMT,
431
  QUERY_NODE_DROP_MOUNT_STMT,
432
  QUERY_NODE_SCAN_DATABASE_STMT,
433
  QUERY_NODE_SCAN_VGROUPS_STMT,
434
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
435
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
436
  QUERY_NODE_CREATE_TOKEN_STMT,
437
  QUERY_NODE_ALTER_TOKEN_STMT,
438
  QUERY_NODE_DROP_TOKEN_STMT,
439
  QUERY_NODE_ALTER_ENCRYPT_KEY_STMT,
440
  QUERY_NODE_CREATE_ROLE_STMT,
441
  QUERY_NODE_DROP_ROLE_STMT,
442
  QUERY_NODE_ALTER_ROLE_STMT,
443
  QUERY_NODE_CREATE_TOTP_SECRET_STMT,
444
  QUERY_NODE_DROP_TOTP_SECRET_STMT,
445
  QUERY_NODE_ALTER_KEY_EXPIRATION_STMT,
446

447

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

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

566
  // logic plan node
567
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
568
  QUERY_NODE_LOGIC_PLAN_JOIN,
569
  QUERY_NODE_LOGIC_PLAN_AGG,
570
  QUERY_NODE_LOGIC_PLAN_PROJECT,
571
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
572
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
573
  QUERY_NODE_LOGIC_PLAN_MERGE,
574
  QUERY_NODE_LOGIC_PLAN_WINDOW,
575
  QUERY_NODE_LOGIC_PLAN_FILL,
576
  QUERY_NODE_LOGIC_PLAN_SORT,
577
  QUERY_NODE_LOGIC_PLAN_PARTITION,
578
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
579
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
580
  QUERY_NODE_LOGIC_SUBPLAN,
581
  QUERY_NODE_LOGIC_PLAN,
582
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
583
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
584
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
585
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
586
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
587

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

680
typedef struct {
681
  int32_t     vgId;
682
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
683
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
684
  const char* dbFName;
685
  const char* tbName;
686
} SBuildTableInput;
687

688
typedef struct {
689
  char    db[TSDB_DB_FNAME_LEN];
690
  int64_t dbId;
691
  int32_t vgVersion;
692
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
693
  int64_t stateTs;
694
} SBuildUseDBInput;
695

696
typedef struct SField {
697
  char    name[TSDB_COL_NAME_LEN];
698
  uint8_t type;
699
  int8_t  flags;
700
  int32_t bytes;
701
} SField;
702

703
typedef struct SFieldWithOptions {
704
  char     name[TSDB_COL_NAME_LEN];
705
  uint8_t  type;
706
  int8_t   flags;
707
  int32_t  bytes;
708
  uint32_t compress;
709
  STypeMod typeMod;
710
} SFieldWithOptions;
711

712
typedef struct SRetention {
713
  int64_t freq;
714
  int64_t keep;
715
  int8_t  freqUnit;
716
  int8_t  keepUnit;
717
} SRetention;
718

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

721
#pragma pack(push, 1)
722
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
723
typedef struct SEp {
724
  char     fqdn[TSDB_FQDN_LEN];
725
  uint16_t port;
726
} SEp;
727

728
typedef struct {
729
  int32_t contLen;
730
  int32_t vgId;
731
} SMsgHead;
732

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

744
// Submit message for this TSDB
745
typedef struct {
746
  SMsgHead header;
747
  int64_t  version;
748
  int32_t  length;
749
  int32_t  numOfBlocks;
750
  char     blocks[];
751
} SSubmitReq;
752

753
typedef struct {
754
  int32_t totalLen;
755
  int32_t len;
756
  STSRow* row;
757
} SSubmitBlkIter;
758

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

774
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
775
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
776
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
777
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
778
// for debug
779
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
780

781
typedef struct {
782
  bool     hasRef;
783
  col_id_t id;
784
  char     refDbName[TSDB_DB_NAME_LEN];
785
  char     refTableName[TSDB_TABLE_NAME_LEN];
786
  char     refColName[TSDB_COL_NAME_LEN];
787
  char     colName[TSDB_COL_NAME_LEN];     // for tmq get json
788
} SColRef;
789

790
typedef struct {
791
  int32_t  nCols;
792
  int32_t  version;
793
  SColRef* pColRef;
794
} SColRefWrapper;
795

796
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
797
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
798
typedef struct {
799
  int32_t vgId;
800
  SColRef colRef;
801
} SColRefEx;
802

803
typedef struct {
804
  int16_t colId;
805
  char    refDbName[TSDB_DB_NAME_LEN];
806
  char    refTableName[TSDB_TABLE_NAME_LEN];
807
  char    refColName[TSDB_COL_NAME_LEN];
808
} SRefColInfo;
809

810
typedef struct SVCTableRefCols {
811
  uint64_t     uid;
812
  int32_t      numOfSrcTbls;
813
  int32_t      numOfColRefs;
814
  SRefColInfo* refCols;
815
} SVCTableRefCols;
816

817
typedef struct SVCTableMergeInfo {
818
  uint64_t uid;
819
  int32_t  numOfSrcTbls;
820
} SVCTableMergeInfo;
821

822
typedef struct {
823
  int32_t    nCols;
824
  SColRefEx* pColRefEx;
825
} SColRefExWrapper;
826

827
struct SSchema {
828
  int8_t   type;
829
  int8_t   flags;
830
  col_id_t colId;
831
  int32_t  bytes;
832
  char     name[TSDB_COL_NAME_LEN];
833
};
834
struct SSchemaExt {
835
  col_id_t colId;
836
  uint32_t compress;
837
  STypeMod typeMod;
838
};
839

840
struct SSchemaRsma {
841
  int64_t    interval[2];
842
  int32_t    nFuncs;
843
  int8_t     tbType;
844
  tb_uid_t   tbUid;
845
  func_id_t* funcIds;
846
  char       tbName[TSDB_TABLE_NAME_LEN];
847
};
848

849
struct SSchema2 {
850
  int8_t   type;
851
  int8_t   flags;
852
  col_id_t colId;
853
  int32_t  bytes;
854
  char     name[TSDB_COL_NAME_LEN];
855
  uint32_t compress;
856
};
857

858
typedef struct {
859
  char        tbName[TSDB_TABLE_NAME_LEN];
860
  char        stbName[TSDB_TABLE_NAME_LEN];
861
  char        dbFName[TSDB_DB_FNAME_LEN];
862
  int64_t     dbId;
863
  int32_t     numOfTags;
864
  int32_t     numOfColumns;
865
  int8_t      precision;
866
  int8_t      tableType;
867
  int32_t     sversion;
868
  int32_t     tversion;
869
  int32_t     rversion;
870
  uint64_t    suid;
871
  uint64_t    tuid;
872
  int32_t     vgId;
873
  union {
874
    uint8_t flag;
875
    struct {
876
      uint8_t sysInfo : 1;
877
      uint8_t isAudit : 1;
878
      uint8_t privCat : 3;  // ESysTblPrivCat
879
      uint8_t reserved : 3;
880
    };
881
  };
882
  int64_t     ownerId;
883
  SSchema*    pSchemas;
884
  SSchemaExt* pSchemaExt;
885
  int8_t      virtualStb;
886
  int32_t     numOfColRefs;
887
  SColRef*    pColRefs;
888
} STableMetaRsp;
889

890
typedef struct {
891
  int32_t        code;
892
  int64_t        uid;
893
  char*          tblFName;
894
  int32_t        numOfRows;
895
  int32_t        affectedRows;
896
  int64_t        sver;
897
  STableMetaRsp* pMeta;
898
} SSubmitBlkRsp;
899

900
typedef struct {
901
  int32_t numOfRows;
902
  int32_t affectedRows;
903
  int32_t nBlocks;
904
  union {
905
    SArray*        pArray;
906
    SSubmitBlkRsp* pBlocks;
907
  };
908
} SSubmitRsp;
909

910
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
911
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
912
// void    tFreeSSubmitBlkRsp(void* param);
913
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
914

915
#define COL_SMA_ON       ((int8_t)0x1)
916
#define COL_IDX_ON       ((int8_t)0x2)
917
#define COL_IS_KEY       ((int8_t)0x4)
918
#define COL_SET_NULL     ((int8_t)0x10)
919
#define COL_SET_VAL      ((int8_t)0x20)
920
#define COL_IS_SYSINFO   ((int8_t)0x40)
921
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
922
#define COL_REF_BY_STM   ((int8_t)0x08)
923

924
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
925
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
926

927
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
928
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
929
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
930

931
#define SSCHMEA_SET_IDX_ON(s) \
932
  do {                        \
933
    (s)->flags |= COL_IDX_ON; \
934
  } while (0)
935

936
#define SSCHMEA_SET_IDX_OFF(s)   \
937
  do {                           \
938
    (s)->flags &= (~COL_IDX_ON); \
939
  } while (0)
940

941
#define SSCHEMA_SET_TYPE_MOD(s)     \
942
  do {                              \
943
    (s)->flags |= COL_HAS_TYPE_MOD; \
944
  } while (0)
945

946
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
947

948
#define SSCHMEA_TYPE(s)  ((s)->type)
949
#define SSCHMEA_FLAGS(s) ((s)->flags)
950
#define SSCHMEA_COLID(s) ((s)->colId)
951
#define SSCHMEA_BYTES(s) ((s)->bytes)
952
#define SSCHMEA_NAME(s)  ((s)->name)
953

954
typedef struct {
955
  bool    tsEnableMonitor;
956
  int32_t tsMonitorInterval;
957
  int32_t tsSlowLogThreshold;
958
  int32_t tsSlowLogMaxLen;
959
  int32_t tsSlowLogScope;
960
  int32_t tsSlowLogThresholdTest;  // Obsolete
961
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
962
} SMonitorParas;
963

964
typedef struct {
965
  STypeMod typeMod;
966
} SExtSchema;
967

968
bool hasExtSchema(const SExtSchema* pExtSchema);
969

970
typedef struct {
971
  int32_t      nCols;
972
  int32_t      version;
973
  SSchema*     pSchema;
974
  SSchemaRsma* pRsma;
975
} SSchemaWrapper;
976

977
typedef struct {
978
  col_id_t id;
979
  uint32_t alg;
980
} SColCmpr;
981

982
typedef struct {
983
  int32_t   nCols;
984
  int32_t   version;
985
  SColCmpr* pColCmpr;
986
} SColCmprWrapper;
987

988
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
989
  if (pRef->pColRef) {
408,974✔
990
    return TSDB_CODE_INVALID_PARA;
×
991
  }
992
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
408,974✔
993
  if (pRef->pColRef == NULL) {
408,974✔
994
    return terrno;
×
995
  }
996
  pRef->nCols = nCols;
408,974✔
997
  for (int32_t i = 0; i < nCols; i++) {
151,215,544✔
998
    pRef->pColRef[i].hasRef = false;
150,806,570✔
999
    pRef->pColRef[i].id = (col_id_t)(i + 1);
150,806,570✔
1000
  }
1001
  return 0;
408,974✔
1002
}
1003

1004
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1005
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1006
    terrno = TSDB_CODE_INVALID_PARA;
1007
    return NULL;
1008
  }
1009

1010
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1011
  if (pDstWrapper == NULL) {
1012
    return NULL;
1013
  }
1014
  pDstWrapper->nCols = pSrcWrapper->nCols;
1015
  pDstWrapper->version = pSrcWrapper->version;
1016

1017
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1018
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1019
  if (pDstWrapper->pColCmpr == NULL) {
1020
    taosMemoryFree(pDstWrapper);
1021
    return NULL;
1022
  }
1023
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1024

1025
  return pDstWrapper;
1026
}
1027

1028
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1029
  if (!(!pCmpr->pColCmpr)) {
6,872,073✔
1030
    return TSDB_CODE_INVALID_PARA;
×
1031
  }
1032
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,872,073✔
1033
  if (pCmpr->pColCmpr == NULL) {
6,872,073✔
1034
    return terrno;
×
1035
  }
1036
  pCmpr->nCols = nCols;
6,872,073✔
1037
  return 0;
6,872,073✔
1038
}
1039

1040
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1041
  pCmpr->nCols = pSchema->nCols;
1042
  if (!(!pCmpr->pColCmpr)) {
1043
    return TSDB_CODE_INVALID_PARA;
1044
  }
1045
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1046
  if (pCmpr->pColCmpr == NULL) {
1047
    return terrno;
1048
  }
1049
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1050
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1051
    SSchema*  pColSchema = &pSchema->pSchema[i];
1052
    pColCmpr->id = pColSchema->colId;
1053
    pColCmpr->alg = 0;
1054
  }
1055
  return 0;
1056
}
1057

1058
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1059
  if (pWrapper == NULL) return;
1060

1061
  taosMemoryFreeClear(pWrapper->pColCmpr);
1062
  taosMemoryFreeClear(pWrapper);
1063
}
1064
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1065
  if (pSchemaWrapper->pSchema == NULL) return NULL;
651,656,035✔
1066

1067
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
650,947,254✔
1068
  if (pSW == NULL) {
651,190,237✔
1069
    return NULL;
×
1070
  }
1071
  pSW->nCols = pSchemaWrapper->nCols;
651,190,237✔
1072
  pSW->version = pSchemaWrapper->version;
650,997,787✔
1073
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
651,328,123✔
1074
  if (pSW->pSchema == NULL) {
650,593,379✔
1075
    taosMemoryFree(pSW);
×
1076
    return NULL;
×
1077
  }
1078

1079
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
650,681,018✔
1080
  return pSW;
651,755,288✔
1081
}
1082

1083
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
157,748,743✔
1084
  if (pSchemaWrapper) {
1,464,751,723✔
1085
    taosMemoryFree(pSchemaWrapper->pSchema);
1,012,440,958✔
1086
    if (pSchemaWrapper->pRsma) {
1,012,277,910✔
1087
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
27,084✔
1088
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
27,084✔
1089
    }
1090
    taosMemoryFree(pSchemaWrapper);
1,011,507,879✔
1091
  }
1092
}
1,420,395,712✔
1093

1094
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1095
  if (pSchemaWrapper) {
1096
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1097
    if (pSchemaWrapper->pRsma) {
1098
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1099
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1100
    }
1101
  }
1102
}
1103

1104
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
8,593,035✔
1105
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
8,593,035✔
1106
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
8,594,217✔
1107
  }
1108
}
8,593,635✔
1109

1110
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1111
  int32_t tlen = 0;
2,668,848✔
1112
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,670,120✔
1113
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,668,848✔
1114
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,668,848✔
1115
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,668,848✔
1116
  tlen += taosEncodeString(buf, pSchema->name);
2,668,848✔
1117
  return tlen;
2,668,848✔
1118
}
1119

1120
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1121
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,202,990✔
1122
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,202,672✔
1123
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,202,672✔
1124
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,202,672✔
1125
  buf = taosDecodeStringTo(buf, pSchema->name);
1,202,672✔
1126
  return (void*)buf;
1,202,672✔
1127
}
1128

1129
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1130
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1131
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1132
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1133
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1134
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1135
  return 0;
2,147,483,647✔
1136
}
1137

1138
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1139
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1140
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1141
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1142
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1143
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1144
  return 0;
2,147,483,647✔
1145
}
1146

1147
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1148
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1149
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1150
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1151
  return 0;
2,147,483,647✔
1152
}
1153

1154
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1155
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1156
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1157
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1158
  return 0;
2,147,483,647✔
1159
}
1160

1161
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1162
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
903,708,496✔
1163
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
903,708,496✔
1164
  if (pColRef->hasRef) {
451,854,248✔
1165
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
599,781,892✔
1166
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
599,781,892✔
1167
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
599,781,892✔
1168
  }
1169
  return 0;
451,854,248✔
1170
}
1171

1172
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1173
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
452,308,736✔
1174
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
452,308,736✔
1175
  if (pColRef->hasRef) {
226,154,368✔
1176
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
150,140,757✔
1177
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
150,140,757✔
1178
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
150,140,757✔
1179
  }
1180

1181
  return 0;
226,154,368✔
1182
}
1183

1184
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1185
  int32_t tlen = 0;
442,462✔
1186
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
442,462✔
1187
  tlen += taosEncodeVariantI32(buf, pSW->version);
442,462✔
1188
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,111,310✔
1189
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,337,696✔
1190
  }
1191
  return tlen;
442,462✔
1192
}
1193

1194
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1195
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
191,753✔
1196
  buf = taosDecodeVariantI32(buf, &pSW->version);
191,753✔
1197
  if (pSW->nCols > 0) {
191,753✔
1198
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
191,753✔
1199
    if (pSW->pSchema == NULL) {
191,753✔
1200
      return NULL;
×
1201
    }
1202

1203
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,394,425✔
1204
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,405,344✔
1205
    }
1206
  } else {
1207
    pSW->pSchema = NULL;
×
1208
  }
1209
  return (void*)buf;
191,753✔
1210
}
1211

1212
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1213
  if (pSW == NULL) {
291,352,561✔
1214
    return TSDB_CODE_INVALID_PARA;
×
1215
  }
1216
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
582,648,721✔
1217
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
582,369,875✔
1218
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1219
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1220
  }
1221
  return 0;
291,810,935✔
1222
}
1223

1224
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1225
  if (pSW == NULL) {
126,725,690✔
1226
    return TSDB_CODE_INVALID_PARA;
×
1227
  }
1228
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
253,402,112✔
1229
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
253,384,378✔
1230

1231
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
126,707,956✔
1232
  if (pSW->pSchema == NULL) {
126,631,566✔
1233
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1234
  }
1235
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,367,399,684✔
1236
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1237
  }
1238

1239
  return 0;
126,800,037✔
1240
}
1241

1242
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1243
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1244
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1245

1246
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1247
  if (pSW->pSchema == NULL) {
2,115,440,686✔
1248
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1249
  }
1250
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1251
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1252
  }
1253

1254
  return 0;
2,118,196,767✔
1255
}
1256

1257
typedef struct {
1258
  char     name[TSDB_TABLE_FNAME_LEN];
1259
  int8_t   igExists;
1260
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1261
  int8_t   reserved[6];
1262
  tb_uid_t suid;
1263
  int64_t  delay1;
1264
  int64_t  delay2;
1265
  int64_t  watermark1;
1266
  int64_t  watermark2;
1267
  int32_t  ttl;
1268
  int32_t  colVer;
1269
  int32_t  tagVer;
1270
  int32_t  numOfColumns;
1271
  int32_t  numOfTags;
1272
  int32_t  numOfFuncs;
1273
  int32_t  commentLen;
1274
  int32_t  ast1Len;
1275
  int32_t  ast2Len;
1276
  SArray*  pColumns;  // array of SFieldWithOptions
1277
  SArray*  pTags;     // array of SField
1278
  SArray*  pFuncs;
1279
  char*    pComment;
1280
  char*    pAst1;
1281
  char*    pAst2;
1282
  int64_t  deleteMark1;
1283
  int64_t  deleteMark2;
1284
  int32_t  sqlLen;
1285
  char*    sql;
1286
  int64_t  keep;
1287
  int8_t   virtualStb;
1288
} SMCreateStbReq;
1289

1290
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1291
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1292
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1293

1294
typedef struct {
1295
  STableMetaRsp* pMeta;
1296
} SMCreateStbRsp;
1297

1298
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1299
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1300
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1301

1302
typedef struct {
1303
  char     name[TSDB_TABLE_FNAME_LEN];
1304
  int8_t   igNotExists;
1305
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1306
  int8_t   reserved[6];
1307
  tb_uid_t suid;
1308
  int32_t  sqlLen;
1309
  char*    sql;
1310
} SMDropStbReq;
1311

1312
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1313
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1314
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1315

1316
typedef struct {
1317
  char    name[TSDB_TABLE_FNAME_LEN];
1318
  int8_t  alterType;
1319
  int32_t numOfFields;
1320
  SArray* pFields;
1321
  int32_t ttl;
1322
  int32_t commentLen;
1323
  char*   comment;
1324
  int32_t sqlLen;
1325
  char*   sql;
1326
  int64_t keep;
1327
  SArray* pTypeMods;
1328
} SMAlterStbReq;
1329

1330
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1331
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1332
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1333

1334
typedef struct SEpSet {
1335
  int8_t inUse;
1336
  int8_t numOfEps;
1337
  SEp    eps[TSDB_MAX_REPLICA];
1338
} SEpSet;
1339

1340
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1341
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1342
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1343
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1344

1345
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1346
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1347

1348
typedef struct {
1349
  int8_t  connType;
1350
  int32_t pid;
1351
  int32_t totpCode;
1352
  char    app[TSDB_APP_NAME_LEN];
1353
  char    db[TSDB_DB_NAME_LEN];
1354
  char    user[TSDB_USER_LEN];
1355
  char    passwd[TSDB_PASSWORD_LEN];
1356
  char    token[TSDB_TOKEN_LEN];
1357
  int64_t startTime;
1358
  int64_t connectTime;
1359
  char    sVer[TSDB_VERSION_LEN];
1360
  char    signature[20]; // SHA1 produces a 20-byte signature
1361
} SConnectReq;
1362

1363
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1364
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1365
void    tSignConnectReq(SConnectReq* pReq);
1366
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1367

1368
typedef struct {
1369
  int64_t       clusterId;
1370
  int32_t       acctId;
1371
  uint32_t      connId;
1372
  int32_t       dnodeNum;
1373
  int8_t        superUser;
1374
  int8_t        sysInfo;
1375
  int8_t        connType;
1376
  int8_t        enableAuditDelete;
1377
  SEpSet        epSet;
1378
  int32_t       svrTimestamp;
1379
  int32_t       passVer;
1380
  int32_t       authVer;
1381
  char          sVer[TSDB_VERSION_LEN];
1382
  char          sDetailVer[128];
1383
  int64_t       whiteListVer;
1384
  int64_t       timeWhiteListVer;
1385
  int64_t       userId;
1386
  SMonitorParas monitorParas;
1387
  char          user[TSDB_USER_LEN];
1388
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1389
  int8_t        enableAuditSelect;
1390
  int8_t        enableAuditInsert;
1391
  int8_t        auditLevel;
1392
} SConnectRsp;
1393

1394
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1395
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1396

1397
typedef struct {
1398
  char    user[TSDB_USER_LEN];
1399
  char    pass[TSDB_PASSWORD_LEN];
1400
  int32_t maxUsers;
1401
  int32_t maxDbs;
1402
  int32_t maxTimeSeries;
1403
  int32_t maxStreams;
1404
  int32_t accessState;  // Configured only by command
1405
  int64_t maxStorage;
1406
} SCreateAcctReq, SAlterAcctReq;
1407

1408
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1409
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1410

1411
typedef struct {
1412
  char    user[TSDB_USER_LEN];
1413
  int8_t  ignoreNotExists;
1414
  int32_t sqlLen;
1415
  char*   sql;
1416
} SDropUserReq, SDropAcctReq;
1417

1418
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1419
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1420
void    tFreeSDropUserReq(SDropUserReq* pReq);
1421

1422
typedef struct {
1423
  char name[TSDB_ROLE_LEN];
1424
  union {
1425
    uint8_t flag;
1426
    struct {
1427
      uint8_t ignoreExists : 1;
1428
      uint8_t reserve : 7;
1429
    };
1430
  };
1431
  int32_t sqlLen;
1432
  char*   sql;
1433
} SCreateRoleReq;
1434

1435
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1436
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1437
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1438

1439
typedef struct {
1440
  char name[TSDB_ROLE_LEN];
1441
  union {
1442
    uint8_t flag;
1443
    struct {
1444
      uint8_t ignoreNotExists : 1;
1445
      uint8_t reserve : 7;
1446
    };
1447
  };
1448
  int32_t sqlLen;
1449
  char*   sql;
1450
} SDropRoleReq;
1451

1452
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1453
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1454
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1455

1456
typedef struct {
1457
  SPrivSet privSet;
1458
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1459
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1460
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1461
  // delete can only specify conditions by cond and cannot specify columns
1462
  char*    cond;     // for table privileges
1463
  int32_t  condLen;  // for table privileges
1464
} SPrivSetReqArgs;
1465

1466
typedef struct {
1467
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1468
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1469
  union {
1470
    uint32_t flag;
1471
    struct {
1472
      uint32_t lock : 1;     // lock or unlock role
1473
      uint32_t add : 1;      // add or remove
1474
      uint32_t sysPriv : 1;  // system or object privileges
1475
      uint32_t objLevel : 2;
1476
      uint32_t ignoreNotExists : 1;
1477
      uint32_t reserve : 26;
1478
    };
1479
  };
1480
  union {
1481
    SPrivSetReqArgs privileges;
1482
    char            roleName[TSDB_ROLE_LEN];
1483
  };
1484
  char    principal[TSDB_ROLE_LEN];      // role or user name
1485
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1486
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1487
  int32_t sqlLen;
1488
  char*   sql;
1489
} SAlterRoleReq;
1490

1491
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1492
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1493
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1494

1495
typedef struct {
1496
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1497
  int32_t sqlLen;
1498
  char*   sql;
1499
} SDropEncryptAlgrReq;
1500

1501
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1502
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1503
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1504

1505
typedef struct SIpV4Range {
1506
  uint32_t ip;
1507
  uint32_t mask;
1508
} SIpV4Range;
1509

1510
typedef struct SIpv6Range {
1511
  uint64_t addr[2];
1512
  uint32_t mask;
1513
} SIpV6Range;
1514

1515
typedef struct {
1516
  int8_t type;   // 0: IPv4, 1: IPv6
1517
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1518
  union {
1519
    SIpV4Range ipV4;
1520
    SIpV6Range ipV6;
1521
  };
1522
} SIpRange;
1523

1524
typedef struct {
1525
  int32_t    num;
1526
  SIpV4Range pIpRange[];
1527
} SIpWhiteList;
1528

1529
typedef struct {
1530
  int32_t  num;
1531
  SIpRange pIpRanges[];
1532
} SIpWhiteListDual;
1533

1534
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1535
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1536
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1537
int32_t           createDefaultIp6Range(SIpRange* pRange);
1538
int32_t           createDefaultIp4Range(SIpRange* pRange);
1539

1540
typedef struct {
1541
  int32_t sessPerUser;
1542
  int32_t sessConnTime;
1543
  int32_t sessConnIdleTime;
1544
  int32_t sessMaxConcurrency;
1545
  int32_t sessMaxCallVnodeNum;
1546
} SUserSessCfg;
1547

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

1552
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1553
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1554
typedef struct {
1555
  int16_t year;
1556
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1557
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1558
  int8_t hour;
1559
  int8_t minute;
1560
  int8_t neg;   // this is a negative entry
1561
  int32_t duration; // duration in minute
1562
} SDateTimeRange;
1563

1564
bool isValidDateTimeRange(SDateTimeRange* pRange);
1565
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1566
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1567

1568
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1569
typedef struct {
1570
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1571
  bool neg;         // this is a negative entry
1572
  int32_t duration; // duration in seconds
1573
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1574
} SDateTimeWhiteListItem;
1575

1576
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1577
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1578

1579
typedef struct {
1580
  int32_t num;
1581
  SDateTimeWhiteListItem ranges[];
1582
} SDateTimeWhiteList;
1583

1584
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1585
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1586

1587

1588
typedef struct {
1589
  int8_t createType;
1590

1591
  int8_t hasSessionPerUser;
1592
  int8_t hasConnectTime;
1593
  int8_t hasConnectIdleTime;
1594
  int8_t hasCallPerSession;
1595
  int8_t hasVnodePerCall;
1596
  int8_t hasFailedLoginAttempts;
1597
  int8_t hasPasswordLifeTime;
1598
  int8_t hasPasswordReuseTime;
1599
  int8_t hasPasswordReuseMax;
1600
  int8_t hasPasswordLockTime;
1601
  int8_t hasPasswordGraceTime;
1602
  int8_t hasInactiveAccountTime;
1603
  int8_t hasAllowTokenNum;
1604

1605
  int8_t superUser;  // denote if it is a super user or not
1606
  int8_t ignoreExists;
1607

1608
  char   user[TSDB_USER_LEN];
1609
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1610
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1611

1612
  int8_t sysInfo;
1613
  int8_t createDb;
1614
  int8_t isImport;
1615
  int8_t changepass;
1616
  int8_t enable;
1617

1618
  int8_t negIpRanges;
1619
  int8_t negTimeRanges;
1620

1621
  int32_t sessionPerUser;
1622
  int32_t connectTime;
1623
  int32_t connectIdleTime;
1624
  int32_t callPerSession;
1625
  int32_t vnodePerCall;
1626
  int32_t failedLoginAttempts;
1627
  int32_t passwordLifeTime;
1628
  int32_t passwordReuseTime;
1629
  int32_t passwordReuseMax;
1630
  int32_t passwordLockTime;
1631
  int32_t passwordGraceTime;
1632
  int32_t inactiveAccountTime;
1633
  int32_t allowTokenNum;
1634

1635
  int32_t         numIpRanges;
1636
  SIpRange*       pIpDualRanges;
1637
  int32_t         numTimeRanges;
1638
  SDateTimeRange* pTimeRanges;
1639

1640
  int32_t sqlLen;
1641
  char*   sql;
1642
} SCreateUserReq;
1643

1644
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1645
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1646
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1647

1648
typedef struct {
1649
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1650
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1651
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1652
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1653
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1654
  int32_t sqlLen;
1655
  char*   sql;
1656
} SCreateEncryptAlgrReq;
1657

1658
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1659
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1660
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1661

1662
typedef struct {
1663
  int32_t dnodeId;
1664
  int64_t analVer;
1665
} SRetrieveAnalyticsAlgoReq;
1666

1667
typedef struct {
1668
  int64_t   ver;
1669
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1670
} SRetrieveAnalyticAlgoRsp;
1671

1672
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1673
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1674
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1675
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1676
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1677

1678
typedef struct {
1679
  int8_t alterType;
1680

1681
  int8_t isView;
1682

1683
  int8_t hasPassword;
1684
  int8_t hasTotpseed;
1685
  int8_t hasEnable;
1686
  int8_t hasSysinfo;
1687
  int8_t hasCreatedb;
1688
  int8_t hasChangepass;
1689
  int8_t hasSessionPerUser;
1690
  int8_t hasConnectTime;
1691
  int8_t hasConnectIdleTime;
1692
  int8_t hasCallPerSession;
1693
  int8_t hasVnodePerCall;
1694
  int8_t hasFailedLoginAttempts;
1695
  int8_t hasPasswordLifeTime;
1696
  int8_t hasPasswordReuseTime;
1697
  int8_t hasPasswordReuseMax;
1698
  int8_t hasPasswordLockTime;
1699
  int8_t hasPasswordGraceTime;
1700
  int8_t hasInactiveAccountTime;
1701
  int8_t hasAllowTokenNum;
1702

1703
  int8_t enable;
1704
  int8_t sysinfo;
1705
  int8_t createdb;
1706
  int8_t changepass;
1707

1708
  char   user[TSDB_USER_LEN];
1709
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1710
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1711
  int32_t sessionPerUser;
1712
  int32_t connectTime;
1713
  int32_t connectIdleTime;
1714
  int32_t callPerSession;
1715
  int32_t vnodePerCall;
1716
  int32_t failedLoginAttempts;
1717
  int32_t passwordLifeTime;
1718
  int32_t passwordReuseTime;
1719
  int32_t passwordReuseMax;
1720
  int32_t passwordLockTime;
1721
  int32_t passwordGraceTime;
1722
  int32_t inactiveAccountTime;
1723
  int32_t allowTokenNum;
1724

1725
  int32_t         numIpRanges;
1726
  int32_t         numTimeRanges;
1727
  int32_t         numDropIpRanges;
1728
  int32_t         numDropTimeRanges;
1729
  SIpRange*       pIpRanges;
1730
  SDateTimeRange* pTimeRanges;
1731
  SIpRange*       pDropIpRanges;
1732
  SDateTimeRange* pDropTimeRanges;
1733
  SPrivSet        privileges;
1734

1735
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1736
  char        tabName[TSDB_TABLE_NAME_LEN];
1737
  char*       tagCond;
1738
  int32_t     tagCondLen;
1739
  int32_t     sqlLen;
1740
  char*       sql;
1741
} SAlterUserReq;
1742

1743
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1744
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1745
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1746

1747
typedef struct {
1748
  char    name[TSDB_TOKEN_NAME_LEN];
1749
  char    user[TSDB_USER_LEN];
1750
  int8_t  enable;
1751
  int8_t  ignoreExists;
1752
  int32_t ttl;
1753
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1754
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1755

1756
  int32_t sqlLen;
1757
  char*   sql;
1758
} SCreateTokenReq;
1759

1760
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1761
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1762
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1763

1764
typedef struct {
1765
  char name[TSDB_TOKEN_NAME_LEN];
1766
  char user[TSDB_USER_LEN];
1767
  char token[TSDB_TOKEN_LEN];
1768
} SCreateTokenRsp;
1769

1770
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1771
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1772
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1773

1774
typedef struct {
1775
  char    name[TSDB_TOKEN_NAME_LEN];
1776

1777
  int8_t hasEnable;
1778
  int8_t hasTtl;
1779
  int8_t hasProvider;
1780
  int8_t hasExtraInfo;
1781

1782
  int8_t  enable;
1783
  int32_t ttl;
1784
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1785
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1786

1787
  int32_t     sqlLen;
1788
  char*       sql;
1789
} SAlterTokenReq;
1790

1791
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1792
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1793
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1794

1795
typedef struct {
1796
  char    name[TSDB_TOKEN_NAME_LEN];
1797
  int8_t  ignoreNotExists;
1798
  int32_t sqlLen;
1799
  char*   sql;
1800
} SDropTokenReq;
1801

1802
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1803
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1804
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1805

1806
typedef struct {
1807
  char    user[TSDB_USER_LEN];
1808
  int32_t sqlLen;
1809
  char*   sql;
1810
} SCreateTotpSecretReq;
1811

1812
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1813
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1814
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1815

1816
typedef struct {
1817
  char user[TSDB_USER_LEN];
1818
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1819
} SCreateTotpSecretRsp;
1820

1821
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1822
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1823

1824
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1825
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1826
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1827
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1828

1829
typedef struct {
1830
  char user[TSDB_USER_LEN];
1831
} SGetUserAuthReq;
1832

1833
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1834
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1835

1836
typedef struct {
1837
  int8_t  enabled;
1838
  int32_t expireTime;
1839
} STokenStatus;
1840

1841
typedef struct {
1842
  char    user[TSDB_USER_LEN];
1843
  int64_t userId;
1844
  int32_t version;
1845
  int32_t passVer;
1846
  int8_t  superAuth;
1847
  int8_t  sysInfo;
1848
  int8_t  enable;
1849
  int8_t  dropped;
1850
  union {
1851
    uint8_t flags;
1852
    struct {
1853
      uint8_t privLevel : 3;
1854
      uint8_t withInsertCond : 1;
1855
      uint8_t reserve : 4;
1856
    };
1857
  };
1858
  SPrivSet  sysPrivs;
1859
  SHashObj* objPrivs;
1860
  SHashObj* selectTbs;
1861
  SHashObj* insertTbs;
1862
  SHashObj* deleteTbs;
1863
  SHashObj* ownedDbs;
1864
  int64_t   whiteListVer;
1865

1866
  SUserSessCfg sessCfg;
1867
  int64_t      timeWhiteListVer;
1868
  SHashObj*    tokens;
1869
} SGetUserAuthRsp;
1870

1871
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1872
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1873
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1874

1875
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1876
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1877
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1878
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1879

1880
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1881
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1882
typedef struct {
1883
  int64_t ver;
1884
  char    user[TSDB_USER_LEN];
1885
  int32_t numOfRange;
1886
  union {
1887
    SIpV4Range* pIpRanges;
1888
    SIpRange*   pIpDualRanges;
1889
  };
1890
} SUpdateUserIpWhite;
1891

1892
typedef struct {
1893
  int64_t             ver;
1894
  int                 numOfUser;
1895
  SUpdateUserIpWhite* pUserIpWhite;
1896
} SUpdateIpWhite;
1897

1898
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1899
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1900
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1901
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1902

1903
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1904
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1905
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1906

1907

1908
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1909
// corresponding response struct is different.
1910
typedef struct {
1911
  int64_t ver;
1912
} SRetrieveWhiteListReq;
1913

1914
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1915
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1916

1917

1918
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1919
// corresponding response struct is different.
1920
typedef struct {
1921
  char user[TSDB_USER_LEN];
1922
} SGetUserWhiteListReq;
1923

1924
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1925
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1926

1927
typedef struct {
1928
  char    user[TSDB_USER_LEN];
1929
  int32_t numWhiteLists;
1930
  union {
1931
    SIpV4Range* pWhiteLists;
1932
    SIpRange*   pWhiteListsDual;
1933
  };
1934
} SGetUserIpWhiteListRsp;
1935

1936
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1937
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1938
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1939
void    tIpRangeSetDefaultMask(SIpRange* range);
1940

1941
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1942
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1943
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1944

1945
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1946
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1947
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1948

1949
typedef struct {
1950
  int64_t ver;
1951
  char    user[TSDB_USER_LEN];
1952
  int32_t numWhiteLists;
1953
  SDateTimeWhiteListItem* pWhiteLists;
1954
} SUserDateTimeWhiteList;
1955

1956

1957
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1958
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1959
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1960
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1961

1962
typedef struct {
1963
  int64_t             ver;
1964
  int                 numOfUser;
1965
  SUserDateTimeWhiteList *pUsers;
1966
} SRetrieveDateTimeWhiteListRsp;
1967

1968
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1969
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1970
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1971
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1972

1973
/*
1974
 * for client side struct, only column id, type, bytes are necessary
1975
 * But for data in vnode side, we need all the following information.
1976
 */
1977
typedef struct {
1978
  union {
1979
    col_id_t colId;
1980
    int16_t  slotId;
1981
  };
1982

1983
  uint8_t precision;
1984
  uint8_t scale;
1985
  int32_t bytes;
1986
  int8_t  type;
1987
  uint8_t pk;
1988
  bool    noData;
1989
} SColumnInfo;
1990

1991
typedef struct STimeWindow {
1992
  TSKEY skey;
1993
  TSKEY ekey;
1994
} STimeWindow;
1995

1996
typedef struct SQueryHint {
1997
  bool batchScan;
1998
} SQueryHint;
1999

2000
typedef struct {
2001
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2002
  int32_t tsLen;          // total length of ts comp block
2003
  int32_t tsNumOfBlocks;  // ts comp block numbers
2004
  int32_t tsOrder;        // ts comp block order
2005
} STsBufInfo;
2006

2007
typedef struct {
2008
  void*       timezone;
2009
  char        intervalUnit;
2010
  char        slidingUnit;
2011
  char        offsetUnit;
2012
  int8_t      precision;
2013
  int64_t     interval;
2014
  int64_t     sliding;
2015
  int64_t     offset;
2016
  STimeWindow timeRange;
2017
} SInterval;
2018

2019
typedef struct STbVerInfo {
2020
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2021
  int32_t sversion;
2022
  int32_t tversion;
2023
  int32_t rversion;  // virtual table's column ref's version
2024
} STbVerInfo;
2025

2026
typedef struct {
2027
  int32_t code;
2028
  int64_t affectedRows;
2029
  SArray* tbVerInfo;  // STbVerInfo
2030
} SQueryTableRsp;
2031

2032
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2033

2034
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2035

2036
typedef struct {
2037
  SMsgHead header;
2038
  char     dbFName[TSDB_DB_FNAME_LEN];
2039
  char     tbName[TSDB_TABLE_NAME_LEN];
2040
} STableCfgReq;
2041

2042
typedef struct {
2043
  char        tbName[TSDB_TABLE_NAME_LEN];
2044
  char        stbName[TSDB_TABLE_NAME_LEN];
2045
  char        dbFName[TSDB_DB_FNAME_LEN];
2046
  int32_t     numOfTags;
2047
  int32_t     numOfColumns;
2048
  int8_t      tableType;
2049
  int64_t     delay1;
2050
  int64_t     delay2;
2051
  int64_t     watermark1;
2052
  int64_t     watermark2;
2053
  int32_t     ttl;
2054
  int32_t     keep;
2055
  int64_t     ownerId;
2056
  SArray*     pFuncs;
2057
  int32_t     commentLen;
2058
  char*       pComment;
2059
  SSchema*    pSchemas;
2060
  int32_t     tagsLen;
2061
  char*       pTags;
2062
  SSchemaExt* pSchemaExt;
2063
  union {
2064
    uint8_t flag;
2065
    struct {
2066
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2067
      uint8_t isAudit : 1;
2068
      uint8_t reserve : 6;
2069
    };
2070
  };
2071
  SColRef* pColRefs;
2072
} STableCfg;
2073

2074
typedef STableCfg STableCfgRsp;
2075

2076
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2077
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2078

2079
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2080
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2081
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2082

2083
typedef struct {
2084
  SMsgHead header;
2085
  tb_uid_t suid;
2086
} SVSubTablesReq;
2087

2088
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2089
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2090

2091
typedef struct {
2092
  int32_t vgId;
2093
  SArray* pTables;  // SArray<SVCTableRefCols*>
2094
} SVSubTablesRsp;
2095

2096
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2097
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2098
void    tDestroySVSubTablesRsp(void* rsp);
2099

2100
typedef struct {
2101
  SMsgHead header;
2102
  tb_uid_t suid;
2103
} SVStbRefDbsReq;
2104

2105
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2106
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2107

2108
typedef struct {
2109
  int32_t vgId;
2110
  SArray* pDbs;  // SArray<char* (db name)>
2111
} SVStbRefDbsRsp;
2112

2113
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2114
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2115
void    tDestroySVStbRefDbsRsp(void* rsp);
2116

2117
typedef struct {
2118
  char    db[TSDB_DB_FNAME_LEN];
2119
  int32_t numOfVgroups;
2120
  int32_t numOfStables;  // single_stable
2121
  int32_t buffer;        // MB
2122
  int32_t pageSize;
2123
  int32_t pages;
2124
  int32_t cacheLastSize;
2125
  int32_t daysPerFile;
2126
  int32_t daysToKeep0;
2127
  int32_t daysToKeep1;
2128
  int32_t daysToKeep2;
2129
  int32_t keepTimeOffset;
2130
  int32_t minRows;
2131
  int32_t maxRows;
2132
  int32_t walFsyncPeriod;
2133
  int8_t  walLevel;
2134
  int8_t  precision;  // time resolution
2135
  int8_t  compression;
2136
  int8_t  replications;
2137
  int8_t  strict;
2138
  int8_t  cacheLast;
2139
  int8_t  schemaless;
2140
  int8_t  ignoreExist;
2141
  int32_t numOfRetensions;
2142
  SArray* pRetensions;  // SRetention
2143
  int32_t walRetentionPeriod;
2144
  int64_t walRetentionSize;
2145
  int32_t walRollPeriod;
2146
  int64_t walSegmentSize;
2147
  int32_t sstTrigger;
2148
  int16_t hashPrefix;
2149
  int16_t hashSuffix;
2150
  int32_t ssChunkSize;
2151
  int32_t ssKeepLocal;
2152
  int8_t  ssCompact;
2153
  int32_t tsdbPageSize;
2154
  int32_t sqlLen;
2155
  char*   sql;
2156
  int8_t  withArbitrator;
2157
  int8_t  encryptAlgorithm;
2158
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2159
  // 1. add auto-compact parameters
2160
  int32_t compactInterval;    // minutes
2161
  int32_t compactStartTime;   // minutes
2162
  int32_t compactEndTime;     // minutes
2163
  int8_t  compactTimeOffset;  // hour
2164
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2165
  int8_t  isAudit;
2166
  int8_t  allowDrop;
2167
} SCreateDbReq;
2168

2169
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2170
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2171
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2172

2173
typedef struct {
2174
  char    db[TSDB_DB_FNAME_LEN];
2175
  int32_t buffer;
2176
  int32_t pageSize;
2177
  int32_t pages;
2178
  int32_t cacheLastSize;
2179
  int32_t daysPerFile;
2180
  int32_t daysToKeep0;
2181
  int32_t daysToKeep1;
2182
  int32_t daysToKeep2;
2183
  int32_t keepTimeOffset;
2184
  int32_t walFsyncPeriod;
2185
  int8_t  walLevel;
2186
  int8_t  strict;
2187
  int8_t  cacheLast;
2188
  int8_t  replications;
2189
  int32_t sstTrigger;
2190
  int32_t minRows;
2191
  int32_t walRetentionPeriod;
2192
  int32_t walRetentionSize;
2193
  int32_t ssKeepLocal;
2194
  int8_t  ssCompact;
2195
  int32_t sqlLen;
2196
  char*   sql;
2197
  int8_t  withArbitrator;
2198
  // 1. add auto-compact parameters
2199
  int32_t compactInterval;
2200
  int32_t compactStartTime;
2201
  int32_t compactEndTime;
2202
  int8_t  compactTimeOffset;
2203
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2204
  int8_t  isAudit;
2205
  int8_t  allowDrop;
2206
} SAlterDbReq;
2207

2208
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2209
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2210
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2211

2212
typedef struct {
2213
  char    db[TSDB_DB_FNAME_LEN];
2214
  int8_t  ignoreNotExists;
2215
  int8_t  force;
2216
  int32_t sqlLen;
2217
  char*   sql;
2218
} SDropDbReq;
2219

2220
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2221
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2222
void    tFreeSDropDbReq(SDropDbReq* pReq);
2223

2224
typedef struct {
2225
  char    db[TSDB_DB_FNAME_LEN];
2226
  int64_t uid;
2227
} SDropDbRsp;
2228

2229
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2230
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2231

2232
typedef struct {
2233
  char    name[TSDB_MOUNT_NAME_LEN];
2234
  int64_t uid;
2235
} SDropMountRsp;
2236

2237
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2238
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2239

2240
typedef struct {
2241
  char    db[TSDB_DB_FNAME_LEN];
2242
  int64_t dbId;
2243
  int32_t vgVersion;
2244
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2245
  int64_t stateTs;     // ms
2246
} SUseDbReq;
2247

2248
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2249
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2250

2251
typedef struct {
2252
  char    db[TSDB_DB_FNAME_LEN];
2253
  int64_t uid;
2254
  int32_t vgVersion;
2255
  int32_t vgNum;
2256
  int16_t hashPrefix;
2257
  int16_t hashSuffix;
2258
  int8_t  hashMethod;
2259
  union {
2260
    uint8_t flags;
2261
    struct {
2262
      uint8_t isMount : 1;  // TS-5868
2263
      uint8_t padding : 7;
2264
    };
2265
  };
2266
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2267
  int32_t errCode;
2268
  int64_t stateTs;  // ms
2269
} SUseDbRsp;
2270

2271
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2272
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2273
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2274
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2275
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2276

2277
typedef struct {
2278
  char db[TSDB_DB_FNAME_LEN];
2279
} SDbCfgReq;
2280

2281
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2282
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2283

2284
typedef struct {
2285
  char db[TSDB_DB_FNAME_LEN];
2286
} SSsMigrateDbReq;
2287

2288
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2289
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2290

2291
typedef struct {
2292
  int32_t ssMigrateId;
2293
  bool    bAccepted;
2294
} SSsMigrateDbRsp;
2295

2296
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2297
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2298

2299
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2300
typedef struct {
2301
  int32_t ssMigrateId;
2302
} SListSsMigrateFileSetsReq;
2303

2304
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2305
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2306

2307
typedef struct {
2308
  int32_t ssMigrateId;
2309
  int32_t vgId;       // vgroup id
2310
  SArray* pFileSets;  // SArray<int32_t>
2311
} SListSsMigrateFileSetsRsp;
2312

2313
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2314
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2315
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2316

2317
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2318
typedef struct {
2319
  int32_t ssMigrateId;
2320
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2321
  int32_t fid;
2322
  int64_t startTimeSec;
2323
} SSsMigrateFileSetReq;
2324

2325
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2326
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2327

2328
typedef struct {
2329
  int32_t ssMigrateId;
2330
  int32_t nodeId;  // node id of the leader vnode
2331
  int32_t vgId;
2332
  int32_t fid;
2333
} SSsMigrateFileSetRsp;
2334

2335
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2336
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2337

2338
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2339
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2340
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2341
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2342
#define SSMIGRATE_FILESET_STATE_FAILED      4
2343

2344
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2345
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2346
// while as a request, the 'state' field is not used.
2347
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2348
typedef struct {
2349
  int32_t ssMigrateId;  // ss migrate id
2350
  int32_t nodeId;       // node id of the leader vnode
2351
  int32_t vgId;         // vgroup id
2352
  int32_t fid;          // file set id
2353
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2354
} SSsMigrateProgress;
2355

2356
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2357
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2358

2359
// Request for TDMT_MND_KILL_SSMIGRATE
2360
typedef struct {
2361
  int32_t ssMigrateId;
2362
  int32_t sqlLen;
2363
  char*   sql;
2364
} SKillSsMigrateReq;
2365

2366
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2367
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2368
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2369

2370
// Request for TDMT_VND_KILL_SSMIGRATE
2371
typedef struct {
2372
  int32_t ssMigrateId;
2373
} SVnodeKillSsMigrateReq;
2374

2375
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2376
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2377

2378
typedef struct {
2379
  int32_t vgId;
2380
  int64_t keepVersion;
2381
} SMndSetVgroupKeepVersionReq;
2382

2383
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2384
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2385

2386
typedef struct {
2387
  int32_t timestampSec;
2388
  int32_t ttlDropMaxCount;
2389
  int32_t nUids;
2390
  SArray* pTbUids;
2391
} SVDropTtlTableReq;
2392

2393
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2394
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2395

2396
typedef struct {
2397
  char    db[TSDB_DB_FNAME_LEN];
2398
  int64_t dbId;
2399
  int64_t ownerId;
2400
  int32_t cfgVersion;
2401
  int32_t numOfVgroups;
2402
  int32_t numOfStables;
2403
  int32_t buffer;
2404
  int32_t cacheSize;
2405
  int32_t pageSize;
2406
  int32_t pages;
2407
  int32_t daysPerFile;
2408
  int32_t daysToKeep0;
2409
  int32_t daysToKeep1;
2410
  int32_t daysToKeep2;
2411
  int32_t keepTimeOffset;
2412
  int32_t minRows;
2413
  int32_t maxRows;
2414
  int32_t walFsyncPeriod;
2415
  int16_t hashPrefix;
2416
  int16_t hashSuffix;
2417
  int8_t  hashMethod;
2418
  int8_t  walLevel;
2419
  int8_t  precision;
2420
  int8_t  compression;
2421
  int8_t  replications;
2422
  int8_t  strict;
2423
  int8_t  cacheLast;
2424
  int8_t  encryptAlgr;
2425
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2426
  int32_t ssChunkSize;
2427
  int32_t ssKeepLocal;
2428
  int8_t  ssCompact;
2429
  union {
2430
    uint8_t flags;
2431
    struct {
2432
      uint8_t isMount : 1;    // TS-5868
2433
      uint8_t allowDrop : 1;  // TS-7232
2434
      uint8_t padding : 6;
2435
    };
2436
  };
2437
  int8_t  compactTimeOffset;
2438
  int32_t compactInterval;
2439
  int32_t compactStartTime;
2440
  int32_t compactEndTime;
2441
  int32_t tsdbPageSize;
2442
  int32_t walRetentionPeriod;
2443
  int32_t walRollPeriod;
2444
  int64_t walRetentionSize;
2445
  int64_t walSegmentSize;
2446
  int32_t numOfRetensions;
2447
  SArray* pRetensions;
2448
  int8_t  schemaless;
2449
  int16_t sstTrigger;
2450
  int8_t  withArbitrator;
2451
  int8_t  isAudit;
2452
} SDbCfgRsp;
2453

2454
typedef SDbCfgRsp SDbCfgInfo;
2455

2456
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2457
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2458
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2459
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2460
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2461

2462
typedef struct {
2463
  int32_t rowNum;
2464
} SQnodeListReq;
2465

2466
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2467
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2468

2469
typedef struct {
2470
  int32_t rowNum;
2471
} SDnodeListReq;
2472

2473
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2474

2475
typedef struct {
2476
  int32_t useless;  // useless
2477
} SServerVerReq;
2478

2479
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2480
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2481

2482
typedef struct {
2483
  char ver[TSDB_VERSION_LEN];
2484
} SServerVerRsp;
2485

2486
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2487
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2488

2489
typedef struct SQueryNodeAddr {
2490
  int32_t nodeId;  // vgId or qnodeId
2491
  SEpSet  epSet;
2492
} SQueryNodeAddr;
2493

2494
typedef struct {
2495
  SQueryNodeAddr addr;
2496
  uint64_t       load;
2497
} SQueryNodeLoad;
2498

2499
typedef struct {
2500
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2501
} SQnodeListRsp;
2502

2503
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2504
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2505
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2506

2507

2508
typedef struct SDownstreamSourceNode {
2509
  ENodeType      type;
2510
  SQueryNodeAddr addr;
2511
  uint64_t       clientId;
2512
  uint64_t       taskId;
2513
  uint64_t       sId;
2514
  uint64_t       srcTaskId;
2515
  int32_t        execId;
2516
  int32_t        fetchMsgType;
2517
  bool           localExec;
2518
} SDownstreamSourceNode;
2519

2520

2521

2522
typedef struct SDNodeAddr {
2523
  int32_t nodeId;  // dnodeId
2524
  SEpSet  epSet;
2525
} SDNodeAddr;
2526

2527
typedef struct {
2528
  SArray* dnodeList;  // SArray<SDNodeAddr>
2529
} SDnodeListRsp;
2530

2531
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2532
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2533
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2534

2535
typedef struct {
2536
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2537
} STableTSMAInfoRsp;
2538

2539
typedef struct {
2540
  SUseDbRsp*         useDbRsp;
2541
  SDbCfgRsp*         cfgRsp;
2542
  STableTSMAInfoRsp* pTsmaRsp;
2543
  int32_t            dbTsmaVersion;
2544
  char               db[TSDB_DB_FNAME_LEN];
2545
  int64_t            dbId;
2546
} SDbHbRsp;
2547

2548
typedef struct {
2549
  SArray* pArray;  // Array of SDbHbRsp
2550
} SDbHbBatchRsp;
2551

2552
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2553
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2554
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2555

2556
typedef struct {
2557
  SArray* pArray;  // Array of SGetUserAuthRsp
2558
} SUserAuthBatchRsp;
2559

2560
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2561
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2562
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2563

2564
typedef struct {
2565
  char        db[TSDB_DB_FNAME_LEN];
2566
  STimeWindow timeRange;
2567
  int32_t     sqlLen;
2568
  char*       sql;
2569
  SArray*     vgroupIds;
2570
  int32_t     compactId;
2571
  int8_t      metaOnly;
2572
  int8_t      force;
2573
} SCompactDbReq;
2574

2575
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2576
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2577
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2578

2579
typedef struct {
2580
  union {
2581
    int32_t compactId;
2582
    int32_t id;
2583
  };
2584
  int8_t bAccepted;
2585
} SCompactDbRsp;
2586

2587
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2588
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2589

2590
typedef struct {
2591
  union {
2592
    int32_t compactId;
2593
    int32_t id;
2594
  };
2595
  int32_t sqlLen;
2596
  char*   sql;
2597
} SKillCompactReq;
2598

2599
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2600
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2601
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2602

2603
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2604
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2605

2606
typedef struct {
2607
  char    name[TSDB_FUNC_NAME_LEN];
2608
  int8_t  igExists;
2609
  int8_t  funcType;
2610
  int8_t  scriptType;
2611
  int8_t  outputType;
2612
  int32_t outputLen;
2613
  int32_t bufSize;
2614
  int32_t codeLen;
2615
  int64_t signature;
2616
  char*   pComment;
2617
  char*   pCode;
2618
  int8_t  orReplace;
2619
} SCreateFuncReq;
2620

2621
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2622
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2623
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2624

2625
typedef struct {
2626
  char   name[TSDB_FUNC_NAME_LEN];
2627
  int8_t igNotExists;
2628
} SDropFuncReq;
2629

2630
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2631
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2632

2633
typedef struct {
2634
  int32_t numOfFuncs;
2635
  bool    ignoreCodeComment;
2636
  SArray* pFuncNames;
2637
} SRetrieveFuncReq;
2638

2639
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2640
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2641
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2642

2643
typedef struct {
2644
  char    name[TSDB_FUNC_NAME_LEN];
2645
  int8_t  funcType;
2646
  int8_t  scriptType;
2647
  int8_t  outputType;
2648
  int32_t outputLen;
2649
  int32_t bufSize;
2650
  int64_t signature;
2651
  int32_t commentSize;
2652
  int32_t codeSize;
2653
  char*   pComment;
2654
  char*   pCode;
2655
} SFuncInfo;
2656

2657
typedef struct {
2658
  int32_t funcVersion;
2659
  int64_t funcCreatedTime;
2660
} SFuncExtraInfo;
2661

2662
typedef struct {
2663
  int32_t numOfFuncs;
2664
  SArray* pFuncInfos;
2665
  SArray* pFuncExtraInfos;
2666
} SRetrieveFuncRsp;
2667

2668
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2669
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2670
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2671
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2672

2673
typedef struct {
2674
  int32_t       statusInterval;
2675
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2676
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2677
  char          locale[TD_LOCALE_LEN];      // tsLocale
2678
  char          charset[TD_LOCALE_LEN];     // tsCharset
2679
  int8_t        ttlChangeOnWrite;
2680
  int8_t        enableWhiteList;
2681
  int8_t        encryptionKeyStat;
2682
  uint32_t      encryptionKeyChksum;
2683
  SMonitorParas monitorParas;
2684
  int32_t       statusIntervalMs;
2685
} SClusterCfg;
2686

2687
typedef struct {
2688
  int32_t openVnodes;
2689
  int32_t dropVnodes;
2690
  int32_t totalVnodes;
2691
  int32_t masterNum;
2692
  int64_t numOfSelectReqs;
2693
  int64_t numOfInsertReqs;
2694
  int64_t numOfInsertSuccessReqs;
2695
  int64_t numOfBatchInsertReqs;
2696
  int64_t numOfBatchInsertSuccessReqs;
2697
  int64_t errors;
2698
} SVnodesStat;
2699

2700
typedef struct {
2701
  int32_t vgId;
2702
  int8_t  syncState;
2703
  int8_t  syncRestore;
2704
  int64_t syncTerm;
2705
  int64_t roleTimeMs;
2706
  int64_t startTimeMs;
2707
  int8_t  syncCanRead;
2708
  int64_t cacheUsage;
2709
  int64_t numOfTables;
2710
  int64_t numOfTimeSeries;
2711
  int64_t totalStorage;
2712
  int64_t compStorage;
2713
  int64_t pointsWritten;
2714
  int64_t numOfSelectReqs;
2715
  int64_t numOfInsertReqs;
2716
  int64_t numOfInsertSuccessReqs;
2717
  int64_t numOfBatchInsertReqs;
2718
  int64_t numOfBatchInsertSuccessReqs;
2719
  int32_t numOfCachedTables;
2720
  int32_t learnerProgress;  // use one reservered
2721
  int64_t syncAppliedIndex;
2722
  int64_t syncCommitIndex;
2723
  int64_t bufferSegmentUsed;
2724
  int64_t bufferSegmentSize;
2725
  int32_t snapSeq;
2726
  int64_t syncTotalIndex;
2727
} SVnodeLoad;
2728

2729
typedef struct {
2730
  int64_t total_requests;
2731
  int64_t total_rows;
2732
  int64_t total_bytes;
2733
  double  write_size;
2734
  double  cache_hit_ratio;
2735
  int64_t rpc_queue_wait;
2736
  int64_t preprocess_time;
2737

2738
  int64_t memory_table_size;
2739
  int64_t commit_count;
2740
  int64_t merge_count;
2741
  double  commit_time;
2742
  double  merge_time;
2743
  int64_t block_commit_time;
2744
  int64_t memtable_wait_time;
2745
} SVnodeMetrics;
2746

2747
typedef struct {
2748
  int32_t     vgId;
2749
  int64_t     numOfTables;
2750
  int64_t     memSize;
2751
  int64_t     l1Size;
2752
  int64_t     l2Size;
2753
  int64_t     l3Size;
2754
  int64_t     cacheSize;
2755
  int64_t     walSize;
2756
  int64_t     metaSize;
2757
  int64_t     rawDataSize;
2758
  int64_t     ssSize;
2759
  const char* dbname;
2760
  int8_t      estimateRawData;
2761
} SDbSizeStatisInfo;
2762

2763
typedef struct {
2764
  int32_t vgId;
2765
  int64_t nTimeSeries;
2766
} SVnodeLoadLite;
2767

2768
typedef struct {
2769
  int8_t  syncState;
2770
  int64_t syncTerm;
2771
  int8_t  syncRestore;
2772
  int64_t roleTimeMs;
2773
} SMnodeLoad;
2774

2775
typedef struct {
2776
  int32_t dnodeId;
2777
  int64_t numOfProcessedQuery;
2778
  int64_t numOfProcessedCQuery;
2779
  int64_t numOfProcessedFetch;
2780
  int64_t numOfProcessedDrop;
2781
  int64_t numOfProcessedNotify;
2782
  int64_t numOfProcessedHb;
2783
  int64_t numOfProcessedDelete;
2784
  int64_t cacheDataSize;
2785
  int64_t numOfQueryInQueue;
2786
  int64_t numOfFetchInQueue;
2787
  int64_t timeInQueryQueue;
2788
  int64_t timeInFetchQueue;
2789
} SQnodeLoad;
2790

2791
typedef struct {
2792
  int32_t     sver;      // software version
2793
  int64_t     dnodeVer;  // dnode table version in sdb
2794
  int32_t     dnodeId;
2795
  int64_t     clusterId;
2796
  int64_t     rebootTime;
2797
  int64_t     updateTime;
2798
  float       numOfCores;
2799
  int32_t     numOfSupportVnodes;
2800
  int32_t     numOfDiskCfg;
2801
  int64_t     memTotal;
2802
  int64_t     memAvail;
2803
  char        dnodeEp[TSDB_EP_LEN];
2804
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2805
  SMnodeLoad  mload;
2806
  SQnodeLoad  qload;
2807
  SClusterCfg clusterCfg;
2808
  SArray*     pVloads;  // array of SVnodeLoad
2809
  int32_t     statusSeq;
2810
  int64_t     ipWhiteVer;
2811
  int64_t     timeWhiteVer;
2812
  int64_t     analVer;
2813
  int64_t     timestamp;
2814
  char        auditDB[TSDB_DB_FNAME_LEN];
2815
  char        auditToken[TSDB_TOKEN_LEN];
2816
} SStatusReq;
2817

2818
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2819
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2820
void    tFreeSStatusReq(SStatusReq* pReq);
2821

2822
typedef struct {
2823
  int32_t forceReadConfig;
2824
  int32_t cver;
2825
  SArray* array;
2826
} SConfigReq;
2827

2828
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2829
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2830
void    tFreeSConfigReq(SConfigReq* pReq);
2831

2832
typedef struct {
2833
  int32_t dnodeId;
2834
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2835
} SDnodeInfoReq;
2836

2837
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2838
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2839

2840
typedef enum {
2841
  MONITOR_TYPE_COUNTER = 0,
2842
  MONITOR_TYPE_SLOW_LOG = 1,
2843
} MONITOR_TYPE;
2844

2845
typedef struct {
2846
  int32_t      contLen;
2847
  char*        pCont;
2848
  MONITOR_TYPE type;
2849
} SStatisReq;
2850

2851
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2852
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2853
void    tFreeSStatisReq(SStatisReq* pReq);
2854

2855
typedef struct {
2856
  char    db[TSDB_DB_FNAME_LEN];
2857
  char    table[TSDB_TABLE_NAME_LEN];
2858
  char    operation[AUDIT_OPERATION_LEN];
2859
  int32_t sqlLen;
2860
  char*   pSql;
2861
  double  duration;
2862
  int64_t affectedRows;
2863
} SAuditReq;
2864
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2865
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2866
void    tFreeSAuditReq(SAuditReq* pReq);
2867

2868
typedef struct {
2869
  SArray* auditArr;
2870
} SBatchAuditReq;
2871
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2872
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2873
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2874

2875
typedef struct {
2876
  int32_t dnodeId;
2877
  int64_t clusterId;
2878
  SArray* pVloads;
2879
} SNotifyReq;
2880

2881
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2882
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2883
void    tFreeSNotifyReq(SNotifyReq* pReq);
2884

2885
typedef struct {
2886
  int32_t dnodeId;
2887
  int64_t clusterId;
2888
} SDnodeCfg;
2889

2890
typedef struct {
2891
  int32_t id;
2892
  int8_t  isMnode;
2893
  SEp     ep;
2894
} SDnodeEp;
2895

2896
typedef struct {
2897
  int32_t id;
2898
  int8_t  isMnode;
2899
  int8_t  offlineReason;
2900
  SEp     ep;
2901
  char    active[TSDB_ACTIVE_KEY_LEN];
2902
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2903
} SDnodeInfo;
2904

2905
typedef struct {
2906
  int64_t   dnodeVer;
2907
  SDnodeCfg dnodeCfg;
2908
  SArray*   pDnodeEps;  // Array of SDnodeEp
2909
  int32_t   statusSeq;
2910
  int64_t   ipWhiteVer;
2911
  int64_t   analVer;
2912
  int64_t   timeWhiteVer;
2913
  char      auditDB[TSDB_DB_FNAME_LEN];
2914
  char      auditToken[TSDB_TOKEN_LEN];
2915
} SStatusRsp;
2916

2917
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2918
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2919
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2920

2921
typedef struct {
2922
  int32_t forceReadConfig;
2923
  int32_t isConifgVerified;
2924
  int32_t isVersionVerified;
2925
  int32_t cver;
2926
  SArray* array;
2927
} SConfigRsp;
2928

2929
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2930
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2931
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2932

2933
typedef struct {
2934
  int32_t dnodeId;
2935
  int32_t keyVersion;  // Local key version
2936
} SKeySyncReq;
2937

2938
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2939
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2940

2941
typedef struct {
2942
  int32_t keyVersion;        // mnode's key version
2943
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2944
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2945
  char    svrKey[129];       // Server key (if needUpdate)
2946
  char    dbKey[129];        // Database key (if needUpdate)
2947
  char    cfgKey[129];       // Config key (if needUpdate)
2948
  char    metaKey[129];      // Metadata key (if needUpdate)
2949
  char    dataKey[129];      // Data key (if needUpdate)
2950
  int32_t algorithm;         // Encryption algorithm for master keys
2951
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2952
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2953
  int64_t createTime;        // Key creation time
2954
  int64_t svrKeyUpdateTime;  // Server key update time
2955
  int64_t dbKeyUpdateTime;   // Database key update time
2956
} SKeySyncRsp;
2957

2958
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2959
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2960

2961
typedef struct {
2962
  int32_t reserved;
2963
} SMTimerReq;
2964

2965
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2966
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2967

2968
typedef struct SOrphanTask {
2969
  int64_t streamId;
2970
  int32_t taskId;
2971
  int32_t nodeId;
2972
} SOrphanTask;
2973

2974
typedef struct SMStreamDropOrphanMsg {
2975
  SArray* pList;  // SArray<SOrphanTask>
2976
} SMStreamDropOrphanMsg;
2977

2978
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2979
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2980
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2981

2982
typedef struct {
2983
  int32_t  id;
2984
  uint16_t port;                 // node sync Port
2985
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2986
} SReplica;
2987

2988
typedef struct {
2989
  int32_t  vgId;
2990
  char     db[TSDB_DB_FNAME_LEN];
2991
  int64_t  dbUid;
2992
  int32_t  vgVersion;
2993
  int32_t  numOfStables;
2994
  int32_t  buffer;
2995
  int32_t  pageSize;
2996
  int32_t  pages;
2997
  int32_t  cacheLastSize;
2998
  int32_t  daysPerFile;
2999
  int32_t  daysToKeep0;
3000
  int32_t  daysToKeep1;
3001
  int32_t  daysToKeep2;
3002
  int32_t  keepTimeOffset;
3003
  int32_t  minRows;
3004
  int32_t  maxRows;
3005
  int32_t  walFsyncPeriod;
3006
  uint32_t hashBegin;
3007
  uint32_t hashEnd;
3008
  int8_t   hashMethod;
3009
  int8_t   walLevel;
3010
  int8_t   precision;
3011
  int8_t   compression;
3012
  int8_t   strict;
3013
  int8_t   cacheLast;
3014
  int8_t   isTsma;
3015
  int8_t   replica;
3016
  int8_t   selfIndex;
3017
  SReplica replicas[TSDB_MAX_REPLICA];
3018
  int32_t  numOfRetensions;
3019
  SArray*  pRetensions;  // SRetention
3020
  void*    pTsma;
3021
  int32_t  walRetentionPeriod;
3022
  int64_t  walRetentionSize;
3023
  int32_t  walRollPeriod;
3024
  int64_t  walSegmentSize;
3025
  int16_t  sstTrigger;
3026
  int16_t  hashPrefix;
3027
  int16_t  hashSuffix;
3028
  int32_t  tsdbPageSize;
3029
  int32_t  ssChunkSize;
3030
  int32_t  ssKeepLocal;
3031
  int8_t   ssCompact;
3032
  int64_t  reserved[6];
3033
  int8_t   learnerReplica;
3034
  int8_t   learnerSelfIndex;
3035
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3036
  int32_t  changeVersion;
3037
  int8_t   encryptAlgorithm;
3038
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3039
  union {
3040
    uint8_t flags;
3041
    struct {
3042
      uint8_t isAudit : 1;
3043
      uint8_t allowDrop : 1;
3044
      uint8_t padding : 6;
3045
    };
3046
  };
3047
} SCreateVnodeReq;
3048

3049
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3050
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3051
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3052

3053
typedef struct {
3054
  union {
3055
    int32_t compactId;
3056
    int32_t id;
3057
  };
3058
  int32_t vgId;
3059
  int32_t dnodeId;
3060
} SQueryCompactProgressReq;
3061

3062
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3063
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3064

3065
typedef struct {
3066
  union {
3067
    int32_t compactId;
3068
    int32_t id;
3069
  };
3070
  int32_t vgId;
3071
  int32_t dnodeId;
3072
  int32_t numberFileset;
3073
  int32_t finished;
3074
  int32_t progress;
3075
  int64_t remainingTime;
3076
} SQueryCompactProgressRsp;
3077

3078
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3079
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3080

3081
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3082
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3083

3084
typedef struct {
3085
  int32_t vgId;
3086
  int32_t dnodeId;
3087
  int64_t dbUid;
3088
  char    db[TSDB_DB_FNAME_LEN];
3089
  int64_t reserved[8];
3090
} SDropVnodeReq;
3091

3092
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3093
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3094

3095
typedef struct {
3096
  char    colName[TSDB_COL_NAME_LEN];
3097
  char    stb[TSDB_TABLE_FNAME_LEN];
3098
  int64_t stbUid;
3099
  int64_t dbUid;
3100
  int64_t reserved[8];
3101
} SDropIndexReq;
3102

3103
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3104
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3105

3106
typedef struct {
3107
  int64_t dbUid;
3108
  char    db[TSDB_DB_FNAME_LEN];
3109
  union {
3110
    int64_t compactStartTime;
3111
    int64_t startTime;
3112
  };
3113

3114
  STimeWindow tw;
3115
  union {
3116
    int32_t compactId;
3117
    int32_t id;
3118
  };
3119
  int8_t metaOnly;
3120
  union {
3121
    uint16_t flags;
3122
    struct {
3123
      uint16_t optrType : 3;     // ETsdbOpType
3124
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3125
      uint16_t reserved : 12;
3126
    };
3127
  };
3128
  int8_t force;  // force compact
3129
} SCompactVnodeReq;
3130

3131
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3132
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3133

3134
typedef struct {
3135
  union {
3136
    int32_t compactId;
3137
    int32_t taskId;
3138
  };
3139
  int32_t vgId;
3140
  int32_t dnodeId;
3141
} SVKillCompactReq;
3142

3143
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3144
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3145

3146
typedef SVKillCompactReq SVKillRetentionReq;
3147

3148
typedef struct {
3149
  char        db[TSDB_DB_FNAME_LEN];
3150
  int32_t     maxSpeed;
3151
  int32_t     sqlLen;
3152
  char*       sql;
3153
  SArray*     vgroupIds;
3154
  STimeWindow tw;  // unit is second
3155
  union {
3156
    uint32_t flags;
3157
    struct {
3158
      uint32_t optrType : 3;     // ETsdbOpType
3159
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3160
      uint32_t reserved : 28;
3161
    };
3162
  };
3163
} STrimDbReq;
3164

3165
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3166
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3167
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3168

3169
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3170

3171
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3172
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3173

3174
typedef struct {
3175
  int32_t vgVersion;
3176
  int32_t buffer;
3177
  int32_t pageSize;
3178
  int32_t pages;
3179
  int32_t cacheLastSize;
3180
  int32_t daysPerFile;
3181
  int32_t daysToKeep0;
3182
  int32_t daysToKeep1;
3183
  int32_t daysToKeep2;
3184
  int32_t keepTimeOffset;
3185
  int32_t walFsyncPeriod;
3186
  int8_t  walLevel;
3187
  int8_t  strict;
3188
  int8_t  cacheLast;
3189
  int64_t reserved[7];
3190
  // 1st modification
3191
  int16_t sttTrigger;
3192
  int32_t minRows;
3193
  // 2nd modification
3194
  int32_t walRetentionPeriod;
3195
  int32_t walRetentionSize;
3196
  int32_t ssKeepLocal;
3197
  int8_t  ssCompact;
3198
  int8_t  allowDrop;
3199
} SAlterVnodeConfigReq;
3200

3201
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3202
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3203

3204
typedef struct {
3205
  int32_t  vgId;
3206
  int8_t   strict;
3207
  int8_t   selfIndex;
3208
  int8_t   replica;
3209
  SReplica replicas[TSDB_MAX_REPLICA];
3210
  int64_t  reserved[8];
3211
  int8_t   learnerSelfIndex;
3212
  int8_t   learnerReplica;
3213
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3214
  int32_t  changeVersion;
3215
  int32_t  electBaseLine;
3216
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3217

3218
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3219
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3220

3221
typedef struct {
3222
  int32_t vgId;
3223
  int8_t  disable;
3224
} SDisableVnodeWriteReq;
3225

3226
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3227
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3228

3229
typedef struct {
3230
  int32_t  srcVgId;
3231
  int32_t  dstVgId;
3232
  uint32_t hashBegin;
3233
  uint32_t hashEnd;
3234
  int32_t  changeVersion;
3235
  int32_t  reserved;
3236
} SAlterVnodeHashRangeReq;
3237

3238
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3239
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3240

3241
#define REQ_OPT_TBNAME 0x0
3242
#define REQ_OPT_TBUID  0x01
3243
typedef struct {
3244
  SMsgHead header;
3245
  char     dbFName[TSDB_DB_FNAME_LEN];
3246
  char     tbName[TSDB_TABLE_NAME_LEN];
3247
  uint8_t  option;
3248
  uint8_t  autoCreateCtb;
3249
} STableInfoReq;
3250

3251
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3252
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3253

3254
typedef struct {
3255
  int8_t  metaClone;  // create local clone of the cached table meta
3256
  int32_t numOfVgroups;
3257
  int32_t numOfTables;
3258
  int32_t numOfUdfs;
3259
  char    tableNames[];
3260
} SMultiTableInfoReq;
3261

3262
// todo refactor
3263
typedef struct SVgroupInfo {
3264
  int32_t  vgId;
3265
  uint32_t hashBegin;
3266
  uint32_t hashEnd;
3267
  SEpSet   epSet;
3268
  union {
3269
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3270
    int32_t taskId;      // used in stream
3271
  };
3272
} SVgroupInfo;
3273

3274
typedef struct {
3275
  int32_t     numOfVgroups;
3276
  SVgroupInfo vgroups[];
3277
} SVgroupsInfo;
3278

3279
typedef struct {
3280
  STableMetaRsp* pMeta;
3281
} SMAlterStbRsp;
3282

3283
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3284
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3285
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3286

3287
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3288
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3289
void    tFreeSTableMetaRsp(void* pRsp);
3290
void    tFreeSTableIndexRsp(void* info);
3291

3292
typedef struct {
3293
  SArray* pMetaRsp;   // Array of STableMetaRsp
3294
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3295
} SSTbHbRsp;
3296

3297
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3298
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3299
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3300

3301
typedef struct {
3302
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3303
} SViewHbRsp;
3304

3305
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3306
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3307
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3308

3309
typedef struct {
3310
  int32_t numOfTables;
3311
  int32_t numOfVgroup;
3312
  int32_t numOfUdf;
3313
  int32_t contLen;
3314
  int8_t  compressed;  // denote if compressed or not
3315
  int32_t rawLen;      // size before compress
3316
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3317
  char    meta[];
3318
} SMultiTableMeta;
3319

3320
typedef struct {
3321
  int32_t dataLen;
3322
  char    name[TSDB_TABLE_FNAME_LEN];
3323
  char*   data;
3324
} STagData;
3325

3326
typedef struct {
3327
  int32_t  opType;
3328
  uint32_t valLen;
3329
  char*    val;
3330
} SShowVariablesReq;
3331

3332
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3333
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3334
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3335

3336
typedef struct {
3337
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3338
  char value[TSDB_CONFIG_PATH_LEN + 1];
3339
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3340
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3341
  char info[TSDB_CONFIG_INFO_LEN + 1];
3342
} SVariablesInfo;
3343

3344
typedef struct {
3345
  SArray* variables;  // SArray<SVariablesInfo>
3346
} SShowVariablesRsp;
3347

3348
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3349
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3350

3351
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3352

3353
/*
3354
 * sql: show tables like '%a_%'
3355
 * payload is the query condition, e.g., '%a_%'
3356
 * payloadLen is the length of payload
3357
 */
3358
typedef struct {
3359
  int32_t type;
3360
  char    db[TSDB_DB_FNAME_LEN];
3361
  int32_t payloadLen;
3362
  char*   payload;
3363
} SShowReq;
3364

3365
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3366
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3367
void tFreeSShowReq(SShowReq* pReq);
3368

3369
typedef struct {
3370
  int64_t       showId;
3371
  STableMetaRsp tableMeta;
3372
} SShowRsp, SVShowTablesRsp;
3373

3374
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3375
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3376
// void    tFreeSShowRsp(SShowRsp* pRsp);
3377

3378
typedef struct {
3379
  char    db[TSDB_DB_FNAME_LEN];
3380
  char    tb[TSDB_TABLE_NAME_LEN];
3381
  char    user[TSDB_USER_LEN];
3382
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3383
  int64_t showId;
3384
  int64_t compactId;  // for compact
3385
  bool    withFull;   // for show users full
3386
} SRetrieveTableReq;
3387

3388
typedef struct SSysTableSchema {
3389
  int8_t   type;
3390
  col_id_t colId;
3391
  int32_t  bytes;
3392
} SSysTableSchema;
3393

3394
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3395
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3396

3397
#define RETRIEVE_TABLE_RSP_VERSION         0
3398
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3399
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3400

3401
typedef struct {
3402
  int64_t useconds;
3403
  int8_t  completed;  // all results are returned to client
3404
  int8_t  precision;
3405
  int8_t  compressed;
3406
  int8_t  streamBlockType;
3407
  int32_t payloadLen;
3408
  int32_t compLen;
3409
  int32_t numOfBlocks;
3410
  int64_t numOfRows;  // from int32_t change to int64_t
3411
  int64_t numOfCols;
3412
  int64_t skey;
3413
  int64_t ekey;
3414
  int64_t version;                         // for stream
3415
  TSKEY   watermark;                       // for stream
3416
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3417
  char    data[];
3418
} SRetrieveTableRsp;
3419

3420
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3421

3422
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3423
  do {                                          \
3424
    ((int32_t*)(_p))[0] = (_compLen);           \
3425
    ((int32_t*)(_p))[1] = (_fullLen);           \
3426
  } while (0);
3427

3428
typedef struct {
3429
  int64_t version;
3430
  int64_t numOfRows;
3431
  int8_t  compressed;
3432
  int8_t  precision;
3433
  char    data[];
3434
} SRetrieveTableRspForTmq;
3435

3436
typedef struct {
3437
  int64_t handle;
3438
  int64_t useconds;
3439
  int8_t  completed;  // all results are returned to client
3440
  int8_t  precision;
3441
  int8_t  compressed;
3442
  int32_t compLen;
3443
  int32_t numOfRows;
3444
  int32_t fullLen;
3445
  char    data[];
3446
} SRetrieveMetaTableRsp;
3447

3448
typedef struct SExplainExecInfo {
3449
  double   startupCost;
3450
  double   totalCost;
3451
  uint64_t numOfRows;
3452
  uint32_t verboseLen;
3453
  void*    verboseInfo;
3454
} SExplainExecInfo;
3455

3456
typedef struct {
3457
  int32_t           numOfPlans;
3458
  SExplainExecInfo* subplanInfo;
3459
} SExplainRsp;
3460

3461
typedef struct {
3462
  SExplainRsp rsp;
3463
  uint64_t    qId;
3464
  uint64_t    cId;
3465
  uint64_t    tId;
3466
  int64_t     rId;
3467
  int32_t     eId;
3468
} SExplainLocalRsp;
3469

3470
typedef struct STableScanAnalyzeInfo {
3471
  uint64_t totalRows;
3472
  uint64_t totalCheckedRows;
3473
  uint32_t totalBlocks;
3474
  uint32_t loadBlocks;
3475
  uint32_t loadBlockStatis;
3476
  uint32_t skipBlocks;
3477
  uint32_t filterOutBlocks;
3478
  double   elapsedTime;
3479
  double   filterTime;
3480
} STableScanAnalyzeInfo;
3481

3482
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3483
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3484
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3485

3486
typedef struct {
3487
  char    config[TSDB_DNODE_CONFIG_LEN];
3488
  char    value[TSDB_CLUSTER_VALUE_LEN];
3489
  int32_t sqlLen;
3490
  char*   sql;
3491
} SMCfgClusterReq;
3492

3493
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3494
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3495
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3496

3497
typedef struct {
3498
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3499
  int32_t port;
3500
  int32_t sqlLen;
3501
  char*   sql;
3502
} SCreateDnodeReq;
3503

3504
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3505
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3506
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3507

3508
typedef struct {
3509
  int32_t dnodeId;
3510
  char    fqdn[TSDB_FQDN_LEN];
3511
  int32_t port;
3512
  int8_t  force;
3513
  int8_t  unsafe;
3514
  int32_t sqlLen;
3515
  char*   sql;
3516
} SDropDnodeReq;
3517

3518
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3519
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3520
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3521

3522
enum {
3523
  RESTORE_TYPE__ALL = 1,
3524
  RESTORE_TYPE__MNODE,
3525
  RESTORE_TYPE__VNODE,
3526
  RESTORE_TYPE__QNODE,
3527
};
3528

3529
typedef struct {
3530
  int32_t dnodeId;
3531
  int8_t  restoreType;
3532
  int32_t sqlLen;
3533
  char*   sql;
3534
} SRestoreDnodeReq;
3535

3536
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3537
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3538
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3539

3540
typedef struct {
3541
  int32_t dnodeId;
3542
  char    config[TSDB_DNODE_CONFIG_LEN];
3543
  char    value[TSDB_DNODE_VALUE_LEN];
3544
  int32_t sqlLen;
3545
  char*   sql;
3546
} SMCfgDnodeReq;
3547

3548
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3549
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3550
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3551

3552
typedef struct {
3553
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3554
  char    newKey[ENCRYPT_KEY_LEN + 1];
3555
  int32_t sqlLen;
3556
  char*   sql;
3557
} SMAlterEncryptKeyReq;
3558

3559
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3560
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3561
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3562

3563
typedef struct {
3564
  int32_t days;
3565
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3566
  int32_t sqlLen;
3567
  char*   sql;
3568
} SMAlterKeyExpirationReq;
3569

3570
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3571
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3572
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3573

3574
typedef struct {
3575
  char    config[TSDB_DNODE_CONFIG_LEN];
3576
  char    value[TSDB_DNODE_VALUE_LEN];
3577
  int32_t version;
3578
} SDCfgDnodeReq;
3579

3580
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3581
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3582

3583
typedef struct {
3584
  int32_t dnodeId;
3585
  int32_t sqlLen;
3586
  char*   sql;
3587
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3588
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3589

3590
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3591
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3592

3593
typedef struct {
3594
  int32_t nodeId;
3595
  SEpSet  epSet;
3596
} SNodeEpSet;
3597

3598
typedef struct {
3599
  int32_t    snodeId;
3600
  SNodeEpSet leaders[2];
3601
  SNodeEpSet replica;
3602
  int32_t    sqlLen;
3603
  char*      sql;
3604
} SDCreateSnodeReq;
3605

3606
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3607
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3608
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3609

3610
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3611
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3612
typedef struct {
3613
  int8_t   replica;
3614
  SReplica replicas[TSDB_MAX_REPLICA];
3615
  int8_t   learnerReplica;
3616
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3617
  int64_t  lastIndex;
3618
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3619
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3620

3621
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3622
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3623

3624
typedef struct {
3625
  int32_t urlLen;
3626
  int32_t sqlLen;
3627
  char*   url;
3628
  char*   sql;
3629
} SMCreateAnodeReq;
3630

3631
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3632
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3633
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3634

3635
typedef struct {
3636
  int32_t anodeId;
3637
  int32_t sqlLen;
3638
  char*   sql;
3639
} SMDropAnodeReq, SMUpdateAnodeReq;
3640

3641
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3642
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3643
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3644
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3645
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3646
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3647

3648
typedef struct {
3649
  int32_t dnodeId;
3650
  int32_t bnodeProto;
3651
  int32_t sqlLen;
3652
  char*   sql;
3653
} SMCreateBnodeReq, SDCreateBnodeReq;
3654

3655
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3656
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3657
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3658

3659
typedef struct {
3660
  int32_t dnodeId;
3661
  int32_t sqlLen;
3662
  char*   sql;
3663
} SMDropBnodeReq, SDDropBnodeReq;
3664

3665
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3666
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3667
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3668

3669
typedef struct {
3670
  bool        shouldFree;
3671
  int32_t     len;
3672
  const char* ptr;
3673
} CowStr;
3674
/**
3675
 * @brief Create a CowStr object.
3676
 *
3677
 * @param len: length of the string.
3678
 * @param ptr: pointer to the string input.
3679
 * @param shouldClone: whether to clone the string.
3680
 * @return CowStr object.
3681
 */
3682
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3683
/**
3684
 * @brief Set a CowStr object with given string.
3685
 *
3686
 * @param cow: pointer to the CowStr object.
3687
 * @param len: length of the string.
3688
 * @param ptr: pointer to the string input.
3689
 * @param shouldFree: whether to free the string.
3690
 */
3691
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3692
/**
3693
 * @brief Clone a CowStr object without copy the string.
3694
 *
3695
 * @param cow: pointer to the CowStr object.
3696
 * @return CowStr object.
3697
 */
3698
CowStr xCloneRefCowStr(CowStr* cow);
3699
/**
3700
 * @brief Convert a CowStr object to a string.
3701
 *
3702
 * @param cow: pointer to the CowStr object.
3703
 */
3704
char* xCowStrToStr(CowStr* cow);
3705
/**
3706
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3707
 *
3708
 * @param cow: pointer to the CowStr object.
3709
 */
3710
void xFreeCowStr(CowStr* cow);
3711
/**
3712
 * @brief Encode and push a CowStr object into the encoder.
3713
 *
3714
 * @param encoder
3715
 * @param cow
3716
 * @return int32_t
3717
 */
3718
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3719
/**
3720
 * @brief Decode a CowStr from the encoder.
3721
 *
3722
 * @param decoder
3723
 * @param cow
3724
 * @param shouldClone
3725
 * @return int32_t
3726
 */
3727
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3728

3729
typedef struct {
3730
  int32_t sqlLen;
3731
  int32_t urlLen;
3732
  int32_t userLen;
3733
  int32_t passLen;
3734
  int32_t passIsMd5;
3735
  char*   sql;
3736
  char*   url;
3737
  char*   user;
3738
  char*   pass;
3739
  CowStr  token;
3740
} SMCreateXnodeReq, SDCreateXnodeReq;
3741

3742
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3743
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3744
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3745

3746
typedef struct {
3747
  int32_t xnodeId;
3748
  int32_t force;
3749
  int32_t urlLen;
3750
  int32_t sqlLen;
3751
  char*   url;
3752
  char*   sql;
3753
} SMDropXnodeReq, SDDropXnodeReq;
3754

3755
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3756
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3757
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3758

3759
typedef struct {
3760
  int32_t id;
3761
  CowStr  token;
3762
  CowStr  user;
3763
  CowStr  pass;
3764
  int32_t urlLen;
3765
  int32_t sqlLen;
3766
  char*   url;
3767
  char*   sql;
3768
} SMUpdateXnodeReq;
3769
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3770
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3771
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3772

3773
typedef struct {
3774
  int32_t xnodeId;
3775
  int32_t sqlLen;
3776
  char*   sql;
3777
} SMDrainXnodeReq;
3778
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3779
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3780
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3781
typedef enum {
3782
  XNODE_TASK_SOURCE_DSN = 1,
3783
  XNODE_TASK_SOURCE_DATABASE,
3784
  XNODE_TASK_SOURCE_TOPIC,
3785
} ENodeXTaskSourceType;
3786

3787
typedef enum {
3788
  XNODE_TASK_SINK_DSN = 1,
3789
  XNODE_TASK_SINK_DATABASE,
3790
} ENodeXTaskSinkType;
3791

3792
typedef struct {
3793
  ENodeXTaskSourceType type;
3794
  CowStr               cstr;
3795
} xTaskSource;
3796
/**
3797
 * @brief Deallocate a xTaskSource object.
3798
 *
3799
 * @param source ptr
3800
 */
3801
void xFreeTaskSource(xTaskSource* source);
3802
/**
3803
 * @brief Create a xTaskSource object with cloned source string.
3804
 *
3805
 * @param sourceType: source type.
3806
 * @param len: length of source string.
3807
 * @param source: source string ptr.
3808
 * @return xTaskSource object
3809
 */
3810
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3811
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3812
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3813
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3814
const char* xGetTaskSourceStr(xTaskSource* source);
3815
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3816
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3817

3818
typedef struct {
3819
  ENodeXTaskSinkType type;
3820
  CowStr             cstr;
3821
} xTaskSink;
3822
/**
3823
 * @brief Deallocate a xTaskSink object.
3824
 *
3825
 * @param sink ptr
3826
 */
3827
void xFreeTaskSink(xTaskSink* sink);
3828
/**
3829
 * @brief Create a xTaskSink object with cloned name string.
3830
 *
3831
 * @param sinkType: sink type.
3832
 * @param len: length of sink string.
3833
 * @param ptr: sink string ptr.
3834
 * @return xTaskSink object
3835
 */
3836
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3837
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3838
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3839
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3840
const char* xGetTaskSinkStr(xTaskSink* sink);
3841
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3842
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3843

3844
typedef struct {
3845
  int32_t via;
3846
  CowStr  parser;
3847
  // CowStr  reason;
3848
  CowStr  trigger;
3849
  CowStr  health;
3850
  int32_t optionsNum;
3851
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3852
} xTaskOptions;
3853
/**
3854
 * @brief Deallocate a xTaskOptions object.
3855
 *
3856
 * @param options ptr
3857
 */
3858
void    xFreeTaskOptions(xTaskOptions* options);
3859
void    printXnodeTaskOptions(xTaskOptions* options);
3860
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3861
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3862

3863
typedef struct {
3864
  int32_t sqlLen;
3865
  char*   sql;
3866
  int32_t      xnodeId;
3867
  CowStr       name;
3868
  xTaskSource  source;
3869
  xTaskSink    sink;
3870
  xTaskOptions options;
3871
} SMCreateXnodeTaskReq;
3872
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3873
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3874
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3875

3876
typedef struct {
3877
  int32_t     tid;
3878
  CowStr      name;
3879
  int32_t     via;
3880
  int32_t     xnodeId;
3881
  CowStr      status;
3882
  xTaskSource source;
3883
  xTaskSink   sink;
3884
  CowStr      parser;
3885
  CowStr      reason;
3886
  CowStr      updateName;
3887
  CowStr      labels;
3888
  int32_t     sqlLen;
3889
  char*       sql;
3890
} SMUpdateXnodeTaskReq;
3891
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3892
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3893
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3894

3895
typedef struct {
3896
  int32_t id;
3897
  bool    force;
3898
  CowStr  name;
3899
  int32_t sqlLen;
3900
  char*   sql;
3901
} SMDropXnodeTaskReq;
3902
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3903
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3904
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3905

3906
typedef struct {
3907
  int32_t tid;
3908
  CowStr  name;
3909
  int32_t sqlLen;
3910
  char*   sql;
3911
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3912
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3913
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3914
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3915

3916
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3917
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3918
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3919

3920
typedef struct {
3921
  int32_t tid;
3922
  int32_t via;
3923
  int32_t xnodeId;
3924
  CowStr  status;
3925
  CowStr  config;
3926
  CowStr  reason;
3927
  int32_t sqlLen;
3928
  char*   sql;
3929
} SMCreateXnodeJobReq;
3930
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3931
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3932
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3933

3934
typedef struct {
3935
  int32_t jid;
3936
  int32_t via;
3937
  int32_t xnodeId;
3938
  CowStr  status;
3939
  int32_t configLen;
3940
  int32_t reasonLen;
3941
  int32_t sqlLen;
3942
  char*   config;
3943
  char*   reason;
3944
  char*   sql;
3945
} SMUpdateXnodeJobReq;
3946
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3947
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3948
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3949

3950
typedef struct {
3951
  int32_t jid;
3952
  int32_t xnodeId;
3953
  int32_t sqlLen;
3954
  char*   sql;
3955
} SMRebalanceXnodeJobReq;
3956
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3957
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3958
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3959

3960
typedef struct {
3961
  CowStr  ast;
3962
  int32_t sqlLen;
3963
  char*   sql;
3964
} SMRebalanceXnodeJobsWhereReq;
3965
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3966
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3967
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3968

3969
typedef struct {
3970
  int32_t jid;
3971
  CowStr  ast;
3972
  int32_t sqlLen;
3973
  char*   sql;
3974
} SMDropXnodeJobReq;
3975
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3976
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3977
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3978

3979
typedef struct {
3980
  int32_t      sqlLen;
3981
  char*        sql;
3982
  CowStr       name;
3983
  CowStr       status;
3984
  xTaskOptions options;
3985
} SMCreateXnodeAgentReq;
3986
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3987
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3988
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3989

3990
typedef struct {
3991
  int32_t      sqlLen;
3992
  char*        sql;
3993
  int32_t      id;
3994
  CowStr       name;
3995
  xTaskOptions options;
3996
} SMUpdateXnodeAgentReq;
3997
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3998
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3999
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4000

4001
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4002
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4003
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4004
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4005

4006
typedef struct {
4007
  int32_t vgId;
4008
  int32_t hbSeq;
4009
} SVArbHbReqMember;
4010

4011
typedef struct {
4012
  int32_t dnodeId;
4013
  char*   arbToken;
4014
  int64_t arbTerm;
4015
  SArray* hbMembers;  // SVArbHbReqMember
4016
} SVArbHeartBeatReq;
4017

4018
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4019
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4020
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4021

4022
typedef struct {
4023
  int32_t vgId;
4024
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4025
  int32_t hbSeq;
4026
} SVArbHbRspMember;
4027

4028
typedef struct {
4029
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4030
  int32_t dnodeId;
4031
  SArray* hbMembers;  // SVArbHbRspMember
4032
} SVArbHeartBeatRsp;
4033

4034
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4035
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4036
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4037

4038
typedef struct {
4039
  char*   arbToken;
4040
  int64_t arbTerm;
4041
  char*   member0Token;
4042
  char*   member1Token;
4043
} SVArbCheckSyncReq;
4044

4045
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4046
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4047
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4048

4049
typedef struct {
4050
  char*   arbToken;
4051
  char*   member0Token;
4052
  char*   member1Token;
4053
  int32_t vgId;
4054
  int32_t errCode;
4055
} SVArbCheckSyncRsp;
4056

4057
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4058
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4059
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4060

4061
typedef struct {
4062
  char*   arbToken;
4063
  int64_t arbTerm;
4064
  char*   memberToken;
4065
  int8_t  force;
4066
} SVArbSetAssignedLeaderReq;
4067

4068
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4069
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4070
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4071

4072
typedef struct {
4073
  char*   arbToken;
4074
  char*   memberToken;
4075
  int32_t vgId;
4076
} SVArbSetAssignedLeaderRsp;
4077

4078
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4079
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4080
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4081

4082
typedef struct {
4083
  int32_t dnodeId;
4084
  char*   token;
4085
} SMArbUpdateGroupMember;
4086

4087
typedef struct {
4088
  int32_t dnodeId;
4089
  char*   token;
4090
  int8_t  acked;
4091
} SMArbUpdateGroupAssigned;
4092

4093
typedef struct {
4094
  int32_t                  vgId;
4095
  int64_t                  dbUid;
4096
  SMArbUpdateGroupMember   members[2];
4097
  int8_t                   isSync;
4098
  int8_t                   assignedAcked;
4099
  SMArbUpdateGroupAssigned assignedLeader;
4100
  int64_t                  version;
4101
  int32_t                  code;
4102
  int64_t                  updateTimeMs;
4103
} SMArbUpdateGroup;
4104

4105
typedef struct {
4106
  SArray* updateArray;  // SMArbUpdateGroup
4107
} SMArbUpdateGroupBatchReq;
4108

4109
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4110
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4111
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4112

4113
typedef struct {
4114
  char queryStrId[TSDB_QUERY_ID_LEN];
4115
} SKillQueryReq;
4116

4117
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4118
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4119

4120
typedef struct {
4121
  uint32_t connId;
4122
} SKillConnReq;
4123

4124
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4125
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4126

4127
typedef struct {
4128
  int32_t transId;
4129
} SKillTransReq;
4130

4131
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4132
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4133

4134
typedef struct {
4135
  int32_t useless;  // useless
4136
  int32_t sqlLen;
4137
  char*   sql;
4138
} SBalanceVgroupReq;
4139

4140
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4141
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4142
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4143

4144
typedef struct {
4145
  int32_t useless;  // useless
4146
  int32_t sqlLen;
4147
  char*   sql;
4148
} SAssignLeaderReq;
4149

4150
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4151
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4152
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4153
typedef struct {
4154
  int32_t vgId1;
4155
  int32_t vgId2;
4156
} SMergeVgroupReq;
4157

4158
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4159
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4160

4161
typedef struct {
4162
  int32_t vgId;
4163
  int32_t dnodeId1;
4164
  int32_t dnodeId2;
4165
  int32_t dnodeId3;
4166
  int32_t sqlLen;
4167
  char*   sql;
4168
} SRedistributeVgroupReq;
4169

4170
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4171
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4172
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4173

4174
typedef struct {
4175
  int32_t reserved;
4176
  int32_t vgId;
4177
  int32_t sqlLen;
4178
  char*   sql;
4179
  char    db[TSDB_DB_FNAME_LEN];
4180
} SBalanceVgroupLeaderReq;
4181

4182
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4183
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4184
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4185

4186
typedef struct {
4187
  int32_t vgId;
4188
} SForceBecomeFollowerReq;
4189

4190
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4191
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4192

4193
typedef struct {
4194
  int32_t vgId;
4195
  bool    force;
4196
} SSplitVgroupReq;
4197

4198
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4199
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4200

4201
typedef struct {
4202
  char user[TSDB_USER_LEN];
4203
  char spi;
4204
  char encrypt;
4205
  char secret[TSDB_PASSWORD_LEN];
4206
  char ckey[TSDB_PASSWORD_LEN];
4207
} SAuthReq, SAuthRsp;
4208

4209
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4210
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4211

4212
typedef struct {
4213
  int32_t statusCode;
4214
  char    details[1024];
4215
} SServerStatusRsp;
4216

4217
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4218
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4219

4220
/**
4221
 * The layout of the query message payload is as following:
4222
 * +--------------------+---------------------------------+
4223
 * |Sql statement       | Physical plan                   |
4224
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4225
 * +--------------------+---------------------------------+
4226
 */
4227
typedef struct SSubQueryMsg {
4228
  SMsgHead header;
4229
  uint64_t sId;
4230
  uint64_t queryId;
4231
  uint64_t clientId;
4232
  uint64_t taskId;
4233
  int64_t  refId;
4234
  int32_t  execId;
4235
  int32_t  msgMask;
4236
  int32_t  subQType;
4237
  int8_t   taskType;
4238
  int8_t   explain;
4239
  int8_t   needFetch;
4240
  int8_t   compress;
4241
  uint32_t sqlLen;
4242
  char*    sql;
4243
  uint32_t msgLen;
4244
  char*    msg;
4245
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4246
} SSubQueryMsg;
4247

4248
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4249
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4250
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4251

4252
typedef struct {
4253
  SMsgHead header;
4254
  uint64_t sId;
4255
  uint64_t queryId;
4256
  uint64_t taskId;
4257
} SSinkDataReq;
4258

4259
typedef struct {
4260
  SMsgHead header;
4261
  uint64_t sId;
4262
  uint64_t queryId;
4263
  uint64_t clientId;
4264
  uint64_t taskId;
4265
  int32_t  execId;
4266
} SQueryContinueReq;
4267

4268
typedef struct {
4269
  SMsgHead header;
4270
  uint64_t sId;
4271
  uint64_t queryId;
4272
  uint64_t taskId;
4273
} SResReadyReq;
4274

4275
typedef struct {
4276
  int32_t code;
4277
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4278
  int32_t sversion;
4279
  int32_t tversion;
4280
} SResReadyRsp;
4281

4282
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4283

4284
typedef struct SOperatorParam {
4285
  int32_t opType;
4286
  int32_t downstreamIdx;
4287
  void*   value;
4288
  SArray* pChildren;  // SArray<SOperatorParam*>
4289
  bool    reUse;
4290
} SOperatorParam;
4291

4292
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4293

4294
// virtual table's colId to origin table's colname
4295
typedef struct SColIdNameKV {
4296
  col_id_t colId;
4297
  char     colName[TSDB_COL_NAME_LEN];
4298
} SColIdNameKV;
4299

4300
#define COL_MASK_ON   ((int8_t)0x1)
4301
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4302
#define COL_SET_MASK_ON(c)     \
4303
  do {                         \
4304
    (c)->flags |= COL_MASK_ON; \
4305
  } while (0)
4306

4307
typedef struct SColNameFlag {
4308
  col_id_t colId;
4309
  char     colName[TSDB_COL_NAME_LEN];
4310
  int8_t   flags;  // 0x01: COL_MASK_ON
4311
} SColNameFlag;
4312

4313
typedef struct SColIdPair {
4314
  col_id_t  vtbColId;
4315
  col_id_t  orgColId;
4316
  SDataType type;
4317
} SColIdPair;
4318

4319
typedef struct SColIdSlotIdPair {
4320
  int32_t  vtbSlotId;
4321
  col_id_t orgColId;
4322
} SColIdSlotIdPair;
4323

4324
typedef struct SOrgTbInfo {
4325
  int32_t vgId;
4326
  char    tbName[TSDB_TABLE_FNAME_LEN];
4327
  SArray* colMap;  // SArray<SColIdNameKV>
4328
} SOrgTbInfo;
4329

4330
void destroySOrgTbInfo(void *info);
4331

4332
typedef enum {
4333
  DYN_TYPE_STB_JOIN = 1,
4334
  DYN_TYPE_VSTB_SINGLE_SCAN,
4335
  DYN_TYPE_VSTB_BATCH_SCAN,
4336
  DYN_TYPE_VSTB_WIN_SCAN,
4337
} ETableScanDynType;
4338

4339
typedef enum {
4340
  DYN_TYPE_SCAN_PARAM = 1,
4341
  NOTIFY_TYPE_SCAN_PARAM,
4342
} ETableScanGetParamType;
4343

4344
typedef struct STableScanOperatorParam {
4345
  ETableScanGetParamType paramType;
4346
  /* for building scan data source */
4347
  bool                   tableSeq;
4348
  bool                   isNewParam;
4349
  uint64_t               groupid;
4350
  SArray*                pUidList;
4351
  SOrgTbInfo*            pOrgTbInfo;
4352
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4353
  SArray*                pTagList;
4354
  STimeWindow            window;
4355
  ETableScanDynType      dynType;
4356
  /* for notifying source step done */
4357
  bool                   notifyToProcess;  // received notify STEP DONE message
4358
  TSKEY                  notifyTs;         // notify timestamp
4359
} STableScanOperatorParam;
4360

4361
typedef struct STagScanOperatorParam {
4362
  tb_uid_t vcUid;
4363
} STagScanOperatorParam;
4364

4365
typedef struct SRefColIdGroup {
4366
  SArray* pSlotIdList;  // SArray<int32_t>
4367
} SRefColIdGroup;
4368

4369
typedef struct SVTableScanOperatorParam {
4370
  uint64_t        uid;
4371
  STimeWindow     window;
4372
  SOperatorParam* pTagScanOp;
4373
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4374
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4375
} SVTableScanOperatorParam;
4376

4377
typedef struct SMergeOperatorParam {
4378
  int32_t         winNum;
4379
} SMergeOperatorParam;
4380

4381
typedef struct SAggOperatorParam {
4382
  bool            needCleanRes;
4383
} SAggOperatorParam;
4384

4385
typedef struct SExternalWindowOperatorParam {
4386
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4387
} SExternalWindowOperatorParam;
4388

4389
typedef struct SDynQueryCtrlOperatorParam {
4390
  STimeWindow    window;
4391
} SDynQueryCtrlOperatorParam;
4392

4393
struct SStreamRuntimeFuncInfo;
4394
typedef struct {
4395
  SMsgHead        header;
4396
  uint64_t        sId;
4397
  uint64_t        queryId;
4398
  uint64_t        clientId;
4399
  uint64_t        taskId;
4400
  uint64_t        srcTaskId;  // used for subQ
4401
  uint64_t        blockIdx;   // used for subQ
4402
  int32_t         execId;
4403
  SOperatorParam* pOpParam;
4404

4405
  // used for new-stream
4406
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4407
  bool                           reset;
4408
  bool                           dynTbname;
4409
  // used for new-stream
4410
} SResFetchReq;
4411

4412
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4413
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4414
void    tDestroySResFetchReq(SResFetchReq* pReq);
4415
typedef struct {
4416
  SMsgHead header;
4417
  uint64_t clientId;
4418
} SSchTasksStatusReq;
4419

4420
typedef struct {
4421
  uint64_t queryId;
4422
  uint64_t clientId;
4423
  uint64_t taskId;
4424
  int64_t  refId;
4425
  int32_t  subJobId;
4426
  int32_t  execId;
4427
  int8_t   status;
4428
} STaskStatus;
4429

4430
typedef struct {
4431
  int64_t refId;
4432
  SArray* taskStatus;  // SArray<STaskStatus>
4433
} SSchedulerStatusRsp;
4434

4435
typedef struct {
4436
  uint64_t queryId;
4437
  uint64_t taskId;
4438
  int8_t   action;
4439
} STaskAction;
4440

4441
typedef struct SQueryNodeEpId {
4442
  int32_t nodeId;  // vgId or qnodeId
4443
  SEp     ep;
4444
} SQueryNodeEpId;
4445

4446
typedef struct {
4447
  SMsgHead       header;
4448
  uint64_t       clientId;
4449
  SQueryNodeEpId epId;
4450
  SArray*        taskAction;  // SArray<STaskAction>
4451
} SSchedulerHbReq;
4452

4453
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4454
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4455
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4456

4457
typedef struct {
4458
  SQueryNodeEpId epId;
4459
  SArray*        taskStatus;  // SArray<STaskStatus>
4460
} SSchedulerHbRsp;
4461

4462
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4463
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4464
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4465

4466
typedef struct {
4467
  SMsgHead header;
4468
  uint64_t sId;
4469
  uint64_t queryId;
4470
  uint64_t clientId;
4471
  uint64_t taskId;
4472
  int64_t  refId;
4473
  int32_t  execId;
4474
} STaskCancelReq;
4475

4476
typedef struct {
4477
  int32_t code;
4478
} STaskCancelRsp;
4479

4480
typedef struct {
4481
  SMsgHead header;
4482
  uint64_t sId;
4483
  uint64_t queryId;
4484
  uint64_t clientId;
4485
  uint64_t taskId;
4486
  int64_t  refId;
4487
  int32_t  execId;
4488
} STaskDropReq;
4489

4490
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4491
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4492

4493
typedef enum {
4494
  TASK_NOTIFY_FINISHED = 1,
4495
} ETaskNotifyType;
4496

4497
typedef struct {
4498
  SMsgHead        header;
4499
  uint64_t        sId;
4500
  uint64_t        queryId;
4501
  uint64_t        clientId;
4502
  uint64_t        taskId;
4503
  int64_t         refId;
4504
  int32_t         execId;
4505
  ETaskNotifyType type;
4506
} STaskNotifyReq;
4507

4508
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4509
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4510

4511
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4512
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4513

4514
typedef struct {
4515
  int32_t code;
4516
} STaskDropRsp;
4517

4518
#define STREAM_TRIGGER_AT_ONCE                 1
4519
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4520
#define STREAM_TRIGGER_MAX_DELAY               3
4521
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4522
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4523

4524
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4525
#define STREAM_FILL_HISTORY_ON        1
4526
#define STREAM_FILL_HISTORY_OFF       0
4527
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4528
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4529
#define STREAM_CREATE_STABLE_TRUE     1
4530
#define STREAM_CREATE_STABLE_FALSE    0
4531

4532
typedef struct SVgroupVer {
4533
  int32_t vgId;
4534
  int64_t ver;
4535
} SVgroupVer;
4536

4537
enum {
4538
  TOPIC_SUB_TYPE__DB = 1,
4539
  TOPIC_SUB_TYPE__TABLE,
4540
  TOPIC_SUB_TYPE__COLUMN,
4541
};
4542

4543
#define DEFAULT_MAX_POLL_INTERVAL  300000
4544
#define DEFAULT_SESSION_TIMEOUT    12000
4545
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4546
#define DEFAULT_MIN_POLL_ROWS      4096
4547

4548
typedef struct {
4549
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4550
  int8_t igExists;
4551
  int8_t subType;
4552
  int8_t withMeta;
4553
  char*  sql;
4554
  char   subDbName[TSDB_DB_FNAME_LEN];
4555
  char*  ast;
4556
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4557
  int8_t reload;
4558
} SCMCreateTopicReq;
4559

4560
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4561
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4562
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4563

4564
typedef struct {
4565
  int64_t consumerId;
4566
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4567

4568
typedef struct {
4569
  int64_t consumerId;
4570
  char    cgroup[TSDB_CGROUP_LEN];
4571
  char    clientId[TSDB_CLIENT_ID_LEN];
4572
  char    user[TSDB_USER_LEN];
4573
  char    fqdn[TSDB_FQDN_LEN];
4574
  SArray* topicNames;  // SArray<char**>
4575

4576
  int8_t  withTbName;
4577
  int8_t  autoCommit;
4578
  int32_t autoCommitInterval;
4579
  int8_t  resetOffsetCfg;
4580
  int8_t  enableReplay;
4581
  int8_t  enableBatchMeta;
4582
  int32_t sessionTimeoutMs;
4583
  int32_t maxPollIntervalMs;
4584
  int64_t ownerId;
4585
} SCMSubscribeReq;
4586

4587
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4588
  int32_t tlen = 0;
703,732✔
4589
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
703,732✔
4590
  tlen += taosEncodeString(buf, pReq->cgroup);
703,732✔
4591
  tlen += taosEncodeString(buf, pReq->clientId);
703,732✔
4592

4593
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
703,732✔
4594
  tlen += taosEncodeFixedI32(buf, topicNum);
703,363✔
4595

4596
  for (int32_t i = 0; i < topicNum; i++) {
982,888✔
4597
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
559,063✔
4598
  }
4599

4600
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
703,350✔
4601
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
703,350✔
4602
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
703,350✔
4603
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
703,350✔
4604
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
703,719✔
4605
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
703,350✔
4606
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
703,313✔
4607
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
703,350✔
4608
  tlen += taosEncodeString(buf, pReq->user);
703,719✔
4609
  tlen += taosEncodeString(buf, pReq->fqdn);
703,350✔
4610

4611
  return tlen;
703,682✔
4612
}
4613

4614
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4615
  void* start = buf;
357,958✔
4616
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
357,958✔
4617
  buf = taosDecodeStringTo(buf, pReq->cgroup);
357,958✔
4618
  buf = taosDecodeStringTo(buf, pReq->clientId);
357,958✔
4619

4620
  int32_t topicNum = 0;
357,958✔
4621
  buf = taosDecodeFixedI32(buf, &topicNum);
357,958✔
4622

4623
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
357,958✔
4624
  if (pReq->topicNames == NULL) {
357,958✔
UNCOV
4625
    return terrno;
×
4626
  }
4627
  for (int32_t i = 0; i < topicNum; i++) {
521,513✔
4628
    char* name = NULL;
163,555✔
4629
    buf = taosDecodeString(buf, &name);
163,555✔
4630
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
327,110✔
UNCOV
4631
      return terrno;
×
4632
    }
4633
  }
4634

4635
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
357,958✔
4636
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
357,958✔
4637
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
357,958✔
4638
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
357,958✔
4639
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
357,958✔
4640
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
357,958✔
4641
  if ((char*)buf - (char*)start < len) {
357,958✔
4642
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
357,958✔
4643
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
357,958✔
4644
    buf = taosDecodeStringTo(buf, pReq->user);
357,958✔
4645
    buf = taosDecodeStringTo(buf, pReq->fqdn);
715,916✔
4646
  } else {
4647
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4648
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4649
  }
4650

4651
  return 0;
357,958✔
4652
}
4653

4654
typedef struct {
4655
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4656
  SArray* removedConsumers;  // SArray<int64_t>
4657
  SArray* newConsumers;      // SArray<int64_t>
4658
} SMqRebInfo;
4659

4660
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4661
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
323,322✔
4662
  if (pRebInfo == NULL) {
323,322✔
4663
    return NULL;
×
4664
  }
4665
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
323,322✔
4666
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
323,322✔
4667
  if (pRebInfo->removedConsumers == NULL) {
323,322✔
UNCOV
4668
    goto _err;
×
4669
  }
4670
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
323,322✔
4671
  if (pRebInfo->newConsumers == NULL) {
323,322✔
UNCOV
4672
    goto _err;
×
4673
  }
4674
  return pRebInfo;
323,322✔
UNCOV
4675
_err:
×
UNCOV
4676
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4677
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4678
  taosMemoryFreeClear(pRebInfo);
×
4679
  return NULL;
×
4680
}
4681

4682
typedef struct {
4683
  int64_t streamId;
4684
  int64_t checkpointId;
4685
  char    streamName[TSDB_STREAM_FNAME_LEN];
4686
} SMStreamDoCheckpointMsg;
4687

4688
typedef struct {
4689
  int64_t status;
4690
} SMVSubscribeRsp;
4691

4692
typedef struct {
4693
  char    name[TSDB_TOPIC_FNAME_LEN];
4694
  int8_t  igNotExists;
4695
  int32_t sqlLen;
4696
  char*   sql;
4697
  int8_t  force;
4698
} SMDropTopicReq;
4699

4700
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4701
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4702
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4703

4704
typedef struct {
4705
  char    name[TSDB_TOPIC_FNAME_LEN];
4706
  int8_t  igNotExists;
4707
  int32_t sqlLen;
4708
  char*   sql;
4709
} SMReloadTopicReq;
4710

4711
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4712
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4713
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4714

4715
typedef struct {
4716
  char   topic[TSDB_TOPIC_FNAME_LEN];
4717
  char   cgroup[TSDB_CGROUP_LEN];
4718
  int8_t igNotExists;
4719
  int8_t force;
4720
} SMDropCgroupReq;
4721

4722
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4723
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4724

4725
typedef struct {
4726
  int8_t reserved;
4727
} SMDropCgroupRsp;
4728

4729
typedef struct {
4730
  char    name[TSDB_TABLE_FNAME_LEN];
4731
  int8_t  alterType;
4732
  SSchema schema;
4733
} SAlterTopicReq;
4734

4735
typedef struct {
4736
  SMsgHead head;
4737
  char     name[TSDB_TABLE_FNAME_LEN];
4738
  int64_t  tuid;
4739
  int32_t  sverson;
4740
  int32_t  execLen;
4741
  char*    executor;
4742
  int32_t  sqlLen;
4743
  char*    sql;
4744
} SDCreateTopicReq;
4745

4746
typedef struct {
4747
  SMsgHead head;
4748
  char     name[TSDB_TABLE_FNAME_LEN];
4749
  int64_t  tuid;
4750
} SDDropTopicReq;
4751

4752
typedef struct {
4753
  char*      name;
4754
  int64_t    uid;
4755
  int64_t    interval[2];
4756
  int8_t     intervalUnit;
4757
  int16_t    nFuncs;
4758
  col_id_t*  funcColIds;  // column ids specified by user
4759
  func_id_t* funcIds;     // function ids specified by user
4760
} SRSmaParam;
4761

4762
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4763
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4764

4765
// TDMT_VND_CREATE_STB ==============
4766
typedef struct SVCreateStbReq {
4767
  char*           name;
4768
  tb_uid_t        suid;
4769
  int8_t          rollup;
4770
  SSchemaWrapper  schemaRow;
4771
  SSchemaWrapper  schemaTag;
4772
  SRSmaParam      rsmaParam;
4773
  int32_t         alterOriDataLen;
4774
  void*           alterOriData;
4775
  int8_t          source;
4776
  int8_t          colCmpred;
4777
  SColCmprWrapper colCmpr;
4778
  int64_t         keep;
4779
  int64_t         ownerId;
4780
  SExtSchema*     pExtSchemas;
4781
  int8_t          virtualStb;
4782
} SVCreateStbReq;
4783

4784
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4785
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4786

4787
// TDMT_VND_DROP_STB ==============
4788
typedef struct SVDropStbReq {
4789
  char*    name;
4790
  tb_uid_t suid;
4791
} SVDropStbReq;
4792

4793
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4794
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4795

4796
// TDMT_VND_CREATE_TABLE ==============
4797
#define TD_CREATE_IF_NOT_EXISTS       0x1
4798
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4799
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4800
typedef struct SVCreateTbReq {
4801
  int32_t  flags;
4802
  char*    name;
4803
  tb_uid_t uid;
4804
  int64_t  btime;
4805
  int32_t  ttl;
4806
  int32_t  commentLen;
4807
  char*    comment;
4808
  int8_t   type;
4809
  union {
4810
    struct {
4811
      char*    stbName;  // super table name
4812
      uint8_t  tagNum;
4813
      tb_uid_t suid;
4814
      SArray*  tagName;
4815
      uint8_t* pTag;
4816
    } ctb;
4817
    struct {
4818
      SSchemaWrapper schemaRow;
4819
      int64_t        userId;
4820
    } ntb;
4821
  };
4822
  int32_t         sqlLen;
4823
  char*           sql;
4824
  SColCmprWrapper colCmpr;
4825
  SExtSchema*     pExtSchemas;
4826
  SColRefWrapper  colRef;  // col reference for virtual table
4827
} SVCreateTbReq;
4828

4829
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4830
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4831
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4832
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4833

4834
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4835
  if (NULL == req) {
2,147,483,647✔
4836
    return;
2,147,483,647✔
4837
  }
4838

4839
  taosMemoryFreeClear(req->sql);
80,734,152✔
4840
  taosMemoryFreeClear(req->name);
80,737,372✔
4841
  taosMemoryFreeClear(req->comment);
80,747,267✔
4842
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
80,694,827✔
4843
    taosMemoryFreeClear(req->ctb.pTag);
73,582,255✔
4844
    taosMemoryFreeClear(req->ctb.stbName);
73,549,486✔
4845
    taosArrayDestroy(req->ctb.tagName);
73,572,912✔
4846
    req->ctb.tagName = NULL;
73,535,024✔
4847
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,141,123✔
4848
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,141,123✔
4849
  }
4850
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
80,693,206✔
4851
  taosMemoryFreeClear(req->pExtSchemas);
80,724,686✔
4852
  taosMemoryFreeClear(req->colRef.pColRef);
80,712,198✔
4853
}
4854

4855
typedef struct {
4856
  int32_t nReqs;
4857
  union {
4858
    SVCreateTbReq* pReqs;
4859
    SArray*        pArray;
4860
  };
4861
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4862
} SVCreateTbBatchReq;
4863

4864
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4865
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4866
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4867

4868
typedef struct {
4869
  int32_t        code;
4870
  STableMetaRsp* pMeta;
4871
} SVCreateTbRsp, SVUpdateTbRsp;
4872

4873
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4874
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4875
void tFreeSVCreateTbRsp(void* param);
4876

4877
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4878
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4879

4880
typedef struct {
4881
  int32_t nRsps;
4882
  union {
4883
    SVCreateTbRsp* pRsps;
4884
    SArray*        pArray;
4885
  };
4886
} SVCreateTbBatchRsp;
4887

4888
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4889
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4890

4891
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4892
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4893

4894
// TDMT_VND_DROP_TABLE =================
4895
typedef struct {
4896
  char*    name;
4897
  uint64_t suid;  // for tmq in wal format
4898
  int64_t  uid;
4899
  int8_t   igNotExists;
4900
  int8_t   isVirtual;
4901
} SVDropTbReq;
4902

4903
typedef struct {
4904
  int32_t code;
4905
} SVDropTbRsp;
4906

4907
typedef struct {
4908
  int32_t nReqs;
4909
  union {
4910
    SVDropTbReq* pReqs;
4911
    SArray*      pArray;
4912
  };
4913
} SVDropTbBatchReq;
4914

4915
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4916
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4917

4918
typedef struct {
4919
  int32_t nRsps;
4920
  union {
4921
    SVDropTbRsp* pRsps;
4922
    SArray*      pArray;
4923
  };
4924
} SVDropTbBatchRsp;
4925

4926
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4927
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4928

4929
// TDMT_VND_ALTER_TABLE =====================
4930
typedef struct SMultiTagUpateVal {
4931
  char*    tagName;
4932
  int32_t  colId;
4933
  int8_t   tagType;
4934
  int8_t   tagFree;
4935
  uint32_t nTagVal;
4936
  uint8_t* pTagVal;
4937
  int8_t   isNull;
4938
  SArray*  pTagArray;
4939
} SMultiTagUpateVal;
4940
typedef struct SVAlterTbReq {
4941
  char*   tbName;
4942
  int8_t  action;
4943
  char*   colName;
4944
  int32_t colId;
4945
  // TSDB_ALTER_TABLE_ADD_COLUMN
4946
  int8_t  type;
4947
  int8_t  flags;
4948
  int32_t bytes;
4949
  // TSDB_ALTER_TABLE_DROP_COLUMN
4950
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4951
  int8_t   colModType;
4952
  int32_t  colModBytes;
4953
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4954
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4955
  int8_t   isNull;
4956
  int8_t   tagType;
4957
  int8_t   tagFree;
4958
  uint32_t nTagVal;
4959
  uint8_t* pTagVal;
4960
  SArray*  pTagArray;
4961
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4962
  int8_t   updateTTL;
4963
  int32_t  newTTL;
4964
  int32_t  newCommentLen;
4965
  char*    newComment;
4966
  int64_t  ctimeMs;    // fill by vnode
4967
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4968
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4969
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4970
  // for Add column
4971
  STypeMod typeMod;
4972
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4973
  char* refDbName;
4974
  char* refTbName;
4975
  char* refColName;
4976
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4977
} SVAlterTbReq;
4978

4979
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4980
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4981
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4982
void    tfreeMultiTagUpateVal(void* pMultiTag);
4983

4984
typedef struct {
4985
  int32_t        code;
4986
  STableMetaRsp* pMeta;
4987
} SVAlterTbRsp;
4988

4989
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4990
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4991
// ======================
4992

4993
typedef struct {
4994
  SMsgHead head;
4995
  int64_t  uid;
4996
  int32_t  tid;
4997
  int16_t  tversion;
4998
  int16_t  colId;
4999
  int8_t   type;
5000
  int16_t  bytes;
5001
  int32_t  tagValLen;
5002
  int16_t  numOfTags;
5003
  int32_t  schemaLen;
5004
  char     data[];
5005
} SUpdateTagValReq;
5006

5007
typedef struct {
5008
  SMsgHead head;
5009
} SUpdateTagValRsp;
5010

5011
typedef struct {
5012
  SMsgHead head;
5013
} SVShowTablesReq;
5014

5015
typedef struct {
5016
  SMsgHead head;
5017
  int32_t  id;
5018
} SVShowTablesFetchReq;
5019

5020
typedef struct {
5021
  int64_t useconds;
5022
  int8_t  completed;  // all results are returned to client
5023
  int8_t  precision;
5024
  int8_t  compressed;
5025
  int32_t compLen;
5026
  int32_t numOfRows;
5027
  char    data[];
5028
} SVShowTablesFetchRsp;
5029

5030
typedef struct {
5031
  int64_t consumerId;
5032
  int32_t epoch;
5033
  char    cgroup[TSDB_CGROUP_LEN];
5034
} SMqAskEpReq;
5035

5036
typedef struct {
5037
  int32_t key;
5038
  int32_t valueLen;
5039
  void*   value;
5040
} SKv;
5041

5042
typedef struct {
5043
  int64_t tscRid;
5044
  int8_t  connType;
5045
} SClientHbKey;
5046

5047
typedef struct {
5048
  int64_t tid;
5049
  char    status[TSDB_JOB_STATUS_LEN];
5050
} SQuerySubDesc;
5051

5052
typedef struct {
5053
  char     sql[TSDB_SHOW_SQL_LEN];
5054
  uint64_t queryId;
5055
  int64_t  useconds;
5056
  int64_t  stime;  // timestamp precision ms
5057
  int64_t  reqRid;
5058
  bool     stableQuery;
5059
  bool     isSubQuery;
5060
  char     fqdn[TSDB_FQDN_LEN];
5061
  int32_t  subPlanNum;
5062
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5063
} SQueryDesc;
5064

5065
typedef struct {
5066
  uint32_t connId;
5067
  SArray*  queryDesc;  // SArray<SQueryDesc>
5068
} SQueryHbReqBasic;
5069

5070
typedef struct {
5071
  uint32_t connId;
5072
  uint64_t killRid;
5073
  int32_t  totalDnodes;
5074
  int32_t  onlineDnodes;
5075
  int8_t   killConnection;
5076
  int8_t   align[3];
5077
  SEpSet   epSet;
5078
  SArray*  pQnodeList;
5079
} SQueryHbRspBasic;
5080

5081
typedef struct SAppClusterSummary {
5082
  uint64_t numOfInsertsReq;
5083
  uint64_t numOfInsertRows;
5084
  uint64_t insertElapsedTime;
5085
  uint64_t insertBytes;  // submit to tsdb since launched.
5086

5087
  uint64_t fetchBytes;
5088
  uint64_t numOfQueryReq;
5089
  uint64_t queryElapsedTime;
5090
  uint64_t numOfSlowQueries;
5091
  uint64_t totalRequests;
5092
  uint64_t currentRequests;  // the number of SRequestObj
5093
} SAppClusterSummary;
5094

5095
typedef struct {
5096
  int64_t            appId;
5097
  int32_t            pid;
5098
  char               name[TSDB_APP_NAME_LEN];
5099
  int64_t            startTime;
5100
  SAppClusterSummary summary;
5101
} SAppHbReq;
5102

5103
typedef struct {
5104
  SClientHbKey      connKey;
5105
  int64_t           clusterId;
5106
  SAppHbReq         app;
5107
  SQueryHbReqBasic* query;
5108
  SHashObj*         info;  // hash<Skv.key, Skv>
5109
  char              user[TSDB_USER_LEN];
5110
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5111
  char              userApp[TSDB_APP_NAME_LEN];
5112
  uint32_t          userIp;
5113
  SIpRange          userDualIp;
5114
  char              sVer[TSDB_VERSION_LEN];
5115
  char              cInfo[CONNECTOR_INFO_LEN];
5116
} SClientHbReq;
5117

5118
typedef struct {
5119
  int64_t reqId;
5120
  SArray* reqs;  // SArray<SClientHbReq>
5121
  int64_t ipWhiteListVer;
5122
} SClientHbBatchReq;
5123

5124
typedef struct {
5125
  SClientHbKey      connKey;
5126
  int32_t           status;
5127
  SQueryHbRspBasic* query;
5128
  SArray*           info;  // Array<Skv>
5129
} SClientHbRsp;
5130

5131
typedef struct {
5132
  int64_t       reqId;
5133
  int64_t       rspId;
5134
  int32_t       svrTimestamp;
5135
  SArray*       rsps;  // SArray<SClientHbRsp>
5136
  SMonitorParas monitorParas;
5137
  int8_t        enableAuditDelete;
5138
  int8_t        enableStrongPass;
5139
  int8_t        enableAuditSelect;
5140
  int8_t        enableAuditInsert;
5141
  int8_t        auditLevel;
5142
} SClientHbBatchRsp;
5143

5144
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
389,646,185✔
5145

5146
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5147
  void* pIter = taosHashIterate(info, NULL);
46,220,577✔
5148
  while (pIter != NULL) {
109,194,515✔
5149
    SKv* kv = (SKv*)pIter;
62,971,164✔
5150
    taosMemoryFreeClear(kv->value);
62,971,164✔
5151
    pIter = taosHashIterate(info, pIter);
62,970,795✔
5152
  }
5153
}
46,223,351✔
5154

5155
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
30,180,583✔
5156
  SQueryDesc* desc = (SQueryDesc*)pDesc;
30,180,583✔
5157
  if (desc->subDesc) {
30,180,583✔
5158
    taosArrayDestroy(desc->subDesc);
20,489,316✔
5159
    desc->subDesc = NULL;
20,488,452✔
5160
  }
5161
}
30,179,578✔
5162

5163
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
52,933,457✔
5164
  SClientHbReq* req = (SClientHbReq*)pReq;
135,844,891✔
5165
  if (req->query) {
135,844,891✔
5166
    if (req->query->queryDesc) {
52,931,863✔
5167
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
24,526,009✔
5168
    }
5169
    taosMemoryFreeClear(req->query);
52,932,991✔
5170
  }
5171

5172
  if (req->info) {
135,846,094✔
5173
    tFreeReqKvHash(req->info);
46,222,156✔
5174
    taosHashCleanup(req->info);
46,223,351✔
5175
    req->info = NULL;
46,220,731✔
5176
  }
5177
}
108,414,224✔
5178

5179
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5180
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5181

5182
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5183
  if (pReq == NULL) return;
22,505,319✔
5184
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
22,505,319✔
5185
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
22,505,319✔
5186
  taosMemoryFree(pReq);
22,505,319✔
5187
}
5188

5189
static FORCE_INLINE void tFreeClientKv(void* pKv) {
62,737,197✔
5190
  SKv* kv = (SKv*)pKv;
62,737,197✔
5191
  if (kv) {
62,737,197✔
5192
    taosMemoryFreeClear(kv->value);
62,737,729✔
5193
  }
5194
}
62,738,219✔
5195

5196
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
52,678,148✔
5197
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
52,678,148✔
5198
  if (rsp->query) {
52,678,148✔
5199
    taosArrayDestroy(rsp->query->pQnodeList);
52,665,368✔
5200
    taosMemoryFreeClear(rsp->query);
52,664,611✔
5201
  }
5202
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
52,688,813✔
5203
}
27,179,548✔
5204

5205
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5206
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
43,503,732✔
5207
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
43,503,732✔
5208
}
43,508,544✔
5209

5210
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5211
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5212
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5213

5214
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5215
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
373,703,924✔
5216
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
373,700,777✔
5217
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
373,700,459✔
5218
  return 0;
186,849,687✔
5219
}
5220

5221
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5222
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
123,031,365✔
5223
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
123,032,234✔
5224
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
61,515,968✔
5225
  if (pKv->value == NULL) {
61,515,641✔
UNCOV
5226
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5227
  }
5228
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
61,516,685✔
5229
  return 0;
61,516,461✔
5230
}
5231

5232
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5233
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
313,109,806✔
5234
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
313,103,416✔
5235
  return 0;
156,555,026✔
5236
}
5237

5238
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5239
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
102,997,101✔
5240
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
103,000,716✔
5241
  return 0;
51,501,845✔
5242
}
5243

5244
typedef struct {
5245
  int32_t vgId;
5246
  // TODO stas
5247
} SMqReportVgInfo;
5248

5249
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5250
  int32_t tlen = 0;
5251
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5252
  return tlen;
5253
}
5254

5255
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5256
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5257
  return buf;
5258
}
5259

5260
typedef struct {
5261
  int32_t epoch;
5262
  int64_t topicUid;
5263
  char    name[TSDB_TOPIC_FNAME_LEN];
5264
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5265
} SMqTopicInfo;
5266

5267
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5268
  int32_t tlen = 0;
5269
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5270
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5271
  tlen += taosEncodeString(buf, pTopicInfo->name);
5272
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5273
  tlen += taosEncodeFixedI32(buf, sz);
5274
  for (int32_t i = 0; i < sz; i++) {
5275
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5276
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5277
  }
5278
  return tlen;
5279
}
5280

5281
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5282
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5283
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5284
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5285
  int32_t sz;
5286
  buf = taosDecodeFixedI32(buf, &sz);
5287
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5288
    return NULL;
5289
  }
5290
  for (int32_t i = 0; i < sz; i++) {
5291
    SMqReportVgInfo vgInfo;
5292
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5293
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5294
      return NULL;
5295
    }
5296
  }
5297
  return buf;
5298
}
5299

5300
typedef struct {
5301
  int32_t status;  // ask hb endpoint
5302
  int32_t epoch;
5303
  int64_t consumerId;
5304
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5305
} SMqReportReq;
5306

5307
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5308
  int32_t tlen = 0;
5309
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5310
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5311
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5312
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5313
  tlen += taosEncodeFixedI32(buf, sz);
5314
  for (int32_t i = 0; i < sz; i++) {
5315
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5316
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5317
  }
5318
  return tlen;
5319
}
5320

5321
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5322
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5323
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5324
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5325
  int32_t sz;
5326
  buf = taosDecodeFixedI32(buf, &sz);
5327
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5328
    return NULL;
5329
  }
5330
  for (int32_t i = 0; i < sz; i++) {
5331
    SMqTopicInfo topicInfo;
5332
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5333
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5334
      return NULL;
5335
    }
5336
  }
5337
  return buf;
5338
}
5339

5340
typedef struct {
5341
  SMsgHead head;
5342
  int64_t  leftForVer;
5343
  int32_t  vgId;
5344
  int64_t  consumerId;
5345
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5346
} SMqVDeleteReq;
5347

5348
typedef struct {
5349
  int8_t reserved;
5350
} SMqVDeleteRsp;
5351

5352
typedef struct {
5353
  char**  name;
5354
  int32_t count;
5355
  int8_t igNotExists;
5356
} SMDropStreamReq;
5357

5358
typedef struct {
5359
  int8_t reserved;
5360
} SMDropStreamRsp;
5361

5362
typedef struct {
5363
  SMsgHead head;
5364
  int64_t  resetRelHalt;  // reset related stream task halt status
5365
  int64_t  streamId;
5366
  int32_t  taskId;
5367
} SVDropStreamTaskReq;
5368

5369
typedef struct {
5370
  int8_t reserved;
5371
} SVDropStreamTaskRsp;
5372

5373
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5374
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5375
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5376

5377
typedef struct {
5378
  char*  name;
5379
  int8_t igNotExists;
5380
} SMPauseStreamReq;
5381

5382
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5383
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5384
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5385

5386
typedef struct {
5387
  char*  name;
5388
  int8_t igNotExists;
5389
  int8_t igUntreated;
5390
} SMResumeStreamReq;
5391

5392
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5393
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5394
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5395

5396
typedef struct {
5397
  char*       name;
5398
  int8_t      calcAll;
5399
  STimeWindow timeRange;
5400
} SMRecalcStreamReq;
5401

5402
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5403
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5404
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5405

5406

5407
typedef struct SVndSetKeepVersionReq {
5408
  int64_t keepVersion;
5409
} SVndSetKeepVersionReq;
5410

5411
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5412
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5413

5414
typedef struct SVUpdateCheckpointInfoReq {
5415
  SMsgHead head;
5416
  int64_t  streamId;
5417
  int32_t  taskId;
5418
  int64_t  checkpointId;
5419
  int64_t  checkpointVer;
5420
  int64_t  checkpointTs;
5421
  int32_t  transId;
5422
  int64_t  hStreamId;  // add encode/decode
5423
  int64_t  hTaskId;
5424
  int8_t   dropRelHTask;
5425
} SVUpdateCheckpointInfoReq;
5426

5427
typedef struct {
5428
  int64_t leftForVer;
5429
  int32_t vgId;
5430
  int64_t oldConsumerId;
5431
  int64_t newConsumerId;
5432
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5433
  int8_t  subType;
5434
  int8_t  withMeta;
5435
  char*   qmsg;  // SubPlanToString
5436
  SSchemaWrapper schema;
5437
  int64_t suid;
5438
} SMqRebVgReq;
5439

5440
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5441
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5442

5443
// tqOffset
5444
enum {
5445
  TMQ_OFFSET__RESET_NONE = -3,
5446
  TMQ_OFFSET__RESET_EARLIEST = -2,
5447
  TMQ_OFFSET__RESET_LATEST = -1,
5448
  TMQ_OFFSET__LOG = 1,
5449
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5450
  TMQ_OFFSET__SNAPSHOT_META = 3,
5451
};
5452

5453
enum {
5454
  WITH_DATA = 0,
5455
  WITH_META = 1,
5456
  ONLY_META = 2,
5457
};
5458

5459
#define TQ_OFFSET_VERSION 1
5460

5461
typedef struct {
5462
  int8_t type;
5463
  union {
5464
    // snapshot
5465
    struct {
5466
      int64_t uid;
5467
      int64_t ts;
5468
      SValue  primaryKey;
5469
    };
5470
    // log
5471
    struct {
5472
      int64_t version;
5473
    };
5474
  };
5475
} STqOffsetVal;
5476

5477
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5478
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,932,144✔
5479
  pOffsetVal->uid = uid;
7,930,638✔
5480
  pOffsetVal->ts = ts;
7,930,892✔
5481
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,931,494✔
5482
    taosMemoryFree(pOffsetVal->primaryKey.pData);
302✔
5483
  }
5484
  pOffsetVal->primaryKey = primaryKey;
7,930,946✔
5485
}
7,929,976✔
5486

5487
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5488
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
47,595✔
5489
  pOffsetVal->uid = uid;
47,595✔
5490
}
47,595✔
5491

5492
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5493
  pOffsetVal->type = TMQ_OFFSET__LOG;
27,681,393✔
5494
  pOffsetVal->version = ver;
27,680,091✔
5495
}
27,680,749✔
5496

5497
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5498
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5499
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5500
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5501
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5502
void    tOffsetDestroy(void* pVal);
5503

5504
typedef struct {
5505
  STqOffsetVal val;
5506
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5507
} STqOffset;
5508

5509
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5510
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5511
void    tDeleteSTqOffset(void* val);
5512

5513
typedef struct SMqVgOffset {
5514
  int64_t   consumerId;
5515
  STqOffset offset;
5516
} SMqVgOffset;
5517

5518
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5519
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5520

5521
typedef struct {
5522
  char    name[TSDB_TABLE_FNAME_LEN];
5523
  char    stb[TSDB_TABLE_FNAME_LEN];
5524
  int8_t  igExists;
5525
  int8_t  intervalUnit;
5526
  int8_t  slidingUnit;
5527
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5528
  int32_t dstVgId;   // for stream
5529
  int64_t interval;
5530
  int64_t offset;
5531
  int64_t sliding;
5532
  int64_t maxDelay;
5533
  int64_t watermark;
5534
  int32_t exprLen;        // strlen + 1
5535
  int32_t tagsFilterLen;  // strlen + 1
5536
  int32_t sqlLen;         // strlen + 1
5537
  int32_t astLen;         // strlen + 1
5538
  char*   expr;
5539
  char*   tagsFilter;
5540
  char*   sql;
5541
  char*   ast;
5542
  int64_t deleteMark;
5543
  int64_t lastTs;
5544
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5545
  SArray* pVgroupVerList;
5546
  int8_t  recursiveTsma;
5547
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5548
  char*   createStreamReq;
5549
  int32_t streamReqLen;
5550
  char*   dropStreamReq;
5551
  int32_t dropStreamReqLen;
5552
  int64_t uid;
5553
} SMCreateSmaReq;
5554

5555
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5556
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5557
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5558

5559
typedef struct {
5560
  char    name[TSDB_TABLE_FNAME_LEN];
5561
  int8_t  igNotExists;
5562
  char*   dropStreamReq;
5563
  int32_t dropStreamReqLen;
5564
} SMDropSmaReq;
5565

5566
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5567
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5568
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5569

5570
typedef struct {
5571
  char name[TSDB_TABLE_NAME_LEN];
5572
  union {
5573
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5574
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5575
  };
5576
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5577
  union {
5578
    int8_t igExists;   // used by mnode
5579
    int8_t alterType;  // used by vnode
5580
  };
5581
  int8_t     intervalUnit;
5582
  int16_t    nFuncs;       // number of functions specified by user
5583
  col_id_t*  funcColIds;   // column ids specified by user
5584
  func_id_t* funcIds;      // function ids specified by user
5585
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5586
  int64_t    tbUid;
5587
  int64_t    uid;     // rsma uid
5588
  int32_t    sqlLen;  // strlen + 1
5589
  char*      sql;
5590
} SMCreateRsmaReq;
5591

5592
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5593
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5594
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5595

5596
typedef SMCreateRsmaReq SVCreateRsmaReq;
5597

5598
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5599
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5600
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5601

5602
typedef SMCreateRsmaReq SVAlterRsmaReq;
5603

5604
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5605
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5606
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5607

5608
typedef struct {
5609
  char       name[TSDB_TABLE_NAME_LEN];
5610
  int8_t     alterType;
5611
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5612
  int8_t     igNotExists;
5613
  int16_t    nFuncs;      // number of functions specified by user
5614
  col_id_t*  funcColIds;  // column ids specified by user
5615
  func_id_t* funcIds;     // function ids specified by user
5616
  int32_t    sqlLen;      // strlen + 1
5617
  char*      sql;
5618
} SMAlterRsmaReq;
5619

5620
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5621
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5622
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5623

5624
typedef struct {
5625
  int64_t    id;
5626
  char       name[TSDB_TABLE_NAME_LEN];
5627
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5628
  int64_t    ownerId;
5629
  int32_t    code;
5630
  int32_t    version;
5631
  int8_t     tbType;
5632
  int8_t     intervalUnit;
5633
  col_id_t   nFuncs;
5634
  col_id_t   nColNames;
5635
  int64_t    interval[2];
5636
  col_id_t*  funcColIds;
5637
  func_id_t* funcIds;
5638
  SArray*    colNames;
5639
} SRsmaInfoRsp;
5640

5641
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5642
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5643
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5644

5645
typedef struct {
5646
  char   name[TSDB_TABLE_FNAME_LEN];
5647
  int8_t igNotExists;
5648
} SMDropRsmaReq;
5649

5650
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5651
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5652

5653
typedef struct {
5654
  char    name[TSDB_TABLE_NAME_LEN];
5655
  char    tbName[TSDB_TABLE_NAME_LEN];
5656
  int64_t uid;
5657
  int64_t tbUid;
5658
  int8_t  tbType;
5659
} SVDropRsmaReq;
5660

5661
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5662
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5663

5664
typedef struct {
5665
  char   dbFName[TSDB_DB_FNAME_LEN];
5666
  char   stbName[TSDB_TABLE_NAME_LEN];
5667
  char   colName[TSDB_COL_NAME_LEN];
5668
  char   idxName[TSDB_INDEX_FNAME_LEN];
5669
  int8_t idxType;
5670
} SCreateTagIndexReq;
5671

5672
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5673
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5674

5675
typedef SMDropSmaReq SDropTagIndexReq;
5676

5677
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5678
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5679

5680
typedef struct {
5681
  int8_t         version;       // for compatibility(default 0)
5682
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5683
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5684
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5685
  int32_t        dstVgId;
5686
  char           indexName[TSDB_INDEX_NAME_LEN];
5687
  int32_t        exprLen;
5688
  int32_t        tagsFilterLen;
5689
  int64_t        indexUid;
5690
  tb_uid_t       tableUid;  // super/child/common table uid
5691
  tb_uid_t       dstTbUid;  // for dstVgroup
5692
  int64_t        interval;
5693
  int64_t        offset;  // use unit by precision of DB
5694
  int64_t        sliding;
5695
  char*          dstTbName;  // for dstVgroup
5696
  char*          expr;       // sma expression
5697
  char*          tagsFilter;
5698
  SSchemaWrapper schemaRow;  // for dstVgroup
5699
  SSchemaWrapper schemaTag;  // for dstVgroup
5700
} STSma;                     // Time-range-wise SMA
5701

5702
typedef STSma SVCreateTSmaReq;
5703

5704
typedef struct {
5705
  int8_t  type;  // 0 status report, 1 update data
5706
  int64_t indexUid;
5707
  int64_t skey;  // start TS key of interval/sliding window
5708
} STSmaMsg;
5709

5710
typedef struct {
5711
  int64_t indexUid;
5712
  char    indexName[TSDB_INDEX_NAME_LEN];
5713
} SVDropTSmaReq;
5714

5715
typedef struct {
5716
  int tmp;  // TODO: to avoid compile error
5717
} SVCreateTSmaRsp, SVDropTSmaRsp;
5718

5719
#if 0
5720
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5721
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5722
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5723
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5724
#endif
5725

5726
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5727
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5728
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5729
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5730

5731
typedef struct {
5732
  int32_t number;
5733
  STSma*  tSma;
5734
} STSmaWrapper;
5735

5736
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5737
  if (pSma) {
×
UNCOV
5738
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5739
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5740
    taosMemoryFreeClear(pSma->tagsFilter);
×
5741
  }
UNCOV
5742
}
×
5743

5744
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5745
  if (pSW) {
×
UNCOV
5746
    if (pSW->tSma) {
×
UNCOV
5747
      if (deepCopy) {
×
UNCOV
5748
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5749
          tDestroyTSma(pSW->tSma + i);
×
5750
        }
5751
      }
UNCOV
5752
      taosMemoryFreeClear(pSW->tSma);
×
5753
    }
5754
  }
5755
}
×
5756

5757
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5758
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5759
  taosMemoryFreeClear(pSW);
×
UNCOV
5760
  return NULL;
×
5761
}
5762

5763
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5764
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5765

5766
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5767
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5768

UNCOV
5769
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5770
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5771
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5772
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5773
  }
5774
  return 0;
×
5775
}
5776

UNCOV
5777
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5778
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5779
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5780
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5781
  }
UNCOV
5782
  return 0;
×
5783
}
5784

5785
typedef struct {
5786
  int idx;
5787
} SMCreateFullTextReq;
5788

5789
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5790
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5791
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5792

5793
typedef struct {
5794
  char   name[TSDB_TABLE_FNAME_LEN];
5795
  int8_t igNotExists;
5796
} SMDropFullTextReq;
5797

5798
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5799
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5800

5801
typedef struct {
5802
  char indexFName[TSDB_INDEX_FNAME_LEN];
5803
} SUserIndexReq;
5804

5805
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5806
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5807

5808
typedef struct {
5809
  char dbFName[TSDB_DB_FNAME_LEN];
5810
  char tblFName[TSDB_TABLE_FNAME_LEN];
5811
  char colName[TSDB_COL_NAME_LEN];
5812
  char owner[TSDB_USER_LEN];
5813
  char indexType[TSDB_INDEX_TYPE_LEN];
5814
  char indexExts[TSDB_INDEX_EXTS_LEN];
5815
} SUserIndexRsp;
5816

5817
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5818
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5819

5820
typedef struct {
5821
  char tbFName[TSDB_TABLE_FNAME_LEN];
5822
} STableIndexReq;
5823

5824
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5825
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5826

5827
typedef struct {
5828
  int8_t  intervalUnit;
5829
  int8_t  slidingUnit;
5830
  int64_t interval;
5831
  int64_t offset;
5832
  int64_t sliding;
5833
  int64_t dstTbUid;
5834
  int32_t dstVgId;
5835
  SEpSet  epSet;
5836
  char*   expr;
5837
} STableIndexInfo;
5838

5839
typedef struct {
5840
  char     tbName[TSDB_TABLE_NAME_LEN];
5841
  char     dbFName[TSDB_DB_FNAME_LEN];
5842
  uint64_t suid;
5843
  int32_t  version;
5844
  int32_t  indexSize;
5845
  SArray*  pIndex;  // STableIndexInfo
5846
} STableIndexRsp;
5847

5848
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5849
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5850
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5851

5852
void tFreeSTableIndexInfo(void* pInfo);
5853

5854
typedef struct {
5855
  int8_t  mqMsgType;
5856
  int32_t code;
5857
  int32_t epoch;
5858
  int64_t consumerId;
5859
  int64_t walsver;
5860
  int64_t walever;
5861
} SMqRspHead;
5862

5863
typedef struct {
5864
  SMsgHead     head;
5865
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5866
  int8_t       withTbName;
5867
  int8_t       useSnapshot;
5868
  int32_t      epoch;
5869
  uint64_t     reqId;
5870
  int64_t      consumerId;
5871
  int64_t      timeout;
5872
  STqOffsetVal reqOffset;
5873
  int8_t       enableReplay;
5874
  int8_t       sourceExcluded;
5875
  int8_t       rawData;
5876
  int32_t      minPollRows;
5877
  int8_t       enableBatchMeta;
5878
  SHashObj*    uidHash;  // to find if uid is duplicated
5879
} SMqPollReq;
5880

5881
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5882
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5883
void    tDestroySMqPollReq(SMqPollReq* pReq);
5884

5885
typedef struct {
5886
  int32_t vgId;
5887
  int64_t offset;
5888
  SEpSet  epSet;
5889
} SMqSubVgEp;
5890

5891
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5892
  int32_t tlen = 0;
2,172,960✔
5893
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,172,960✔
5894
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,172,960✔
5895
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,172,960✔
5896
  return tlen;
2,172,960✔
5897
}
5898

5899
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5900
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,076,943✔
5901
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,076,943✔
5902
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,076,943✔
5903
  return buf;
1,076,943✔
5904
}
5905

5906
typedef struct {
5907
  char           topic[TSDB_TOPIC_FNAME_LEN];
5908
  char           db[TSDB_DB_FNAME_LEN];
5909
  SArray*        vgs;  // SArray<SMqSubVgEp>
5910
} SMqSubTopicEp;
5911

5912
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5913
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5914
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5915

5916
typedef struct {
5917
  SMqRspHead   head;
5918
  STqOffsetVal rspOffset;
5919
  int16_t      resMsgType;
5920
  int32_t      metaRspLen;
5921
  void*        metaRsp;
5922
} SMqMetaRsp;
5923

5924
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5925
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5926
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5927

5928
#define MQ_DATA_RSP_VERSION 100
5929

5930
typedef struct {
5931
  SMqRspHead   head;
5932
  STqOffsetVal rspOffset;
5933
  STqOffsetVal reqOffset;
5934
  int32_t      blockNum;
5935
  int8_t       withTbName;
5936
  int8_t       withSchema;
5937
  SArray*      blockDataLen;
5938
  SArray*      blockData;
5939
  SArray*      blockTbName;
5940
  SArray*      blockSchema;
5941

5942
  union {
5943
    struct {
5944
      int64_t sleepTime;
5945
    };
5946
    struct {
5947
      int32_t createTableNum;
5948
      SArray* createTableLen;
5949
      SArray* createTableReq;
5950
    };
5951
    struct {
5952
      int32_t len;
5953
      void*   rawData;
5954
    };
5955
  };
5956
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5957
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5958
  bool  timeout;
5959
} SMqDataRsp;
5960

5961
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5962
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5963
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5964
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5965
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5966

5967
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5968
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5969
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5970

5971
typedef struct SMqBatchMetaRsp {
5972
  SMqRspHead   head;  // not serialize
5973
  STqOffsetVal rspOffset;
5974
  SArray*      batchMetaLen;
5975
  SArray*      batchMetaReq;
5976
  void*        pMetaBuff;    // not serialize
5977
  uint32_t     metaBuffLen;  // not serialize
5978
} SMqBatchMetaRsp;
5979

5980
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5981
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5982
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5983
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5984

5985
typedef struct {
5986
  int32_t    code;
5987
  SArray*    topics;  // SArray<SMqSubTopicEp>
5988
} SMqAskEpRsp;
5989

5990
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5991
  int32_t tlen = 0;
7,317,283✔
5992
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5993
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,317,283✔
5994
  tlen += taosEncodeFixedI32(buf, sz);
7,317,941✔
5995
  for (int32_t i = 0; i < sz; i++) {
8,961,709✔
5996
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,648,820✔
5997
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,648,820✔
5998
  }
5999
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,312,889✔
6000

6001
  return tlen;
7,316,571✔
6002
}
6003

6004
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6005
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6006
  int32_t sz;
3,270,057✔
6007
  buf = taosDecodeFixedI32(buf, &sz);
3,345,357✔
6008
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,345,357✔
6009
  if (pRsp->topics == NULL) {
3,345,004✔
UNCOV
6010
    return NULL;
×
6011
  }
6012
  for (int32_t i = 0; i < sz; i++) {
4,168,326✔
6013
    SMqSubTopicEp topicEp;
809,545✔
6014
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
823,322✔
6015
    if (buf == NULL) {
823,322✔
UNCOV
6016
      return NULL;
×
6017
    }
6018
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,646,644✔
UNCOV
6019
      return NULL;
×
6020
    }
6021
  }
6022
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,345,004✔
6023

6024
  return buf;
3,345,004✔
6025
}
6026

6027
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6028
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,303,029✔
6029
}
9,303,418✔
6030

6031
typedef struct {
6032
  int32_t      vgId;
6033
  STqOffsetVal offset;
6034
  int64_t      rows;
6035
  int64_t      ever;
6036
} OffsetRows;
6037

6038
typedef struct {
6039
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6040
  SArray* offsetRows;
6041
} TopicOffsetRows;
6042

6043
typedef struct {
6044
  int64_t consumerId;
6045
  int32_t epoch;
6046
  SArray* topics;
6047
  int8_t  pollFlag;
6048
} SMqHbReq;
6049

6050
typedef struct {
6051
  char   topic[TSDB_TOPIC_FNAME_LEN];
6052
  int8_t noPrivilege;
6053
} STopicPrivilege;
6054

6055
typedef struct {
6056
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6057
  int32_t debugFlag;
6058
} SMqHbRsp;
6059

6060
typedef struct {
6061
  SMsgHead head;
6062
  int64_t  consumerId;
6063
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6064
} SMqSeekReq;
6065

6066
#define TD_AUTO_CREATE_TABLE 0x1
6067
typedef struct {
6068
  int64_t       suid;
6069
  int64_t       uid;
6070
  int32_t       sver;
6071
  uint32_t      nData;
6072
  uint8_t*      pData;
6073
  SVCreateTbReq cTbReq;
6074
} SVSubmitBlk;
6075

6076
typedef struct {
6077
  SMsgHead header;
6078
  uint64_t sId;
6079
  uint64_t queryId;
6080
  uint64_t clientId;
6081
  uint64_t taskId;
6082
  uint32_t sqlLen;
6083
  uint32_t phyLen;
6084
  char*    sql;
6085
  char*    msg;
6086
  int8_t   source;
6087
} SVDeleteReq;
6088

6089
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6090
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6091

6092
typedef struct {
6093
  int64_t affectedRows;
6094
} SVDeleteRsp;
6095

6096
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6097
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6098

6099
typedef struct SDeleteRes {
6100
  uint64_t suid;
6101
  SArray*  uidList;
6102
  int64_t  skey;
6103
  int64_t  ekey;
6104
  int64_t  affectedRows;
6105
  char     tableFName[TSDB_TABLE_NAME_LEN];
6106
  char     tsColName[TSDB_COL_NAME_LEN];
6107
  int64_t  ctimeMs;  // fill by vnode
6108
  int8_t   source;
6109
} SDeleteRes;
6110

6111
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6112
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6113

6114
typedef struct {
6115
  // int64_t uid;
6116
  char    tbname[TSDB_TABLE_NAME_LEN];
6117
  int64_t startTs;
6118
  int64_t endTs;
6119
} SSingleDeleteReq;
6120

6121
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6122
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6123

6124
typedef struct {
6125
  int64_t suid;
6126
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6127
  int64_t ctimeMs;     // fill by vnode
6128
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6129
} SBatchDeleteReq;
6130

6131
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6132
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6133
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6134

6135
typedef struct {
6136
  int32_t msgIdx;
6137
  int32_t msgType;
6138
  int32_t msgLen;
6139
  void*   msg;
6140
} SBatchMsg;
6141

6142
typedef struct {
6143
  SMsgHead header;
6144
  SArray*  pMsgs;  // SArray<SBatchMsg>
6145
} SBatchReq;
6146

6147
typedef struct {
6148
  int32_t reqType;
6149
  int32_t msgIdx;
6150
  int32_t msgLen;
6151
  int32_t rspCode;
6152
  void*   msg;
6153
} SBatchRspMsg;
6154

6155
typedef struct {
6156
  SArray* pRsps;  // SArray<SBatchRspMsg>
6157
} SBatchRsp;
6158

6159
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6160
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6161
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
95,218,350✔
6162
  if (NULL == msg) {
95,218,350✔
UNCOV
6163
    return;
×
6164
  }
6165
  SBatchMsg* pMsg = (SBatchMsg*)msg;
95,218,350✔
6166
  taosMemoryFree(pMsg->msg);
95,218,350✔
6167
}
6168

6169
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6170
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6171

6172
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
131,557,884✔
6173
  if (NULL == p) {
131,557,884✔
UNCOV
6174
    return;
×
6175
  }
6176

6177
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
131,557,884✔
6178
  taosMemoryFree(pRsp->msg);
131,557,884✔
6179
}
6180

6181
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6182
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6183
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6184
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6185
void    tDestroySMqHbReq(SMqHbReq* pReq);
6186

6187
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6188
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6189
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6190

6191
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6192
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6193

6194
#define TD_REQ_FROM_APP               0x0
6195
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6196
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6197
#define SUBMIT_REQ_FROM_FILE          0x4
6198
#define TD_REQ_FROM_TAOX              0x8
6199
#define TD_REQ_FROM_SML               0x10
6200
#define SUBMIT_REQUEST_VERSION        (2)
6201
#define SUBMIT_REQ_WITH_BLOB          0x10
6202
#define SUBMIT_REQ_SCHEMA_RES         0x20
6203
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6204

6205
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6206

6207
typedef struct {
6208
  int32_t        flags;
6209
  SVCreateTbReq* pCreateTbReq;
6210
  int64_t        suid;
6211
  int64_t        uid;
6212
  int32_t        sver;
6213
  union {
6214
    SArray* aRowP;
6215
    SArray* aCol;
6216
  };
6217
  int64_t   ctimeMs;
6218
  SBlobSet* pBlobSet;
6219
} SSubmitTbData;
6220

6221
typedef struct {
6222
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6223
  SArray* aSubmitBlobData;
6224
  bool    raw;
6225
} SSubmitReq2;
6226

6227
typedef struct {
6228
  SMsgHead header;
6229
  int64_t  version;
6230
  char     data[];  // SSubmitReq2
6231
} SSubmitReq2Msg;
6232

6233
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6234
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6235
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6236
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6237
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6238

6239
typedef struct {
6240
  int32_t affectedRows;
6241
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6242
} SSubmitRsp2;
6243

6244
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6245
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6246
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6247

6248
#define TSDB_MSG_FLG_ENCODE 0x1
6249
#define TSDB_MSG_FLG_DECODE 0x2
6250
#define TSDB_MSG_FLG_CMPT   0x3
6251

6252
typedef struct {
6253
  union {
6254
    struct {
6255
      void*   msgStr;
6256
      int32_t msgLen;
6257
      int64_t ver;
6258
    };
6259
    void* pDataBlock;
6260
  };
6261
} SPackedData;
6262

6263
typedef struct {
6264
  char     fullname[TSDB_VIEW_FNAME_LEN];
6265
  char     name[TSDB_VIEW_NAME_LEN];
6266
  char     dbFName[TSDB_DB_FNAME_LEN];
6267
  char*    querySql;
6268
  char*    sql;
6269
  int8_t   orReplace;
6270
  int8_t   precision;
6271
  int32_t  numOfCols;
6272
  SSchema* pSchema;
6273
} SCMCreateViewReq;
6274

6275
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6276
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6277
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6278

6279
typedef struct {
6280
  char   fullname[TSDB_VIEW_FNAME_LEN];
6281
  char   name[TSDB_VIEW_NAME_LEN];
6282
  char   dbFName[TSDB_DB_FNAME_LEN];
6283
  char*  sql;
6284
  int8_t igNotExists;
6285
} SCMDropViewReq;
6286

6287
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6288
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6289
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6290

6291
typedef struct {
6292
  char fullname[TSDB_VIEW_FNAME_LEN];
6293
} SViewMetaReq;
6294
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6295
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6296

6297
typedef struct {
6298
  char     name[TSDB_VIEW_NAME_LEN];
6299
  char     dbFName[TSDB_DB_FNAME_LEN];
6300
  char*    createUser;
6301
  int64_t  ownerId;
6302
  uint64_t dbId;
6303
  uint64_t viewId;
6304
  char*    querySql;
6305
  int8_t   precision;
6306
  int8_t   type;
6307
  int32_t  version;
6308
  int32_t  numOfCols;
6309
  SSchema* pSchema;
6310
} SViewMetaRsp;
6311
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6312
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6313
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6314
typedef struct {
6315
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6316
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6317
} STableTSMAInfoReq;
6318

6319
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6320
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6321

6322
typedef struct {
6323
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6324
  union {
6325
    uint8_t flags;
6326
    struct {
6327
      uint8_t withColName : 1;
6328
      uint8_t reserved : 7;
6329
    };
6330
  };
6331

6332
} SRsmaInfoReq;
6333

6334
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6335
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6336

6337
typedef struct {
6338
  int32_t  funcId;
6339
  col_id_t colId;
6340
} STableTSMAFuncInfo;
6341

6342
typedef struct {
6343
  char     name[TSDB_TABLE_NAME_LEN];
6344
  uint64_t tsmaId;
6345
  char     targetTb[TSDB_TABLE_NAME_LEN];
6346
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6347
  char     tb[TSDB_TABLE_NAME_LEN];
6348
  char     dbFName[TSDB_DB_FNAME_LEN];
6349
  uint64_t suid;
6350
  uint64_t destTbUid;
6351
  uint64_t dbId;
6352
  int32_t  version;
6353
  int64_t  interval;
6354
  int8_t   unit;
6355
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6356
  SArray*  pTags;      // SArray<SSchema>
6357
  SArray*  pUsedCols;  // SArray<SSchema>
6358
  char*    ast;
6359

6360
  int64_t streamUid;
6361
  int64_t reqTs;
6362
  int64_t rspTs;
6363
  int64_t delayDuration;  // ms
6364
  bool    fillHistoryFinished;
6365

6366
  void* streamAddr;  // for stream task, the address of the stream task
6367
} STableTSMAInfo;
6368

6369
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6370
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6371
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6372
void    tFreeTableTSMAInfo(void* p);
6373
void    tFreeAndClearTableTSMAInfo(void* p);
6374
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6375

6376
#define STSMAHbRsp            STableTSMAInfoRsp
6377
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6378
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6379
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6380

6381
typedef struct SDropCtbWithTsmaSingleVgReq {
6382
  SVgroupInfo vgInfo;
6383
  SArray*     pTbs;  // SVDropTbReq
6384
} SMDropTbReqsOnSingleVg;
6385

6386
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6387
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6388
void    tFreeSMDropTbReqOnSingleVg(void* p);
6389

6390
typedef struct SDropTbsReq {
6391
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6392
} SMDropTbsReq;
6393

6394
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6395
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6396
void    tFreeSMDropTbsReq(void*);
6397

6398
typedef struct SVFetchTtlExpiredTbsRsp {
6399
  SArray* pExpiredTbs;  // SVDropTbReq
6400
  int32_t vgId;
6401
} SVFetchTtlExpiredTbsRsp;
6402

6403
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6404
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6405

6406
void tFreeFetchTtlExpiredTbsRsp(void* p);
6407

6408
void setDefaultOptionsForField(SFieldWithOptions* field);
6409
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6410

6411
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6412
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6413

6414

6415
typedef struct {
6416
  char    id[TSDB_INSTANCE_ID_LEN];
6417
  char    type[TSDB_INSTANCE_TYPE_LEN];
6418
  char    desc[TSDB_INSTANCE_DESC_LEN];
6419
  int32_t expire;
6420
} SInstanceRegisterReq;
6421

6422
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6423
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6424

6425
typedef struct {
6426
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6427
} SInstanceListReq;
6428

6429
typedef struct {
6430
  int32_t count;
6431
  char**  ids;  // Array of instance IDs
6432
} SInstanceListRsp;
6433

6434
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6435
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6436
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6437
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6438

6439
#ifdef USE_MOUNT
6440
typedef struct {
6441
  char     mountName[TSDB_MOUNT_NAME_LEN];
6442
  int8_t   ignoreExist;
6443
  int16_t  nMounts;
6444
  int32_t* dnodeIds;
6445
  char**   mountPaths;
6446
  int32_t  sqlLen;
6447
  char*    sql;
6448
} SCreateMountReq;
6449

6450
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6451
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6452
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6453

6454
typedef struct {
6455
  char    mountName[TSDB_MOUNT_NAME_LEN];
6456
  int8_t  ignoreNotExists;
6457
  int32_t sqlLen;
6458
  char*   sql;
6459
} SDropMountReq;
6460

6461
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6462
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6463
void    tFreeSDropMountReq(SDropMountReq* pReq);
6464

6465
typedef struct {
6466
  char     mountName[TSDB_MOUNT_NAME_LEN];
6467
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6468
  int64_t  mountUid;
6469
  int32_t  dnodeId;
6470
  uint32_t valLen;
6471
  int8_t   ignoreExist;
6472
  void*    pVal;
6473
} SRetrieveMountPathReq;
6474

6475
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6476
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6477

6478
typedef struct {
6479
  // path
6480
  int32_t diskPrimary;
6481
  // vgInfo
6482
  int32_t  vgId;
6483
  int32_t  cacheLastSize;
6484
  int32_t  szPage;
6485
  int32_t  szCache;
6486
  uint64_t szBuf;
6487
  int8_t   cacheLast;
6488
  int8_t   standby;
6489
  int8_t   hashMethod;
6490
  uint32_t hashBegin;
6491
  uint32_t hashEnd;
6492
  int16_t  hashPrefix;
6493
  int16_t  hashSuffix;
6494
  int16_t  sttTrigger;
6495
  // syncInfo
6496
  int32_t replications;
6497
  // tsdbInfo
6498
  int8_t  precision;
6499
  int8_t  compression;
6500
  int8_t  slLevel;
6501
  int32_t daysPerFile;
6502
  int32_t keep0;
6503
  int32_t keep1;
6504
  int32_t keep2;
6505
  int32_t keepTimeOffset;
6506
  int32_t minRows;
6507
  int32_t maxRows;
6508
  int32_t tsdbPageSize;
6509
  int32_t ssChunkSize;
6510
  int32_t ssKeepLocal;
6511
  int8_t  ssCompact;
6512
  union {
6513
    uint8_t flags;
6514
    struct {
6515
      uint8_t isAudit : 1;
6516
      uint8_t allowDrop : 1;
6517
      uint8_t reserved : 6;
6518
    };
6519
  };
6520
  // walInfo
6521
  int32_t walFsyncPeriod;      // millisecond
6522
  int32_t walRetentionPeriod;  // secs
6523
  int32_t walRollPeriod;       // secs
6524
  int64_t walRetentionSize;
6525
  int64_t walSegSize;
6526
  int32_t walLevel;
6527
  // encryptInfo
6528
  int32_t encryptAlgorithm;
6529
  // SVState
6530
  int64_t committed;
6531
  int64_t commitID;
6532
  int64_t commitTerm;
6533
  // stats
6534
  int64_t numOfSTables;
6535
  int64_t numOfCTables;
6536
  int64_t numOfNTables;
6537
  // dbInfo
6538
  uint64_t dbId;
6539
} SMountVgInfo;
6540

6541
typedef struct {
6542
  SMCreateStbReq req;
6543
  SArray*        pColExts;  // element: column id
6544
  SArray*        pTagExts;  // element: tag id
6545
} SMountStbInfo;
6546

6547
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6548
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6549

6550
typedef struct {
6551
  char     dbName[TSDB_DB_FNAME_LEN];
6552
  uint64_t dbId;
6553
  SArray*  pVgs;   // SMountVgInfo
6554
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6555
} SMountDbInfo;
6556

6557
typedef struct {
6558
  // common fields
6559
  char     mountName[TSDB_MOUNT_NAME_LEN];
6560
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6561
  int8_t   ignoreExist;
6562
  int64_t  mountUid;
6563
  int64_t  clusterId;
6564
  int32_t  dnodeId;
6565
  uint32_t valLen;
6566
  void*    pVal;
6567

6568
  // response fields
6569
  SArray* pDbs;  // SMountDbInfo
6570

6571
  // memory fields, no serialized
6572
  SArray*   pDisks[TFS_MAX_TIERS];
6573
  TdFilePtr pFile;
6574
} SMountInfo;
6575

6576
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6577
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6578
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6579

6580
typedef struct {
6581
  SCreateVnodeReq createReq;
6582
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6583
  char            mountName[TSDB_MOUNT_NAME_LEN];
6584
  int64_t         mountId;
6585
  int32_t         diskPrimary;
6586
  int32_t         mountVgId;
6587
  int64_t         committed;
6588
  int64_t         commitID;
6589
  int64_t         commitTerm;
6590
  int64_t         numOfSTables;
6591
  int64_t         numOfCTables;
6592
  int64_t         numOfNTables;
6593
} SMountVnodeReq;
6594

6595
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6596
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6597
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6598

6599
#endif  // USE_MOUNT
6600

6601
#pragma pack(pop)
6602

6603
typedef struct {
6604
  char        db[TSDB_DB_FNAME_LEN];
6605
  STimeWindow timeRange;
6606
  int32_t     sqlLen;
6607
  char*       sql;
6608
  SArray*     vgroupIds;
6609
} SScanDbReq;
6610

6611
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6612
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6613
void    tFreeSScanDbReq(SScanDbReq* pReq);
6614

6615
typedef struct {
6616
  int32_t scanId;
6617
  int8_t  bAccepted;
6618
} SScanDbRsp;
6619

6620
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6621
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6622

6623
typedef struct {
6624
  int32_t scanId;
6625
  int32_t sqlLen;
6626
  char*   sql;
6627
} SKillScanReq;
6628

6629
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6630
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6631
void    tFreeSKillScanReq(SKillScanReq* pReq);
6632

6633
typedef struct {
6634
  int32_t scanId;
6635
  int32_t vgId;
6636
  int32_t dnodeId;
6637
} SVKillScanReq;
6638

6639
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6640
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6641

6642
typedef struct {
6643
  int32_t scanId;
6644
  int32_t vgId;
6645
  int32_t dnodeId;
6646
  int32_t numberFileset;
6647
  int32_t finished;
6648
  int32_t progress;
6649
  int64_t remainingTime;
6650
} SQueryScanProgressRsp;
6651

6652
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6653
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6654

6655
typedef struct {
6656
  int32_t scanId;
6657
  int32_t vgId;
6658
  int32_t dnodeId;
6659
} SQueryScanProgressReq;
6660

6661
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6662
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6663

6664
typedef struct {
6665
  int64_t     dbUid;
6666
  char        db[TSDB_DB_FNAME_LEN];
6667
  int64_t     scanStartTime;
6668
  STimeWindow tw;
6669
  int32_t     scanId;
6670
} SScanVnodeReq;
6671

6672
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6673
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6674

6675
#ifdef __cplusplus
6676
}
6677
#endif
6678

6679
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6680
 
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