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

taosdata / TDengine / #4945

30 Jan 2026 06:19AM UTC coverage: 66.87% (+0.02%) from 66.849%
#4945

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1126 of 2018 new or added lines in 72 files covered. (55.8%)

13708 existing lines in 159 files now uncovered.

205277 of 306978 relevant lines covered (66.87%)

126353544.65 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;
1,404✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,004,149,134✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
961,300,839✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,965,449,973✔
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

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

444

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

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

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

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

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

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

693
typedef struct SField {
694
  char    name[TSDB_COL_NAME_LEN];
695
  uint8_t type;
696
  int8_t  flags;
697
  int32_t bytes;
698
} SField;
699

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

709
typedef struct SRetention {
710
  int64_t freq;
711
  int64_t keep;
712
  int8_t  freqUnit;
713
  int8_t  keepUnit;
714
} SRetention;
715

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

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

725
typedef struct {
726
  int32_t contLen;
727
  int32_t vgId;
728
} SMsgHead;
729

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

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

750
typedef struct {
751
  int32_t totalLen;
752
  int32_t len;
753
  STSRow* row;
754
} SSubmitBlkIter;
755

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

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

778
typedef struct {
779
  bool     hasRef;
780
  col_id_t id;
781
  char     refDbName[TSDB_DB_NAME_LEN];
782
  char     refTableName[TSDB_TABLE_NAME_LEN];
783
  char     refColName[TSDB_COL_NAME_LEN];
784
} SColRef;
785

786
typedef struct {
787
  int32_t  nCols;
788
  int32_t  version;
789
  SColRef* pColRef;
790
} SColRefWrapper;
791

792
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
793
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
794
typedef struct {
795
  int32_t vgId;
796
  SColRef colRef;
797
} SColRefEx;
798

799
typedef struct {
800
  int16_t colId;
801
  char    refDbName[TSDB_DB_NAME_LEN];
802
  char    refTableName[TSDB_TABLE_NAME_LEN];
803
  char    refColName[TSDB_COL_NAME_LEN];
804
} SRefColInfo;
805

806
typedef struct SVCTableRefCols {
807
  uint64_t     uid;
808
  int32_t      numOfSrcTbls;
809
  int32_t      numOfColRefs;
810
  SRefColInfo* refCols;
811
} SVCTableRefCols;
812

813
typedef struct SVCTableMergeInfo {
814
  uint64_t uid;
815
  int32_t  numOfSrcTbls;
816
} SVCTableMergeInfo;
817

818
typedef struct {
819
  int32_t    nCols;
820
  SColRefEx* pColRefEx;
821
} SColRefExWrapper;
822

823
struct SSchema {
824
  int8_t   type;
825
  int8_t   flags;
826
  col_id_t colId;
827
  int32_t  bytes;
828
  char     name[TSDB_COL_NAME_LEN];
829
};
830
struct SSchemaExt {
831
  col_id_t colId;
832
  uint32_t compress;
833
  STypeMod typeMod;
834
};
835

836
struct SSchemaRsma {
837
  int64_t    interval[2];
838
  int32_t    nFuncs;
839
  int8_t     tbType;
840
  tb_uid_t   tbUid;
841
  func_id_t* funcIds;
842
  char       tbName[TSDB_TABLE_NAME_LEN];
843
};
844

845
struct SSchema2 {
846
  int8_t   type;
847
  int8_t   flags;
848
  col_id_t colId;
849
  int32_t  bytes;
850
  char     name[TSDB_COL_NAME_LEN];
851
  uint32_t compress;
852
};
853

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

886
typedef struct {
887
  int32_t        code;
888
  int64_t        uid;
889
  char*          tblFName;
890
  int32_t        numOfRows;
891
  int32_t        affectedRows;
892
  int64_t        sver;
893
  STableMetaRsp* pMeta;
894
} SSubmitBlkRsp;
895

896
typedef struct {
897
  int32_t numOfRows;
898
  int32_t affectedRows;
899
  int32_t nBlocks;
900
  union {
901
    SArray*        pArray;
902
    SSubmitBlkRsp* pBlocks;
903
  };
904
} SSubmitRsp;
905

906
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
907
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
908
// void    tFreeSSubmitBlkRsp(void* param);
909
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
910

911
#define COL_SMA_ON       ((int8_t)0x1)
912
#define COL_IDX_ON       ((int8_t)0x2)
913
#define COL_IS_KEY       ((int8_t)0x4)
914
#define COL_SET_NULL     ((int8_t)0x10)
915
#define COL_SET_VAL      ((int8_t)0x20)
916
#define COL_IS_SYSINFO   ((int8_t)0x40)
917
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
918
#define COL_REF_BY_STM   ((int8_t)0x08)
919

920
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
921
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
922

923
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
924
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
925
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
926

927
#define SSCHMEA_SET_IDX_ON(s) \
928
  do {                        \
929
    (s)->flags |= COL_IDX_ON; \
930
  } while (0)
931

932
#define SSCHMEA_SET_IDX_OFF(s)   \
933
  do {                           \
934
    (s)->flags &= (~COL_IDX_ON); \
935
  } while (0)
936

937
#define SSCHEMA_SET_TYPE_MOD(s)     \
938
  do {                              \
939
    (s)->flags |= COL_HAS_TYPE_MOD; \
940
  } while (0)
941

942
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
943

944
#define SSCHMEA_TYPE(s)  ((s)->type)
945
#define SSCHMEA_FLAGS(s) ((s)->flags)
946
#define SSCHMEA_COLID(s) ((s)->colId)
947
#define SSCHMEA_BYTES(s) ((s)->bytes)
948
#define SSCHMEA_NAME(s)  ((s)->name)
949

950
typedef struct {
951
  bool    tsEnableMonitor;
952
  int32_t tsMonitorInterval;
953
  int32_t tsSlowLogThreshold;
954
  int32_t tsSlowLogMaxLen;
955
  int32_t tsSlowLogScope;
956
  int32_t tsSlowLogThresholdTest;  // Obsolete
957
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
958
} SMonitorParas;
959

960
typedef struct {
961
  STypeMod typeMod;
962
} SExtSchema;
963

964
bool hasExtSchema(const SExtSchema* pExtSchema);
965

966
typedef struct {
967
  int32_t      nCols;
968
  int32_t      version;
969
  SSchema*     pSchema;
970
  SSchemaRsma* pRsma;
971
} SSchemaWrapper;
972

973
typedef struct {
974
  col_id_t id;
975
  uint32_t alg;
976
} SColCmpr;
977

978
typedef struct {
979
  int32_t   nCols;
980
  int32_t   version;
981
  SColCmpr* pColCmpr;
982
} SColCmprWrapper;
983

984
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
985
  if (pRef->pColRef) {
353,740✔
UNCOV
986
    return TSDB_CODE_INVALID_PARA;
×
987
  }
988
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
353,740✔
989
  if (pRef->pColRef == NULL) {
353,740✔
UNCOV
990
    return terrno;
×
991
  }
992
  pRef->nCols = nCols;
353,740✔
993
  for (int32_t i = 0; i < nCols; i++) {
141,386,902✔
994
    pRef->pColRef[i].hasRef = false;
141,033,162✔
995
    pRef->pColRef[i].id = (col_id_t)(i + 1);
141,033,162✔
996
  }
997
  return 0;
353,740✔
998
}
999

1000
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1001
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1002
    terrno = TSDB_CODE_INVALID_PARA;
1003
    return NULL;
1004
  }
1005

1006
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1007
  if (pDstWrapper == NULL) {
1008
    return NULL;
1009
  }
1010
  pDstWrapper->nCols = pSrcWrapper->nCols;
1011
  pDstWrapper->version = pSrcWrapper->version;
1012

1013
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1014
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1015
  if (pDstWrapper->pColCmpr == NULL) {
1016
    taosMemoryFree(pDstWrapper);
1017
    return NULL;
1018
  }
1019
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1020

1021
  return pDstWrapper;
1022
}
1023

1024
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1025
  if (!(!pCmpr->pColCmpr)) {
5,401,676✔
UNCOV
1026
    return TSDB_CODE_INVALID_PARA;
×
1027
  }
1028
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
5,401,676✔
1029
  if (pCmpr->pColCmpr == NULL) {
5,401,676✔
UNCOV
1030
    return terrno;
×
1031
  }
1032
  pCmpr->nCols = nCols;
5,401,676✔
1033
  return 0;
5,401,676✔
1034
}
1035

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

1054
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1055
  if (pWrapper == NULL) return;
1056

1057
  taosMemoryFreeClear(pWrapper->pColCmpr);
1058
  taosMemoryFreeClear(pWrapper);
1059
}
1060
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1061
  if (pSchemaWrapper->pSchema == NULL) return NULL;
568,044,616✔
1062

1063
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
567,749,061✔
1064
  if (pSW == NULL) {
567,828,905✔
UNCOV
1065
    return NULL;
×
1066
  }
1067
  pSW->nCols = pSchemaWrapper->nCols;
567,828,905✔
1068
  pSW->version = pSchemaWrapper->version;
567,818,743✔
1069
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
568,057,685✔
1070
  if (pSW->pSchema == NULL) {
567,667,421✔
UNCOV
1071
    taosMemoryFree(pSW);
×
UNCOV
1072
    return NULL;
×
1073
  }
1074

1075
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
567,596,577✔
1076
  return pSW;
568,141,945✔
1077
}
1078

1079
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
302,078,357✔
1080
  if (pSchemaWrapper) {
1,612,078,389✔
1081
    taosMemoryFree(pSchemaWrapper->pSchema);
911,588,107✔
1082
    if (pSchemaWrapper->pRsma) {
911,383,271✔
1083
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
25,884✔
1084
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
25,884✔
1085
    }
1086
    taosMemoryFree(pSchemaWrapper);
911,302,959✔
1087
  }
1088
}
1,570,160,994✔
1089

1090
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1091
  if (pSchemaWrapper) {
1092
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1093
    if (pSchemaWrapper->pRsma) {
1094
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1095
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1096
    }
1097
  }
1098
}
1099

1100
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,378,808✔
1101
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,378,808✔
1102
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,378,781✔
1103
  }
1104
}
7,377,116✔
1105

1106
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1107
  int32_t tlen = 0;
2,584,700✔
1108
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,585,948✔
1109
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,584,700✔
1110
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,584,700✔
1111
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,584,700✔
1112
  tlen += taosEncodeString(buf, pSchema->name);
2,584,700✔
1113
  return tlen;
2,584,700✔
1114
}
1115

1116
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1117
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,152,174✔
1118
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,151,862✔
1119
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,151,862✔
1120
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,151,862✔
1121
  buf = taosDecodeStringTo(buf, pSchema->name);
1,151,862✔
1122
  return (void*)buf;
1,151,862✔
1123
}
1124

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

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

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

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

1157
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1158
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
724,683,944✔
1159
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
724,683,944✔
1160
  if (pColRef->hasRef) {
362,341,972✔
1161
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
434,438,016✔
1162
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
434,438,016✔
1163
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
434,438,016✔
1164
  }
1165
  return 0;
362,341,972✔
1166
}
1167

1168
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1169
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
362,679,870✔
1170
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
362,679,870✔
1171
  if (pColRef->hasRef) {
181,339,935✔
1172
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
108,756,128✔
1173
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
108,756,128✔
1174
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
108,756,128✔
1175
  }
1176

1177
  return 0;
181,339,935✔
1178
}
1179

1180
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1181
  int32_t tlen = 0;
422,232✔
1182
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
422,232✔
1183
  tlen += taosEncodeVariantI32(buf, pSW->version);
422,232✔
1184
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,006,932✔
1185
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,169,400✔
1186
  }
1187
  return tlen;
422,232✔
1188
}
1189

1190
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1191
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
183,393✔
1192
  buf = taosDecodeVariantI32(buf, &pSW->version);
183,393✔
1193
  if (pSW->nCols > 0) {
183,393✔
1194
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
183,393✔
1195
    if (pSW->pSchema == NULL) {
183,393✔
UNCOV
1196
      return NULL;
×
1197
    }
1198

1199
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,335,255✔
1200
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,303,724✔
1201
    }
1202
  } else {
UNCOV
1203
    pSW->pSchema = NULL;
×
1204
  }
1205
  return (void*)buf;
183,393✔
1206
}
1207

1208
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1209
  if (pSW == NULL) {
450,124,330✔
UNCOV
1210
    return TSDB_CODE_INVALID_PARA;
×
1211
  }
1212
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
900,277,673✔
1213
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
900,191,706✔
1214
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1215
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1216
  }
1217
  return 0;
450,322,713✔
1218
}
1219

1220
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1221
  if (pSW == NULL) {
181,819,683✔
UNCOV
1222
    return TSDB_CODE_INVALID_PARA;
×
1223
  }
1224
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
363,603,758✔
1225
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
363,598,656✔
1226

1227
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
181,814,581✔
1228
  if (pSW->pSchema == NULL) {
181,759,017✔
UNCOV
1229
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1230
  }
1231
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,677,609,213✔
1232
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1233
  }
1234

1235
  return 0;
181,859,331✔
1236
}
1237

1238
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1239
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1240
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1241

1242
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1243
  if (pSW->pSchema == NULL) {
1,734,956,450✔
UNCOV
1244
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1245
  }
1246
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1247
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1248
  }
1249

1250
  return 0;
1,735,833,764✔
1251
}
1252

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

1286
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1287
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1288
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1289

1290
typedef struct {
1291
  STableMetaRsp* pMeta;
1292
} SMCreateStbRsp;
1293

1294
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1295
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1296
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1297

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

1308
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1309
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1310
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1311

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

1326
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1327
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1328
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1329

1330
typedef struct SEpSet {
1331
  int8_t inUse;
1332
  int8_t numOfEps;
1333
  SEp    eps[TSDB_MAX_REPLICA];
1334
} SEpSet;
1335

1336
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1337
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1338
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1339
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1340

1341
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1342
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1343

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

1359
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1360
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1361
void    tSignConnectReq(SConnectReq* pReq);
1362
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1363

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

1390
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1391
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1392

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

1404
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1405
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1406

1407
typedef struct {
1408
  char    user[TSDB_USER_LEN];
1409
  int8_t  ignoreNotExists;
1410
  int32_t sqlLen;
1411
  char*   sql;
1412
} SDropUserReq, SDropAcctReq;
1413

1414
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1415
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1416
void    tFreeSDropUserReq(SDropUserReq* pReq);
1417

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

1431
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1432
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1433
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1434

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

1448
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1449
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1450
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1451

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

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

1487
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1488
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1489
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1490

1491
typedef struct {
1492
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1493
  int32_t sqlLen;
1494
  char*   sql;
1495
} SDropEncryptAlgrReq;
1496

1497
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1498
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1499
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1500

1501
typedef struct SIpV4Range {
1502
  uint32_t ip;
1503
  uint32_t mask;
1504
} SIpV4Range;
1505

1506
typedef struct SIpv6Range {
1507
  uint64_t addr[2];
1508
  uint32_t mask;
1509
} SIpV6Range;
1510

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

1520
typedef struct {
1521
  int32_t    num;
1522
  SIpV4Range pIpRange[];
1523
} SIpWhiteList;
1524

1525
typedef struct {
1526
  int32_t  num;
1527
  SIpRange pIpRanges[];
1528
} SIpWhiteListDual;
1529

1530
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1531
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1532
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1533
int32_t           createDefaultIp6Range(SIpRange* pRange);
1534
int32_t           createDefaultIp4Range(SIpRange* pRange);
1535

1536
typedef struct {
1537
  int32_t sessPerUser;
1538
  int32_t sessConnTime;
1539
  int32_t sessConnIdleTime;
1540
  int32_t sessMaxConcurrency;
1541
  int32_t sessMaxCallVnodeNum;
1542
} SUserSessCfg;
1543

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

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

1560
bool isValidDateTimeRange(SDateTimeRange* pRange);
1561
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1562
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1563

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

1572
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1573
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1574

1575
typedef struct {
1576
  int32_t num;
1577
  SDateTimeWhiteListItem ranges[];
1578
} SDateTimeWhiteList;
1579

1580
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1581
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1582

1583

1584
typedef struct {
1585
  int8_t createType;
1586
  int8_t superUser;  // denote if it is a super user or not
1587
  int8_t ignoreExists;
1588

1589
  char   user[TSDB_USER_LEN];
1590
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1591
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1592

1593
  int8_t sysInfo;
1594
  int8_t createDb;
1595
  int8_t isImport;
1596
  int8_t changepass;
1597
  int8_t enable;
1598

1599
  int8_t negIpRanges;
1600
  int8_t negTimeRanges;
1601

1602
  int32_t sessionPerUser;
1603
  int32_t connectTime;
1604
  int32_t connectIdleTime;
1605
  int32_t callPerSession;
1606
  int32_t vnodePerCall;
1607
  int32_t failedLoginAttempts;
1608
  int32_t passwordLifeTime;
1609
  int32_t passwordReuseTime;
1610
  int32_t passwordReuseMax;
1611
  int32_t passwordLockTime;
1612
  int32_t passwordGraceTime;
1613
  int32_t inactiveAccountTime;
1614
  int32_t allowTokenNum;
1615

1616
  int32_t         numIpRanges;
1617
  SIpRange*       pIpDualRanges;
1618
  int32_t         numTimeRanges;
1619
  SDateTimeRange* pTimeRanges;
1620

1621
  int32_t sqlLen;
1622
  char*   sql;
1623
} SCreateUserReq;
1624

1625
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1626
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1627
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1628

1629
typedef struct {
1630
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1631
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1632
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1633
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1634
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1635
  int32_t sqlLen;
1636
  char*   sql;
1637
} SCreateEncryptAlgrReq;
1638

1639
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1640
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1641
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1642

1643
typedef struct {
1644
  int32_t dnodeId;
1645
  int64_t analVer;
1646
} SRetrieveAnalyticsAlgoReq;
1647

1648
typedef struct {
1649
  int64_t   ver;
1650
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1651
} SRetrieveAnalyticAlgoRsp;
1652

1653
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1654
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1655
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1656
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1657
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1658

1659
typedef struct {
1660
  int8_t alterType;
1661

1662
  int8_t isView;
1663

1664
  int8_t hasPassword;
1665
  int8_t hasTotpseed;
1666
  int8_t hasEnable;
1667
  int8_t hasSysinfo;
1668
  int8_t hasCreatedb;
1669
  int8_t hasChangepass;
1670
  int8_t hasSessionPerUser;
1671
  int8_t hasConnectTime;
1672
  int8_t hasConnectIdleTime;
1673
  int8_t hasCallPerSession;
1674
  int8_t hasVnodePerCall;
1675
  int8_t hasFailedLoginAttempts;
1676
  int8_t hasPasswordLifeTime;
1677
  int8_t hasPasswordReuseTime;
1678
  int8_t hasPasswordReuseMax;
1679
  int8_t hasPasswordLockTime;
1680
  int8_t hasPasswordGraceTime;
1681
  int8_t hasInactiveAccountTime;
1682
  int8_t hasAllowTokenNum;
1683

1684
  int8_t enable;
1685
  int8_t sysinfo;
1686
  int8_t createdb;
1687
  int8_t changepass;
1688

1689
  char   user[TSDB_USER_LEN];
1690
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1691
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1692
  int32_t sessionPerUser;
1693
  int32_t connectTime;
1694
  int32_t connectIdleTime;
1695
  int32_t callPerSession;
1696
  int32_t vnodePerCall;
1697
  int32_t failedLoginAttempts;
1698
  int32_t passwordLifeTime;
1699
  int32_t passwordReuseTime;
1700
  int32_t passwordReuseMax;
1701
  int32_t passwordLockTime;
1702
  int32_t passwordGraceTime;
1703
  int32_t inactiveAccountTime;
1704
  int32_t allowTokenNum;
1705

1706
  int32_t         numIpRanges;
1707
  int32_t         numTimeRanges;
1708
  int32_t         numDropIpRanges;
1709
  int32_t         numDropTimeRanges;
1710
  SIpRange*       pIpRanges;
1711
  SDateTimeRange* pTimeRanges;
1712
  SIpRange*       pDropIpRanges;
1713
  SDateTimeRange* pDropTimeRanges;
1714
  SPrivSet        privileges;
1715

1716
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1717
  char        tabName[TSDB_TABLE_NAME_LEN];
1718
  char*       tagCond;
1719
  int32_t     tagCondLen;
1720
  int32_t     sqlLen;
1721
  char*       sql;
1722
} SAlterUserReq;
1723

1724
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1725
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1726
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1727

1728
typedef struct {
1729
  char    name[TSDB_TOKEN_NAME_LEN];
1730
  char    user[TSDB_USER_LEN];
1731
  int8_t  enable;
1732
  int8_t  ignoreExists;
1733
  int32_t ttl;
1734
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1735
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1736

1737
  int32_t sqlLen;
1738
  char*   sql;
1739
} SCreateTokenReq;
1740

1741
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1742
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1743
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1744

1745
typedef struct {
1746
  char name[TSDB_TOKEN_NAME_LEN];
1747
  char user[TSDB_USER_LEN];
1748
  char token[TSDB_TOKEN_LEN];
1749
} SCreateTokenRsp;
1750

1751
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1752
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1753
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1754

1755
typedef struct {
1756
  char    name[TSDB_TOKEN_NAME_LEN];
1757

1758
  int8_t hasEnable;
1759
  int8_t hasTtl;
1760
  int8_t hasProvider;
1761
  int8_t hasExtraInfo;
1762

1763
  int8_t  enable;
1764
  int32_t ttl;
1765
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1766
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1767

1768
  int32_t     sqlLen;
1769
  char*       sql;
1770
} SAlterTokenReq;
1771

1772
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1773
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1774
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1775

1776
typedef struct {
1777
  char    name[TSDB_TOKEN_NAME_LEN];
1778
  int8_t  ignoreNotExists;
1779
  int32_t sqlLen;
1780
  char*   sql;
1781
} SDropTokenReq;
1782

1783
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1784
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1785
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1786

1787
typedef struct {
1788
  char    user[TSDB_USER_LEN];
1789
  int32_t sqlLen;
1790
  char*   sql;
1791
} SCreateTotpSecretReq;
1792

1793
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1794
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1795
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1796

1797
typedef struct {
1798
  char user[TSDB_USER_LEN];
1799
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1800
} SCreateTotpSecretRsp;
1801

1802
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1803
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1804

1805
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1806
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1807
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1808
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1809

1810
typedef struct {
1811
  char user[TSDB_USER_LEN];
1812
} SGetUserAuthReq;
1813

1814
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1815
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1816

1817
typedef struct {
1818
  int8_t  enabled;
1819
  int32_t expireTime;
1820
} STokenStatus;
1821

1822
typedef struct {
1823
  char    user[TSDB_USER_LEN];
1824
  int64_t userId;
1825
  int32_t version;
1826
  int32_t passVer;
1827
  int8_t  superAuth;
1828
  int8_t  sysInfo;
1829
  int8_t  enable;
1830
  int8_t  dropped;
1831
  union {
1832
    uint8_t flags;
1833
    struct {
1834
      uint8_t privLevel : 3;
1835
      uint8_t withInsertCond : 1;
1836
      uint8_t reserve : 4;
1837
    };
1838
  };
1839
  SPrivSet  sysPrivs;
1840
  SHashObj* objPrivs;
1841
  SHashObj* selectTbs;
1842
  SHashObj* insertTbs;
1843
  SHashObj* deleteTbs;
1844
  SHashObj* ownedDbs;
1845
  int64_t   whiteListVer;
1846

1847
  SUserSessCfg sessCfg;
1848
  int64_t      timeWhiteListVer;
1849
  SHashObj*    tokens;
1850
} SGetUserAuthRsp;
1851

1852
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1853
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1854
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1855

1856
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1857
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1858
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1859
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1860

1861
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1862
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1863
typedef struct {
1864
  int64_t ver;
1865
  char    user[TSDB_USER_LEN];
1866
  int32_t numOfRange;
1867
  union {
1868
    SIpV4Range* pIpRanges;
1869
    SIpRange*   pIpDualRanges;
1870
  };
1871
} SUpdateUserIpWhite;
1872

1873
typedef struct {
1874
  int64_t             ver;
1875
  int                 numOfUser;
1876
  SUpdateUserIpWhite* pUserIpWhite;
1877
} SUpdateIpWhite;
1878

1879
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1880
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1881
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1882
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1883

1884
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1885
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1886
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1887

1888

1889
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1890
// corresponding response struct is different.
1891
typedef struct {
1892
  int64_t ver;
1893
} SRetrieveWhiteListReq;
1894

1895
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1896
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1897

1898

1899
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1900
// corresponding response struct is different.
1901
typedef struct {
1902
  char user[TSDB_USER_LEN];
1903
} SGetUserWhiteListReq;
1904

1905
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1906
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1907

1908
typedef struct {
1909
  char    user[TSDB_USER_LEN];
1910
  int32_t numWhiteLists;
1911
  union {
1912
    SIpV4Range* pWhiteLists;
1913
    SIpRange*   pWhiteListsDual;
1914
  };
1915
} SGetUserIpWhiteListRsp;
1916

1917
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1918
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1919
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1920
void    tIpRangeSetDefaultMask(SIpRange* range);
1921

1922
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1923
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1924
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1925

1926
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1927
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1928
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1929

1930
typedef struct {
1931
  int64_t ver;
1932
  char    user[TSDB_USER_LEN];
1933
  int32_t numWhiteLists;
1934
  SDateTimeWhiteListItem* pWhiteLists;
1935
} SUserDateTimeWhiteList;
1936

1937

1938
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1939
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1940
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1941
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1942

1943
typedef struct {
1944
  int64_t             ver;
1945
  int                 numOfUser;
1946
  SUserDateTimeWhiteList *pUsers;
1947
} SRetrieveDateTimeWhiteListRsp;
1948

1949
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1950
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1951
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1952
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1953

1954
/*
1955
 * for client side struct, only column id, type, bytes are necessary
1956
 * But for data in vnode side, we need all the following information.
1957
 */
1958
typedef struct {
1959
  union {
1960
    col_id_t colId;
1961
    int16_t  slotId;
1962
  };
1963

1964
  uint8_t precision;
1965
  uint8_t scale;
1966
  int32_t bytes;
1967
  int8_t  type;
1968
  uint8_t pk;
1969
  bool    noData;
1970
} SColumnInfo;
1971

1972
typedef struct STimeWindow {
1973
  TSKEY skey;
1974
  TSKEY ekey;
1975
} STimeWindow;
1976

1977
typedef struct SQueryHint {
1978
  bool batchScan;
1979
} SQueryHint;
1980

1981
typedef struct {
1982
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1983
  int32_t tsLen;          // total length of ts comp block
1984
  int32_t tsNumOfBlocks;  // ts comp block numbers
1985
  int32_t tsOrder;        // ts comp block order
1986
} STsBufInfo;
1987

1988
typedef struct {
1989
  void*       timezone;
1990
  char        intervalUnit;
1991
  char        slidingUnit;
1992
  char        offsetUnit;
1993
  int8_t      precision;
1994
  int64_t     interval;
1995
  int64_t     sliding;
1996
  int64_t     offset;
1997
  STimeWindow timeRange;
1998
} SInterval;
1999

2000
typedef struct STbVerInfo {
2001
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2002
  int32_t sversion;
2003
  int32_t tversion;
2004
  int32_t rversion;  // virtual table's column ref's version
2005
} STbVerInfo;
2006

2007
typedef struct {
2008
  int32_t code;
2009
  int64_t affectedRows;
2010
  SArray* tbVerInfo;  // STbVerInfo
2011
} SQueryTableRsp;
2012

2013
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2014

2015
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2016

2017
typedef struct {
2018
  SMsgHead header;
2019
  char     dbFName[TSDB_DB_FNAME_LEN];
2020
  char     tbName[TSDB_TABLE_NAME_LEN];
2021
} STableCfgReq;
2022

2023
typedef struct {
2024
  char        tbName[TSDB_TABLE_NAME_LEN];
2025
  char        stbName[TSDB_TABLE_NAME_LEN];
2026
  char        dbFName[TSDB_DB_FNAME_LEN];
2027
  int32_t     numOfTags;
2028
  int32_t     numOfColumns;
2029
  int8_t      tableType;
2030
  int64_t     delay1;
2031
  int64_t     delay2;
2032
  int64_t     watermark1;
2033
  int64_t     watermark2;
2034
  int32_t     ttl;
2035
  int32_t     keep;
2036
  int64_t     ownerId;
2037
  SArray*     pFuncs;
2038
  int32_t     commentLen;
2039
  char*       pComment;
2040
  SSchema*    pSchemas;
2041
  int32_t     tagsLen;
2042
  char*       pTags;
2043
  SSchemaExt* pSchemaExt;
2044
  union {
2045
    uint8_t flag;
2046
    struct {
2047
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2048
      uint8_t isAudit : 1;
2049
      uint8_t reserve : 6;
2050
    };
2051
  };
2052
  SColRef* pColRefs;
2053
} STableCfg;
2054

2055
typedef STableCfg STableCfgRsp;
2056

2057
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2058
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2059

2060
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2061
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2062
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2063

2064
typedef struct {
2065
  SMsgHead header;
2066
  tb_uid_t suid;
2067
} SVSubTablesReq;
2068

2069
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2070
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2071

2072
typedef struct {
2073
  int32_t vgId;
2074
  SArray* pTables;  // SArray<SVCTableRefCols*>
2075
} SVSubTablesRsp;
2076

2077
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2078
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2079
void    tDestroySVSubTablesRsp(void* rsp);
2080

2081
typedef struct {
2082
  SMsgHead header;
2083
  tb_uid_t suid;
2084
} SVStbRefDbsReq;
2085

2086
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2087
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2088

2089
typedef struct {
2090
  int32_t vgId;
2091
  SArray* pDbs;  // SArray<char* (db name)>
2092
} SVStbRefDbsRsp;
2093

2094
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2095
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2096
void    tDestroySVStbRefDbsRsp(void* rsp);
2097

2098
typedef struct {
2099
  char    db[TSDB_DB_FNAME_LEN];
2100
  int32_t numOfVgroups;
2101
  int32_t numOfStables;  // single_stable
2102
  int32_t buffer;        // MB
2103
  int32_t pageSize;
2104
  int32_t pages;
2105
  int32_t cacheLastSize;
2106
  int32_t daysPerFile;
2107
  int32_t daysToKeep0;
2108
  int32_t daysToKeep1;
2109
  int32_t daysToKeep2;
2110
  int32_t keepTimeOffset;
2111
  int32_t minRows;
2112
  int32_t maxRows;
2113
  int32_t walFsyncPeriod;
2114
  int8_t  walLevel;
2115
  int8_t  precision;  // time resolution
2116
  int8_t  compression;
2117
  int8_t  replications;
2118
  int8_t  strict;
2119
  int8_t  cacheLast;
2120
  int8_t  schemaless;
2121
  int8_t  ignoreExist;
2122
  int32_t numOfRetensions;
2123
  SArray* pRetensions;  // SRetention
2124
  int32_t walRetentionPeriod;
2125
  int64_t walRetentionSize;
2126
  int32_t walRollPeriod;
2127
  int64_t walSegmentSize;
2128
  int32_t sstTrigger;
2129
  int16_t hashPrefix;
2130
  int16_t hashSuffix;
2131
  int32_t ssChunkSize;
2132
  int32_t ssKeepLocal;
2133
  int8_t  ssCompact;
2134
  int32_t tsdbPageSize;
2135
  int32_t sqlLen;
2136
  char*   sql;
2137
  int8_t  withArbitrator;
2138
  int8_t  encryptAlgorithm;
2139
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2140
  // 1. add auto-compact parameters
2141
  int32_t compactInterval;    // minutes
2142
  int32_t compactStartTime;   // minutes
2143
  int32_t compactEndTime;     // minutes
2144
  int8_t  compactTimeOffset;  // hour
2145
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2146
  int8_t  isAudit;
2147
  int8_t  allowDrop;
2148
} SCreateDbReq;
2149

2150
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2151
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2152
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2153

2154
typedef struct {
2155
  char    db[TSDB_DB_FNAME_LEN];
2156
  int32_t buffer;
2157
  int32_t pageSize;
2158
  int32_t pages;
2159
  int32_t cacheLastSize;
2160
  int32_t daysPerFile;
2161
  int32_t daysToKeep0;
2162
  int32_t daysToKeep1;
2163
  int32_t daysToKeep2;
2164
  int32_t keepTimeOffset;
2165
  int32_t walFsyncPeriod;
2166
  int8_t  walLevel;
2167
  int8_t  strict;
2168
  int8_t  cacheLast;
2169
  int8_t  replications;
2170
  int32_t sstTrigger;
2171
  int32_t minRows;
2172
  int32_t walRetentionPeriod;
2173
  int32_t walRetentionSize;
2174
  int32_t ssKeepLocal;
2175
  int8_t  ssCompact;
2176
  int32_t sqlLen;
2177
  char*   sql;
2178
  int8_t  withArbitrator;
2179
  // 1. add auto-compact parameters
2180
  int32_t compactInterval;
2181
  int32_t compactStartTime;
2182
  int32_t compactEndTime;
2183
  int8_t  compactTimeOffset;
2184
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2185
  int8_t  isAudit;
2186
  int8_t  allowDrop;
2187
} SAlterDbReq;
2188

2189
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2190
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2191
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2192

2193
typedef struct {
2194
  char    db[TSDB_DB_FNAME_LEN];
2195
  int8_t  ignoreNotExists;
2196
  int8_t  force;
2197
  int32_t sqlLen;
2198
  char*   sql;
2199
} SDropDbReq;
2200

2201
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2202
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2203
void    tFreeSDropDbReq(SDropDbReq* pReq);
2204

2205
typedef struct {
2206
  char    db[TSDB_DB_FNAME_LEN];
2207
  int64_t uid;
2208
} SDropDbRsp;
2209

2210
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2211
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2212

2213
typedef struct {
2214
  char    name[TSDB_MOUNT_NAME_LEN];
2215
  int64_t uid;
2216
} SDropMountRsp;
2217

2218
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2219
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2220

2221
typedef struct {
2222
  char    db[TSDB_DB_FNAME_LEN];
2223
  int64_t dbId;
2224
  int32_t vgVersion;
2225
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2226
  int64_t stateTs;     // ms
2227
} SUseDbReq;
2228

2229
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2230
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2231

2232
typedef struct {
2233
  char    db[TSDB_DB_FNAME_LEN];
2234
  int64_t uid;
2235
  int32_t vgVersion;
2236
  int32_t vgNum;
2237
  int16_t hashPrefix;
2238
  int16_t hashSuffix;
2239
  int8_t  hashMethod;
2240
  union {
2241
    uint8_t flags;
2242
    struct {
2243
      uint8_t isMount : 1;  // TS-5868
2244
      uint8_t padding : 7;
2245
    };
2246
  };
2247
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2248
  int32_t errCode;
2249
  int64_t stateTs;  // ms
2250
} SUseDbRsp;
2251

2252
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2253
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2254
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2255
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2256
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2257

2258
typedef struct {
2259
  char db[TSDB_DB_FNAME_LEN];
2260
} SDbCfgReq;
2261

2262
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2263
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2264

2265
typedef struct {
2266
  char db[TSDB_DB_FNAME_LEN];
2267
} SSsMigrateDbReq;
2268

2269
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2270
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2271

2272
typedef struct {
2273
  int32_t ssMigrateId;
2274
  bool    bAccepted;
2275
} SSsMigrateDbRsp;
2276

2277
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2278
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2279

2280
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2281
typedef struct {
2282
  int32_t ssMigrateId;
2283
} SListSsMigrateFileSetsReq;
2284

2285
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2286
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2287

2288
typedef struct {
2289
  int32_t ssMigrateId;
2290
  int32_t vgId;       // vgroup id
2291
  SArray* pFileSets;  // SArray<int32_t>
2292
} SListSsMigrateFileSetsRsp;
2293

2294
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2295
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2296
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2297

2298
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2299
typedef struct {
2300
  int32_t ssMigrateId;
2301
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2302
  int32_t fid;
2303
  int64_t startTimeSec;
2304
} SSsMigrateFileSetReq;
2305

2306
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2307
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2308

2309
typedef struct {
2310
  int32_t ssMigrateId;
2311
  int32_t nodeId;  // node id of the leader vnode
2312
  int32_t vgId;
2313
  int32_t fid;
2314
} SSsMigrateFileSetRsp;
2315

2316
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2317
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2318

2319
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2320
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2321
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2322
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2323
#define SSMIGRATE_FILESET_STATE_FAILED      4
2324

2325
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2326
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2327
// while as a request, the 'state' field is not used.
2328
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2329
typedef struct {
2330
  int32_t ssMigrateId;  // ss migrate id
2331
  int32_t nodeId;       // node id of the leader vnode
2332
  int32_t vgId;         // vgroup id
2333
  int32_t fid;          // file set id
2334
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2335
} SSsMigrateProgress;
2336

2337
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2338
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2339

2340
// Request for TDMT_MND_KILL_SSMIGRATE
2341
typedef struct {
2342
  int32_t ssMigrateId;
2343
  int32_t sqlLen;
2344
  char*   sql;
2345
} SKillSsMigrateReq;
2346

2347
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2348
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2349
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2350

2351
// Request for TDMT_VND_KILL_SSMIGRATE
2352
typedef struct {
2353
  int32_t ssMigrateId;
2354
} SVnodeKillSsMigrateReq;
2355

2356
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2357
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2358

2359
typedef struct {
2360
  int32_t vgId;
2361
  int64_t keepVersion;
2362
} SMndSetVgroupKeepVersionReq;
2363

2364
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2365
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2366

2367
typedef struct {
2368
  int32_t timestampSec;
2369
  int32_t ttlDropMaxCount;
2370
  int32_t nUids;
2371
  SArray* pTbUids;
2372
} SVDropTtlTableReq;
2373

2374
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2375
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2376

2377
typedef struct {
2378
  char    db[TSDB_DB_FNAME_LEN];
2379
  int64_t dbId;
2380
  int64_t ownerId;
2381
  int32_t cfgVersion;
2382
  int32_t numOfVgroups;
2383
  int32_t numOfStables;
2384
  int32_t buffer;
2385
  int32_t cacheSize;
2386
  int32_t pageSize;
2387
  int32_t pages;
2388
  int32_t daysPerFile;
2389
  int32_t daysToKeep0;
2390
  int32_t daysToKeep1;
2391
  int32_t daysToKeep2;
2392
  int32_t keepTimeOffset;
2393
  int32_t minRows;
2394
  int32_t maxRows;
2395
  int32_t walFsyncPeriod;
2396
  int16_t hashPrefix;
2397
  int16_t hashSuffix;
2398
  int8_t  hashMethod;
2399
  int8_t  walLevel;
2400
  int8_t  precision;
2401
  int8_t  compression;
2402
  int8_t  replications;
2403
  int8_t  strict;
2404
  int8_t  cacheLast;
2405
  int8_t  encryptAlgr;
2406
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2407
  int32_t ssChunkSize;
2408
  int32_t ssKeepLocal;
2409
  int8_t  ssCompact;
2410
  union {
2411
    uint8_t flags;
2412
    struct {
2413
      uint8_t isMount : 1;    // TS-5868
2414
      uint8_t allowDrop : 1;  // TS-7232
2415
      uint8_t padding : 6;
2416
    };
2417
  };
2418
  int8_t  compactTimeOffset;
2419
  int32_t compactInterval;
2420
  int32_t compactStartTime;
2421
  int32_t compactEndTime;
2422
  int32_t tsdbPageSize;
2423
  int32_t walRetentionPeriod;
2424
  int32_t walRollPeriod;
2425
  int64_t walRetentionSize;
2426
  int64_t walSegmentSize;
2427
  int32_t numOfRetensions;
2428
  SArray* pRetensions;
2429
  int8_t  schemaless;
2430
  int16_t sstTrigger;
2431
  int8_t  withArbitrator;
2432
  int8_t  isAudit;
2433
} SDbCfgRsp;
2434

2435
typedef SDbCfgRsp SDbCfgInfo;
2436

2437
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2438
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2439
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2440
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2441
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2442

2443
typedef struct {
2444
  int32_t rowNum;
2445
} SQnodeListReq;
2446

2447
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2448
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2449

2450
typedef struct {
2451
  int32_t rowNum;
2452
} SDnodeListReq;
2453

2454
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2455

2456
typedef struct {
2457
  int32_t useless;  // useless
2458
} SServerVerReq;
2459

2460
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2461
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2462

2463
typedef struct {
2464
  char ver[TSDB_VERSION_LEN];
2465
} SServerVerRsp;
2466

2467
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2468
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2469

2470
typedef struct SQueryNodeAddr {
2471
  int32_t nodeId;  // vgId or qnodeId
2472
  SEpSet  epSet;
2473
} SQueryNodeAddr;
2474

2475
typedef struct {
2476
  SQueryNodeAddr addr;
2477
  uint64_t       load;
2478
} SQueryNodeLoad;
2479

2480
typedef struct {
2481
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2482
} SQnodeListRsp;
2483

2484
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2485
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2486
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2487

2488

2489
typedef struct SDownstreamSourceNode {
2490
  ENodeType      type;
2491
  SQueryNodeAddr addr;
2492
  uint64_t       clientId;
2493
  uint64_t       taskId;
2494
  uint64_t       sId;
2495
  uint64_t       srcTaskId;
2496
  int32_t        execId;
2497
  int32_t        fetchMsgType;
2498
  bool           localExec;
2499
} SDownstreamSourceNode;
2500

2501

2502

2503
typedef struct SDNodeAddr {
2504
  int32_t nodeId;  // dnodeId
2505
  SEpSet  epSet;
2506
} SDNodeAddr;
2507

2508
typedef struct {
2509
  SArray* dnodeList;  // SArray<SDNodeAddr>
2510
} SDnodeListRsp;
2511

2512
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2513
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2514
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2515

2516
typedef struct {
2517
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2518
} STableTSMAInfoRsp;
2519

2520
typedef struct {
2521
  SUseDbRsp*         useDbRsp;
2522
  SDbCfgRsp*         cfgRsp;
2523
  STableTSMAInfoRsp* pTsmaRsp;
2524
  int32_t            dbTsmaVersion;
2525
  char               db[TSDB_DB_FNAME_LEN];
2526
  int64_t            dbId;
2527
} SDbHbRsp;
2528

2529
typedef struct {
2530
  SArray* pArray;  // Array of SDbHbRsp
2531
} SDbHbBatchRsp;
2532

2533
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2534
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2535
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2536

2537
typedef struct {
2538
  SArray* pArray;  // Array of SGetUserAuthRsp
2539
} SUserAuthBatchRsp;
2540

2541
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2542
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2543
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2544

2545
typedef struct {
2546
  char        db[TSDB_DB_FNAME_LEN];
2547
  STimeWindow timeRange;
2548
  int32_t     sqlLen;
2549
  char*       sql;
2550
  SArray*     vgroupIds;
2551
  int32_t     compactId;
2552
  int8_t      metaOnly;
2553
  int8_t      force;
2554
} SCompactDbReq;
2555

2556
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2557
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2558
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2559

2560
typedef struct {
2561
  union {
2562
    int32_t compactId;
2563
    int32_t id;
2564
  };
2565
  int8_t bAccepted;
2566
} SCompactDbRsp;
2567

2568
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2569
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2570

2571
typedef struct {
2572
  union {
2573
    int32_t compactId;
2574
    int32_t id;
2575
  };
2576
  int32_t sqlLen;
2577
  char*   sql;
2578
} SKillCompactReq;
2579

2580
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2581
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2582
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2583

2584
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2585
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2586

2587
typedef struct {
2588
  char    name[TSDB_FUNC_NAME_LEN];
2589
  int8_t  igExists;
2590
  int8_t  funcType;
2591
  int8_t  scriptType;
2592
  int8_t  outputType;
2593
  int32_t outputLen;
2594
  int32_t bufSize;
2595
  int32_t codeLen;
2596
  int64_t signature;
2597
  char*   pComment;
2598
  char*   pCode;
2599
  int8_t  orReplace;
2600
} SCreateFuncReq;
2601

2602
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2603
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2604
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2605

2606
typedef struct {
2607
  char   name[TSDB_FUNC_NAME_LEN];
2608
  int8_t igNotExists;
2609
} SDropFuncReq;
2610

2611
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2612
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2613

2614
typedef struct {
2615
  int32_t numOfFuncs;
2616
  bool    ignoreCodeComment;
2617
  SArray* pFuncNames;
2618
} SRetrieveFuncReq;
2619

2620
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2621
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2622
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2623

2624
typedef struct {
2625
  char    name[TSDB_FUNC_NAME_LEN];
2626
  int8_t  funcType;
2627
  int8_t  scriptType;
2628
  int8_t  outputType;
2629
  int32_t outputLen;
2630
  int32_t bufSize;
2631
  int64_t signature;
2632
  int32_t commentSize;
2633
  int32_t codeSize;
2634
  char*   pComment;
2635
  char*   pCode;
2636
} SFuncInfo;
2637

2638
typedef struct {
2639
  int32_t funcVersion;
2640
  int64_t funcCreatedTime;
2641
} SFuncExtraInfo;
2642

2643
typedef struct {
2644
  int32_t numOfFuncs;
2645
  SArray* pFuncInfos;
2646
  SArray* pFuncExtraInfos;
2647
} SRetrieveFuncRsp;
2648

2649
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2650
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2651
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2652
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2653

2654
typedef struct {
2655
  int32_t       statusInterval;
2656
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2657
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2658
  char          locale[TD_LOCALE_LEN];      // tsLocale
2659
  char          charset[TD_LOCALE_LEN];     // tsCharset
2660
  int8_t        ttlChangeOnWrite;
2661
  int8_t        enableWhiteList;
2662
  int8_t        encryptionKeyStat;
2663
  uint32_t      encryptionKeyChksum;
2664
  SMonitorParas monitorParas;
2665
  int32_t       statusIntervalMs;
2666
} SClusterCfg;
2667

2668
typedef struct {
2669
  int32_t openVnodes;
2670
  int32_t dropVnodes;
2671
  int32_t totalVnodes;
2672
  int32_t masterNum;
2673
  int64_t numOfSelectReqs;
2674
  int64_t numOfInsertReqs;
2675
  int64_t numOfInsertSuccessReqs;
2676
  int64_t numOfBatchInsertReqs;
2677
  int64_t numOfBatchInsertSuccessReqs;
2678
  int64_t errors;
2679
} SVnodesStat;
2680

2681
typedef struct {
2682
  int32_t vgId;
2683
  int8_t  syncState;
2684
  int8_t  syncRestore;
2685
  int64_t syncTerm;
2686
  int64_t roleTimeMs;
2687
  int64_t startTimeMs;
2688
  int8_t  syncCanRead;
2689
  int64_t cacheUsage;
2690
  int64_t numOfTables;
2691
  int64_t numOfTimeSeries;
2692
  int64_t totalStorage;
2693
  int64_t compStorage;
2694
  int64_t pointsWritten;
2695
  int64_t numOfSelectReqs;
2696
  int64_t numOfInsertReqs;
2697
  int64_t numOfInsertSuccessReqs;
2698
  int64_t numOfBatchInsertReqs;
2699
  int64_t numOfBatchInsertSuccessReqs;
2700
  int32_t numOfCachedTables;
2701
  int32_t learnerProgress;  // use one reservered
2702
  int64_t syncAppliedIndex;
2703
  int64_t syncCommitIndex;
2704
  int64_t bufferSegmentUsed;
2705
  int64_t bufferSegmentSize;
2706
  int32_t snapSeq;
2707
  int64_t syncTotalIndex;
2708
} SVnodeLoad;
2709

2710
typedef struct {
2711
  int64_t total_requests;
2712
  int64_t total_rows;
2713
  int64_t total_bytes;
2714
  double  write_size;
2715
  double  cache_hit_ratio;
2716
  int64_t rpc_queue_wait;
2717
  int64_t preprocess_time;
2718

2719
  int64_t memory_table_size;
2720
  int64_t commit_count;
2721
  int64_t merge_count;
2722
  double  commit_time;
2723
  double  merge_time;
2724
  int64_t block_commit_time;
2725
  int64_t memtable_wait_time;
2726
} SVnodeMetrics;
2727

2728
typedef struct {
2729
  int32_t     vgId;
2730
  int64_t     numOfTables;
2731
  int64_t     memSize;
2732
  int64_t     l1Size;
2733
  int64_t     l2Size;
2734
  int64_t     l3Size;
2735
  int64_t     cacheSize;
2736
  int64_t     walSize;
2737
  int64_t     metaSize;
2738
  int64_t     rawDataSize;
2739
  int64_t     ssSize;
2740
  const char* dbname;
2741
  int8_t      estimateRawData;
2742
} SDbSizeStatisInfo;
2743

2744
typedef struct {
2745
  int32_t vgId;
2746
  int64_t nTimeSeries;
2747
} SVnodeLoadLite;
2748

2749
typedef struct {
2750
  int8_t  syncState;
2751
  int64_t syncTerm;
2752
  int8_t  syncRestore;
2753
  int64_t roleTimeMs;
2754
} SMnodeLoad;
2755

2756
typedef struct {
2757
  int32_t dnodeId;
2758
  int64_t numOfProcessedQuery;
2759
  int64_t numOfProcessedCQuery;
2760
  int64_t numOfProcessedFetch;
2761
  int64_t numOfProcessedDrop;
2762
  int64_t numOfProcessedNotify;
2763
  int64_t numOfProcessedHb;
2764
  int64_t numOfProcessedDelete;
2765
  int64_t cacheDataSize;
2766
  int64_t numOfQueryInQueue;
2767
  int64_t numOfFetchInQueue;
2768
  int64_t timeInQueryQueue;
2769
  int64_t timeInFetchQueue;
2770
} SQnodeLoad;
2771

2772
typedef struct {
2773
  int32_t     sver;      // software version
2774
  int64_t     dnodeVer;  // dnode table version in sdb
2775
  int32_t     dnodeId;
2776
  int64_t     clusterId;
2777
  int64_t     rebootTime;
2778
  int64_t     updateTime;
2779
  float       numOfCores;
2780
  int32_t     numOfSupportVnodes;
2781
  int32_t     numOfDiskCfg;
2782
  int64_t     memTotal;
2783
  int64_t     memAvail;
2784
  char        dnodeEp[TSDB_EP_LEN];
2785
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2786
  SMnodeLoad  mload;
2787
  SQnodeLoad  qload;
2788
  SClusterCfg clusterCfg;
2789
  SArray*     pVloads;  // array of SVnodeLoad
2790
  int32_t     statusSeq;
2791
  int64_t     ipWhiteVer;
2792
  int64_t     timeWhiteVer;
2793
  int64_t     analVer;
2794
  int64_t     timestamp;
2795
  char        auditDB[TSDB_DB_FNAME_LEN];
2796
  char        auditToken[TSDB_TOKEN_LEN];
2797
} SStatusReq;
2798

2799
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2800
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2801
void    tFreeSStatusReq(SStatusReq* pReq);
2802

2803
typedef struct {
2804
  int32_t forceReadConfig;
2805
  int32_t cver;
2806
  SArray* array;
2807
} SConfigReq;
2808

2809
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2810
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2811
void    tFreeSConfigReq(SConfigReq* pReq);
2812

2813
typedef struct {
2814
  int32_t dnodeId;
2815
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2816
} SDnodeInfoReq;
2817

2818
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2819
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2820

2821
typedef enum {
2822
  MONITOR_TYPE_COUNTER = 0,
2823
  MONITOR_TYPE_SLOW_LOG = 1,
2824
} MONITOR_TYPE;
2825

2826
typedef struct {
2827
  int32_t      contLen;
2828
  char*        pCont;
2829
  MONITOR_TYPE type;
2830
} SStatisReq;
2831

2832
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2833
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2834
void    tFreeSStatisReq(SStatisReq* pReq);
2835

2836
typedef struct {
2837
  char    db[TSDB_DB_FNAME_LEN];
2838
  char    table[TSDB_TABLE_NAME_LEN];
2839
  char    operation[AUDIT_OPERATION_LEN];
2840
  int32_t sqlLen;
2841
  char*   pSql;
2842
  double  duration;
2843
  int64_t affectedRows;
2844
} SAuditReq;
2845
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2846
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2847
void    tFreeSAuditReq(SAuditReq* pReq);
2848

2849
typedef struct {
2850
  SArray* auditArr;
2851
} SBatchAuditReq;
2852
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2853
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2854
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2855

2856
typedef struct {
2857
  int32_t dnodeId;
2858
  int64_t clusterId;
2859
  SArray* pVloads;
2860
} SNotifyReq;
2861

2862
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2863
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2864
void    tFreeSNotifyReq(SNotifyReq* pReq);
2865

2866
typedef struct {
2867
  int32_t dnodeId;
2868
  int64_t clusterId;
2869
} SDnodeCfg;
2870

2871
typedef struct {
2872
  int32_t id;
2873
  int8_t  isMnode;
2874
  SEp     ep;
2875
} SDnodeEp;
2876

2877
typedef struct {
2878
  int32_t id;
2879
  int8_t  isMnode;
2880
  int8_t  offlineReason;
2881
  SEp     ep;
2882
  char    active[TSDB_ACTIVE_KEY_LEN];
2883
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2884
} SDnodeInfo;
2885

2886
typedef struct {
2887
  int64_t   dnodeVer;
2888
  SDnodeCfg dnodeCfg;
2889
  SArray*   pDnodeEps;  // Array of SDnodeEp
2890
  int32_t   statusSeq;
2891
  int64_t   ipWhiteVer;
2892
  int64_t   analVer;
2893
  int64_t   timeWhiteVer;
2894
  char      auditDB[TSDB_DB_FNAME_LEN];
2895
  char      auditToken[TSDB_TOKEN_LEN];
2896
} SStatusRsp;
2897

2898
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2899
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2900
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2901

2902
typedef struct {
2903
  int32_t forceReadConfig;
2904
  int32_t isConifgVerified;
2905
  int32_t isVersionVerified;
2906
  int32_t cver;
2907
  SArray* array;
2908
} SConfigRsp;
2909

2910
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2911
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2912
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2913

2914
typedef struct {
2915
  int32_t dnodeId;
2916
  int32_t keyVersion;  // Local key version
2917
} SKeySyncReq;
2918

2919
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2920
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2921

2922
typedef struct {
2923
  int32_t keyVersion;        // mnode's key version
2924
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2925
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2926
  char    svrKey[129];       // Server key (if needUpdate)
2927
  char    dbKey[129];        // Database key (if needUpdate)
2928
  char    cfgKey[129];       // Config key (if needUpdate)
2929
  char    metaKey[129];      // Metadata key (if needUpdate)
2930
  char    dataKey[129];      // Data key (if needUpdate)
2931
  int32_t algorithm;         // Encryption algorithm for master keys
2932
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2933
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2934
  int64_t createTime;        // Key creation time
2935
  int64_t svrKeyUpdateTime;  // Server key update time
2936
  int64_t dbKeyUpdateTime;   // Database key update time
2937
} SKeySyncRsp;
2938

2939
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2940
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2941

2942
typedef struct {
2943
  int32_t reserved;
2944
} SMTimerReq;
2945

2946
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2947
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2948

2949
typedef struct SOrphanTask {
2950
  int64_t streamId;
2951
  int32_t taskId;
2952
  int32_t nodeId;
2953
} SOrphanTask;
2954

2955
typedef struct SMStreamDropOrphanMsg {
2956
  SArray* pList;  // SArray<SOrphanTask>
2957
} SMStreamDropOrphanMsg;
2958

2959
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2960
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2961
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2962

2963
typedef struct {
2964
  int32_t  id;
2965
  uint16_t port;                 // node sync Port
2966
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2967
} SReplica;
2968

2969
typedef struct {
2970
  int32_t  vgId;
2971
  char     db[TSDB_DB_FNAME_LEN];
2972
  int64_t  dbUid;
2973
  int32_t  vgVersion;
2974
  int32_t  numOfStables;
2975
  int32_t  buffer;
2976
  int32_t  pageSize;
2977
  int32_t  pages;
2978
  int32_t  cacheLastSize;
2979
  int32_t  daysPerFile;
2980
  int32_t  daysToKeep0;
2981
  int32_t  daysToKeep1;
2982
  int32_t  daysToKeep2;
2983
  int32_t  keepTimeOffset;
2984
  int32_t  minRows;
2985
  int32_t  maxRows;
2986
  int32_t  walFsyncPeriod;
2987
  uint32_t hashBegin;
2988
  uint32_t hashEnd;
2989
  int8_t   hashMethod;
2990
  int8_t   walLevel;
2991
  int8_t   precision;
2992
  int8_t   compression;
2993
  int8_t   strict;
2994
  int8_t   cacheLast;
2995
  int8_t   isTsma;
2996
  int8_t   replica;
2997
  int8_t   selfIndex;
2998
  SReplica replicas[TSDB_MAX_REPLICA];
2999
  int32_t  numOfRetensions;
3000
  SArray*  pRetensions;  // SRetention
3001
  void*    pTsma;
3002
  int32_t  walRetentionPeriod;
3003
  int64_t  walRetentionSize;
3004
  int32_t  walRollPeriod;
3005
  int64_t  walSegmentSize;
3006
  int16_t  sstTrigger;
3007
  int16_t  hashPrefix;
3008
  int16_t  hashSuffix;
3009
  int32_t  tsdbPageSize;
3010
  int32_t  ssChunkSize;
3011
  int32_t  ssKeepLocal;
3012
  int8_t   ssCompact;
3013
  int64_t  reserved[6];
3014
  int8_t   learnerReplica;
3015
  int8_t   learnerSelfIndex;
3016
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3017
  int32_t  changeVersion;
3018
  int8_t   encryptAlgorithm;
3019
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3020
  union {
3021
    uint8_t flags;
3022
    struct {
3023
      uint8_t isAudit : 1;
3024
      uint8_t allowDrop : 1;
3025
      uint8_t padding : 6;
3026
    };
3027
  };
3028
} SCreateVnodeReq;
3029

3030
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3031
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3032
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3033

3034
typedef struct {
3035
  union {
3036
    int32_t compactId;
3037
    int32_t id;
3038
  };
3039
  int32_t vgId;
3040
  int32_t dnodeId;
3041
} SQueryCompactProgressReq;
3042

3043
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3044
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3045

3046
typedef struct {
3047
  union {
3048
    int32_t compactId;
3049
    int32_t id;
3050
  };
3051
  int32_t vgId;
3052
  int32_t dnodeId;
3053
  int32_t numberFileset;
3054
  int32_t finished;
3055
  int32_t progress;
3056
  int64_t remainingTime;
3057
} SQueryCompactProgressRsp;
3058

3059
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3060
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3061

3062
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3063
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3064

3065
typedef struct {
3066
  int32_t vgId;
3067
  int32_t dnodeId;
3068
  int64_t dbUid;
3069
  char    db[TSDB_DB_FNAME_LEN];
3070
  int64_t reserved[8];
3071
} SDropVnodeReq;
3072

3073
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3074
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3075

3076
typedef struct {
3077
  char    colName[TSDB_COL_NAME_LEN];
3078
  char    stb[TSDB_TABLE_FNAME_LEN];
3079
  int64_t stbUid;
3080
  int64_t dbUid;
3081
  int64_t reserved[8];
3082
} SDropIndexReq;
3083

3084
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3085
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3086

3087
typedef struct {
3088
  int64_t dbUid;
3089
  char    db[TSDB_DB_FNAME_LEN];
3090
  union {
3091
    int64_t compactStartTime;
3092
    int64_t startTime;
3093
  };
3094

3095
  STimeWindow tw;
3096
  union {
3097
    int32_t compactId;
3098
    int32_t id;
3099
  };
3100
  int8_t metaOnly;
3101
  union {
3102
    uint16_t flags;
3103
    struct {
3104
      uint16_t optrType : 3;     // ETsdbOpType
3105
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3106
      uint16_t reserved : 12;
3107
    };
3108
  };
3109
  int8_t force;  // force compact
3110
} SCompactVnodeReq;
3111

3112
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3113
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3114

3115
typedef struct {
3116
  union {
3117
    int32_t compactId;
3118
    int32_t taskId;
3119
  };
3120
  int32_t vgId;
3121
  int32_t dnodeId;
3122
} SVKillCompactReq;
3123

3124
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3125
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3126

3127
typedef SVKillCompactReq SVKillRetentionReq;
3128

3129
typedef struct {
3130
  char        db[TSDB_DB_FNAME_LEN];
3131
  int32_t     maxSpeed;
3132
  int32_t     sqlLen;
3133
  char*       sql;
3134
  SArray*     vgroupIds;
3135
  STimeWindow tw;  // unit is second
3136
  union {
3137
    uint32_t flags;
3138
    struct {
3139
      uint32_t optrType : 3;     // ETsdbOpType
3140
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3141
      uint32_t reserved : 28;
3142
    };
3143
  };
3144
} STrimDbReq;
3145

3146
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3147
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3148
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3149

3150
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3151

3152
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3153
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3154

3155
typedef struct {
3156
  int32_t vgVersion;
3157
  int32_t buffer;
3158
  int32_t pageSize;
3159
  int32_t pages;
3160
  int32_t cacheLastSize;
3161
  int32_t daysPerFile;
3162
  int32_t daysToKeep0;
3163
  int32_t daysToKeep1;
3164
  int32_t daysToKeep2;
3165
  int32_t keepTimeOffset;
3166
  int32_t walFsyncPeriod;
3167
  int8_t  walLevel;
3168
  int8_t  strict;
3169
  int8_t  cacheLast;
3170
  int64_t reserved[7];
3171
  // 1st modification
3172
  int16_t sttTrigger;
3173
  int32_t minRows;
3174
  // 2nd modification
3175
  int32_t walRetentionPeriod;
3176
  int32_t walRetentionSize;
3177
  int32_t ssKeepLocal;
3178
  int8_t  ssCompact;
3179
  int8_t  allowDrop;
3180
} SAlterVnodeConfigReq;
3181

3182
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3183
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3184

3185
typedef struct {
3186
  int32_t  vgId;
3187
  int8_t   strict;
3188
  int8_t   selfIndex;
3189
  int8_t   replica;
3190
  SReplica replicas[TSDB_MAX_REPLICA];
3191
  int64_t  reserved[8];
3192
  int8_t   learnerSelfIndex;
3193
  int8_t   learnerReplica;
3194
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3195
  int32_t  changeVersion;
3196
  int32_t  electBaseLine;
3197
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3198

3199
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3200
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3201

3202
typedef struct {
3203
  int32_t vgId;
3204
  int8_t  disable;
3205
} SDisableVnodeWriteReq;
3206

3207
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3208
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3209

3210
typedef struct {
3211
  int32_t  srcVgId;
3212
  int32_t  dstVgId;
3213
  uint32_t hashBegin;
3214
  uint32_t hashEnd;
3215
  int32_t  changeVersion;
3216
  int32_t  reserved;
3217
} SAlterVnodeHashRangeReq;
3218

3219
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3220
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3221

3222
#define REQ_OPT_TBNAME 0x0
3223
#define REQ_OPT_TBUID  0x01
3224
typedef struct {
3225
  SMsgHead header;
3226
  char     dbFName[TSDB_DB_FNAME_LEN];
3227
  char     tbName[TSDB_TABLE_NAME_LEN];
3228
  uint8_t  option;
3229
  uint8_t  autoCreateCtb;
3230
} STableInfoReq;
3231

3232
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3233
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3234

3235
typedef struct {
3236
  int8_t  metaClone;  // create local clone of the cached table meta
3237
  int32_t numOfVgroups;
3238
  int32_t numOfTables;
3239
  int32_t numOfUdfs;
3240
  char    tableNames[];
3241
} SMultiTableInfoReq;
3242

3243
// todo refactor
3244
typedef struct SVgroupInfo {
3245
  int32_t  vgId;
3246
  uint32_t hashBegin;
3247
  uint32_t hashEnd;
3248
  SEpSet   epSet;
3249
  union {
3250
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3251
    int32_t taskId;      // used in stream
3252
  };
3253
} SVgroupInfo;
3254

3255
typedef struct {
3256
  int32_t     numOfVgroups;
3257
  SVgroupInfo vgroups[];
3258
} SVgroupsInfo;
3259

3260
typedef struct {
3261
  STableMetaRsp* pMeta;
3262
} SMAlterStbRsp;
3263

3264
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3265
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3266
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3267

3268
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3269
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3270
void    tFreeSTableMetaRsp(void* pRsp);
3271
void    tFreeSTableIndexRsp(void* info);
3272

3273
typedef struct {
3274
  SArray* pMetaRsp;   // Array of STableMetaRsp
3275
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3276
} SSTbHbRsp;
3277

3278
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3279
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3280
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3281

3282
typedef struct {
3283
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3284
} SViewHbRsp;
3285

3286
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3287
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3288
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3289

3290
typedef struct {
3291
  int32_t numOfTables;
3292
  int32_t numOfVgroup;
3293
  int32_t numOfUdf;
3294
  int32_t contLen;
3295
  int8_t  compressed;  // denote if compressed or not
3296
  int32_t rawLen;      // size before compress
3297
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3298
  char    meta[];
3299
} SMultiTableMeta;
3300

3301
typedef struct {
3302
  int32_t dataLen;
3303
  char    name[TSDB_TABLE_FNAME_LEN];
3304
  char*   data;
3305
} STagData;
3306

3307
typedef struct {
3308
  int32_t  opType;
3309
  uint32_t valLen;
3310
  char*    val;
3311
} SShowVariablesReq;
3312

3313
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3314
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3315
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3316

3317
typedef struct {
3318
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3319
  char value[TSDB_CONFIG_PATH_LEN + 1];
3320
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3321
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3322
  char info[TSDB_CONFIG_INFO_LEN + 1];
3323
} SVariablesInfo;
3324

3325
typedef struct {
3326
  SArray* variables;  // SArray<SVariablesInfo>
3327
} SShowVariablesRsp;
3328

3329
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3330
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3331

3332
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3333

3334
/*
3335
 * sql: show tables like '%a_%'
3336
 * payload is the query condition, e.g., '%a_%'
3337
 * payloadLen is the length of payload
3338
 */
3339
typedef struct {
3340
  int32_t type;
3341
  char    db[TSDB_DB_FNAME_LEN];
3342
  int32_t payloadLen;
3343
  char*   payload;
3344
} SShowReq;
3345

3346
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3347
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3348
void tFreeSShowReq(SShowReq* pReq);
3349

3350
typedef struct {
3351
  int64_t       showId;
3352
  STableMetaRsp tableMeta;
3353
} SShowRsp, SVShowTablesRsp;
3354

3355
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3356
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3357
// void    tFreeSShowRsp(SShowRsp* pRsp);
3358

3359
typedef struct {
3360
  char    db[TSDB_DB_FNAME_LEN];
3361
  char    tb[TSDB_TABLE_NAME_LEN];
3362
  char    user[TSDB_USER_LEN];
3363
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3364
  int64_t showId;
3365
  int64_t compactId;  // for compact
3366
  bool    withFull;   // for show users full
3367
} SRetrieveTableReq;
3368

3369
typedef struct SSysTableSchema {
3370
  int8_t   type;
3371
  col_id_t colId;
3372
  int32_t  bytes;
3373
} SSysTableSchema;
3374

3375
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3376
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3377

3378
#define RETRIEVE_TABLE_RSP_VERSION         0
3379
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3380
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3381

3382
typedef struct {
3383
  int64_t useconds;
3384
  int8_t  completed;  // all results are returned to client
3385
  int8_t  precision;
3386
  int8_t  compressed;
3387
  int8_t  streamBlockType;
3388
  int32_t payloadLen;
3389
  int32_t compLen;
3390
  int32_t numOfBlocks;
3391
  int64_t numOfRows;  // from int32_t change to int64_t
3392
  int64_t numOfCols;
3393
  int64_t skey;
3394
  int64_t ekey;
3395
  int64_t version;                         // for stream
3396
  TSKEY   watermark;                       // for stream
3397
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3398
  char    data[];
3399
} SRetrieveTableRsp;
3400

3401
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3402

3403
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3404
  do {                                          \
3405
    ((int32_t*)(_p))[0] = (_compLen);           \
3406
    ((int32_t*)(_p))[1] = (_fullLen);           \
3407
  } while (0);
3408

3409
typedef struct {
3410
  int64_t version;
3411
  int64_t numOfRows;
3412
  int8_t  compressed;
3413
  int8_t  precision;
3414
  char    data[];
3415
} SRetrieveTableRspForTmq;
3416

3417
typedef struct {
3418
  int64_t handle;
3419
  int64_t useconds;
3420
  int8_t  completed;  // all results are returned to client
3421
  int8_t  precision;
3422
  int8_t  compressed;
3423
  int32_t compLen;
3424
  int32_t numOfRows;
3425
  int32_t fullLen;
3426
  char    data[];
3427
} SRetrieveMetaTableRsp;
3428

3429
typedef struct SExplainExecInfo {
3430
  double   startupCost;
3431
  double   totalCost;
3432
  uint64_t numOfRows;
3433
  uint32_t verboseLen;
3434
  void*    verboseInfo;
3435
} SExplainExecInfo;
3436

3437
typedef struct {
3438
  int32_t           numOfPlans;
3439
  SExplainExecInfo* subplanInfo;
3440
} SExplainRsp;
3441

3442
typedef struct {
3443
  SExplainRsp rsp;
3444
  uint64_t    qId;
3445
  uint64_t    cId;
3446
  uint64_t    tId;
3447
  int64_t     rId;
3448
  int32_t     eId;
3449
} SExplainLocalRsp;
3450

3451
typedef struct STableScanAnalyzeInfo {
3452
  uint64_t totalRows;
3453
  uint64_t totalCheckedRows;
3454
  uint32_t totalBlocks;
3455
  uint32_t loadBlocks;
3456
  uint32_t loadBlockStatis;
3457
  uint32_t skipBlocks;
3458
  uint32_t filterOutBlocks;
3459
  double   elapsedTime;
3460
  double   filterTime;
3461
} STableScanAnalyzeInfo;
3462

3463
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3464
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3465
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3466

3467
typedef struct {
3468
  char    config[TSDB_DNODE_CONFIG_LEN];
3469
  char    value[TSDB_CLUSTER_VALUE_LEN];
3470
  int32_t sqlLen;
3471
  char*   sql;
3472
} SMCfgClusterReq;
3473

3474
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3475
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3476
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3477

3478
typedef struct {
3479
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3480
  int32_t port;
3481
  int32_t sqlLen;
3482
  char*   sql;
3483
} SCreateDnodeReq;
3484

3485
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3486
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3487
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3488

3489
typedef struct {
3490
  int32_t dnodeId;
3491
  char    fqdn[TSDB_FQDN_LEN];
3492
  int32_t port;
3493
  int8_t  force;
3494
  int8_t  unsafe;
3495
  int32_t sqlLen;
3496
  char*   sql;
3497
} SDropDnodeReq;
3498

3499
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3500
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3501
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3502

3503
enum {
3504
  RESTORE_TYPE__ALL = 1,
3505
  RESTORE_TYPE__MNODE,
3506
  RESTORE_TYPE__VNODE,
3507
  RESTORE_TYPE__QNODE,
3508
};
3509

3510
typedef struct {
3511
  int32_t dnodeId;
3512
  int8_t  restoreType;
3513
  int32_t sqlLen;
3514
  char*   sql;
3515
} SRestoreDnodeReq;
3516

3517
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3518
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3519
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3520

3521
typedef struct {
3522
  int32_t dnodeId;
3523
  char    config[TSDB_DNODE_CONFIG_LEN];
3524
  char    value[TSDB_DNODE_VALUE_LEN];
3525
  int32_t sqlLen;
3526
  char*   sql;
3527
} SMCfgDnodeReq;
3528

3529
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3530
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3531
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3532

3533
typedef struct {
3534
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3535
  char    newKey[ENCRYPT_KEY_LEN + 1];
3536
  int32_t sqlLen;
3537
  char*   sql;
3538
} SMAlterEncryptKeyReq;
3539

3540
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3541
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3542
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3543

3544
typedef struct {
3545
  int32_t days;
3546
  char    strategy[64];
3547
  int32_t sqlLen;
3548
  char*   sql;
3549
} SMAlterKeyExpirationReq;
3550

3551
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3552
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3553
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3554

3555
typedef struct {
3556
  char    config[TSDB_DNODE_CONFIG_LEN];
3557
  char    value[TSDB_DNODE_VALUE_LEN];
3558
  int32_t version;
3559
} SDCfgDnodeReq;
3560

3561
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3562
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3563

3564
typedef struct {
3565
  int32_t dnodeId;
3566
  int32_t sqlLen;
3567
  char*   sql;
3568
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3569
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3570

3571
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3572
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3573

3574
typedef struct {
3575
  int32_t nodeId;
3576
  SEpSet  epSet;
3577
} SNodeEpSet;
3578

3579
typedef struct {
3580
  int32_t    snodeId;
3581
  SNodeEpSet leaders[2];
3582
  SNodeEpSet replica;
3583
  int32_t    sqlLen;
3584
  char*      sql;
3585
} SDCreateSnodeReq;
3586

3587
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3588
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3589
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3590

3591
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3592
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3593
typedef struct {
3594
  int8_t   replica;
3595
  SReplica replicas[TSDB_MAX_REPLICA];
3596
  int8_t   learnerReplica;
3597
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3598
  int64_t  lastIndex;
3599
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3600
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3601

3602
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3603
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3604

3605
typedef struct {
3606
  int32_t urlLen;
3607
  int32_t sqlLen;
3608
  char*   url;
3609
  char*   sql;
3610
} SMCreateAnodeReq;
3611

3612
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3613
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3614
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3615

3616
typedef struct {
3617
  int32_t anodeId;
3618
  int32_t sqlLen;
3619
  char*   sql;
3620
} SMDropAnodeReq, SMUpdateAnodeReq;
3621

3622
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3623
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3624
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3625
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3626
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3627
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3628

3629
typedef struct {
3630
  int32_t dnodeId;
3631
  int32_t bnodeProto;
3632
  int32_t sqlLen;
3633
  char*   sql;
3634
} SMCreateBnodeReq, SDCreateBnodeReq;
3635

3636
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3637
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3638
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3639

3640
typedef struct {
3641
  int32_t dnodeId;
3642
  int32_t sqlLen;
3643
  char*   sql;
3644
} SMDropBnodeReq, SDDropBnodeReq;
3645

3646
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3647
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3648
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3649

3650
typedef struct {
3651
  int32_t sqlLen;
3652
  int32_t urlLen;
3653
  int32_t userLen;
3654
  int32_t passLen;
3655
  int32_t passIsMd5;
3656
  char*   sql;
3657
  char*   url;
3658
  char*   user;
3659
  char*   pass;
3660
} SMCreateXnodeReq, SDCreateXnodeReq;
3661

3662
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3663
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3664
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3665

3666
typedef struct {
3667
  int32_t xnodeId;
3668
  int32_t force;
3669
  int32_t urlLen;
3670
  int32_t sqlLen;
3671
  char*   url;
3672
  char*   sql;
3673
} SMDropXnodeReq, SMUpdateXnodeReq, SDDropXnodeReq;
3674

3675
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3676
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3677
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3678
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3679
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3680
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3681

3682
typedef struct {
3683
  int32_t xnodeId;
3684
  int32_t sqlLen;
3685
  char*   sql;
3686
} SMDrainXnodeReq;
3687
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3688
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3689
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3690

3691
typedef struct {
3692
  bool        shouldFree;
3693
  int32_t     len;
3694
  const char* ptr;
3695
} CowStr;
3696
/**
3697
 * @brief Create a CowStr object.
3698
 *
3699
 * @param len: length of the string.
3700
 * @param ptr: pointer to the string input.
3701
 * @param shouldClone: whether to clone the string.
3702
 * @return CowStr object.
3703
 */
3704
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3705
/**
3706
 * @brief Set a CowStr object with given string.
3707
 *
3708
 * @param cow: pointer to the CowStr object.
3709
 * @param len: length of the string.
3710
 * @param ptr: pointer to the string input.
3711
 * @param shouldFree: whether to free the string.
3712
 */
3713
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3714
/**
3715
 * @brief Clone a CowStr object without copy the string.
3716
 *
3717
 * @param cow: pointer to the CowStr object.
3718
 * @return CowStr object.
3719
 */
3720
CowStr xCloneRefCowStr(CowStr* cow);
3721
/**
3722
 * @brief Convert a CowStr object to a string.
3723
 *
3724
 * @param cow: pointer to the CowStr object.
3725
 */
3726
char* xCowStrToStr(CowStr* cow);
3727
/**
3728
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3729
 *
3730
 * @param cow: pointer to the CowStr object.
3731
 */
3732
void xFreeCowStr(CowStr* cow);
3733
/**
3734
 * @brief Encode and push a CowStr object into the encoder.
3735
 *
3736
 * @param encoder
3737
 * @param cow
3738
 * @return int32_t
3739
 */
3740
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3741
/**
3742
 * @brief Decode a CowStr from the encoder.
3743
 *
3744
 * @param decoder
3745
 * @param cow
3746
 * @param shouldClone
3747
 * @return int32_t
3748
 */
3749
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3750

3751
typedef enum {
3752
  XNODE_TASK_SOURCE_DSN = 1,
3753
  XNODE_TASK_SOURCE_DATABASE,
3754
  XNODE_TASK_SOURCE_TOPIC,
3755
} ENodeXTaskSourceType;
3756

3757
typedef enum {
3758
  XNODE_TASK_SINK_DSN = 1,
3759
  XNODE_TASK_SINK_DATABASE,
3760
} ENodeXTaskSinkType;
3761

3762
typedef struct {
3763
  ENodeXTaskSourceType type;
3764
  CowStr               cstr;
3765
} xTaskSource;
3766
/**
3767
 * @brief Deallocate a xTaskSource object.
3768
 *
3769
 * @param source ptr
3770
 */
3771
void xFreeTaskSource(xTaskSource* source);
3772
/**
3773
 * @brief Create a xTaskSource object with cloned source string.
3774
 *
3775
 * @param sourceType: source type.
3776
 * @param len: length of source string.
3777
 * @param source: source string ptr.
3778
 * @return xTaskSource object
3779
 */
3780
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3781
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3782
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3783
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3784
const char* xGetTaskSourceStr(xTaskSource* source);
3785
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3786
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3787

3788
typedef struct {
3789
  ENodeXTaskSinkType type;
3790
  CowStr             cstr;
3791
} xTaskSink;
3792
/**
3793
 * @brief Deallocate a xTaskSink object.
3794
 *
3795
 * @param sink ptr
3796
 */
3797
void xFreeTaskSink(xTaskSink* sink);
3798
/**
3799
 * @brief Create a xTaskSink object with cloned name string.
3800
 *
3801
 * @param sinkType: sink type.
3802
 * @param len: length of sink string.
3803
 * @param ptr: sink string ptr.
3804
 * @return xTaskSink object
3805
 */
3806
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3807
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3808
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3809
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3810
const char* xGetTaskSinkStr(xTaskSink* sink);
3811
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3812
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3813

3814
typedef struct {
3815
  int32_t via;
3816
  CowStr  parser;
3817
  // CowStr  reason;
3818
  CowStr  trigger;
3819
  CowStr  health;
3820
  int32_t optionsNum;
3821
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3822
} xTaskOptions;
3823
/**
3824
 * @brief Deallocate a xTaskOptions object.
3825
 *
3826
 * @param options ptr
3827
 */
3828
void    xFreeTaskOptions(xTaskOptions* options);
3829
void    printXnodeTaskOptions(xTaskOptions* options);
3830
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3831
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3832

3833
typedef struct {
3834
  int32_t sqlLen;
3835
  char*   sql;
3836
  int32_t      xnodeId;
3837
  CowStr       name;
3838
  xTaskSource  source;
3839
  xTaskSink    sink;
3840
  xTaskOptions options;
3841
} SMCreateXnodeTaskReq;
3842
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3843
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3844
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3845

3846
typedef struct {
3847
  int32_t     tid;
3848
  CowStr      name;
3849
  int32_t     via;
3850
  int32_t     xnodeId;
3851
  CowStr      status;
3852
  xTaskSource source;
3853
  xTaskSink   sink;
3854
  CowStr      parser;
3855
  CowStr      reason;
3856
  CowStr      updateName;
3857
  CowStr      labels;
3858
  int32_t     sqlLen;
3859
  char*       sql;
3860
} SMUpdateXnodeTaskReq;
3861
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3862
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3863
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3864

3865
typedef struct {
3866
  int32_t id;
3867
  bool    force;
3868
  CowStr  name;
3869
  int32_t sqlLen;
3870
  char*   sql;
3871
} SMDropXnodeTaskReq;
3872
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3873
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3874
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3875

3876
typedef struct {
3877
  int32_t tid;
3878
  CowStr  name;
3879
  int32_t sqlLen;
3880
  char*   sql;
3881
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3882
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3883
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3884
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3885

3886
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3887
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3888
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3889

3890
typedef struct {
3891
  int32_t tid;
3892
  int32_t via;
3893
  int32_t xnodeId;
3894
  CowStr  status;
3895
  CowStr  config;
3896
  CowStr  reason;
3897
  int32_t sqlLen;
3898
  char*   sql;
3899
} SMCreateXnodeJobReq;
3900
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3901
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3902
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3903

3904
typedef struct {
3905
  int32_t jid;
3906
  int32_t via;
3907
  int32_t xnodeId;
3908
  CowStr  status;
3909
  int32_t configLen;
3910
  int32_t reasonLen;
3911
  int32_t sqlLen;
3912
  char*   config;
3913
  char*   reason;
3914
  char*   sql;
3915
} SMUpdateXnodeJobReq;
3916
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3917
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3918
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3919

3920
typedef struct {
3921
  int32_t jid;
3922
  int32_t xnodeId;
3923
  int32_t sqlLen;
3924
  char*   sql;
3925
} SMRebalanceXnodeJobReq;
3926
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3927
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3928
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3929

3930
typedef struct {
3931
  CowStr  ast;
3932
  int32_t sqlLen;
3933
  char*   sql;
3934
} SMRebalanceXnodeJobsWhereReq;
3935
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3936
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3937
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3938

3939
typedef struct {
3940
  int32_t jid;
3941
  CowStr  ast;
3942
  int32_t sqlLen;
3943
  char*   sql;
3944
} SMDropXnodeJobReq;
3945
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3946
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3947
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3948

3949
typedef struct {
3950
  int32_t      sqlLen;
3951
  char*        sql;
3952
  CowStr       name;
3953
  CowStr       status;
3954
  xTaskOptions options;
3955
} SMCreateXnodeAgentReq;
3956
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3957
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3958
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3959

3960
typedef struct {
3961
  int32_t      sqlLen;
3962
  char*        sql;
3963
  int32_t      id;
3964
  CowStr       name;
3965
  xTaskOptions options;
3966
} SMUpdateXnodeAgentReq;
3967
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3968
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3969
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
3970

3971
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3972
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3973
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3974
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
3975

3976
typedef struct {
3977
  int32_t vgId;
3978
  int32_t hbSeq;
3979
} SVArbHbReqMember;
3980

3981
typedef struct {
3982
  int32_t dnodeId;
3983
  char*   arbToken;
3984
  int64_t arbTerm;
3985
  SArray* hbMembers;  // SVArbHbReqMember
3986
} SVArbHeartBeatReq;
3987

3988
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3989
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3990
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3991

3992
typedef struct {
3993
  int32_t vgId;
3994
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3995
  int32_t hbSeq;
3996
} SVArbHbRspMember;
3997

3998
typedef struct {
3999
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4000
  int32_t dnodeId;
4001
  SArray* hbMembers;  // SVArbHbRspMember
4002
} SVArbHeartBeatRsp;
4003

4004
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4005
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4006
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4007

4008
typedef struct {
4009
  char*   arbToken;
4010
  int64_t arbTerm;
4011
  char*   member0Token;
4012
  char*   member1Token;
4013
} SVArbCheckSyncReq;
4014

4015
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4016
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4017
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4018

4019
typedef struct {
4020
  char*   arbToken;
4021
  char*   member0Token;
4022
  char*   member1Token;
4023
  int32_t vgId;
4024
  int32_t errCode;
4025
} SVArbCheckSyncRsp;
4026

4027
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4028
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4029
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4030

4031
typedef struct {
4032
  char*   arbToken;
4033
  int64_t arbTerm;
4034
  char*   memberToken;
4035
  int8_t  force;
4036
} SVArbSetAssignedLeaderReq;
4037

4038
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4039
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4040
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4041

4042
typedef struct {
4043
  char*   arbToken;
4044
  char*   memberToken;
4045
  int32_t vgId;
4046
} SVArbSetAssignedLeaderRsp;
4047

4048
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4049
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4050
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4051

4052
typedef struct {
4053
  int32_t dnodeId;
4054
  char*   token;
4055
} SMArbUpdateGroupMember;
4056

4057
typedef struct {
4058
  int32_t dnodeId;
4059
  char*   token;
4060
  int8_t  acked;
4061
} SMArbUpdateGroupAssigned;
4062

4063
typedef struct {
4064
  int32_t                  vgId;
4065
  int64_t                  dbUid;
4066
  SMArbUpdateGroupMember   members[2];
4067
  int8_t                   isSync;
4068
  int8_t                   assignedAcked;
4069
  SMArbUpdateGroupAssigned assignedLeader;
4070
  int64_t                  version;
4071
  int32_t                  code;
4072
  int64_t                  updateTimeMs;
4073
} SMArbUpdateGroup;
4074

4075
typedef struct {
4076
  SArray* updateArray;  // SMArbUpdateGroup
4077
} SMArbUpdateGroupBatchReq;
4078

4079
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4080
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4081
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4082

4083
typedef struct {
4084
  char queryStrId[TSDB_QUERY_ID_LEN];
4085
} SKillQueryReq;
4086

4087
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4088
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4089

4090
typedef struct {
4091
  uint32_t connId;
4092
} SKillConnReq;
4093

4094
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4095
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4096

4097
typedef struct {
4098
  int32_t transId;
4099
} SKillTransReq;
4100

4101
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4102
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4103

4104
typedef struct {
4105
  int32_t useless;  // useless
4106
  int32_t sqlLen;
4107
  char*   sql;
4108
} SBalanceVgroupReq;
4109

4110
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4111
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4112
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4113

4114
typedef struct {
4115
  int32_t useless;  // useless
4116
  int32_t sqlLen;
4117
  char*   sql;
4118
} SAssignLeaderReq;
4119

4120
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4121
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4122
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4123
typedef struct {
4124
  int32_t vgId1;
4125
  int32_t vgId2;
4126
} SMergeVgroupReq;
4127

4128
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4129
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4130

4131
typedef struct {
4132
  int32_t vgId;
4133
  int32_t dnodeId1;
4134
  int32_t dnodeId2;
4135
  int32_t dnodeId3;
4136
  int32_t sqlLen;
4137
  char*   sql;
4138
} SRedistributeVgroupReq;
4139

4140
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4141
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4142
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4143

4144
typedef struct {
4145
  int32_t reserved;
4146
  int32_t vgId;
4147
  int32_t sqlLen;
4148
  char*   sql;
4149
  char    db[TSDB_DB_FNAME_LEN];
4150
} SBalanceVgroupLeaderReq;
4151

4152
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4153
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4154
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4155

4156
typedef struct {
4157
  int32_t vgId;
4158
} SForceBecomeFollowerReq;
4159

4160
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4161
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4162

4163
typedef struct {
4164
  int32_t vgId;
4165
  bool    force;
4166
} SSplitVgroupReq;
4167

4168
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4169
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4170

4171
typedef struct {
4172
  char user[TSDB_USER_LEN];
4173
  char spi;
4174
  char encrypt;
4175
  char secret[TSDB_PASSWORD_LEN];
4176
  char ckey[TSDB_PASSWORD_LEN];
4177
} SAuthReq, SAuthRsp;
4178

4179
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4180
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4181

4182
typedef struct {
4183
  int32_t statusCode;
4184
  char    details[1024];
4185
} SServerStatusRsp;
4186

4187
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4188
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4189

4190
/**
4191
 * The layout of the query message payload is as following:
4192
 * +--------------------+---------------------------------+
4193
 * |Sql statement       | Physical plan                   |
4194
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4195
 * +--------------------+---------------------------------+
4196
 */
4197
typedef struct SSubQueryMsg {
4198
  SMsgHead header;
4199
  uint64_t sId;
4200
  uint64_t queryId;
4201
  uint64_t clientId;
4202
  uint64_t taskId;
4203
  int64_t  refId;
4204
  int32_t  execId;
4205
  int32_t  msgMask;
4206
  int32_t  subQType;
4207
  int8_t   taskType;
4208
  int8_t   explain;
4209
  int8_t   needFetch;
4210
  int8_t   compress;
4211
  uint32_t sqlLen;
4212
  char*    sql;
4213
  uint32_t msgLen;
4214
  char*    msg;
4215
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4216
} SSubQueryMsg;
4217

4218
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4219
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4220
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4221

4222
typedef struct {
4223
  SMsgHead header;
4224
  uint64_t sId;
4225
  uint64_t queryId;
4226
  uint64_t taskId;
4227
} SSinkDataReq;
4228

4229
typedef struct {
4230
  SMsgHead header;
4231
  uint64_t sId;
4232
  uint64_t queryId;
4233
  uint64_t clientId;
4234
  uint64_t taskId;
4235
  int32_t  execId;
4236
} SQueryContinueReq;
4237

4238
typedef struct {
4239
  SMsgHead header;
4240
  uint64_t sId;
4241
  uint64_t queryId;
4242
  uint64_t taskId;
4243
} SResReadyReq;
4244

4245
typedef struct {
4246
  int32_t code;
4247
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4248
  int32_t sversion;
4249
  int32_t tversion;
4250
} SResReadyRsp;
4251

4252
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4253

4254
typedef struct SOperatorParam {
4255
  int32_t opType;
4256
  int32_t downstreamIdx;
4257
  void*   value;
4258
  SArray* pChildren;  // SArray<SOperatorParam*>
4259
  bool    reUse;
4260
} SOperatorParam;
4261

4262
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4263

4264
typedef struct SColIdNameKV {
4265
  col_id_t colId;
4266
  char     colName[TSDB_COL_NAME_LEN];
4267
} SColIdNameKV;
4268

4269
#define COL_MASK_ON   ((int8_t)0x1)
4270
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4271
#define COL_SET_MASK_ON(c)     \
4272
  do {                         \
4273
    (c)->flags |= COL_MASK_ON; \
4274
  } while (0)
4275

4276
typedef struct SColNameFlag {
4277
  col_id_t colId;
4278
  char     colName[TSDB_COL_NAME_LEN];
4279
  int8_t   flags;  // 0x01: COL_MASK_ON
4280
} SColNameFlag;
4281

4282
typedef struct SColIdPair {
4283
  col_id_t  vtbColId;
4284
  col_id_t  orgColId;
4285
  SDataType type;
4286
} SColIdPair;
4287

4288
typedef struct SColIdSlotIdPair {
4289
  int32_t  vtbSlotId;
4290
  col_id_t orgColId;
4291
} SColIdSlotIdPair;
4292

4293
typedef struct SOrgTbInfo {
4294
  int32_t vgId;
4295
  char    tbName[TSDB_TABLE_FNAME_LEN];
4296
  SArray* colMap;  // SArray<SColIdNameKV>
4297
} SOrgTbInfo;
4298

4299
void destroySOrgTbInfo(void *info);
4300

4301
typedef enum {
4302
  DYN_TYPE_STB_JOIN = 1,
4303
  DYN_TYPE_VSTB_SINGLE_SCAN,
4304
  DYN_TYPE_VSTB_BATCH_SCAN,
4305
  DYN_TYPE_VSTB_WIN_SCAN,
4306
} ETableScanDynType;
4307

4308
typedef enum {
4309
  DYN_TYPE_SCAN_PARAM = 1,
4310
  NOTIFY_TYPE_SCAN_PARAM,
4311
} ETableScanGetParamType;
4312

4313
typedef struct STableScanOperatorParam {
4314
  ETableScanGetParamType paramType;
4315
  /* for building scan data source */
4316
  bool                   tableSeq;
4317
  bool                   isNewParam;
4318
  uint64_t               groupid;
4319
  SArray*                pUidList;
4320
  SOrgTbInfo*            pOrgTbInfo;
4321
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4322
  SArray*                pTagList;
4323
  STimeWindow            window;
4324
  ETableScanDynType      dynType;
4325
  /* for notifying source step done */
4326
  bool                   notifyToProcess;  // received notify STEP DONE message
4327
  TSKEY                  notifyTs;         // notify timestamp
4328
} STableScanOperatorParam;
4329

4330
typedef struct STagScanOperatorParam {
4331
  tb_uid_t vcUid;
4332
} STagScanOperatorParam;
4333

4334
typedef struct SVTableScanOperatorParam {
4335
  uint64_t        uid;
4336
  STimeWindow     window;
4337
  SOperatorParam* pTagScanOp;
4338
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4339
} SVTableScanOperatorParam;
4340

4341
typedef struct SMergeOperatorParam {
4342
  int32_t         winNum;
4343
} SMergeOperatorParam;
4344

4345
typedef struct SAggOperatorParam {
4346
  bool            needCleanRes;
4347
} SAggOperatorParam;
4348

4349
typedef struct SExternalWindowOperatorParam {
4350
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4351
} SExternalWindowOperatorParam;
4352

4353
typedef struct SDynQueryCtrlOperatorParam {
4354
  STimeWindow    window;
4355
} SDynQueryCtrlOperatorParam;
4356

4357
struct SStreamRuntimeFuncInfo;
4358
typedef struct {
4359
  SMsgHead        header;
4360
  uint64_t        sId;
4361
  uint64_t        queryId;
4362
  uint64_t        clientId;
4363
  uint64_t        taskId;
4364
  uint64_t        srcTaskId;  // used for subQ
4365
  uint64_t        blockIdx;   // used for subQ
4366
  int32_t         execId;
4367
  SOperatorParam* pOpParam;
4368

4369
  // used for new-stream
4370
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4371
  bool                           reset;
4372
  bool                           dynTbname;
4373
  // used for new-stream
4374
} SResFetchReq;
4375

4376
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4377
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4378
void    tDestroySResFetchReq(SResFetchReq* pReq);
4379
typedef struct {
4380
  SMsgHead header;
4381
  uint64_t clientId;
4382
} SSchTasksStatusReq;
4383

4384
typedef struct {
4385
  uint64_t queryId;
4386
  uint64_t clientId;
4387
  uint64_t taskId;
4388
  int64_t  refId;
4389
  int32_t  subJobId;
4390
  int32_t  execId;
4391
  int8_t   status;
4392
} STaskStatus;
4393

4394
typedef struct {
4395
  int64_t refId;
4396
  SArray* taskStatus;  // SArray<STaskStatus>
4397
} SSchedulerStatusRsp;
4398

4399
typedef struct {
4400
  uint64_t queryId;
4401
  uint64_t taskId;
4402
  int8_t   action;
4403
} STaskAction;
4404

4405
typedef struct SQueryNodeEpId {
4406
  int32_t nodeId;  // vgId or qnodeId
4407
  SEp     ep;
4408
} SQueryNodeEpId;
4409

4410
typedef struct {
4411
  SMsgHead       header;
4412
  uint64_t       clientId;
4413
  SQueryNodeEpId epId;
4414
  SArray*        taskAction;  // SArray<STaskAction>
4415
} SSchedulerHbReq;
4416

4417
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4418
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4419
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4420

4421
typedef struct {
4422
  SQueryNodeEpId epId;
4423
  SArray*        taskStatus;  // SArray<STaskStatus>
4424
} SSchedulerHbRsp;
4425

4426
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4427
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4428
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4429

4430
typedef struct {
4431
  SMsgHead header;
4432
  uint64_t sId;
4433
  uint64_t queryId;
4434
  uint64_t clientId;
4435
  uint64_t taskId;
4436
  int64_t  refId;
4437
  int32_t  execId;
4438
} STaskCancelReq;
4439

4440
typedef struct {
4441
  int32_t code;
4442
} STaskCancelRsp;
4443

4444
typedef struct {
4445
  SMsgHead header;
4446
  uint64_t sId;
4447
  uint64_t queryId;
4448
  uint64_t clientId;
4449
  uint64_t taskId;
4450
  int64_t  refId;
4451
  int32_t  execId;
4452
} STaskDropReq;
4453

4454
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4455
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4456

4457
typedef enum {
4458
  TASK_NOTIFY_FINISHED = 1,
4459
} ETaskNotifyType;
4460

4461
typedef struct {
4462
  SMsgHead        header;
4463
  uint64_t        sId;
4464
  uint64_t        queryId;
4465
  uint64_t        clientId;
4466
  uint64_t        taskId;
4467
  int64_t         refId;
4468
  int32_t         execId;
4469
  ETaskNotifyType type;
4470
} STaskNotifyReq;
4471

4472
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4473
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4474

4475
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4476
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4477

4478
typedef struct {
4479
  int32_t code;
4480
} STaskDropRsp;
4481

4482
#define STREAM_TRIGGER_AT_ONCE                 1
4483
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4484
#define STREAM_TRIGGER_MAX_DELAY               3
4485
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4486
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4487

4488
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4489
#define STREAM_FILL_HISTORY_ON        1
4490
#define STREAM_FILL_HISTORY_OFF       0
4491
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4492
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4493
#define STREAM_CREATE_STABLE_TRUE     1
4494
#define STREAM_CREATE_STABLE_FALSE    0
4495

4496
typedef struct SVgroupVer {
4497
  int32_t vgId;
4498
  int64_t ver;
4499
} SVgroupVer;
4500

4501
typedef struct STaskNotifyEventStat {
4502
  int64_t notifyEventAddTimes;     // call times of add function
4503
  int64_t notifyEventAddElems;     // elements added by add function
4504
  double  notifyEventAddCostSec;   // time cost of add function
4505
  int64_t notifyEventPushTimes;    // call times of push function
4506
  int64_t notifyEventPushElems;    // elements pushed by push function
4507
  double  notifyEventPushCostSec;  // time cost of push function
4508
  int64_t notifyEventPackTimes;    // call times of pack function
4509
  int64_t notifyEventPackElems;    // elements packed by pack function
4510
  double  notifyEventPackCostSec;  // time cost of pack function
4511
  int64_t notifyEventSendTimes;    // call times of send function
4512
  int64_t notifyEventSendElems;    // elements sent by send function
4513
  double  notifyEventSendCostSec;  // time cost of send function
4514
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4515
} STaskNotifyEventStat;
4516

4517
enum {
4518
  TOPIC_SUB_TYPE__DB = 1,
4519
  TOPIC_SUB_TYPE__TABLE,
4520
  TOPIC_SUB_TYPE__COLUMN,
4521
};
4522

4523
#define DEFAULT_MAX_POLL_INTERVAL  300000
4524
#define DEFAULT_SESSION_TIMEOUT    12000
4525
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4526
#define DEFAULT_MIN_POLL_ROWS      4096
4527

4528
typedef struct {
4529
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4530
  int8_t igExists;
4531
  int8_t subType;
4532
  int8_t withMeta;
4533
  char*  sql;
4534
  char   subDbName[TSDB_DB_FNAME_LEN];
4535
  char*  ast;
4536
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4537
  int8_t reload;
4538
} SCMCreateTopicReq;
4539

4540
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4541
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4542
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4543

4544
typedef struct {
4545
  int64_t consumerId;
4546
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4547

4548
typedef struct {
4549
  int64_t consumerId;
4550
  char    cgroup[TSDB_CGROUP_LEN];
4551
  char    clientId[TSDB_CLIENT_ID_LEN];
4552
  char    user[TSDB_USER_LEN];
4553
  char    fqdn[TSDB_FQDN_LEN];
4554
  SArray* topicNames;  // SArray<char**>
4555

4556
  int8_t  withTbName;
4557
  int8_t  autoCommit;
4558
  int32_t autoCommitInterval;
4559
  int8_t  resetOffsetCfg;
4560
  int8_t  enableReplay;
4561
  int8_t  enableBatchMeta;
4562
  int32_t sessionTimeoutMs;
4563
  int32_t maxPollIntervalMs;
4564
  int64_t ownerId;
4565
} SCMSubscribeReq;
4566

4567
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4568
  int32_t tlen = 0;
654,388✔
4569
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
654,388✔
4570
  tlen += taosEncodeString(buf, pReq->cgroup);
654,388✔
4571
  tlen += taosEncodeString(buf, pReq->clientId);
654,388✔
4572

4573
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
654,388✔
4574
  tlen += taosEncodeFixedI32(buf, topicNum);
654,388✔
4575

4576
  for (int32_t i = 0; i < topicNum; i++) {
910,334✔
4577
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
511,892✔
4578
  }
4579

4580
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
654,388✔
4581
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
654,388✔
4582
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
654,075✔
4583
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
654,388✔
4584
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
654,388✔
4585
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
654,075✔
4586
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
654,075✔
4587
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
654,075✔
4588
  tlen += taosEncodeString(buf, pReq->user);
654,075✔
4589
  tlen += taosEncodeString(buf, pReq->fqdn);
654,388✔
4590

4591
  return tlen;
654,075✔
4592
}
4593

4594
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4595
  void* start = buf;
343,138✔
4596
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
343,138✔
4597
  buf = taosDecodeStringTo(buf, pReq->cgroup);
343,138✔
4598
  buf = taosDecodeStringTo(buf, pReq->clientId);
343,138✔
4599

4600
  int32_t topicNum = 0;
343,138✔
4601
  buf = taosDecodeFixedI32(buf, &topicNum);
343,138✔
4602

4603
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
343,138✔
4604
  if (pReq->topicNames == NULL) {
343,138✔
UNCOV
4605
    return terrno;
×
4606
  }
4607
  for (int32_t i = 0; i < topicNum; i++) {
497,272✔
4608
    char* name = NULL;
154,134✔
4609
    buf = taosDecodeString(buf, &name);
154,134✔
4610
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
308,268✔
UNCOV
4611
      return terrno;
×
4612
    }
4613
  }
4614

4615
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
343,138✔
4616
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
343,138✔
4617
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
343,138✔
4618
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
343,138✔
4619
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
343,138✔
4620
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
343,138✔
4621
  if ((char*)buf - (char*)start < len) {
343,138✔
4622
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
343,138✔
4623
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
343,138✔
4624
    buf = taosDecodeStringTo(buf, pReq->user);
343,138✔
4625
    buf = taosDecodeStringTo(buf, pReq->fqdn);
686,276✔
4626
  } else {
UNCOV
4627
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4628
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4629
  }
4630

4631
  return 0;
343,138✔
4632
}
4633

4634
typedef struct {
4635
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4636
  SArray* removedConsumers;  // SArray<int64_t>
4637
  SArray* newConsumers;      // SArray<int64_t>
4638
} SMqRebInfo;
4639

4640
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4641
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
323,678✔
4642
  if (pRebInfo == NULL) {
323,678✔
UNCOV
4643
    return NULL;
×
4644
  }
4645
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
323,678✔
4646
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
323,678✔
4647
  if (pRebInfo->removedConsumers == NULL) {
323,678✔
UNCOV
4648
    goto _err;
×
4649
  }
4650
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
323,678✔
4651
  if (pRebInfo->newConsumers == NULL) {
323,678✔
4652
    goto _err;
×
4653
  }
4654
  return pRebInfo;
323,678✔
UNCOV
4655
_err:
×
UNCOV
4656
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4657
  taosArrayDestroy(pRebInfo->newConsumers);
×
4658
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4659
  return NULL;
×
4660
}
4661

4662
typedef struct {
4663
  int64_t streamId;
4664
  int64_t checkpointId;
4665
  char    streamName[TSDB_STREAM_FNAME_LEN];
4666
} SMStreamDoCheckpointMsg;
4667

4668
typedef struct {
4669
  int64_t status;
4670
} SMVSubscribeRsp;
4671

4672
typedef struct {
4673
  char    name[TSDB_TOPIC_FNAME_LEN];
4674
  int8_t  igNotExists;
4675
  int32_t sqlLen;
4676
  char*   sql;
4677
  int8_t  force;
4678
} SMDropTopicReq;
4679

4680
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4681
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4682
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4683

4684
typedef struct {
4685
  char    name[TSDB_TOPIC_FNAME_LEN];
4686
  int8_t  igNotExists;
4687
  int32_t sqlLen;
4688
  char*   sql;
4689
} SMReloadTopicReq;
4690

4691
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4692
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4693
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4694

4695
typedef struct {
4696
  char   topic[TSDB_TOPIC_FNAME_LEN];
4697
  char   cgroup[TSDB_CGROUP_LEN];
4698
  int8_t igNotExists;
4699
  int8_t force;
4700
} SMDropCgroupReq;
4701

4702
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4703
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4704

4705
typedef struct {
4706
  int8_t reserved;
4707
} SMDropCgroupRsp;
4708

4709
typedef struct {
4710
  char    name[TSDB_TABLE_FNAME_LEN];
4711
  int8_t  alterType;
4712
  SSchema schema;
4713
} SAlterTopicReq;
4714

4715
typedef struct {
4716
  SMsgHead head;
4717
  char     name[TSDB_TABLE_FNAME_LEN];
4718
  int64_t  tuid;
4719
  int32_t  sverson;
4720
  int32_t  execLen;
4721
  char*    executor;
4722
  int32_t  sqlLen;
4723
  char*    sql;
4724
} SDCreateTopicReq;
4725

4726
typedef struct {
4727
  SMsgHead head;
4728
  char     name[TSDB_TABLE_FNAME_LEN];
4729
  int64_t  tuid;
4730
} SDDropTopicReq;
4731

4732
typedef struct {
4733
  char*      name;
4734
  int64_t    uid;
4735
  int64_t    interval[2];
4736
  int8_t     intervalUnit;
4737
  int16_t    nFuncs;
4738
  col_id_t*  funcColIds;  // column ids specified by user
4739
  func_id_t* funcIds;     // function ids specified by user
4740
} SRSmaParam;
4741

4742
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4743
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4744

4745
// TDMT_VND_CREATE_STB ==============
4746
typedef struct SVCreateStbReq {
4747
  char*           name;
4748
  tb_uid_t        suid;
4749
  int8_t          rollup;
4750
  SSchemaWrapper  schemaRow;
4751
  SSchemaWrapper  schemaTag;
4752
  SRSmaParam      rsmaParam;
4753
  int32_t         alterOriDataLen;
4754
  void*           alterOriData;
4755
  int8_t          source;
4756
  int8_t          colCmpred;
4757
  SColCmprWrapper colCmpr;
4758
  int64_t         keep;
4759
  int64_t         ownerId;
4760
  SExtSchema*     pExtSchemas;
4761
  int8_t          virtualStb;
4762
} SVCreateStbReq;
4763

4764
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4765
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4766

4767
// TDMT_VND_DROP_STB ==============
4768
typedef struct SVDropStbReq {
4769
  char*    name;
4770
  tb_uid_t suid;
4771
} SVDropStbReq;
4772

4773
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4774
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4775

4776
// TDMT_VND_CREATE_TABLE ==============
4777
#define TD_CREATE_IF_NOT_EXISTS       0x1
4778
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4779
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4780
typedef struct SVCreateTbReq {
4781
  int32_t  flags;
4782
  char*    name;
4783
  tb_uid_t uid;
4784
  int64_t  btime;
4785
  int32_t  ttl;
4786
  int32_t  commentLen;
4787
  char*    comment;
4788
  int8_t   type;
4789
  union {
4790
    struct {
4791
      char*    stbName;  // super table name
4792
      uint8_t  tagNum;
4793
      tb_uid_t suid;
4794
      SArray*  tagName;
4795
      uint8_t* pTag;
4796
    } ctb;
4797
    struct {
4798
      SSchemaWrapper schemaRow;
4799
      int64_t        userId;
4800
    } ntb;
4801
  };
4802
  int32_t         sqlLen;
4803
  char*           sql;
4804
  SColCmprWrapper colCmpr;
4805
  SExtSchema*     pExtSchemas;
4806
  SColRefWrapper  colRef;  // col reference for virtual table
4807
} SVCreateTbReq;
4808

4809
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4810
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4811
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4812
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4813

4814
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4815
  if (NULL == req) {
2,147,483,647✔
4816
    return;
2,147,483,647✔
4817
  }
4818

4819
  taosMemoryFreeClear(req->sql);
72,279,726✔
4820
  taosMemoryFreeClear(req->name);
72,279,288✔
4821
  taosMemoryFreeClear(req->comment);
72,273,961✔
4822
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
72,282,674✔
4823
    taosMemoryFreeClear(req->ctb.pTag);
66,629,866✔
4824
    taosMemoryFreeClear(req->ctb.stbName);
66,625,140✔
4825
    taosArrayDestroy(req->ctb.tagName);
66,638,229✔
4826
    req->ctb.tagName = NULL;
66,579,128✔
4827
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
5,655,618✔
4828
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
5,655,832✔
4829
  }
4830
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
72,247,879✔
4831
  taosMemoryFreeClear(req->pExtSchemas);
72,276,592✔
4832
  taosMemoryFreeClear(req->colRef.pColRef);
72,278,051✔
4833
}
4834

4835
typedef struct {
4836
  int32_t nReqs;
4837
  union {
4838
    SVCreateTbReq* pReqs;
4839
    SArray*        pArray;
4840
  };
4841
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4842
} SVCreateTbBatchReq;
4843

4844
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4845
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4846
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4847

4848
typedef struct {
4849
  int32_t        code;
4850
  STableMetaRsp* pMeta;
4851
} SVCreateTbRsp, SVUpdateTbRsp;
4852

4853
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4854
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4855
void tFreeSVCreateTbRsp(void* param);
4856

4857
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4858
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4859

4860
typedef struct {
4861
  int32_t nRsps;
4862
  union {
4863
    SVCreateTbRsp* pRsps;
4864
    SArray*        pArray;
4865
  };
4866
} SVCreateTbBatchRsp;
4867

4868
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4869
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4870

4871
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4872
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4873

4874
// TDMT_VND_DROP_TABLE =================
4875
typedef struct {
4876
  char*    name;
4877
  uint64_t suid;  // for tmq in wal format
4878
  int64_t  uid;
4879
  int8_t   igNotExists;
4880
  int8_t   isVirtual;
4881
} SVDropTbReq;
4882

4883
typedef struct {
4884
  int32_t code;
4885
} SVDropTbRsp;
4886

4887
typedef struct {
4888
  int32_t nReqs;
4889
  union {
4890
    SVDropTbReq* pReqs;
4891
    SArray*      pArray;
4892
  };
4893
} SVDropTbBatchReq;
4894

4895
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4896
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4897

4898
typedef struct {
4899
  int32_t nRsps;
4900
  union {
4901
    SVDropTbRsp* pRsps;
4902
    SArray*      pArray;
4903
  };
4904
} SVDropTbBatchRsp;
4905

4906
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4907
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4908

4909
// TDMT_VND_ALTER_TABLE =====================
4910
typedef struct SMultiTagUpateVal {
4911
  char*    tagName;
4912
  int32_t  colId;
4913
  int8_t   tagType;
4914
  int8_t   tagFree;
4915
  uint32_t nTagVal;
4916
  uint8_t* pTagVal;
4917
  int8_t   isNull;
4918
  SArray*  pTagArray;
4919
} SMultiTagUpateVal;
4920
typedef struct SVAlterTbReq {
4921
  char*   tbName;
4922
  int8_t  action;
4923
  char*   colName;
4924
  int32_t colId;
4925
  // TSDB_ALTER_TABLE_ADD_COLUMN
4926
  int8_t  type;
4927
  int8_t  flags;
4928
  int32_t bytes;
4929
  // TSDB_ALTER_TABLE_DROP_COLUMN
4930
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4931
  int8_t   colModType;
4932
  int32_t  colModBytes;
4933
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4934
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4935
  int8_t   isNull;
4936
  int8_t   tagType;
4937
  int8_t   tagFree;
4938
  uint32_t nTagVal;
4939
  uint8_t* pTagVal;
4940
  SArray*  pTagArray;
4941
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4942
  int8_t   updateTTL;
4943
  int32_t  newTTL;
4944
  int32_t  newCommentLen;
4945
  char*    newComment;
4946
  int64_t  ctimeMs;    // fill by vnode
4947
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4948
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4949
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4950
  // for Add column
4951
  STypeMod typeMod;
4952
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4953
  char* refDbName;
4954
  char* refTbName;
4955
  char* refColName;
4956
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4957
} SVAlterTbReq;
4958

4959
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4960
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4961
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4962
void    tfreeMultiTagUpateVal(void* pMultiTag);
4963

4964
typedef struct {
4965
  int32_t        code;
4966
  STableMetaRsp* pMeta;
4967
} SVAlterTbRsp;
4968

4969
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4970
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4971
// ======================
4972

4973
typedef struct {
4974
  SMsgHead head;
4975
  int64_t  uid;
4976
  int32_t  tid;
4977
  int16_t  tversion;
4978
  int16_t  colId;
4979
  int8_t   type;
4980
  int16_t  bytes;
4981
  int32_t  tagValLen;
4982
  int16_t  numOfTags;
4983
  int32_t  schemaLen;
4984
  char     data[];
4985
} SUpdateTagValReq;
4986

4987
typedef struct {
4988
  SMsgHead head;
4989
} SUpdateTagValRsp;
4990

4991
typedef struct {
4992
  SMsgHead head;
4993
} SVShowTablesReq;
4994

4995
typedef struct {
4996
  SMsgHead head;
4997
  int32_t  id;
4998
} SVShowTablesFetchReq;
4999

5000
typedef struct {
5001
  int64_t useconds;
5002
  int8_t  completed;  // all results are returned to client
5003
  int8_t  precision;
5004
  int8_t  compressed;
5005
  int32_t compLen;
5006
  int32_t numOfRows;
5007
  char    data[];
5008
} SVShowTablesFetchRsp;
5009

5010
typedef struct {
5011
  int64_t consumerId;
5012
  int32_t epoch;
5013
  char    cgroup[TSDB_CGROUP_LEN];
5014
} SMqAskEpReq;
5015

5016
typedef struct {
5017
  int32_t key;
5018
  int32_t valueLen;
5019
  void*   value;
5020
} SKv;
5021

5022
typedef struct {
5023
  int64_t tscRid;
5024
  int8_t  connType;
5025
} SClientHbKey;
5026

5027
typedef struct {
5028
  int64_t tid;
5029
  char    status[TSDB_JOB_STATUS_LEN];
5030
} SQuerySubDesc;
5031

5032
typedef struct {
5033
  char     sql[TSDB_SHOW_SQL_LEN];
5034
  uint64_t queryId;
5035
  int64_t  useconds;
5036
  int64_t  stime;  // timestamp precision ms
5037
  int64_t  reqRid;
5038
  bool     stableQuery;
5039
  bool     isSubQuery;
5040
  char     fqdn[TSDB_FQDN_LEN];
5041
  int32_t  subPlanNum;
5042
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5043
} SQueryDesc;
5044

5045
typedef struct {
5046
  uint32_t connId;
5047
  SArray*  queryDesc;  // SArray<SQueryDesc>
5048
} SQueryHbReqBasic;
5049

5050
typedef struct {
5051
  uint32_t connId;
5052
  uint64_t killRid;
5053
  int32_t  totalDnodes;
5054
  int32_t  onlineDnodes;
5055
  int8_t   killConnection;
5056
  int8_t   align[3];
5057
  SEpSet   epSet;
5058
  SArray*  pQnodeList;
5059
} SQueryHbRspBasic;
5060

5061
typedef struct SAppClusterSummary {
5062
  uint64_t numOfInsertsReq;
5063
  uint64_t numOfInsertRows;
5064
  uint64_t insertElapsedTime;
5065
  uint64_t insertBytes;  // submit to tsdb since launched.
5066

5067
  uint64_t fetchBytes;
5068
  uint64_t numOfQueryReq;
5069
  uint64_t queryElapsedTime;
5070
  uint64_t numOfSlowQueries;
5071
  uint64_t totalRequests;
5072
  uint64_t currentRequests;  // the number of SRequestObj
5073
} SAppClusterSummary;
5074

5075
typedef struct {
5076
  int64_t            appId;
5077
  int32_t            pid;
5078
  char               name[TSDB_APP_NAME_LEN];
5079
  int64_t            startTime;
5080
  SAppClusterSummary summary;
5081
} SAppHbReq;
5082

5083
typedef struct {
5084
  SClientHbKey      connKey;
5085
  int64_t           clusterId;
5086
  SAppHbReq         app;
5087
  SQueryHbReqBasic* query;
5088
  SHashObj*         info;  // hash<Skv.key, Skv>
5089
  char              user[TSDB_USER_LEN];
5090
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5091
  char              userApp[TSDB_APP_NAME_LEN];
5092
  uint32_t          userIp;
5093
  SIpRange          userDualIp;
5094
  char              sVer[TSDB_VERSION_LEN];
5095
  char              cInfo[CONNECTOR_INFO_LEN];
5096
} SClientHbReq;
5097

5098
typedef struct {
5099
  int64_t reqId;
5100
  SArray* reqs;  // SArray<SClientHbReq>
5101
  int64_t ipWhiteListVer;
5102
} SClientHbBatchReq;
5103

5104
typedef struct {
5105
  SClientHbKey      connKey;
5106
  int32_t           status;
5107
  SQueryHbRspBasic* query;
5108
  SArray*           info;  // Array<Skv>
5109
} SClientHbRsp;
5110

5111
typedef struct {
5112
  int64_t       reqId;
5113
  int64_t       rspId;
5114
  int32_t       svrTimestamp;
5115
  SArray*       rsps;  // SArray<SClientHbRsp>
5116
  SMonitorParas monitorParas;
5117
  int8_t        enableAuditDelete;
5118
  int8_t        enableStrongPass;
5119
  int8_t        enableAuditSelect;
5120
  int8_t        enableAuditInsert;
5121
  int8_t        auditLevel;
5122
} SClientHbBatchRsp;
5123

5124
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
69,975,385✔
5125

5126
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5127
  void* pIter = taosHashIterate(info, NULL);
48,295,868✔
5128
  while (pIter != NULL) {
113,306,722✔
5129
    SKv* kv = (SKv*)pIter;
65,009,003✔
5130
    taosMemoryFreeClear(kv->value);
65,009,003✔
5131
    pIter = taosHashIterate(info, pIter);
65,008,879✔
5132
  }
5133
}
48,297,719✔
5134

5135
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
31,387,490✔
5136
  SQueryDesc* desc = (SQueryDesc*)pDesc;
31,387,490✔
5137
  if (desc->subDesc) {
31,387,490✔
5138
    taosArrayDestroy(desc->subDesc);
21,969,449✔
5139
    desc->subDesc = NULL;
21,965,812✔
5140
  }
5141
}
31,385,759✔
5142

5143
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
54,672,847✔
5144
  SClientHbReq* req = (SClientHbReq*)pReq;
57,326,837✔
5145
  if (req->query) {
57,326,837✔
5146
    if (req->query->queryDesc) {
54,673,384✔
5147
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
24,822,536✔
5148
    }
5149
    taosMemoryFreeClear(req->query);
54,669,616✔
5150
  }
5151

5152
  if (req->info) {
57,325,423✔
5153
    tFreeReqKvHash(req->info);
48,294,759✔
5154
    taosHashCleanup(req->info);
48,297,719✔
5155
    req->info = NULL;
48,297,215✔
5156
  }
5157
}
29,479,611✔
5158

5159
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5160
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5161

5162
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5163
  if (pReq == NULL) return;
23,509,388✔
5164
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
23,509,388✔
5165
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
23,509,388✔
5166
  taosMemoryFree(pReq);
23,509,388✔
5167
}
5168

5169
static FORCE_INLINE void tFreeClientKv(void* pKv) {
64,800,788✔
5170
  SKv* kv = (SKv*)pKv;
64,800,788✔
5171
  if (kv) {
64,800,788✔
5172
    taosMemoryFreeClear(kv->value);
64,801,941✔
5173
  }
5174
}
64,802,131✔
5175

5176
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
54,508,194✔
5177
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
54,508,194✔
5178
  if (rsp->query) {
54,508,194✔
5179
    taosArrayDestroy(rsp->query->pQnodeList);
54,502,531✔
5180
    taosMemoryFreeClear(rsp->query);
54,503,519✔
5181
  }
5182
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
54,509,276✔
5183
}
27,689,030✔
5184

5185
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5186
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
45,786,900✔
5187
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
45,786,900✔
5188
}
45,790,472✔
5189

5190
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5191
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5192
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5193

5194
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5195
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
407,543,762✔
5196
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
407,544,357✔
5197
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
407,542,404✔
5198
  return 0;
203,770,076✔
5199
}
5200

5201
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5202
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
133,958,110✔
5203
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
133,957,741✔
5204
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
66,978,686✔
5205
  if (pKv->value == NULL) {
66,979,055✔
UNCOV
5206
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5207
  }
5208
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
66,979,055✔
5209
  return 0;
66,979,055✔
5210
}
5211

5212
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5213
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
342,984,992✔
5214
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
342,974,100✔
5215
  return 0;
171,482,437✔
5216
}
5217

5218
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5219
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
113,149,642✔
5220
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
113,151,332✔
5221
  return 0;
56,575,780✔
5222
}
5223

5224
typedef struct {
5225
  int32_t vgId;
5226
  // TODO stas
5227
} SMqReportVgInfo;
5228

5229
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5230
  int32_t tlen = 0;
5231
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5232
  return tlen;
5233
}
5234

5235
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5236
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5237
  return buf;
5238
}
5239

5240
typedef struct {
5241
  int32_t epoch;
5242
  int64_t topicUid;
5243
  char    name[TSDB_TOPIC_FNAME_LEN];
5244
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5245
} SMqTopicInfo;
5246

5247
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5248
  int32_t tlen = 0;
5249
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5250
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5251
  tlen += taosEncodeString(buf, pTopicInfo->name);
5252
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5253
  tlen += taosEncodeFixedI32(buf, sz);
5254
  for (int32_t i = 0; i < sz; i++) {
5255
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5256
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5257
  }
5258
  return tlen;
5259
}
5260

5261
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5262
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5263
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5264
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5265
  int32_t sz;
5266
  buf = taosDecodeFixedI32(buf, &sz);
5267
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5268
    return NULL;
5269
  }
5270
  for (int32_t i = 0; i < sz; i++) {
5271
    SMqReportVgInfo vgInfo;
5272
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5273
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5274
      return NULL;
5275
    }
5276
  }
5277
  return buf;
5278
}
5279

5280
typedef struct {
5281
  int32_t status;  // ask hb endpoint
5282
  int32_t epoch;
5283
  int64_t consumerId;
5284
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5285
} SMqReportReq;
5286

5287
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5288
  int32_t tlen = 0;
5289
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5290
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5291
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5292
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5293
  tlen += taosEncodeFixedI32(buf, sz);
5294
  for (int32_t i = 0; i < sz; i++) {
5295
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5296
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5297
  }
5298
  return tlen;
5299
}
5300

5301
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5302
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5303
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5304
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5305
  int32_t sz;
5306
  buf = taosDecodeFixedI32(buf, &sz);
5307
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5308
    return NULL;
5309
  }
5310
  for (int32_t i = 0; i < sz; i++) {
5311
    SMqTopicInfo topicInfo;
5312
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5313
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5314
      return NULL;
5315
    }
5316
  }
5317
  return buf;
5318
}
5319

5320
typedef struct {
5321
  SMsgHead head;
5322
  int64_t  leftForVer;
5323
  int32_t  vgId;
5324
  int64_t  consumerId;
5325
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5326
} SMqVDeleteReq;
5327

5328
typedef struct {
5329
  int8_t reserved;
5330
} SMqVDeleteRsp;
5331

5332
typedef struct {
5333
  char**  name;
5334
  int32_t count;
5335
  int8_t igNotExists;
5336
} SMDropStreamReq;
5337

5338
typedef struct {
5339
  int8_t reserved;
5340
} SMDropStreamRsp;
5341

5342
typedef struct {
5343
  SMsgHead head;
5344
  int64_t  resetRelHalt;  // reset related stream task halt status
5345
  int64_t  streamId;
5346
  int32_t  taskId;
5347
} SVDropStreamTaskReq;
5348

5349
typedef struct {
5350
  int8_t reserved;
5351
} SVDropStreamTaskRsp;
5352

5353
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5354
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5355
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5356

5357
typedef struct {
5358
  char*  name;
5359
  int8_t igNotExists;
5360
} SMPauseStreamReq;
5361

5362
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5363
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5364
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5365

5366
typedef struct {
5367
  char*  name;
5368
  int8_t igNotExists;
5369
  int8_t igUntreated;
5370
} SMResumeStreamReq;
5371

5372
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5373
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5374
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5375

5376
typedef struct {
5377
  char*       name;
5378
  int8_t      calcAll;
5379
  STimeWindow timeRange;
5380
} SMRecalcStreamReq;
5381

5382
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5383
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5384
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5385

5386

5387
typedef struct SVndSetKeepVersionReq {
5388
  int64_t keepVersion;
5389
} SVndSetKeepVersionReq;
5390

5391
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5392
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5393

5394
typedef struct SVUpdateCheckpointInfoReq {
5395
  SMsgHead head;
5396
  int64_t  streamId;
5397
  int32_t  taskId;
5398
  int64_t  checkpointId;
5399
  int64_t  checkpointVer;
5400
  int64_t  checkpointTs;
5401
  int32_t  transId;
5402
  int64_t  hStreamId;  // add encode/decode
5403
  int64_t  hTaskId;
5404
  int8_t   dropRelHTask;
5405
} SVUpdateCheckpointInfoReq;
5406

5407
typedef struct {
5408
  int64_t leftForVer;
5409
  int32_t vgId;
5410
  int64_t oldConsumerId;
5411
  int64_t newConsumerId;
5412
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5413
  int8_t  subType;
5414
  int8_t  withMeta;
5415
  char*   qmsg;  // SubPlanToString
5416
  SSchemaWrapper schema;
5417
  int64_t suid;
5418
} SMqRebVgReq;
5419

5420
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5421
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5422

5423
// tqOffset
5424
enum {
5425
  TMQ_OFFSET__RESET_NONE = -3,
5426
  TMQ_OFFSET__RESET_EARLIEST = -2,
5427
  TMQ_OFFSET__RESET_LATEST = -1,
5428
  TMQ_OFFSET__LOG = 1,
5429
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5430
  TMQ_OFFSET__SNAPSHOT_META = 3,
5431
};
5432

5433
enum {
5434
  WITH_DATA = 0,
5435
  WITH_META = 1,
5436
  ONLY_META = 2,
5437
};
5438

5439
#define TQ_OFFSET_VERSION 1
5440

5441
typedef struct {
5442
  int8_t type;
5443
  union {
5444
    // snapshot
5445
    struct {
5446
      int64_t uid;
5447
      int64_t ts;
5448
      SValue  primaryKey;
5449
    };
5450
    // log
5451
    struct {
5452
      int64_t version;
5453
    };
5454
  };
5455
} STqOffsetVal;
5456

5457
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5458
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,523,174✔
5459
  pOffsetVal->uid = uid;
7,523,156✔
5460
  pOffsetVal->ts = ts;
7,523,759✔
5461
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,523,440✔
5462
    taosMemoryFree(pOffsetVal->primaryKey.pData);
281✔
5463
  }
5464
  pOffsetVal->primaryKey = primaryKey;
7,522,602✔
5465
}
7,522,281✔
5466

5467
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5468
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
40,349✔
5469
  pOffsetVal->uid = uid;
40,349✔
5470
}
40,349✔
5471

5472
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5473
  pOffsetVal->type = TMQ_OFFSET__LOG;
119,564,460✔
5474
  pOffsetVal->version = ver;
119,564,452✔
5475
}
119,560,683✔
5476

5477
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5478
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5479
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5480
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5481
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5482
void    tOffsetDestroy(void* pVal);
5483

5484
typedef struct {
5485
  STqOffsetVal val;
5486
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5487
} STqOffset;
5488

5489
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5490
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5491
void    tDeleteSTqOffset(void* val);
5492

5493
typedef struct SMqVgOffset {
5494
  int64_t   consumerId;
5495
  STqOffset offset;
5496
} SMqVgOffset;
5497

5498
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5499
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5500

5501
typedef struct {
5502
  char    name[TSDB_TABLE_FNAME_LEN];
5503
  char    stb[TSDB_TABLE_FNAME_LEN];
5504
  int8_t  igExists;
5505
  int8_t  intervalUnit;
5506
  int8_t  slidingUnit;
5507
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5508
  int32_t dstVgId;   // for stream
5509
  int64_t interval;
5510
  int64_t offset;
5511
  int64_t sliding;
5512
  int64_t maxDelay;
5513
  int64_t watermark;
5514
  int32_t exprLen;        // strlen + 1
5515
  int32_t tagsFilterLen;  // strlen + 1
5516
  int32_t sqlLen;         // strlen + 1
5517
  int32_t astLen;         // strlen + 1
5518
  char*   expr;
5519
  char*   tagsFilter;
5520
  char*   sql;
5521
  char*   ast;
5522
  int64_t deleteMark;
5523
  int64_t lastTs;
5524
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5525
  SArray* pVgroupVerList;
5526
  int8_t  recursiveTsma;
5527
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5528
  char*   createStreamReq;
5529
  int32_t streamReqLen;
5530
  char*   dropStreamReq;
5531
  int32_t dropStreamReqLen;
5532
  int64_t uid;
5533
} SMCreateSmaReq;
5534

5535
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5536
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5537
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5538

5539
typedef struct {
5540
  char    name[TSDB_TABLE_FNAME_LEN];
5541
  int8_t  igNotExists;
5542
  char*   dropStreamReq;
5543
  int32_t dropStreamReqLen;
5544
} SMDropSmaReq;
5545

5546
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5547
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5548
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5549

5550
typedef struct {
5551
  char name[TSDB_TABLE_NAME_LEN];
5552
  union {
5553
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5554
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5555
  };
5556
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5557
  union {
5558
    int8_t igExists;   // used by mnode
5559
    int8_t alterType;  // used by vnode
5560
  };
5561
  int8_t     intervalUnit;
5562
  int16_t    nFuncs;       // number of functions specified by user
5563
  col_id_t*  funcColIds;   // column ids specified by user
5564
  func_id_t* funcIds;      // function ids specified by user
5565
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5566
  int64_t    tbUid;
5567
  int64_t    uid;     // rsma uid
5568
  int32_t    sqlLen;  // strlen + 1
5569
  char*      sql;
5570
} SMCreateRsmaReq;
5571

5572
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5573
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5574
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5575

5576
typedef SMCreateRsmaReq SVCreateRsmaReq;
5577

5578
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5579
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5580
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5581

5582
typedef SMCreateRsmaReq SVAlterRsmaReq;
5583

5584
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5585
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5586
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5587

5588
typedef struct {
5589
  char       name[TSDB_TABLE_NAME_LEN];
5590
  int8_t     alterType;
5591
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5592
  int8_t     igNotExists;
5593
  int16_t    nFuncs;      // number of functions specified by user
5594
  col_id_t*  funcColIds;  // column ids specified by user
5595
  func_id_t* funcIds;     // function ids specified by user
5596
  int32_t    sqlLen;      // strlen + 1
5597
  char*      sql;
5598
} SMAlterRsmaReq;
5599

5600
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5601
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5602
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5603

5604
typedef struct {
5605
  int64_t    id;
5606
  char       name[TSDB_TABLE_NAME_LEN];
5607
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5608
  int64_t    ownerId;
5609
  int32_t    code;
5610
  int32_t    version;
5611
  int8_t     tbType;
5612
  int8_t     intervalUnit;
5613
  col_id_t   nFuncs;
5614
  col_id_t   nColNames;
5615
  int64_t    interval[2];
5616
  col_id_t*  funcColIds;
5617
  func_id_t* funcIds;
5618
  SArray*    colNames;
5619
} SRsmaInfoRsp;
5620

5621
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5622
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5623
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5624

5625
typedef struct {
5626
  char   name[TSDB_TABLE_FNAME_LEN];
5627
  int8_t igNotExists;
5628
} SMDropRsmaReq;
5629

5630
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5631
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5632

5633
typedef struct {
5634
  char    name[TSDB_TABLE_NAME_LEN];
5635
  char    tbName[TSDB_TABLE_NAME_LEN];
5636
  int64_t uid;
5637
  int64_t tbUid;
5638
  int8_t  tbType;
5639
} SVDropRsmaReq;
5640

5641
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5642
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5643

5644
typedef struct {
5645
  char   dbFName[TSDB_DB_FNAME_LEN];
5646
  char   stbName[TSDB_TABLE_NAME_LEN];
5647
  char   colName[TSDB_COL_NAME_LEN];
5648
  char   idxName[TSDB_INDEX_FNAME_LEN];
5649
  int8_t idxType;
5650
} SCreateTagIndexReq;
5651

5652
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5653
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5654

5655
typedef SMDropSmaReq SDropTagIndexReq;
5656

5657
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5658
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5659

5660
typedef struct {
5661
  int8_t         version;       // for compatibility(default 0)
5662
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5663
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5664
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5665
  int32_t        dstVgId;
5666
  char           indexName[TSDB_INDEX_NAME_LEN];
5667
  int32_t        exprLen;
5668
  int32_t        tagsFilterLen;
5669
  int64_t        indexUid;
5670
  tb_uid_t       tableUid;  // super/child/common table uid
5671
  tb_uid_t       dstTbUid;  // for dstVgroup
5672
  int64_t        interval;
5673
  int64_t        offset;  // use unit by precision of DB
5674
  int64_t        sliding;
5675
  char*          dstTbName;  // for dstVgroup
5676
  char*          expr;       // sma expression
5677
  char*          tagsFilter;
5678
  SSchemaWrapper schemaRow;  // for dstVgroup
5679
  SSchemaWrapper schemaTag;  // for dstVgroup
5680
} STSma;                     // Time-range-wise SMA
5681

5682
typedef STSma SVCreateTSmaReq;
5683

5684
typedef struct {
5685
  int8_t  type;  // 0 status report, 1 update data
5686
  int64_t indexUid;
5687
  int64_t skey;  // start TS key of interval/sliding window
5688
} STSmaMsg;
5689

5690
typedef struct {
5691
  int64_t indexUid;
5692
  char    indexName[TSDB_INDEX_NAME_LEN];
5693
} SVDropTSmaReq;
5694

5695
typedef struct {
5696
  int tmp;  // TODO: to avoid compile error
5697
} SVCreateTSmaRsp, SVDropTSmaRsp;
5698

5699
#if 0
5700
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5701
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5702
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5703
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5704
#endif
5705

5706
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5707
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5708
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5709
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5710

5711
typedef struct {
5712
  int32_t number;
5713
  STSma*  tSma;
5714
} STSmaWrapper;
5715

5716
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5717
  if (pSma) {
×
UNCOV
5718
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5719
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5720
    taosMemoryFreeClear(pSma->tagsFilter);
×
5721
  }
UNCOV
5722
}
×
5723

5724
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5725
  if (pSW) {
×
UNCOV
5726
    if (pSW->tSma) {
×
UNCOV
5727
      if (deepCopy) {
×
UNCOV
5728
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5729
          tDestroyTSma(pSW->tSma + i);
×
5730
        }
5731
      }
UNCOV
5732
      taosMemoryFreeClear(pSW->tSma);
×
5733
    }
5734
  }
UNCOV
5735
}
×
5736

5737
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5738
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5739
  taosMemoryFreeClear(pSW);
×
UNCOV
5740
  return NULL;
×
5741
}
5742

5743
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5744
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5745

5746
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5747
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5748

UNCOV
5749
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5750
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5751
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5752
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5753
  }
UNCOV
5754
  return 0;
×
5755
}
5756

UNCOV
5757
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5758
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5759
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5760
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5761
  }
UNCOV
5762
  return 0;
×
5763
}
5764

5765
typedef struct {
5766
  int idx;
5767
} SMCreateFullTextReq;
5768

5769
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5770
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5771
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5772

5773
typedef struct {
5774
  char   name[TSDB_TABLE_FNAME_LEN];
5775
  int8_t igNotExists;
5776
} SMDropFullTextReq;
5777

5778
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5779
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5780

5781
typedef struct {
5782
  char indexFName[TSDB_INDEX_FNAME_LEN];
5783
} SUserIndexReq;
5784

5785
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5786
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5787

5788
typedef struct {
5789
  char dbFName[TSDB_DB_FNAME_LEN];
5790
  char tblFName[TSDB_TABLE_FNAME_LEN];
5791
  char colName[TSDB_COL_NAME_LEN];
5792
  char owner[TSDB_USER_LEN];
5793
  char indexType[TSDB_INDEX_TYPE_LEN];
5794
  char indexExts[TSDB_INDEX_EXTS_LEN];
5795
} SUserIndexRsp;
5796

5797
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5798
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5799

5800
typedef struct {
5801
  char tbFName[TSDB_TABLE_FNAME_LEN];
5802
} STableIndexReq;
5803

5804
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5805
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5806

5807
typedef struct {
5808
  int8_t  intervalUnit;
5809
  int8_t  slidingUnit;
5810
  int64_t interval;
5811
  int64_t offset;
5812
  int64_t sliding;
5813
  int64_t dstTbUid;
5814
  int32_t dstVgId;
5815
  SEpSet  epSet;
5816
  char*   expr;
5817
} STableIndexInfo;
5818

5819
typedef struct {
5820
  char     tbName[TSDB_TABLE_NAME_LEN];
5821
  char     dbFName[TSDB_DB_FNAME_LEN];
5822
  uint64_t suid;
5823
  int32_t  version;
5824
  int32_t  indexSize;
5825
  SArray*  pIndex;  // STableIndexInfo
5826
} STableIndexRsp;
5827

5828
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5829
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5830
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5831

5832
void tFreeSTableIndexInfo(void* pInfo);
5833

5834
typedef struct {
5835
  int8_t  mqMsgType;
5836
  int32_t code;
5837
  int32_t epoch;
5838
  int64_t consumerId;
5839
  int64_t walsver;
5840
  int64_t walever;
5841
} SMqRspHead;
5842

5843
typedef struct {
5844
  SMsgHead     head;
5845
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5846
  int8_t       withTbName;
5847
  int8_t       useSnapshot;
5848
  int32_t      epoch;
5849
  uint64_t     reqId;
5850
  int64_t      consumerId;
5851
  int64_t      timeout;
5852
  STqOffsetVal reqOffset;
5853
  int8_t       enableReplay;
5854
  int8_t       sourceExcluded;
5855
  int8_t       rawData;
5856
  int32_t      minPollRows;
5857
  int8_t       enableBatchMeta;
5858
  SHashObj*    uidHash;  // to find if uid is duplicated
5859
} SMqPollReq;
5860

5861
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5862
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5863
void    tDestroySMqPollReq(SMqPollReq* pReq);
5864

5865
typedef struct {
5866
  int32_t vgId;
5867
  int64_t offset;
5868
  SEpSet  epSet;
5869
} SMqSubVgEp;
5870

5871
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5872
  int32_t tlen = 0;
2,557,478✔
5873
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,557,478✔
5874
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,557,478✔
5875
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,557,478✔
5876
  return tlen;
2,557,478✔
5877
}
5878

5879
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5880
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,266,195✔
5881
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,266,195✔
5882
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,266,195✔
5883
  return buf;
1,266,195✔
5884
}
5885

5886
typedef struct {
5887
  char           topic[TSDB_TOPIC_FNAME_LEN];
5888
  char           db[TSDB_DB_FNAME_LEN];
5889
  SArray*        vgs;  // SArray<SMqSubVgEp>
5890
} SMqSubTopicEp;
5891

5892
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5893
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5894
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5895

5896
typedef struct {
5897
  SMqRspHead   head;
5898
  STqOffsetVal rspOffset;
5899
  int16_t      resMsgType;
5900
  int32_t      metaRspLen;
5901
  void*        metaRsp;
5902
} SMqMetaRsp;
5903

5904
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5905
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5906
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5907

5908
#define MQ_DATA_RSP_VERSION 100
5909

5910
typedef struct {
5911
  SMqRspHead   head;
5912
  STqOffsetVal rspOffset;
5913
  STqOffsetVal reqOffset;
5914
  int32_t      blockNum;
5915
  int8_t       withTbName;
5916
  int8_t       withSchema;
5917
  SArray*      blockDataLen;
5918
  SArray*      blockData;
5919
  SArray*      blockTbName;
5920
  SArray*      blockSchema;
5921

5922
  union {
5923
    struct {
5924
      int64_t sleepTime;
5925
    };
5926
    struct {
5927
      int32_t createTableNum;
5928
      SArray* createTableLen;
5929
      SArray* createTableReq;
5930
    };
5931
    struct {
5932
      int32_t len;
5933
      void*   rawData;
5934
    };
5935
  };
5936
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5937
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5938
} SMqDataRsp;
5939

5940
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5941
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5942
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5943
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5944
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5945

5946
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5947
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5948
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5949

5950
typedef struct SMqBatchMetaRsp {
5951
  SMqRspHead   head;  // not serialize
5952
  STqOffsetVal rspOffset;
5953
  SArray*      batchMetaLen;
5954
  SArray*      batchMetaReq;
5955
  void*        pMetaBuff;    // not serialize
5956
  uint32_t     metaBuffLen;  // not serialize
5957
} SMqBatchMetaRsp;
5958

5959
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5960
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5961
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5962
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5963

5964
typedef struct {
5965
  int32_t    code;
5966
  SArray*    topics;  // SArray<SMqSubTopicEp>
5967
} SMqAskEpRsp;
5968

5969
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5970
  int32_t tlen = 0;
7,531,221✔
5971
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5972
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,531,221✔
5973
  tlen += taosEncodeFixedI32(buf, sz);
7,531,548✔
5974
  for (int32_t i = 0; i < sz; i++) {
9,437,276✔
5975
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,906,040✔
5976
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,906,372✔
5977
  }
5978
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,531,236✔
5979

5980
  return tlen;
7,531,216✔
5981
}
5982

5983
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5984
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5985
  int32_t sz;
3,311,218✔
5986
  buf = taosDecodeFixedI32(buf, &sz);
3,381,154✔
5987
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,381,154✔
5988
  if (pRsp->topics == NULL) {
3,381,154✔
UNCOV
5989
    return NULL;
×
5990
  }
5991
  for (int32_t i = 0; i < sz; i++) {
4,310,083✔
5992
    SMqSubTopicEp topicEp;
916,867✔
5993
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
928,929✔
5994
    if (buf == NULL) {
928,929✔
UNCOV
5995
      return NULL;
×
5996
    }
5997
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,857,858✔
UNCOV
5998
      return NULL;
×
5999
    }
6000
  }
6001
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,381,154✔
6002

6003
  return buf;
3,381,154✔
6004
}
6005

6006
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6007
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,586,225✔
6008
}
9,584,922✔
6009

6010
typedef struct {
6011
  int32_t      vgId;
6012
  STqOffsetVal offset;
6013
  int64_t      rows;
6014
  int64_t      ever;
6015
} OffsetRows;
6016

6017
typedef struct {
6018
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6019
  SArray* offsetRows;
6020
} TopicOffsetRows;
6021

6022
typedef struct {
6023
  int64_t consumerId;
6024
  int32_t epoch;
6025
  SArray* topics;
6026
  int8_t  pollFlag;
6027
} SMqHbReq;
6028

6029
typedef struct {
6030
  char   topic[TSDB_TOPIC_FNAME_LEN];
6031
  int8_t noPrivilege;
6032
} STopicPrivilege;
6033

6034
typedef struct {
6035
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6036
  int32_t debugFlag;
6037
} SMqHbRsp;
6038

6039
typedef struct {
6040
  SMsgHead head;
6041
  int64_t  consumerId;
6042
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6043
} SMqSeekReq;
6044

6045
#define TD_AUTO_CREATE_TABLE 0x1
6046
typedef struct {
6047
  int64_t       suid;
6048
  int64_t       uid;
6049
  int32_t       sver;
6050
  uint32_t      nData;
6051
  uint8_t*      pData;
6052
  SVCreateTbReq cTbReq;
6053
} SVSubmitBlk;
6054

6055
typedef struct {
6056
  SMsgHead header;
6057
  uint64_t sId;
6058
  uint64_t queryId;
6059
  uint64_t clientId;
6060
  uint64_t taskId;
6061
  uint32_t sqlLen;
6062
  uint32_t phyLen;
6063
  char*    sql;
6064
  char*    msg;
6065
  int8_t   source;
6066
} SVDeleteReq;
6067

6068
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6069
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6070

6071
typedef struct {
6072
  int64_t affectedRows;
6073
} SVDeleteRsp;
6074

6075
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6076
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6077

6078
typedef struct SDeleteRes {
6079
  uint64_t suid;
6080
  SArray*  uidList;
6081
  int64_t  skey;
6082
  int64_t  ekey;
6083
  int64_t  affectedRows;
6084
  char     tableFName[TSDB_TABLE_NAME_LEN];
6085
  char     tsColName[TSDB_COL_NAME_LEN];
6086
  int64_t  ctimeMs;  // fill by vnode
6087
  int8_t   source;
6088
} SDeleteRes;
6089

6090
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6091
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6092

6093
typedef struct {
6094
  // int64_t uid;
6095
  char    tbname[TSDB_TABLE_NAME_LEN];
6096
  int64_t startTs;
6097
  int64_t endTs;
6098
} SSingleDeleteReq;
6099

6100
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6101
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6102

6103
typedef struct {
6104
  int64_t suid;
6105
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6106
  int64_t ctimeMs;     // fill by vnode
6107
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6108
} SBatchDeleteReq;
6109

6110
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6111
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6112
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6113

6114
typedef struct {
6115
  int32_t msgIdx;
6116
  int32_t msgType;
6117
  int32_t msgLen;
6118
  void*   msg;
6119
} SBatchMsg;
6120

6121
typedef struct {
6122
  SMsgHead header;
6123
  SArray*  pMsgs;  // SArray<SBatchMsg>
6124
} SBatchReq;
6125

6126
typedef struct {
6127
  int32_t reqType;
6128
  int32_t msgIdx;
6129
  int32_t msgLen;
6130
  int32_t rspCode;
6131
  void*   msg;
6132
} SBatchRspMsg;
6133

6134
typedef struct {
6135
  SArray* pRsps;  // SArray<SBatchRspMsg>
6136
} SBatchRsp;
6137

6138
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6139
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6140
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
91,934,640✔
6141
  if (NULL == msg) {
91,934,640✔
UNCOV
6142
    return;
×
6143
  }
6144
  SBatchMsg* pMsg = (SBatchMsg*)msg;
91,934,640✔
6145
  taosMemoryFree(pMsg->msg);
91,934,640✔
6146
}
6147

6148
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6149
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6150

6151
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
129,071,413✔
6152
  if (NULL == p) {
129,071,413✔
UNCOV
6153
    return;
×
6154
  }
6155

6156
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
129,071,413✔
6157
  taosMemoryFree(pRsp->msg);
129,071,413✔
6158
}
6159

6160
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6161
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6162
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6163
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6164
void    tDestroySMqHbReq(SMqHbReq* pReq);
6165

6166
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6167
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6168
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6169

6170
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6171
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6172

6173
#define TD_REQ_FROM_APP               0x0
6174
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6175
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6176
#define SUBMIT_REQ_FROM_FILE          0x4
6177
#define TD_REQ_FROM_TAOX              0x8
6178
#define TD_REQ_FROM_SML               0x10
6179
#define SUBMIT_REQUEST_VERSION        (2)
6180
#define SUBMIT_REQ_WITH_BLOB          0x10
6181
#define SUBMIT_REQ_SCHEMA_RES         0x20
6182
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6183

6184
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6185

6186
typedef struct {
6187
  int32_t        flags;
6188
  SVCreateTbReq* pCreateTbReq;
6189
  int64_t        suid;
6190
  int64_t        uid;
6191
  int32_t        sver;
6192
  union {
6193
    SArray* aRowP;
6194
    SArray* aCol;
6195
  };
6196
  int64_t   ctimeMs;
6197
  SBlobSet* pBlobSet;
6198
} SSubmitTbData;
6199

6200
typedef struct {
6201
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6202
  SArray* aSubmitBlobData;
6203
  bool    raw;
6204
} SSubmitReq2;
6205

6206
typedef struct {
6207
  SMsgHead header;
6208
  int64_t  version;
6209
  char     data[];  // SSubmitReq2
6210
} SSubmitReq2Msg;
6211

6212
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6213
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6214
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6215
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6216
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6217

6218
typedef struct {
6219
  int32_t affectedRows;
6220
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6221
} SSubmitRsp2;
6222

6223
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6224
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6225
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6226

6227
#define TSDB_MSG_FLG_ENCODE 0x1
6228
#define TSDB_MSG_FLG_DECODE 0x2
6229
#define TSDB_MSG_FLG_CMPT   0x3
6230

6231
typedef struct {
6232
  union {
6233
    struct {
6234
      void*   msgStr;
6235
      int32_t msgLen;
6236
      int64_t ver;
6237
    };
6238
    void* pDataBlock;
6239
  };
6240
} SPackedData;
6241

6242
typedef struct {
6243
  char     fullname[TSDB_VIEW_FNAME_LEN];
6244
  char     name[TSDB_VIEW_NAME_LEN];
6245
  char     dbFName[TSDB_DB_FNAME_LEN];
6246
  char*    querySql;
6247
  char*    sql;
6248
  int8_t   orReplace;
6249
  int8_t   precision;
6250
  int32_t  numOfCols;
6251
  SSchema* pSchema;
6252
} SCMCreateViewReq;
6253

6254
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6255
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6256
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6257

6258
typedef struct {
6259
  char   fullname[TSDB_VIEW_FNAME_LEN];
6260
  char   name[TSDB_VIEW_NAME_LEN];
6261
  char   dbFName[TSDB_DB_FNAME_LEN];
6262
  char*  sql;
6263
  int8_t igNotExists;
6264
} SCMDropViewReq;
6265

6266
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6267
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6268
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6269

6270
typedef struct {
6271
  char fullname[TSDB_VIEW_FNAME_LEN];
6272
} SViewMetaReq;
6273
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6274
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6275

6276
typedef struct {
6277
  char     name[TSDB_VIEW_NAME_LEN];
6278
  char     dbFName[TSDB_DB_FNAME_LEN];
6279
  char*    createUser;
6280
  int64_t  ownerId;
6281
  uint64_t dbId;
6282
  uint64_t viewId;
6283
  char*    querySql;
6284
  int8_t   precision;
6285
  int8_t   type;
6286
  int32_t  version;
6287
  int32_t  numOfCols;
6288
  SSchema* pSchema;
6289
} SViewMetaRsp;
6290
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6291
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6292
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6293
typedef struct {
6294
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6295
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6296
} STableTSMAInfoReq;
6297

6298
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6299
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6300

6301
typedef struct {
6302
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6303
  union {
6304
    uint8_t flags;
6305
    struct {
6306
      uint8_t withColName : 1;
6307
      uint8_t reserved : 7;
6308
    };
6309
  };
6310

6311
} SRsmaInfoReq;
6312

6313
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6314
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6315

6316
typedef struct {
6317
  int32_t  funcId;
6318
  col_id_t colId;
6319
} STableTSMAFuncInfo;
6320

6321
typedef struct {
6322
  char     name[TSDB_TABLE_NAME_LEN];
6323
  uint64_t tsmaId;
6324
  char     targetTb[TSDB_TABLE_NAME_LEN];
6325
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6326
  char     tb[TSDB_TABLE_NAME_LEN];
6327
  char     dbFName[TSDB_DB_FNAME_LEN];
6328
  uint64_t suid;
6329
  uint64_t destTbUid;
6330
  uint64_t dbId;
6331
  int32_t  version;
6332
  int64_t  interval;
6333
  int8_t   unit;
6334
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6335
  SArray*  pTags;      // SArray<SSchema>
6336
  SArray*  pUsedCols;  // SArray<SSchema>
6337
  char*    ast;
6338

6339
  int64_t streamUid;
6340
  int64_t reqTs;
6341
  int64_t rspTs;
6342
  int64_t delayDuration;  // ms
6343
  bool    fillHistoryFinished;
6344

6345
  void* streamAddr;  // for stream task, the address of the stream task
6346
} STableTSMAInfo;
6347

6348
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6349
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6350
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6351
void    tFreeTableTSMAInfo(void* p);
6352
void    tFreeAndClearTableTSMAInfo(void* p);
6353
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6354

6355
#define STSMAHbRsp            STableTSMAInfoRsp
6356
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6357
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6358
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6359

6360
typedef struct SDropCtbWithTsmaSingleVgReq {
6361
  SVgroupInfo vgInfo;
6362
  SArray*     pTbs;  // SVDropTbReq
6363
} SMDropTbReqsOnSingleVg;
6364

6365
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6366
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6367
void    tFreeSMDropTbReqOnSingleVg(void* p);
6368

6369
typedef struct SDropTbsReq {
6370
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6371
} SMDropTbsReq;
6372

6373
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6374
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6375
void    tFreeSMDropTbsReq(void*);
6376

6377
typedef struct SVFetchTtlExpiredTbsRsp {
6378
  SArray* pExpiredTbs;  // SVDropTbReq
6379
  int32_t vgId;
6380
} SVFetchTtlExpiredTbsRsp;
6381

6382
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6383
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6384

6385
void tFreeFetchTtlExpiredTbsRsp(void* p);
6386

6387
void setDefaultOptionsForField(SFieldWithOptions* field);
6388
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6389

6390
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6391
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6392

6393

6394
typedef struct {
6395
  char    id[TSDB_INSTANCE_ID_LEN];
6396
  char    type[TSDB_INSTANCE_TYPE_LEN];
6397
  char    desc[TSDB_INSTANCE_DESC_LEN];
6398
  int32_t expire;
6399
} SInstanceRegisterReq;
6400

6401
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6402
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6403

6404
typedef struct {
6405
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6406
} SInstanceListReq;
6407

6408
typedef struct {
6409
  int32_t count;
6410
  char**  ids;  // Array of instance IDs
6411
} SInstanceListRsp;
6412

6413
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6414
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6415
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6416
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6417

6418
#ifdef USE_MOUNT
6419
typedef struct {
6420
  char     mountName[TSDB_MOUNT_NAME_LEN];
6421
  int8_t   ignoreExist;
6422
  int16_t  nMounts;
6423
  int32_t* dnodeIds;
6424
  char**   mountPaths;
6425
  int32_t  sqlLen;
6426
  char*    sql;
6427
} SCreateMountReq;
6428

6429
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6430
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6431
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6432

6433
typedef struct {
6434
  char    mountName[TSDB_MOUNT_NAME_LEN];
6435
  int8_t  ignoreNotExists;
6436
  int32_t sqlLen;
6437
  char*   sql;
6438
} SDropMountReq;
6439

6440
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6441
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6442
void    tFreeSDropMountReq(SDropMountReq* pReq);
6443

6444
typedef struct {
6445
  char     mountName[TSDB_MOUNT_NAME_LEN];
6446
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6447
  int64_t  mountUid;
6448
  int32_t  dnodeId;
6449
  uint32_t valLen;
6450
  int8_t   ignoreExist;
6451
  void*    pVal;
6452
} SRetrieveMountPathReq;
6453

6454
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6455
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6456

6457
typedef struct {
6458
  // path
6459
  int32_t diskPrimary;
6460
  // vgInfo
6461
  int32_t  vgId;
6462
  int32_t  cacheLastSize;
6463
  int32_t  szPage;
6464
  int32_t  szCache;
6465
  uint64_t szBuf;
6466
  int8_t   cacheLast;
6467
  int8_t   standby;
6468
  int8_t   hashMethod;
6469
  uint32_t hashBegin;
6470
  uint32_t hashEnd;
6471
  int16_t  hashPrefix;
6472
  int16_t  hashSuffix;
6473
  int16_t  sttTrigger;
6474
  // syncInfo
6475
  int32_t replications;
6476
  // tsdbInfo
6477
  int8_t  precision;
6478
  int8_t  compression;
6479
  int8_t  slLevel;
6480
  int32_t daysPerFile;
6481
  int32_t keep0;
6482
  int32_t keep1;
6483
  int32_t keep2;
6484
  int32_t keepTimeOffset;
6485
  int32_t minRows;
6486
  int32_t maxRows;
6487
  int32_t tsdbPageSize;
6488
  int32_t ssChunkSize;
6489
  int32_t ssKeepLocal;
6490
  int8_t  ssCompact;
6491
  union {
6492
    uint8_t flags;
6493
    struct {
6494
      uint8_t isAudit : 1;
6495
      uint8_t allowDrop : 1;
6496
      uint8_t reserved : 6;
6497
    };
6498
  };
6499
  // walInfo
6500
  int32_t walFsyncPeriod;      // millisecond
6501
  int32_t walRetentionPeriod;  // secs
6502
  int32_t walRollPeriod;       // secs
6503
  int64_t walRetentionSize;
6504
  int64_t walSegSize;
6505
  int32_t walLevel;
6506
  // encryptInfo
6507
  int32_t encryptAlgorithm;
6508
  // SVState
6509
  int64_t committed;
6510
  int64_t commitID;
6511
  int64_t commitTerm;
6512
  // stats
6513
  int64_t numOfSTables;
6514
  int64_t numOfCTables;
6515
  int64_t numOfNTables;
6516
  // dbInfo
6517
  uint64_t dbId;
6518
} SMountVgInfo;
6519

6520
typedef struct {
6521
  SMCreateStbReq req;
6522
  SArray*        pColExts;  // element: column id
6523
  SArray*        pTagExts;  // element: tag id
6524
} SMountStbInfo;
6525

6526
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6527
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6528

6529
typedef struct {
6530
  char     dbName[TSDB_DB_FNAME_LEN];
6531
  uint64_t dbId;
6532
  SArray*  pVgs;   // SMountVgInfo
6533
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6534
} SMountDbInfo;
6535

6536
typedef struct {
6537
  // common fields
6538
  char     mountName[TSDB_MOUNT_NAME_LEN];
6539
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6540
  int8_t   ignoreExist;
6541
  int64_t  mountUid;
6542
  int64_t  clusterId;
6543
  int32_t  dnodeId;
6544
  uint32_t valLen;
6545
  void*    pVal;
6546

6547
  // response fields
6548
  SArray* pDbs;  // SMountDbInfo
6549

6550
  // memory fields, no serialized
6551
  SArray*   pDisks[TFS_MAX_TIERS];
6552
  TdFilePtr pFile;
6553
} SMountInfo;
6554

6555
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6556
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6557
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6558

6559
typedef struct {
6560
  SCreateVnodeReq createReq;
6561
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6562
  char            mountName[TSDB_MOUNT_NAME_LEN];
6563
  int64_t         mountId;
6564
  int32_t         diskPrimary;
6565
  int32_t         mountVgId;
6566
  int64_t         committed;
6567
  int64_t         commitID;
6568
  int64_t         commitTerm;
6569
  int64_t         numOfSTables;
6570
  int64_t         numOfCTables;
6571
  int64_t         numOfNTables;
6572
} SMountVnodeReq;
6573

6574
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6575
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6576
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6577

6578
#endif  // USE_MOUNT
6579

6580
#pragma pack(pop)
6581

6582
typedef struct {
6583
  char        db[TSDB_DB_FNAME_LEN];
6584
  STimeWindow timeRange;
6585
  int32_t     sqlLen;
6586
  char*       sql;
6587
  SArray*     vgroupIds;
6588
} SScanDbReq;
6589

6590
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6591
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6592
void    tFreeSScanDbReq(SScanDbReq* pReq);
6593

6594
typedef struct {
6595
  int32_t scanId;
6596
  int8_t  bAccepted;
6597
} SScanDbRsp;
6598

6599
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6600
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6601

6602
typedef struct {
6603
  int32_t scanId;
6604
  int32_t sqlLen;
6605
  char*   sql;
6606
} SKillScanReq;
6607

6608
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6609
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6610
void    tFreeSKillScanReq(SKillScanReq* pReq);
6611

6612
typedef struct {
6613
  int32_t scanId;
6614
  int32_t vgId;
6615
  int32_t dnodeId;
6616
} SVKillScanReq;
6617

6618
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6619
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6620

6621
typedef struct {
6622
  int32_t scanId;
6623
  int32_t vgId;
6624
  int32_t dnodeId;
6625
  int32_t numberFileset;
6626
  int32_t finished;
6627
  int32_t progress;
6628
  int64_t remainingTime;
6629
} SQueryScanProgressRsp;
6630

6631
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6632
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6633

6634
typedef struct {
6635
  int32_t scanId;
6636
  int32_t vgId;
6637
  int32_t dnodeId;
6638
} SQueryScanProgressReq;
6639

6640
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6641
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6642

6643
typedef struct {
6644
  int64_t     dbUid;
6645
  char        db[TSDB_DB_FNAME_LEN];
6646
  int64_t     scanStartTime;
6647
  STimeWindow tw;
6648
  int32_t     scanId;
6649
} SScanVnodeReq;
6650

6651
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6652
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6653

6654
#ifdef __cplusplus
6655
}
6656
#endif
6657

6658
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6659
 
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