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

taosdata / TDengine / #4975

05 Mar 2026 08:43AM UTC coverage: 68.37% (+0.7%) from 67.664%
#4975

push

travis-ci

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

250 of 345 new or added lines in 28 files covered. (72.46%)

446 existing lines in 120 files now uncovered.

210600 of 308032 relevant lines covered (68.37%)

130326818.69 hits per line

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

84.12
/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
  }
UNCOV
106
  return false;
×
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,053,675,573✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
1,003,755,879✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,057,431,452✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

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

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

261

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

267

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

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

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

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

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

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

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

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

445

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

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

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

586
  // physical plan node
587
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
588
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
589
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
590
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
591
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
592
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
593
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
594
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
595
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
596
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
597
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
598
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
599
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
600
  QUERY_NODE_PHYSICAL_PLAN_SORT,
601
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
602
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
603
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
604
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
605
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
606
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
607
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
608
  QUERY_NODE_PHYSICAL_PLAN_FILL,
609
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
610
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
611
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
612
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
613
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
614
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
615
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
616
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
617
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
618
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
619
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
620
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
621
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
622
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
623
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
624
  QUERY_NODE_PHYSICAL_SUBPLAN,
625
  QUERY_NODE_PHYSICAL_PLAN,
626
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
627
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
628
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
629
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
630
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
631
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
632
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
633
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
634
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
635
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
636
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
637
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
638
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
639
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
640
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
641
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
642
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
643
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
644
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
645
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
646
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
647
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
648
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
649
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
650
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
651
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
652
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
653
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
654
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
655
  // xnode
656
  QUERY_NODE_CREATE_XNODE_STMT = 1200,  // Xnode
657
  QUERY_NODE_DROP_XNODE_STMT,
658
  QUERY_NODE_DRAIN_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
  QUERY_NODE_ALTER_XNODE_STMT,                // Alter xnode
676
} ENodeType;
677

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

965
bool hasExtSchema(const SExtSchema* pExtSchema);
966

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

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

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

985
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
986
  if (pRef->pColRef) {
388,576✔
987
    return TSDB_CODE_INVALID_PARA;
×
988
  }
989
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
388,576✔
990
  if (pRef->pColRef == NULL) {
388,576✔
991
    return terrno;
×
992
  }
993
  pRef->nCols = nCols;
388,576✔
994
  for (int32_t i = 0; i < nCols; i++) {
145,349,346✔
995
    pRef->pColRef[i].hasRef = false;
144,960,770✔
996
    pRef->pColRef[i].id = (col_id_t)(i + 1);
144,960,770✔
997
  }
998
  return 0;
388,576✔
999
}
1000

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

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

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

1022
  return pDstWrapper;
1023
}
1024

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

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

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

1058
  taosMemoryFreeClear(pWrapper->pColCmpr);
1059
  taosMemoryFreeClear(pWrapper);
1060
}
1061
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1062
  if (pSchemaWrapper->pSchema == NULL) return NULL;
520,260,816✔
1063

1064
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
520,182,576✔
1065
  if (pSW == NULL) {
520,203,536✔
1066
    return NULL;
×
1067
  }
1068
  pSW->nCols = pSchemaWrapper->nCols;
520,203,536✔
1069
  pSW->version = pSchemaWrapper->version;
520,103,917✔
1070
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
520,138,972✔
1071
  if (pSW->pSchema == NULL) {
520,003,259✔
1072
    taosMemoryFree(pSW);
×
1073
    return NULL;
×
1074
  }
1075

1076
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
519,945,355✔
1077
  return pSW;
520,337,171✔
1078
}
1079

1080
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
157,554,964✔
1081
  if (pSchemaWrapper) {
1,463,552,822✔
1082
    taosMemoryFree(pSchemaWrapper->pSchema);
809,589,412✔
1083
    if (pSchemaWrapper->pRsma) {
809,498,422✔
1084
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,973✔
1085
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,973✔
1086
    }
1087
    taosMemoryFree(pSchemaWrapper);
809,331,010✔
1088
  }
1089
}
1,418,498,978✔
1090

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

1101
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,634,055✔
1102
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,634,055✔
1103
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,634,634✔
1104
  }
1105
}
7,632,912✔
1106

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

1117
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1118
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,244,035✔
1119
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,243,717✔
1120
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,243,717✔
1121
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,243,717✔
1122
  buf = taosDecodeStringTo(buf, pSchema->name);
1,243,717✔
1123
  return (void*)buf;
1,243,717✔
1124
}
1125

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

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

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

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

1158
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1159
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
871,083,984✔
1160
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
871,083,984✔
1161
  if (pColRef->hasRef) {
435,541,992✔
1162
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
578,811,784✔
1163
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
578,811,784✔
1164
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
578,811,784✔
1165
  }
1166
  return 0;
435,541,992✔
1167
}
1168

1169
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1170
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
437,506,868✔
1171
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
437,506,868✔
1172
  if (pColRef->hasRef) {
218,753,434✔
1173
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
145,396,299✔
1174
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
145,396,299✔
1175
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
145,396,299✔
1176
  }
1177

1178
  return 0;
218,753,434✔
1179
}
1180

1181
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1182
  int32_t tlen = 0;
457,874✔
1183
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
457,874✔
1184
  tlen += taosEncodeVariantI32(buf, pSW->version);
457,874✔
1185
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,212,806✔
1186
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,509,864✔
1187
  }
1188
  return tlen;
457,874✔
1189
}
1190

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

1200
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,442,284✔
1201
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,487,434✔
1202
    }
1203
  } else {
1204
    pSW->pSchema = NULL;
×
1205
  }
1206
  return (void*)buf;
198,567✔
1207
}
1208

1209
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1210
  if (pSW == NULL) {
287,497,035✔
1211
    return TSDB_CODE_INVALID_PARA;
×
1212
  }
1213
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
574,932,284✔
1214
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
574,743,539✔
1215
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1216
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1217
  }
1218
  return 0;
287,613,630✔
1219
}
1220

1221
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1222
  if (pSW == NULL) {
126,834,247✔
1223
    return TSDB_CODE_INVALID_PARA;
×
1224
  }
1225
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
253,648,182✔
1226
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
253,624,286✔
1227

1228
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
126,810,351✔
1229
  if (pSW->pSchema == NULL) {
126,794,475✔
1230
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1231
  }
1232
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,360,477,824✔
1233
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1234
  }
1235

1236
  return 0;
126,856,083✔
1237
}
1238

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

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

1251
  return 0;
1,829,722,611✔
1252
}
1253

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1584

1585
typedef struct {
1586
  int8_t createType;
1587

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

1602
  int8_t superUser;  // denote if it is a super user or not
1603
  int8_t ignoreExists;
1604

1605
  char   user[TSDB_USER_LEN];
1606
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1607
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1608

1609
  int8_t sysInfo;
1610
  int8_t createDb;
1611
  int8_t isImport;
1612
  int8_t changepass;
1613
  int8_t enable;
1614

1615
  int8_t negIpRanges;
1616
  int8_t negTimeRanges;
1617

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

1632
  int32_t         numIpRanges;
1633
  SIpRange*       pIpDualRanges;
1634
  int32_t         numTimeRanges;
1635
  SDateTimeRange* pTimeRanges;
1636

1637
  int32_t sqlLen;
1638
  char*   sql;
1639
} SCreateUserReq;
1640

1641
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1642
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1643
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1644

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

1655
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1656
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1657
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1658

1659
typedef struct {
1660
  int32_t dnodeId;
1661
  int64_t analVer;
1662
} SRetrieveAnalyticsAlgoReq;
1663

1664
typedef struct {
1665
  int64_t   ver;
1666
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1667
} SRetrieveAnalyticAlgoRsp;
1668

1669
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1670
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1671
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1672
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1673
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1674

1675
typedef struct {
1676
  int8_t alterType;
1677

1678
  int8_t isView;
1679

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

1700
  int8_t enable;
1701
  int8_t sysinfo;
1702
  int8_t createdb;
1703
  int8_t changepass;
1704

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

1722
  int32_t         numIpRanges;
1723
  int32_t         numTimeRanges;
1724
  int32_t         numDropIpRanges;
1725
  int32_t         numDropTimeRanges;
1726
  SIpRange*       pIpRanges;
1727
  SDateTimeRange* pTimeRanges;
1728
  SIpRange*       pDropIpRanges;
1729
  SDateTimeRange* pDropTimeRanges;
1730
  SPrivSet        privileges;
1731

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

1740
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1741
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1742
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1743

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

1753
  int32_t sqlLen;
1754
  char*   sql;
1755
} SCreateTokenReq;
1756

1757
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1758
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1759
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1760

1761
typedef struct {
1762
  char name[TSDB_TOKEN_NAME_LEN];
1763
  char user[TSDB_USER_LEN];
1764
  char token[TSDB_TOKEN_LEN];
1765
} SCreateTokenRsp;
1766

1767
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1768
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1769
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1770

1771
typedef struct {
1772
  char    name[TSDB_TOKEN_NAME_LEN];
1773

1774
  int8_t hasEnable;
1775
  int8_t hasTtl;
1776
  int8_t hasProvider;
1777
  int8_t hasExtraInfo;
1778

1779
  int8_t  enable;
1780
  int32_t ttl;
1781
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1782
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1783

1784
  int32_t     sqlLen;
1785
  char*       sql;
1786
} SAlterTokenReq;
1787

1788
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1789
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1790
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1791

1792
typedef struct {
1793
  char    name[TSDB_TOKEN_NAME_LEN];
1794
  int8_t  ignoreNotExists;
1795
  int32_t sqlLen;
1796
  char*   sql;
1797
} SDropTokenReq;
1798

1799
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1800
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1801
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1802

1803
typedef struct {
1804
  char    user[TSDB_USER_LEN];
1805
  int32_t sqlLen;
1806
  char*   sql;
1807
} SCreateTotpSecretReq;
1808

1809
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1810
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1811
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1812

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

1818
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1819
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1820

1821
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1822
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1823
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1824
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1825

1826
typedef struct {
1827
  char user[TSDB_USER_LEN];
1828
} SGetUserAuthReq;
1829

1830
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1831
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1832

1833
typedef struct {
1834
  int8_t  enabled;
1835
  int32_t expireTime;
1836
} STokenStatus;
1837

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

1863
  SUserSessCfg sessCfg;
1864
  int64_t      timeWhiteListVer;
1865
  SHashObj*    tokens;
1866
} SGetUserAuthRsp;
1867

1868
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1869
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1870
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1871

1872
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1873
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1874
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1875
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1876

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

1889
typedef struct {
1890
  int64_t             ver;
1891
  int                 numOfUser;
1892
  SUpdateUserIpWhite* pUserIpWhite;
1893
} SUpdateIpWhite;
1894

1895
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1896
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1897
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1898
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1899

1900
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1901
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1902
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1903

1904

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

1911
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1912
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1913

1914

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

1921
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1922
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1923

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

1933
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1934
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1935
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1936
void    tIpRangeSetDefaultMask(SIpRange* range);
1937

1938
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1939
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1940
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1941

1942
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1943
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1944
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1945

1946
typedef struct {
1947
  int64_t ver;
1948
  char    user[TSDB_USER_LEN];
1949
  int32_t numWhiteLists;
1950
  SDateTimeWhiteListItem* pWhiteLists;
1951
} SUserDateTimeWhiteList;
1952

1953

1954
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1955
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1956
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1957
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1958

1959
typedef struct {
1960
  int64_t             ver;
1961
  int                 numOfUser;
1962
  SUserDateTimeWhiteList *pUsers;
1963
} SRetrieveDateTimeWhiteListRsp;
1964

1965
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1966
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1967
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1968
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1969

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

1980
  uint8_t precision;
1981
  uint8_t scale;
1982
  int32_t bytes;
1983
  int8_t  type;
1984
  uint8_t pk;
1985
  bool    noData;
1986
} SColumnInfo;
1987

1988
typedef struct STimeWindow {
1989
  TSKEY skey;
1990
  TSKEY ekey;
1991
} STimeWindow;
1992

1993
typedef struct SQueryHint {
1994
  bool batchScan;
1995
} SQueryHint;
1996

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

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

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

2023
typedef struct {
2024
  int32_t code;
2025
  int64_t affectedRows;
2026
  SArray* tbVerInfo;  // STbVerInfo
2027
} SQueryTableRsp;
2028

2029
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2030

2031
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2032

2033
typedef struct {
2034
  SMsgHead header;
2035
  char     dbFName[TSDB_DB_FNAME_LEN];
2036
  char     tbName[TSDB_TABLE_NAME_LEN];
2037
} STableCfgReq;
2038

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

2071
typedef STableCfg STableCfgRsp;
2072

2073
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2074
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2075

2076
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2077
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2078
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2079

2080
typedef struct {
2081
  SMsgHead header;
2082
  tb_uid_t suid;
2083
} SVSubTablesReq;
2084

2085
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2086
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2087

2088
typedef struct {
2089
  int32_t vgId;
2090
  SArray* pTables;  // SArray<SVCTableRefCols*>
2091
} SVSubTablesRsp;
2092

2093
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2094
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2095
void    tDestroySVSubTablesRsp(void* rsp);
2096

2097
typedef struct {
2098
  SMsgHead header;
2099
  tb_uid_t suid;
2100
} SVStbRefDbsReq;
2101

2102
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2103
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2104

2105
typedef struct {
2106
  int32_t vgId;
2107
  SArray* pDbs;  // SArray<char* (db name)>
2108
} SVStbRefDbsRsp;
2109

2110
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2111
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2112
void    tDestroySVStbRefDbsRsp(void* rsp);
2113

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

2166
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2167
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2168
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2169

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

2205
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2206
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2207
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2208

2209
typedef struct {
2210
  char    db[TSDB_DB_FNAME_LEN];
2211
  int8_t  ignoreNotExists;
2212
  int8_t  force;
2213
  int32_t sqlLen;
2214
  char*   sql;
2215
} SDropDbReq;
2216

2217
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2218
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2219
void    tFreeSDropDbReq(SDropDbReq* pReq);
2220

2221
typedef struct {
2222
  char    db[TSDB_DB_FNAME_LEN];
2223
  int64_t uid;
2224
} SDropDbRsp;
2225

2226
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2227
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2228

2229
typedef struct {
2230
  char    name[TSDB_MOUNT_NAME_LEN];
2231
  int64_t uid;
2232
} SDropMountRsp;
2233

2234
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2235
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2236

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

2245
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2246
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2247

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

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

2274
typedef struct {
2275
  char db[TSDB_DB_FNAME_LEN];
2276
} SDbCfgReq;
2277

2278
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2279
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2280

2281
typedef struct {
2282
  char db[TSDB_DB_FNAME_LEN];
2283
} SSsMigrateDbReq;
2284

2285
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2286
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2287

2288
typedef struct {
2289
  int32_t ssMigrateId;
2290
  bool    bAccepted;
2291
} SSsMigrateDbRsp;
2292

2293
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2294
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2295

2296
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2297
typedef struct {
2298
  int32_t ssMigrateId;
2299
} SListSsMigrateFileSetsReq;
2300

2301
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2302
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2303

2304
typedef struct {
2305
  int32_t ssMigrateId;
2306
  int32_t vgId;       // vgroup id
2307
  SArray* pFileSets;  // SArray<int32_t>
2308
} SListSsMigrateFileSetsRsp;
2309

2310
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2311
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2312
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2313

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

2322
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2323
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2324

2325
typedef struct {
2326
  int32_t ssMigrateId;
2327
  int32_t nodeId;  // node id of the leader vnode
2328
  int32_t vgId;
2329
  int32_t fid;
2330
} SSsMigrateFileSetRsp;
2331

2332
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2333
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2334

2335
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2336
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2337
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2338
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2339
#define SSMIGRATE_FILESET_STATE_FAILED      4
2340

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

2353
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2354
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2355

2356
// Request for TDMT_MND_KILL_SSMIGRATE
2357
typedef struct {
2358
  int32_t ssMigrateId;
2359
  int32_t sqlLen;
2360
  char*   sql;
2361
} SKillSsMigrateReq;
2362

2363
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2364
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2365
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2366

2367
// Request for TDMT_VND_KILL_SSMIGRATE
2368
typedef struct {
2369
  int32_t ssMigrateId;
2370
} SVnodeKillSsMigrateReq;
2371

2372
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2373
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2374

2375
typedef struct {
2376
  int32_t vgId;
2377
  int64_t keepVersion;
2378
} SMndSetVgroupKeepVersionReq;
2379

2380
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2381
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2382

2383
typedef struct {
2384
  int32_t timestampSec;
2385
  int32_t ttlDropMaxCount;
2386
  int32_t nUids;
2387
  SArray* pTbUids;
2388
} SVDropTtlTableReq;
2389

2390
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2391
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2392

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

2451
typedef SDbCfgRsp SDbCfgInfo;
2452

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

2459
typedef struct {
2460
  int32_t rowNum;
2461
} SQnodeListReq;
2462

2463
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2464
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2465

2466
typedef struct {
2467
  int32_t rowNum;
2468
} SDnodeListReq;
2469

2470
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2471

2472
typedef struct {
2473
  int32_t useless;  // useless
2474
} SServerVerReq;
2475

2476
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2477
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2478

2479
typedef struct {
2480
  char ver[TSDB_VERSION_LEN];
2481
} SServerVerRsp;
2482

2483
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2484
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2485

2486
typedef struct SQueryNodeAddr {
2487
  int32_t nodeId;  // vgId or qnodeId
2488
  SEpSet  epSet;
2489
} SQueryNodeAddr;
2490

2491
typedef struct {
2492
  SQueryNodeAddr addr;
2493
  uint64_t       load;
2494
} SQueryNodeLoad;
2495

2496
typedef struct {
2497
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2498
} SQnodeListRsp;
2499

2500
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2501
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2502
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2503

2504

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

2517

2518

2519
typedef struct SDNodeAddr {
2520
  int32_t nodeId;  // dnodeId
2521
  SEpSet  epSet;
2522
} SDNodeAddr;
2523

2524
typedef struct {
2525
  SArray* dnodeList;  // SArray<SDNodeAddr>
2526
} SDnodeListRsp;
2527

2528
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2529
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2530
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2531

2532
typedef struct {
2533
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2534
} STableTSMAInfoRsp;
2535

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

2545
typedef struct {
2546
  SArray* pArray;  // Array of SDbHbRsp
2547
} SDbHbBatchRsp;
2548

2549
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2550
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2551
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2552

2553
typedef struct {
2554
  SArray* pArray;  // Array of SGetUserAuthRsp
2555
} SUserAuthBatchRsp;
2556

2557
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2558
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2559
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2560

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

2572
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2573
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2574
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2575

2576
typedef struct {
2577
  union {
2578
    int32_t compactId;
2579
    int32_t id;
2580
  };
2581
  int8_t bAccepted;
2582
} SCompactDbRsp;
2583

2584
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2585
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2586

2587
typedef struct {
2588
  union {
2589
    int32_t compactId;
2590
    int32_t id;
2591
  };
2592
  int32_t sqlLen;
2593
  char*   sql;
2594
} SKillCompactReq;
2595

2596
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2597
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2598
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2599

2600
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2601
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2602

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

2618
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2619
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2620
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2621

2622
typedef struct {
2623
  char   name[TSDB_FUNC_NAME_LEN];
2624
  int8_t igNotExists;
2625
} SDropFuncReq;
2626

2627
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2628
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2629

2630
typedef struct {
2631
  int32_t numOfFuncs;
2632
  bool    ignoreCodeComment;
2633
  SArray* pFuncNames;
2634
} SRetrieveFuncReq;
2635

2636
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2637
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2638
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2639

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

2654
typedef struct {
2655
  int32_t funcVersion;
2656
  int64_t funcCreatedTime;
2657
} SFuncExtraInfo;
2658

2659
typedef struct {
2660
  int32_t numOfFuncs;
2661
  SArray* pFuncInfos;
2662
  SArray* pFuncExtraInfos;
2663
} SRetrieveFuncRsp;
2664

2665
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2666
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2667
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2668
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2669

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

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

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

2726
typedef struct {
2727
  int64_t total_requests;
2728
  int64_t total_rows;
2729
  int64_t total_bytes;
2730
  double  write_size;
2731
  double  cache_hit_ratio;
2732
  int64_t rpc_queue_wait;
2733
  int64_t preprocess_time;
2734

2735
  int64_t memory_table_size;
2736
  int64_t commit_count;
2737
  int64_t merge_count;
2738
  double  commit_time;
2739
  double  merge_time;
2740
  int64_t block_commit_time;
2741
  int64_t memtable_wait_time;
2742
} SVnodeMetrics;
2743

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

2760
typedef struct {
2761
  int32_t vgId;
2762
  int64_t nTimeSeries;
2763
} SVnodeLoadLite;
2764

2765
typedef struct {
2766
  int8_t  syncState;
2767
  int64_t syncTerm;
2768
  int8_t  syncRestore;
2769
  int64_t roleTimeMs;
2770
} SMnodeLoad;
2771

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

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

2815
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2816
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2817
void    tFreeSStatusReq(SStatusReq* pReq);
2818

2819
typedef struct {
2820
  int32_t forceReadConfig;
2821
  int32_t cver;
2822
  SArray* array;
2823
} SConfigReq;
2824

2825
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2826
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2827
void    tFreeSConfigReq(SConfigReq* pReq);
2828

2829
typedef struct {
2830
  int32_t dnodeId;
2831
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2832
} SDnodeInfoReq;
2833

2834
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2835
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2836

2837
typedef enum {
2838
  MONITOR_TYPE_COUNTER = 0,
2839
  MONITOR_TYPE_SLOW_LOG = 1,
2840
} MONITOR_TYPE;
2841

2842
typedef struct {
2843
  int32_t      contLen;
2844
  char*        pCont;
2845
  MONITOR_TYPE type;
2846
} SStatisReq;
2847

2848
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2849
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2850
void    tFreeSStatisReq(SStatisReq* pReq);
2851

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

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

2872
typedef struct {
2873
  int32_t dnodeId;
2874
  int64_t clusterId;
2875
  SArray* pVloads;
2876
} SNotifyReq;
2877

2878
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2879
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2880
void    tFreeSNotifyReq(SNotifyReq* pReq);
2881

2882
typedef struct {
2883
  int32_t dnodeId;
2884
  int64_t clusterId;
2885
} SDnodeCfg;
2886

2887
typedef struct {
2888
  int32_t id;
2889
  int8_t  isMnode;
2890
  SEp     ep;
2891
} SDnodeEp;
2892

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

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

2914
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2915
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2916
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2917

2918
typedef struct {
2919
  int32_t forceReadConfig;
2920
  int32_t isConifgVerified;
2921
  int32_t isVersionVerified;
2922
  int32_t cver;
2923
  SArray* array;
2924
} SConfigRsp;
2925

2926
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2927
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2928
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2929

2930
typedef struct {
2931
  int32_t dnodeId;
2932
  int32_t keyVersion;  // Local key version
2933
} SKeySyncReq;
2934

2935
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2936
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2937

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

2955
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2956
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2957

2958
typedef struct {
2959
  int32_t reserved;
2960
} SMTimerReq;
2961

2962
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2963
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2964

2965
typedef struct SOrphanTask {
2966
  int64_t streamId;
2967
  int32_t taskId;
2968
  int32_t nodeId;
2969
} SOrphanTask;
2970

2971
typedef struct SMStreamDropOrphanMsg {
2972
  SArray* pList;  // SArray<SOrphanTask>
2973
} SMStreamDropOrphanMsg;
2974

2975
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2976
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2977
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2978

2979
typedef struct {
2980
  int32_t  id;
2981
  uint16_t port;                 // node sync Port
2982
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2983
} SReplica;
2984

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

3046
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3047
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3048
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3049

3050
typedef struct {
3051
  union {
3052
    int32_t compactId;
3053
    int32_t id;
3054
  };
3055
  int32_t vgId;
3056
  int32_t dnodeId;
3057
} SQueryCompactProgressReq;
3058

3059
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3060
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3061

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

3075
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3076
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3077

3078
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3079
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3080

3081
typedef struct {
3082
  int32_t vgId;
3083
  int32_t dnodeId;
3084
  int64_t dbUid;
3085
  char    db[TSDB_DB_FNAME_LEN];
3086
  int64_t reserved[8];
3087
} SDropVnodeReq;
3088

3089
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3090
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3091

3092
typedef struct {
3093
  char    colName[TSDB_COL_NAME_LEN];
3094
  char    stb[TSDB_TABLE_FNAME_LEN];
3095
  int64_t stbUid;
3096
  int64_t dbUid;
3097
  int64_t reserved[8];
3098
} SDropIndexReq;
3099

3100
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3101
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3102

3103
typedef struct {
3104
  int64_t dbUid;
3105
  char    db[TSDB_DB_FNAME_LEN];
3106
  union {
3107
    int64_t compactStartTime;
3108
    int64_t startTime;
3109
  };
3110

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

3128
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3129
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3130

3131
typedef struct {
3132
  union {
3133
    int32_t compactId;
3134
    int32_t taskId;
3135
  };
3136
  int32_t vgId;
3137
  int32_t dnodeId;
3138
} SVKillCompactReq;
3139

3140
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3141
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3142

3143
typedef SVKillCompactReq SVKillRetentionReq;
3144

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

3162
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3163
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3164
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3165

3166
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3167

3168
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3169
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3170

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

3198
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3199
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3200

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

3215
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3216
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3217

3218
typedef struct {
3219
  int32_t vgId;
3220
  int8_t  disable;
3221
} SDisableVnodeWriteReq;
3222

3223
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3224
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3225

3226
typedef struct {
3227
  int32_t  srcVgId;
3228
  int32_t  dstVgId;
3229
  uint32_t hashBegin;
3230
  uint32_t hashEnd;
3231
  int32_t  changeVersion;
3232
  int32_t  reserved;
3233
} SAlterVnodeHashRangeReq;
3234

3235
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3236
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3237

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

3248
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3249
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3250

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

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

3271
typedef struct {
3272
  int32_t     numOfVgroups;
3273
  SVgroupInfo vgroups[];
3274
} SVgroupsInfo;
3275

3276
typedef struct {
3277
  STableMetaRsp* pMeta;
3278
} SMAlterStbRsp;
3279

3280
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3281
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3282
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3283

3284
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3285
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3286
void    tFreeSTableMetaRsp(void* pRsp);
3287
void    tFreeSTableIndexRsp(void* info);
3288

3289
typedef struct {
3290
  SArray* pMetaRsp;   // Array of STableMetaRsp
3291
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3292
} SSTbHbRsp;
3293

3294
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3295
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3296
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3297

3298
typedef struct {
3299
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3300
} SViewHbRsp;
3301

3302
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3303
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3304
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3305

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

3317
typedef struct {
3318
  int32_t dataLen;
3319
  char    name[TSDB_TABLE_FNAME_LEN];
3320
  char*   data;
3321
} STagData;
3322

3323
typedef struct {
3324
  int32_t  opType;
3325
  uint32_t valLen;
3326
  char*    val;
3327
} SShowVariablesReq;
3328

3329
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3330
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3331
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3332

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

3341
typedef struct {
3342
  SArray* variables;  // SArray<SVariablesInfo>
3343
} SShowVariablesRsp;
3344

3345
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3346
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3347

3348
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3349

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

3362
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3363
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3364
void tFreeSShowReq(SShowReq* pReq);
3365

3366
typedef struct {
3367
  int64_t       showId;
3368
  STableMetaRsp tableMeta;
3369
} SShowRsp, SVShowTablesRsp;
3370

3371
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3372
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3373
// void    tFreeSShowRsp(SShowRsp* pRsp);
3374

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

3385
typedef struct SSysTableSchema {
3386
  int8_t   type;
3387
  col_id_t colId;
3388
  int32_t  bytes;
3389
} SSysTableSchema;
3390

3391
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3392
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3393

3394
#define RETRIEVE_TABLE_RSP_VERSION         0
3395
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3396
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3397

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

3417
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3418

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

3425
typedef struct {
3426
  int64_t version;
3427
  int64_t numOfRows;
3428
  int8_t  compressed;
3429
  int8_t  precision;
3430
  char    data[];
3431
} SRetrieveTableRspForTmq;
3432

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

3445
typedef struct SExplainExecInfo {
3446
  double   startupCost;
3447
  double   totalCost;
3448
  uint64_t numOfRows;
3449
  uint32_t verboseLen;
3450
  void*    verboseInfo;
3451
} SExplainExecInfo;
3452

3453
typedef struct {
3454
  int32_t           numOfPlans;
3455
  SExplainExecInfo* subplanInfo;
3456
} SExplainRsp;
3457

3458
typedef struct {
3459
  SExplainRsp rsp;
3460
  uint64_t    qId;
3461
  uint64_t    cId;
3462
  uint64_t    tId;
3463
  int64_t     rId;
3464
  int32_t     eId;
3465
} SExplainLocalRsp;
3466

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

3479
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3480
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3481
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3482

3483
typedef struct {
3484
  char    config[TSDB_DNODE_CONFIG_LEN];
3485
  char    value[TSDB_CLUSTER_VALUE_LEN];
3486
  int32_t sqlLen;
3487
  char*   sql;
3488
} SMCfgClusterReq;
3489

3490
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3491
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3492
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3493

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

3501
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3502
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3503
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3504

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

3515
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3516
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3517
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3518

3519
enum {
3520
  RESTORE_TYPE__ALL = 1,
3521
  RESTORE_TYPE__MNODE,
3522
  RESTORE_TYPE__VNODE,
3523
  RESTORE_TYPE__QNODE,
3524
};
3525

3526
typedef struct {
3527
  int32_t dnodeId;
3528
  int8_t  restoreType;
3529
  int32_t sqlLen;
3530
  char*   sql;
3531
} SRestoreDnodeReq;
3532

3533
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3534
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3535
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3536

3537
typedef struct {
3538
  int32_t dnodeId;
3539
  char    config[TSDB_DNODE_CONFIG_LEN];
3540
  char    value[TSDB_DNODE_VALUE_LEN];
3541
  int32_t sqlLen;
3542
  char*   sql;
3543
} SMCfgDnodeReq;
3544

3545
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3546
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3547
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3548

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

3556
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3557
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3558
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3559

3560
typedef struct {
3561
  int32_t days;
3562
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3563
  int32_t sqlLen;
3564
  char*   sql;
3565
} SMAlterKeyExpirationReq;
3566

3567
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3568
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3569
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3570

3571
typedef struct {
3572
  char    config[TSDB_DNODE_CONFIG_LEN];
3573
  char    value[TSDB_DNODE_VALUE_LEN];
3574
  int32_t version;
3575
} SDCfgDnodeReq;
3576

3577
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3578
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3579

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

3587
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3588
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3589

3590
typedef struct {
3591
  int32_t nodeId;
3592
  SEpSet  epSet;
3593
} SNodeEpSet;
3594

3595
typedef struct {
3596
  int32_t    snodeId;
3597
  SNodeEpSet leaders[2];
3598
  SNodeEpSet replica;
3599
  int32_t    sqlLen;
3600
  char*      sql;
3601
} SDCreateSnodeReq;
3602

3603
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3604
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3605
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3606

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

3618
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3619
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3620

3621
typedef struct {
3622
  int32_t urlLen;
3623
  int32_t sqlLen;
3624
  char*   url;
3625
  char*   sql;
3626
} SMCreateAnodeReq;
3627

3628
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3629
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3630
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3631

3632
typedef struct {
3633
  int32_t anodeId;
3634
  int32_t sqlLen;
3635
  char*   sql;
3636
} SMDropAnodeReq, SMUpdateAnodeReq;
3637

3638
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3639
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3640
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3641
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3642
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3643
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3644

3645
typedef struct {
3646
  int32_t dnodeId;
3647
  int32_t bnodeProto;
3648
  int32_t sqlLen;
3649
  char*   sql;
3650
} SMCreateBnodeReq, SDCreateBnodeReq;
3651

3652
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3653
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3654
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3655

3656
typedef struct {
3657
  int32_t dnodeId;
3658
  int32_t sqlLen;
3659
  char*   sql;
3660
} SMDropBnodeReq, SDDropBnodeReq;
3661

3662
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3663
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3664
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3665

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

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

3739
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3740
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3741
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3742

3743
typedef struct {
3744
  int32_t xnodeId;
3745
  int32_t force;
3746
  int32_t urlLen;
3747
  int32_t sqlLen;
3748
  char*   url;
3749
  char*   sql;
3750
} SMDropXnodeReq, SDDropXnodeReq;
3751

3752
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3753
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3754
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3755

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

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

3784
typedef enum {
3785
  XNODE_TASK_SINK_DSN = 1,
3786
  XNODE_TASK_SINK_DATABASE,
3787
} ENodeXTaskSinkType;
3788

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

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

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

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

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

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

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

3913
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3914
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3915
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3916

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

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

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

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

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

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

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

3998
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3999
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4000
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4001
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4002

4003
typedef struct {
4004
  int32_t vgId;
4005
  int32_t hbSeq;
4006
} SVArbHbReqMember;
4007

4008
typedef struct {
4009
  int32_t dnodeId;
4010
  char*   arbToken;
4011
  int64_t arbTerm;
4012
  SArray* hbMembers;  // SVArbHbReqMember
4013
} SVArbHeartBeatReq;
4014

4015
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4016
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4017
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4018

4019
typedef struct {
4020
  int32_t vgId;
4021
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4022
  int32_t hbSeq;
4023
} SVArbHbRspMember;
4024

4025
typedef struct {
4026
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4027
  int32_t dnodeId;
4028
  SArray* hbMembers;  // SVArbHbRspMember
4029
} SVArbHeartBeatRsp;
4030

4031
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4032
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4033
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4034

4035
typedef struct {
4036
  char*   arbToken;
4037
  int64_t arbTerm;
4038
  char*   member0Token;
4039
  char*   member1Token;
4040
} SVArbCheckSyncReq;
4041

4042
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4043
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4044
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4045

4046
typedef struct {
4047
  char*   arbToken;
4048
  char*   member0Token;
4049
  char*   member1Token;
4050
  int32_t vgId;
4051
  int32_t errCode;
4052
} SVArbCheckSyncRsp;
4053

4054
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4055
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4056
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4057

4058
typedef struct {
4059
  char*   arbToken;
4060
  int64_t arbTerm;
4061
  char*   memberToken;
4062
  int8_t  force;
4063
} SVArbSetAssignedLeaderReq;
4064

4065
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4066
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4067
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4068

4069
typedef struct {
4070
  char*   arbToken;
4071
  char*   memberToken;
4072
  int32_t vgId;
4073
} SVArbSetAssignedLeaderRsp;
4074

4075
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4076
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4077
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4078

4079
typedef struct {
4080
  int32_t dnodeId;
4081
  char*   token;
4082
} SMArbUpdateGroupMember;
4083

4084
typedef struct {
4085
  int32_t dnodeId;
4086
  char*   token;
4087
  int8_t  acked;
4088
} SMArbUpdateGroupAssigned;
4089

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

4102
typedef struct {
4103
  SArray* updateArray;  // SMArbUpdateGroup
4104
} SMArbUpdateGroupBatchReq;
4105

4106
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4107
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4108
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4109

4110
typedef struct {
4111
  char queryStrId[TSDB_QUERY_ID_LEN];
4112
} SKillQueryReq;
4113

4114
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4115
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4116

4117
typedef struct {
4118
  uint32_t connId;
4119
} SKillConnReq;
4120

4121
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4122
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4123

4124
typedef struct {
4125
  int32_t transId;
4126
} SKillTransReq;
4127

4128
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4129
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4130

4131
typedef struct {
4132
  int32_t useless;  // useless
4133
  int32_t sqlLen;
4134
  char*   sql;
4135
} SBalanceVgroupReq;
4136

4137
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4138
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4139
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4140

4141
typedef struct {
4142
  int32_t useless;  // useless
4143
  int32_t sqlLen;
4144
  char*   sql;
4145
} SAssignLeaderReq;
4146

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

4155
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4156
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4157

4158
typedef struct {
4159
  int32_t vgId;
4160
  int32_t dnodeId1;
4161
  int32_t dnodeId2;
4162
  int32_t dnodeId3;
4163
  int32_t sqlLen;
4164
  char*   sql;
4165
} SRedistributeVgroupReq;
4166

4167
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4168
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4169
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4170

4171
typedef struct {
4172
  int32_t reserved;
4173
  int32_t vgId;
4174
  int32_t sqlLen;
4175
  char*   sql;
4176
  char    db[TSDB_DB_FNAME_LEN];
4177
} SBalanceVgroupLeaderReq;
4178

4179
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4180
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4181
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4182

4183
typedef struct {
4184
  int32_t vgId;
4185
} SForceBecomeFollowerReq;
4186

4187
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4188
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4189

4190
typedef struct {
4191
  int32_t vgId;
4192
  bool    force;
4193
} SSplitVgroupReq;
4194

4195
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4196
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4197

4198
typedef struct {
4199
  char user[TSDB_USER_LEN];
4200
  char spi;
4201
  char encrypt;
4202
  char secret[TSDB_PASSWORD_LEN];
4203
  char ckey[TSDB_PASSWORD_LEN];
4204
} SAuthReq, SAuthRsp;
4205

4206
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4207
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4208

4209
typedef struct {
4210
  int32_t statusCode;
4211
  char    details[1024];
4212
} SServerStatusRsp;
4213

4214
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4215
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4216

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

4245
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4246
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4247
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4248

4249
typedef struct {
4250
  SMsgHead header;
4251
  uint64_t sId;
4252
  uint64_t queryId;
4253
  uint64_t taskId;
4254
} SSinkDataReq;
4255

4256
typedef struct {
4257
  SMsgHead header;
4258
  uint64_t sId;
4259
  uint64_t queryId;
4260
  uint64_t clientId;
4261
  uint64_t taskId;
4262
  int32_t  execId;
4263
} SQueryContinueReq;
4264

4265
typedef struct {
4266
  SMsgHead header;
4267
  uint64_t sId;
4268
  uint64_t queryId;
4269
  uint64_t taskId;
4270
} SResReadyReq;
4271

4272
typedef struct {
4273
  int32_t code;
4274
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4275
  int32_t sversion;
4276
  int32_t tversion;
4277
} SResReadyRsp;
4278

4279
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4280

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

4289
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4290

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

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

4304
typedef struct SColNameFlag {
4305
  col_id_t colId;
4306
  char     colName[TSDB_COL_NAME_LEN];
4307
  int8_t   flags;  // 0x01: COL_MASK_ON
4308
} SColNameFlag;
4309

4310
typedef struct SColIdPair {
4311
  col_id_t  vtbColId;
4312
  col_id_t  orgColId;
4313
  SDataType type;
4314
} SColIdPair;
4315

4316
typedef struct SColIdSlotIdPair {
4317
  int32_t  vtbSlotId;
4318
  col_id_t orgColId;
4319
} SColIdSlotIdPair;
4320

4321
typedef struct SOrgTbInfo {
4322
  int32_t vgId;
4323
  char    tbName[TSDB_TABLE_FNAME_LEN];
4324
  SArray* colMap;  // SArray<SColIdNameKV>
4325
} SOrgTbInfo;
4326

4327
void destroySOrgTbInfo(void *info);
4328

4329
typedef enum {
4330
  DYN_TYPE_STB_JOIN = 1,
4331
  DYN_TYPE_VSTB_SINGLE_SCAN,
4332
  DYN_TYPE_VSTB_BATCH_SCAN,
4333
  DYN_TYPE_VSTB_WIN_SCAN,
4334
} ETableScanDynType;
4335

4336
typedef enum {
4337
  DYN_TYPE_SCAN_PARAM = 1,
4338
  NOTIFY_TYPE_SCAN_PARAM,
4339
} ETableScanGetParamType;
4340

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

4358
typedef struct STagScanOperatorParam {
4359
  tb_uid_t vcUid;
4360
} STagScanOperatorParam;
4361

4362
typedef struct SRefColIdGroup {
4363
  SArray* pSlotIdList;  // SArray<int32_t>
4364
} SRefColIdGroup;
4365

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

4374
typedef struct SMergeOperatorParam {
4375
  int32_t         winNum;
4376
} SMergeOperatorParam;
4377

4378
typedef struct SAggOperatorParam {
4379
  bool            needCleanRes;
4380
} SAggOperatorParam;
4381

4382
typedef struct SExternalWindowOperatorParam {
4383
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4384
} SExternalWindowOperatorParam;
4385

4386
typedef struct SDynQueryCtrlOperatorParam {
4387
  STimeWindow    window;
4388
} SDynQueryCtrlOperatorParam;
4389

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

4402
  // used for new-stream
4403
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4404
  bool                           reset;
4405
  bool                           dynTbname;
4406
  // used for new-stream
4407
} SResFetchReq;
4408

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

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

4427
typedef struct {
4428
  int64_t refId;
4429
  SArray* taskStatus;  // SArray<STaskStatus>
4430
} SSchedulerStatusRsp;
4431

4432
typedef struct {
4433
  uint64_t queryId;
4434
  uint64_t taskId;
4435
  int8_t   action;
4436
} STaskAction;
4437

4438
typedef struct SQueryNodeEpId {
4439
  int32_t nodeId;  // vgId or qnodeId
4440
  SEp     ep;
4441
} SQueryNodeEpId;
4442

4443
typedef struct {
4444
  SMsgHead       header;
4445
  uint64_t       clientId;
4446
  SQueryNodeEpId epId;
4447
  SArray*        taskAction;  // SArray<STaskAction>
4448
} SSchedulerHbReq;
4449

4450
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4451
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4452
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4453

4454
typedef struct {
4455
  SQueryNodeEpId epId;
4456
  SArray*        taskStatus;  // SArray<STaskStatus>
4457
} SSchedulerHbRsp;
4458

4459
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4460
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4461
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4462

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

4473
typedef struct {
4474
  int32_t code;
4475
} STaskCancelRsp;
4476

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

4487
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4488
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4489

4490
typedef enum {
4491
  TASK_NOTIFY_FINISHED = 1,
4492
} ETaskNotifyType;
4493

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

4505
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4506
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4507

4508
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4509
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4510

4511
typedef struct {
4512
  int32_t code;
4513
} STaskDropRsp;
4514

4515
#define STREAM_TRIGGER_AT_ONCE                 1
4516
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4517
#define STREAM_TRIGGER_MAX_DELAY               3
4518
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4519
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4520

4521
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4522
#define STREAM_FILL_HISTORY_ON        1
4523
#define STREAM_FILL_HISTORY_OFF       0
4524
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4525
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4526
#define STREAM_CREATE_STABLE_TRUE     1
4527
#define STREAM_CREATE_STABLE_FALSE    0
4528

4529
typedef struct SVgroupVer {
4530
  int32_t vgId;
4531
  int64_t ver;
4532
} SVgroupVer;
4533

4534
typedef struct STaskNotifyEventStat {
4535
  int64_t notifyEventAddTimes;     // call times of add function
4536
  int64_t notifyEventAddElems;     // elements added by add function
4537
  double  notifyEventAddCostSec;   // time cost of add function
4538
  int64_t notifyEventPushTimes;    // call times of push function
4539
  int64_t notifyEventPushElems;    // elements pushed by push function
4540
  double  notifyEventPushCostSec;  // time cost of push function
4541
  int64_t notifyEventPackTimes;    // call times of pack function
4542
  int64_t notifyEventPackElems;    // elements packed by pack function
4543
  double  notifyEventPackCostSec;  // time cost of pack function
4544
  int64_t notifyEventSendTimes;    // call times of send function
4545
  int64_t notifyEventSendElems;    // elements sent by send function
4546
  double  notifyEventSendCostSec;  // time cost of send function
4547
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4548
} STaskNotifyEventStat;
4549

4550
enum {
4551
  TOPIC_SUB_TYPE__DB = 1,
4552
  TOPIC_SUB_TYPE__TABLE,
4553
  TOPIC_SUB_TYPE__COLUMN,
4554
};
4555

4556
#define DEFAULT_MAX_POLL_INTERVAL  300000
4557
#define DEFAULT_SESSION_TIMEOUT    12000
4558
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4559
#define DEFAULT_MIN_POLL_ROWS      4096
4560

4561
typedef struct {
4562
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4563
  int8_t igExists;
4564
  int8_t subType;
4565
  int8_t withMeta;
4566
  char*  sql;
4567
  char   subDbName[TSDB_DB_FNAME_LEN];
4568
  char*  ast;
4569
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4570
  int8_t reload;
4571
} SCMCreateTopicReq;
4572

4573
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4574
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4575
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4576

4577
typedef struct {
4578
  int64_t consumerId;
4579
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4580

4581
typedef struct {
4582
  int64_t consumerId;
4583
  char    cgroup[TSDB_CGROUP_LEN];
4584
  char    clientId[TSDB_CLIENT_ID_LEN];
4585
  char    user[TSDB_USER_LEN];
4586
  char    fqdn[TSDB_FQDN_LEN];
4587
  SArray* topicNames;  // SArray<char**>
4588

4589
  int8_t  withTbName;
4590
  int8_t  autoCommit;
4591
  int32_t autoCommitInterval;
4592
  int8_t  resetOffsetCfg;
4593
  int8_t  enableReplay;
4594
  int8_t  enableBatchMeta;
4595
  int32_t sessionTimeoutMs;
4596
  int32_t maxPollIntervalMs;
4597
  int64_t ownerId;
4598
} SCMSubscribeReq;
4599

4600
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4601
  int32_t tlen = 0;
690,382✔
4602
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
690,382✔
4603
  tlen += taosEncodeString(buf, pReq->cgroup);
690,382✔
4604
  tlen += taosEncodeString(buf, pReq->clientId);
690,382✔
4605

4606
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
690,382✔
4607
  tlen += taosEncodeFixedI32(buf, topicNum);
690,382✔
4608

4609
  for (int32_t i = 0; i < topicNum; i++) {
964,648✔
4610
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
548,532✔
4611
  }
4612

4613
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
690,382✔
4614
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
690,382✔
4615
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
690,382✔
4616
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
690,382✔
4617
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
690,382✔
4618
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
690,382✔
4619
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
690,382✔
4620
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
690,382✔
4621
  tlen += taosEncodeString(buf, pReq->user);
690,382✔
4622
  tlen += taosEncodeString(buf, pReq->fqdn);
690,382✔
4623

4624
  return tlen;
690,382✔
4625
}
4626

4627
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4628
  void* start = buf;
371,818✔
4629
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
371,818✔
4630
  buf = taosDecodeStringTo(buf, pReq->cgroup);
371,818✔
4631
  buf = taosDecodeStringTo(buf, pReq->clientId);
371,818✔
4632

4633
  int32_t topicNum = 0;
371,818✔
4634
  buf = taosDecodeFixedI32(buf, &topicNum);
371,818✔
4635

4636
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
371,818✔
4637
  if (pReq->topicNames == NULL) {
371,818✔
4638
    return terrno;
×
4639
  }
4640
  for (int32_t i = 0; i < topicNum; i++) {
540,675✔
4641
    char* name = NULL;
168,857✔
4642
    buf = taosDecodeString(buf, &name);
168,857✔
4643
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
337,714✔
4644
      return terrno;
×
4645
    }
4646
  }
4647

4648
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
371,818✔
4649
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
371,818✔
4650
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
371,818✔
4651
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
371,818✔
4652
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
371,818✔
4653
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
371,818✔
4654
  if ((char*)buf - (char*)start < len) {
371,818✔
4655
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
371,818✔
4656
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
371,818✔
4657
    buf = taosDecodeStringTo(buf, pReq->user);
371,818✔
4658
    buf = taosDecodeStringTo(buf, pReq->fqdn);
743,636✔
4659
  } else {
4660
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4661
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4662
  }
4663

4664
  return 0;
371,818✔
4665
}
4666

4667
typedef struct {
4668
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4669
  SArray* removedConsumers;  // SArray<int64_t>
4670
  SArray* newConsumers;      // SArray<int64_t>
4671
} SMqRebInfo;
4672

4673
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4674
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
336,648✔
4675
  if (pRebInfo == NULL) {
336,648✔
4676
    return NULL;
×
4677
  }
4678
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
336,648✔
4679
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
336,648✔
4680
  if (pRebInfo->removedConsumers == NULL) {
336,648✔
4681
    goto _err;
×
4682
  }
4683
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
336,648✔
4684
  if (pRebInfo->newConsumers == NULL) {
336,648✔
4685
    goto _err;
×
4686
  }
4687
  return pRebInfo;
336,648✔
4688
_err:
×
4689
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4690
  taosArrayDestroy(pRebInfo->newConsumers);
×
4691
  taosMemoryFreeClear(pRebInfo);
×
4692
  return NULL;
×
4693
}
4694

4695
typedef struct {
4696
  int64_t streamId;
4697
  int64_t checkpointId;
4698
  char    streamName[TSDB_STREAM_FNAME_LEN];
4699
} SMStreamDoCheckpointMsg;
4700

4701
typedef struct {
4702
  int64_t status;
4703
} SMVSubscribeRsp;
4704

4705
typedef struct {
4706
  char    name[TSDB_TOPIC_FNAME_LEN];
4707
  int8_t  igNotExists;
4708
  int32_t sqlLen;
4709
  char*   sql;
4710
  int8_t  force;
4711
} SMDropTopicReq;
4712

4713
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4714
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4715
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4716

4717
typedef struct {
4718
  char    name[TSDB_TOPIC_FNAME_LEN];
4719
  int8_t  igNotExists;
4720
  int32_t sqlLen;
4721
  char*   sql;
4722
} SMReloadTopicReq;
4723

4724
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4725
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4726
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4727

4728
typedef struct {
4729
  char   topic[TSDB_TOPIC_FNAME_LEN];
4730
  char   cgroup[TSDB_CGROUP_LEN];
4731
  int8_t igNotExists;
4732
  int8_t force;
4733
} SMDropCgroupReq;
4734

4735
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4736
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4737

4738
typedef struct {
4739
  int8_t reserved;
4740
} SMDropCgroupRsp;
4741

4742
typedef struct {
4743
  char    name[TSDB_TABLE_FNAME_LEN];
4744
  int8_t  alterType;
4745
  SSchema schema;
4746
} SAlterTopicReq;
4747

4748
typedef struct {
4749
  SMsgHead head;
4750
  char     name[TSDB_TABLE_FNAME_LEN];
4751
  int64_t  tuid;
4752
  int32_t  sverson;
4753
  int32_t  execLen;
4754
  char*    executor;
4755
  int32_t  sqlLen;
4756
  char*    sql;
4757
} SDCreateTopicReq;
4758

4759
typedef struct {
4760
  SMsgHead head;
4761
  char     name[TSDB_TABLE_FNAME_LEN];
4762
  int64_t  tuid;
4763
} SDDropTopicReq;
4764

4765
typedef struct {
4766
  char*      name;
4767
  int64_t    uid;
4768
  int64_t    interval[2];
4769
  int8_t     intervalUnit;
4770
  int16_t    nFuncs;
4771
  col_id_t*  funcColIds;  // column ids specified by user
4772
  func_id_t* funcIds;     // function ids specified by user
4773
} SRSmaParam;
4774

4775
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4776
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4777

4778
// TDMT_VND_CREATE_STB ==============
4779
typedef struct SVCreateStbReq {
4780
  char*           name;
4781
  tb_uid_t        suid;
4782
  int8_t          rollup;
4783
  SSchemaWrapper  schemaRow;
4784
  SSchemaWrapper  schemaTag;
4785
  SRSmaParam      rsmaParam;
4786
  int32_t         alterOriDataLen;
4787
  void*           alterOriData;
4788
  int8_t          source;
4789
  int8_t          colCmpred;
4790
  SColCmprWrapper colCmpr;
4791
  int64_t         keep;
4792
  int64_t         ownerId;
4793
  SExtSchema*     pExtSchemas;
4794
  int8_t          virtualStb;
4795
} SVCreateStbReq;
4796

4797
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4798
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4799

4800
// TDMT_VND_DROP_STB ==============
4801
typedef struct SVDropStbReq {
4802
  char*    name;
4803
  tb_uid_t suid;
4804
} SVDropStbReq;
4805

4806
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4807
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4808

4809
// TDMT_VND_CREATE_TABLE ==============
4810
#define TD_CREATE_IF_NOT_EXISTS       0x1
4811
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4812
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4813
typedef struct SVCreateTbReq {
4814
  int32_t  flags;
4815
  char*    name;
4816
  tb_uid_t uid;
4817
  int64_t  btime;
4818
  int32_t  ttl;
4819
  int32_t  commentLen;
4820
  char*    comment;
4821
  int8_t   type;
4822
  union {
4823
    struct {
4824
      char*    stbName;  // super table name
4825
      uint8_t  tagNum;
4826
      tb_uid_t suid;
4827
      SArray*  tagName;
4828
      uint8_t* pTag;
4829
    } ctb;
4830
    struct {
4831
      SSchemaWrapper schemaRow;
4832
      int64_t        userId;
4833
    } ntb;
4834
  };
4835
  int32_t         sqlLen;
4836
  char*           sql;
4837
  SColCmprWrapper colCmpr;
4838
  SExtSchema*     pExtSchemas;
4839
  SColRefWrapper  colRef;  // col reference for virtual table
4840
} SVCreateTbReq;
4841

4842
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4843
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4844
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4845
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4846

4847
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4848
  if (NULL == req) {
2,147,483,647✔
4849
    return;
2,147,483,647✔
4850
  }
4851

4852
  taosMemoryFreeClear(req->sql);
76,921,565✔
4853
  taosMemoryFreeClear(req->name);
76,922,293✔
4854
  taosMemoryFreeClear(req->comment);
76,932,533✔
4855
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
76,941,179✔
4856
    taosMemoryFreeClear(req->ctb.pTag);
69,996,841✔
4857
    taosMemoryFreeClear(req->ctb.stbName);
69,985,849✔
4858
    taosArrayDestroy(req->ctb.tagName);
69,984,090✔
4859
    req->ctb.tagName = NULL;
69,948,405✔
4860
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
6,934,264✔
4861
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
6,934,264✔
4862
  }
4863
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
76,900,593✔
4864
  taosMemoryFreeClear(req->pExtSchemas);
76,924,800✔
4865
  taosMemoryFreeClear(req->colRef.pColRef);
76,930,001✔
4866
}
4867

4868
typedef struct {
4869
  int32_t nReqs;
4870
  union {
4871
    SVCreateTbReq* pReqs;
4872
    SArray*        pArray;
4873
  };
4874
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4875
} SVCreateTbBatchReq;
4876

4877
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4878
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4879
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4880

4881
typedef struct {
4882
  int32_t        code;
4883
  STableMetaRsp* pMeta;
4884
} SVCreateTbRsp, SVUpdateTbRsp;
4885

4886
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4887
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4888
void tFreeSVCreateTbRsp(void* param);
4889

4890
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4891
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4892

4893
typedef struct {
4894
  int32_t nRsps;
4895
  union {
4896
    SVCreateTbRsp* pRsps;
4897
    SArray*        pArray;
4898
  };
4899
} SVCreateTbBatchRsp;
4900

4901
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4902
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4903

4904
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4905
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4906

4907
// TDMT_VND_DROP_TABLE =================
4908
typedef struct {
4909
  char*    name;
4910
  uint64_t suid;  // for tmq in wal format
4911
  int64_t  uid;
4912
  int8_t   igNotExists;
4913
  int8_t   isVirtual;
4914
} SVDropTbReq;
4915

4916
typedef struct {
4917
  int32_t code;
4918
} SVDropTbRsp;
4919

4920
typedef struct {
4921
  int32_t nReqs;
4922
  union {
4923
    SVDropTbReq* pReqs;
4924
    SArray*      pArray;
4925
  };
4926
} SVDropTbBatchReq;
4927

4928
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4929
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4930

4931
typedef struct {
4932
  int32_t nRsps;
4933
  union {
4934
    SVDropTbRsp* pRsps;
4935
    SArray*      pArray;
4936
  };
4937
} SVDropTbBatchRsp;
4938

4939
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4940
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4941

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

4992
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4993
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4994
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4995
void    tfreeMultiTagUpateVal(void* pMultiTag);
4996

4997
typedef struct {
4998
  int32_t        code;
4999
  STableMetaRsp* pMeta;
5000
} SVAlterTbRsp;
5001

5002
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5003
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5004
// ======================
5005

5006
typedef struct {
5007
  SMsgHead head;
5008
  int64_t  uid;
5009
  int32_t  tid;
5010
  int16_t  tversion;
5011
  int16_t  colId;
5012
  int8_t   type;
5013
  int16_t  bytes;
5014
  int32_t  tagValLen;
5015
  int16_t  numOfTags;
5016
  int32_t  schemaLen;
5017
  char     data[];
5018
} SUpdateTagValReq;
5019

5020
typedef struct {
5021
  SMsgHead head;
5022
} SUpdateTagValRsp;
5023

5024
typedef struct {
5025
  SMsgHead head;
5026
} SVShowTablesReq;
5027

5028
typedef struct {
5029
  SMsgHead head;
5030
  int32_t  id;
5031
} SVShowTablesFetchReq;
5032

5033
typedef struct {
5034
  int64_t useconds;
5035
  int8_t  completed;  // all results are returned to client
5036
  int8_t  precision;
5037
  int8_t  compressed;
5038
  int32_t compLen;
5039
  int32_t numOfRows;
5040
  char    data[];
5041
} SVShowTablesFetchRsp;
5042

5043
typedef struct {
5044
  int64_t consumerId;
5045
  int32_t epoch;
5046
  char    cgroup[TSDB_CGROUP_LEN];
5047
} SMqAskEpReq;
5048

5049
typedef struct {
5050
  int32_t key;
5051
  int32_t valueLen;
5052
  void*   value;
5053
} SKv;
5054

5055
typedef struct {
5056
  int64_t tscRid;
5057
  int8_t  connType;
5058
} SClientHbKey;
5059

5060
typedef struct {
5061
  int64_t tid;
5062
  char    status[TSDB_JOB_STATUS_LEN];
5063
} SQuerySubDesc;
5064

5065
typedef struct {
5066
  char     sql[TSDB_SHOW_SQL_LEN];
5067
  uint64_t queryId;
5068
  int64_t  useconds;
5069
  int64_t  stime;  // timestamp precision ms
5070
  int64_t  reqRid;
5071
  bool     stableQuery;
5072
  bool     isSubQuery;
5073
  char     fqdn[TSDB_FQDN_LEN];
5074
  int32_t  subPlanNum;
5075
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5076
} SQueryDesc;
5077

5078
typedef struct {
5079
  uint32_t connId;
5080
  SArray*  queryDesc;  // SArray<SQueryDesc>
5081
} SQueryHbReqBasic;
5082

5083
typedef struct {
5084
  uint32_t connId;
5085
  uint64_t killRid;
5086
  int32_t  totalDnodes;
5087
  int32_t  onlineDnodes;
5088
  int8_t   killConnection;
5089
  int8_t   align[3];
5090
  SEpSet   epSet;
5091
  SArray*  pQnodeList;
5092
} SQueryHbRspBasic;
5093

5094
typedef struct SAppClusterSummary {
5095
  uint64_t numOfInsertsReq;
5096
  uint64_t numOfInsertRows;
5097
  uint64_t insertElapsedTime;
5098
  uint64_t insertBytes;  // submit to tsdb since launched.
5099

5100
  uint64_t fetchBytes;
5101
  uint64_t numOfQueryReq;
5102
  uint64_t queryElapsedTime;
5103
  uint64_t numOfSlowQueries;
5104
  uint64_t totalRequests;
5105
  uint64_t currentRequests;  // the number of SRequestObj
5106
} SAppClusterSummary;
5107

5108
typedef struct {
5109
  int64_t            appId;
5110
  int32_t            pid;
5111
  char               name[TSDB_APP_NAME_LEN];
5112
  int64_t            startTime;
5113
  SAppClusterSummary summary;
5114
} SAppHbReq;
5115

5116
typedef struct {
5117
  SClientHbKey      connKey;
5118
  int64_t           clusterId;
5119
  SAppHbReq         app;
5120
  SQueryHbReqBasic* query;
5121
  SHashObj*         info;  // hash<Skv.key, Skv>
5122
  char              user[TSDB_USER_LEN];
5123
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5124
  char              userApp[TSDB_APP_NAME_LEN];
5125
  uint32_t          userIp;
5126
  SIpRange          userDualIp;
5127
  char              sVer[TSDB_VERSION_LEN];
5128
  char              cInfo[CONNECTOR_INFO_LEN];
5129
} SClientHbReq;
5130

5131
typedef struct {
5132
  int64_t reqId;
5133
  SArray* reqs;  // SArray<SClientHbReq>
5134
  int64_t ipWhiteListVer;
5135
} SClientHbBatchReq;
5136

5137
typedef struct {
5138
  SClientHbKey      connKey;
5139
  int32_t           status;
5140
  SQueryHbRspBasic* query;
5141
  SArray*           info;  // Array<Skv>
5142
} SClientHbRsp;
5143

5144
typedef struct {
5145
  int64_t       reqId;
5146
  int64_t       rspId;
5147
  int32_t       svrTimestamp;
5148
  SArray*       rsps;  // SArray<SClientHbRsp>
5149
  SMonitorParas monitorParas;
5150
  int8_t        enableAuditDelete;
5151
  int8_t        enableStrongPass;
5152
  int8_t        enableAuditSelect;
5153
  int8_t        enableAuditInsert;
5154
  int8_t        auditLevel;
5155
} SClientHbBatchRsp;
5156

5157
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
303,383,007✔
5158

5159
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5160
  void* pIter = taosHashIterate(info, NULL);
54,478,700✔
5161
  while (pIter != NULL) {
127,296,970✔
5162
    SKv* kv = (SKv*)pIter;
72,816,942✔
5163
    taosMemoryFreeClear(kv->value);
72,816,942✔
5164
    pIter = taosHashIterate(info, pIter);
72,818,030✔
5165
  }
5166
}
54,480,028✔
5167

5168
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
36,266,854✔
5169
  SQueryDesc* desc = (SQueryDesc*)pDesc;
36,266,854✔
5170
  if (desc->subDesc) {
36,266,854✔
5171
    taosArrayDestroy(desc->subDesc);
25,352,009✔
5172
    desc->subDesc = NULL;
25,347,630✔
5173
  }
5174
}
36,264,491✔
5175

5176
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
62,418,077✔
5177
  SClientHbReq* req = (SClientHbReq*)pReq;
121,598,221✔
5178
  if (req->query) {
121,598,221✔
5179
    if (req->query->queryDesc) {
62,415,568✔
5180
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
28,730,885✔
5181
    }
5182
    taosMemoryFreeClear(req->query);
62,417,129✔
5183
  }
5184

5185
  if (req->info) {
121,599,182✔
5186
    tFreeReqKvHash(req->info);
54,479,327✔
5187
    taosHashCleanup(req->info);
54,480,028✔
5188
    req->info = NULL;
54,477,143✔
5189
  }
5190
}
89,816,174✔
5191

5192
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5193
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5194

5195
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5196
  if (pReq == NULL) return;
26,019,751✔
5197
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
26,019,751✔
5198
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
26,019,751✔
5199
  taosMemoryFree(pReq);
26,019,751✔
5200
}
5201

5202
static FORCE_INLINE void tFreeClientKv(void* pKv) {
72,557,024✔
5203
  SKv* kv = (SKv*)pKv;
72,557,024✔
5204
  if (kv) {
72,557,024✔
5205
    taosMemoryFreeClear(kv->value);
72,557,024✔
5206
  }
5207
}
72,560,543✔
5208

5209
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
62,145,012✔
5210
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
62,145,012✔
5211
  if (rsp->query) {
62,145,012✔
5212
    taosArrayDestroy(rsp->query->pQnodeList);
62,134,898✔
5213
    taosMemoryFreeClear(rsp->query);
62,134,601✔
5214
  }
5215
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
62,156,860✔
5216
}
31,508,790✔
5217

5218
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5219
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
51,428,039✔
5220
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
51,428,039✔
5221
}
51,434,617✔
5222

5223
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5224
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5225
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5226

5227
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5228
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
432,609,739✔
5229
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
432,611,385✔
5230
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
432,614,953✔
5231
  return 0;
216,307,601✔
5232
}
5233

5234
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5235
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
142,410,890✔
5236
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
142,409,608✔
5237
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
71,203,936✔
5238
  if (pKv->value == NULL) {
71,204,787✔
5239
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5240
  }
5241
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
71,205,207✔
5242
  return 0;
71,205,785✔
5243
}
5244

5245
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5246
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
370,819,299✔
5247
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
370,812,610✔
5248
  return 0;
185,405,553✔
5249
}
5250

5251
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5252
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
121,648,787✔
5253
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
121,653,473✔
5254
  return 0;
60,828,206✔
5255
}
5256

5257
typedef struct {
5258
  int32_t vgId;
5259
  // TODO stas
5260
} SMqReportVgInfo;
5261

5262
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5263
  int32_t tlen = 0;
5264
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5265
  return tlen;
5266
}
5267

5268
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5269
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5270
  return buf;
5271
}
5272

5273
typedef struct {
5274
  int32_t epoch;
5275
  int64_t topicUid;
5276
  char    name[TSDB_TOPIC_FNAME_LEN];
5277
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5278
} SMqTopicInfo;
5279

5280
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5281
  int32_t tlen = 0;
5282
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5283
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5284
  tlen += taosEncodeString(buf, pTopicInfo->name);
5285
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5286
  tlen += taosEncodeFixedI32(buf, sz);
5287
  for (int32_t i = 0; i < sz; i++) {
5288
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5289
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5290
  }
5291
  return tlen;
5292
}
5293

5294
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5295
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5296
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5297
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5298
  int32_t sz;
5299
  buf = taosDecodeFixedI32(buf, &sz);
5300
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5301
    return NULL;
5302
  }
5303
  for (int32_t i = 0; i < sz; i++) {
5304
    SMqReportVgInfo vgInfo;
5305
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5306
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5307
      return NULL;
5308
    }
5309
  }
5310
  return buf;
5311
}
5312

5313
typedef struct {
5314
  int32_t status;  // ask hb endpoint
5315
  int32_t epoch;
5316
  int64_t consumerId;
5317
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5318
} SMqReportReq;
5319

5320
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5321
  int32_t tlen = 0;
5322
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5323
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5324
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5325
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5326
  tlen += taosEncodeFixedI32(buf, sz);
5327
  for (int32_t i = 0; i < sz; i++) {
5328
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5329
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5330
  }
5331
  return tlen;
5332
}
5333

5334
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5335
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5336
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5337
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5338
  int32_t sz;
5339
  buf = taosDecodeFixedI32(buf, &sz);
5340
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5341
    return NULL;
5342
  }
5343
  for (int32_t i = 0; i < sz; i++) {
5344
    SMqTopicInfo topicInfo;
5345
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5346
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5347
      return NULL;
5348
    }
5349
  }
5350
  return buf;
5351
}
5352

5353
typedef struct {
5354
  SMsgHead head;
5355
  int64_t  leftForVer;
5356
  int32_t  vgId;
5357
  int64_t  consumerId;
5358
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5359
} SMqVDeleteReq;
5360

5361
typedef struct {
5362
  int8_t reserved;
5363
} SMqVDeleteRsp;
5364

5365
typedef struct {
5366
  char**  name;
5367
  int32_t count;
5368
  int8_t igNotExists;
5369
} SMDropStreamReq;
5370

5371
typedef struct {
5372
  int8_t reserved;
5373
} SMDropStreamRsp;
5374

5375
typedef struct {
5376
  SMsgHead head;
5377
  int64_t  resetRelHalt;  // reset related stream task halt status
5378
  int64_t  streamId;
5379
  int32_t  taskId;
5380
} SVDropStreamTaskReq;
5381

5382
typedef struct {
5383
  int8_t reserved;
5384
} SVDropStreamTaskRsp;
5385

5386
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5387
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5388
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5389

5390
typedef struct {
5391
  char*  name;
5392
  int8_t igNotExists;
5393
} SMPauseStreamReq;
5394

5395
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5396
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5397
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5398

5399
typedef struct {
5400
  char*  name;
5401
  int8_t igNotExists;
5402
  int8_t igUntreated;
5403
} SMResumeStreamReq;
5404

5405
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5406
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5407
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5408

5409
typedef struct {
5410
  char*       name;
5411
  int8_t      calcAll;
5412
  STimeWindow timeRange;
5413
} SMRecalcStreamReq;
5414

5415
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5416
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5417
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5418

5419

5420
typedef struct SVndSetKeepVersionReq {
5421
  int64_t keepVersion;
5422
} SVndSetKeepVersionReq;
5423

5424
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5425
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5426

5427
typedef struct SVUpdateCheckpointInfoReq {
5428
  SMsgHead head;
5429
  int64_t  streamId;
5430
  int32_t  taskId;
5431
  int64_t  checkpointId;
5432
  int64_t  checkpointVer;
5433
  int64_t  checkpointTs;
5434
  int32_t  transId;
5435
  int64_t  hStreamId;  // add encode/decode
5436
  int64_t  hTaskId;
5437
  int8_t   dropRelHTask;
5438
} SVUpdateCheckpointInfoReq;
5439

5440
typedef struct {
5441
  int64_t leftForVer;
5442
  int32_t vgId;
5443
  int64_t oldConsumerId;
5444
  int64_t newConsumerId;
5445
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5446
  int8_t  subType;
5447
  int8_t  withMeta;
5448
  char*   qmsg;  // SubPlanToString
5449
  SSchemaWrapper schema;
5450
  int64_t suid;
5451
} SMqRebVgReq;
5452

5453
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5454
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5455

5456
// tqOffset
5457
enum {
5458
  TMQ_OFFSET__RESET_NONE = -3,
5459
  TMQ_OFFSET__RESET_EARLIEST = -2,
5460
  TMQ_OFFSET__RESET_LATEST = -1,
5461
  TMQ_OFFSET__LOG = 1,
5462
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5463
  TMQ_OFFSET__SNAPSHOT_META = 3,
5464
};
5465

5466
enum {
5467
  WITH_DATA = 0,
5468
  WITH_META = 1,
5469
  ONLY_META = 2,
5470
};
5471

5472
#define TQ_OFFSET_VERSION 1
5473

5474
typedef struct {
5475
  int8_t type;
5476
  union {
5477
    // snapshot
5478
    struct {
5479
      int64_t uid;
5480
      int64_t ts;
5481
      SValue  primaryKey;
5482
    };
5483
    // log
5484
    struct {
5485
      int64_t version;
5486
    };
5487
  };
5488
} STqOffsetVal;
5489

5490
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5491
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,762,056✔
5492
  pOffsetVal->uid = uid;
7,759,950✔
5493
  pOffsetVal->ts = ts;
7,761,474✔
5494
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,760,217✔
5495
    taosMemoryFree(pOffsetVal->primaryKey.pData);
294✔
5496
  }
5497
  pOffsetVal->primaryKey = primaryKey;
7,757,700✔
5498
}
7,758,634✔
5499

5500
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5501
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
40,280✔
5502
  pOffsetVal->uid = uid;
40,280✔
5503
}
40,280✔
5504

5505
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5506
  pOffsetVal->type = TMQ_OFFSET__LOG;
28,541,372✔
5507
  pOffsetVal->version = ver;
28,541,159✔
5508
}
28,540,795✔
5509

5510
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5511
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5512
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5513
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5514
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5515
void    tOffsetDestroy(void* pVal);
5516

5517
typedef struct {
5518
  STqOffsetVal val;
5519
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5520
} STqOffset;
5521

5522
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5523
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5524
void    tDeleteSTqOffset(void* val);
5525

5526
typedef struct SMqVgOffset {
5527
  int64_t   consumerId;
5528
  STqOffset offset;
5529
} SMqVgOffset;
5530

5531
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5532
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5533

5534
typedef struct {
5535
  char    name[TSDB_TABLE_FNAME_LEN];
5536
  char    stb[TSDB_TABLE_FNAME_LEN];
5537
  int8_t  igExists;
5538
  int8_t  intervalUnit;
5539
  int8_t  slidingUnit;
5540
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5541
  int32_t dstVgId;   // for stream
5542
  int64_t interval;
5543
  int64_t offset;
5544
  int64_t sliding;
5545
  int64_t maxDelay;
5546
  int64_t watermark;
5547
  int32_t exprLen;        // strlen + 1
5548
  int32_t tagsFilterLen;  // strlen + 1
5549
  int32_t sqlLen;         // strlen + 1
5550
  int32_t astLen;         // strlen + 1
5551
  char*   expr;
5552
  char*   tagsFilter;
5553
  char*   sql;
5554
  char*   ast;
5555
  int64_t deleteMark;
5556
  int64_t lastTs;
5557
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5558
  SArray* pVgroupVerList;
5559
  int8_t  recursiveTsma;
5560
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5561
  char*   createStreamReq;
5562
  int32_t streamReqLen;
5563
  char*   dropStreamReq;
5564
  int32_t dropStreamReqLen;
5565
  int64_t uid;
5566
} SMCreateSmaReq;
5567

5568
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5569
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5570
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5571

5572
typedef struct {
5573
  char    name[TSDB_TABLE_FNAME_LEN];
5574
  int8_t  igNotExists;
5575
  char*   dropStreamReq;
5576
  int32_t dropStreamReqLen;
5577
} SMDropSmaReq;
5578

5579
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5580
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5581
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5582

5583
typedef struct {
5584
  char name[TSDB_TABLE_NAME_LEN];
5585
  union {
5586
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5587
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5588
  };
5589
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5590
  union {
5591
    int8_t igExists;   // used by mnode
5592
    int8_t alterType;  // used by vnode
5593
  };
5594
  int8_t     intervalUnit;
5595
  int16_t    nFuncs;       // number of functions specified by user
5596
  col_id_t*  funcColIds;   // column ids specified by user
5597
  func_id_t* funcIds;      // function ids specified by user
5598
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5599
  int64_t    tbUid;
5600
  int64_t    uid;     // rsma uid
5601
  int32_t    sqlLen;  // strlen + 1
5602
  char*      sql;
5603
} SMCreateRsmaReq;
5604

5605
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5606
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5607
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5608

5609
typedef SMCreateRsmaReq SVCreateRsmaReq;
5610

5611
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5612
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5613
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5614

5615
typedef SMCreateRsmaReq SVAlterRsmaReq;
5616

5617
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5618
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5619
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5620

5621
typedef struct {
5622
  char       name[TSDB_TABLE_NAME_LEN];
5623
  int8_t     alterType;
5624
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5625
  int8_t     igNotExists;
5626
  int16_t    nFuncs;      // number of functions specified by user
5627
  col_id_t*  funcColIds;  // column ids specified by user
5628
  func_id_t* funcIds;     // function ids specified by user
5629
  int32_t    sqlLen;      // strlen + 1
5630
  char*      sql;
5631
} SMAlterRsmaReq;
5632

5633
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5634
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5635
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5636

5637
typedef struct {
5638
  int64_t    id;
5639
  char       name[TSDB_TABLE_NAME_LEN];
5640
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5641
  int64_t    ownerId;
5642
  int32_t    code;
5643
  int32_t    version;
5644
  int8_t     tbType;
5645
  int8_t     intervalUnit;
5646
  col_id_t   nFuncs;
5647
  col_id_t   nColNames;
5648
  int64_t    interval[2];
5649
  col_id_t*  funcColIds;
5650
  func_id_t* funcIds;
5651
  SArray*    colNames;
5652
} SRsmaInfoRsp;
5653

5654
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5655
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5656
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5657

5658
typedef struct {
5659
  char   name[TSDB_TABLE_FNAME_LEN];
5660
  int8_t igNotExists;
5661
} SMDropRsmaReq;
5662

5663
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5664
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5665

5666
typedef struct {
5667
  char    name[TSDB_TABLE_NAME_LEN];
5668
  char    tbName[TSDB_TABLE_NAME_LEN];
5669
  int64_t uid;
5670
  int64_t tbUid;
5671
  int8_t  tbType;
5672
} SVDropRsmaReq;
5673

5674
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5675
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5676

5677
typedef struct {
5678
  char   dbFName[TSDB_DB_FNAME_LEN];
5679
  char   stbName[TSDB_TABLE_NAME_LEN];
5680
  char   colName[TSDB_COL_NAME_LEN];
5681
  char   idxName[TSDB_INDEX_FNAME_LEN];
5682
  int8_t idxType;
5683
} SCreateTagIndexReq;
5684

5685
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5686
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5687

5688
typedef SMDropSmaReq SDropTagIndexReq;
5689

5690
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5691
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5692

5693
typedef struct {
5694
  int8_t         version;       // for compatibility(default 0)
5695
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5696
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5697
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5698
  int32_t        dstVgId;
5699
  char           indexName[TSDB_INDEX_NAME_LEN];
5700
  int32_t        exprLen;
5701
  int32_t        tagsFilterLen;
5702
  int64_t        indexUid;
5703
  tb_uid_t       tableUid;  // super/child/common table uid
5704
  tb_uid_t       dstTbUid;  // for dstVgroup
5705
  int64_t        interval;
5706
  int64_t        offset;  // use unit by precision of DB
5707
  int64_t        sliding;
5708
  char*          dstTbName;  // for dstVgroup
5709
  char*          expr;       // sma expression
5710
  char*          tagsFilter;
5711
  SSchemaWrapper schemaRow;  // for dstVgroup
5712
  SSchemaWrapper schemaTag;  // for dstVgroup
5713
} STSma;                     // Time-range-wise SMA
5714

5715
typedef STSma SVCreateTSmaReq;
5716

5717
typedef struct {
5718
  int8_t  type;  // 0 status report, 1 update data
5719
  int64_t indexUid;
5720
  int64_t skey;  // start TS key of interval/sliding window
5721
} STSmaMsg;
5722

5723
typedef struct {
5724
  int64_t indexUid;
5725
  char    indexName[TSDB_INDEX_NAME_LEN];
5726
} SVDropTSmaReq;
5727

5728
typedef struct {
5729
  int tmp;  // TODO: to avoid compile error
5730
} SVCreateTSmaRsp, SVDropTSmaRsp;
5731

5732
#if 0
5733
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5734
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5735
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5736
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5737
#endif
5738

5739
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5740
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5741
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5742
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5743

5744
typedef struct {
5745
  int32_t number;
5746
  STSma*  tSma;
5747
} STSmaWrapper;
5748

5749
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5750
  if (pSma) {
×
5751
    taosMemoryFreeClear(pSma->dstTbName);
×
5752
    taosMemoryFreeClear(pSma->expr);
×
5753
    taosMemoryFreeClear(pSma->tagsFilter);
×
5754
  }
5755
}
×
5756

5757
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5758
  if (pSW) {
×
5759
    if (pSW->tSma) {
×
5760
      if (deepCopy) {
×
5761
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5762
          tDestroyTSma(pSW->tSma + i);
×
5763
        }
5764
      }
5765
      taosMemoryFreeClear(pSW->tSma);
×
5766
    }
5767
  }
5768
}
×
5769

5770
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5771
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5772
  taosMemoryFreeClear(pSW);
×
5773
  return NULL;
×
5774
}
5775

5776
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5777
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5778

5779
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5780
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5781

5782
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5783
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5784
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5785
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5786
  }
5787
  return 0;
×
5788
}
5789

5790
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5791
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5792
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5793
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5794
  }
5795
  return 0;
×
5796
}
5797

5798
typedef struct {
5799
  int idx;
5800
} SMCreateFullTextReq;
5801

5802
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5803
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5804
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5805

5806
typedef struct {
5807
  char   name[TSDB_TABLE_FNAME_LEN];
5808
  int8_t igNotExists;
5809
} SMDropFullTextReq;
5810

5811
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5812
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5813

5814
typedef struct {
5815
  char indexFName[TSDB_INDEX_FNAME_LEN];
5816
} SUserIndexReq;
5817

5818
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5819
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5820

5821
typedef struct {
5822
  char dbFName[TSDB_DB_FNAME_LEN];
5823
  char tblFName[TSDB_TABLE_FNAME_LEN];
5824
  char colName[TSDB_COL_NAME_LEN];
5825
  char owner[TSDB_USER_LEN];
5826
  char indexType[TSDB_INDEX_TYPE_LEN];
5827
  char indexExts[TSDB_INDEX_EXTS_LEN];
5828
} SUserIndexRsp;
5829

5830
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5831
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5832

5833
typedef struct {
5834
  char tbFName[TSDB_TABLE_FNAME_LEN];
5835
} STableIndexReq;
5836

5837
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5838
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5839

5840
typedef struct {
5841
  int8_t  intervalUnit;
5842
  int8_t  slidingUnit;
5843
  int64_t interval;
5844
  int64_t offset;
5845
  int64_t sliding;
5846
  int64_t dstTbUid;
5847
  int32_t dstVgId;
5848
  SEpSet  epSet;
5849
  char*   expr;
5850
} STableIndexInfo;
5851

5852
typedef struct {
5853
  char     tbName[TSDB_TABLE_NAME_LEN];
5854
  char     dbFName[TSDB_DB_FNAME_LEN];
5855
  uint64_t suid;
5856
  int32_t  version;
5857
  int32_t  indexSize;
5858
  SArray*  pIndex;  // STableIndexInfo
5859
} STableIndexRsp;
5860

5861
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5862
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5863
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5864

5865
void tFreeSTableIndexInfo(void* pInfo);
5866

5867
typedef struct {
5868
  int8_t  mqMsgType;
5869
  int32_t code;
5870
  int32_t epoch;
5871
  int64_t consumerId;
5872
  int64_t walsver;
5873
  int64_t walever;
5874
} SMqRspHead;
5875

5876
typedef struct {
5877
  SMsgHead     head;
5878
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5879
  int8_t       withTbName;
5880
  int8_t       useSnapshot;
5881
  int32_t      epoch;
5882
  uint64_t     reqId;
5883
  int64_t      consumerId;
5884
  int64_t      timeout;
5885
  STqOffsetVal reqOffset;
5886
  int8_t       enableReplay;
5887
  int8_t       sourceExcluded;
5888
  int8_t       rawData;
5889
  int32_t      minPollRows;
5890
  int8_t       enableBatchMeta;
5891
  SHashObj*    uidHash;  // to find if uid is duplicated
5892
} SMqPollReq;
5893

5894
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5895
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5896
void    tDestroySMqPollReq(SMqPollReq* pReq);
5897

5898
typedef struct {
5899
  int32_t vgId;
5900
  int64_t offset;
5901
  SEpSet  epSet;
5902
} SMqSubVgEp;
5903

5904
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5905
  int32_t tlen = 0;
2,168,988✔
5906
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,168,988✔
5907
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,168,988✔
5908
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,168,988✔
5909
  return tlen;
2,168,988✔
5910
}
5911

5912
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5913
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,074,377✔
5914
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,074,377✔
5915
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,074,377✔
5916
  return buf;
1,074,377✔
5917
}
5918

5919
typedef struct {
5920
  char           topic[TSDB_TOPIC_FNAME_LEN];
5921
  char           db[TSDB_DB_FNAME_LEN];
5922
  SArray*        vgs;  // SArray<SMqSubVgEp>
5923
} SMqSubTopicEp;
5924

5925
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5926
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5927
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5928

5929
typedef struct {
5930
  SMqRspHead   head;
5931
  STqOffsetVal rspOffset;
5932
  int16_t      resMsgType;
5933
  int32_t      metaRspLen;
5934
  void*        metaRsp;
5935
} SMqMetaRsp;
5936

5937
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5938
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5939
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5940

5941
#define MQ_DATA_RSP_VERSION 100
5942

5943
typedef struct {
5944
  SMqRspHead   head;
5945
  STqOffsetVal rspOffset;
5946
  STqOffsetVal reqOffset;
5947
  int32_t      blockNum;
5948
  int8_t       withTbName;
5949
  int8_t       withSchema;
5950
  SArray*      blockDataLen;
5951
  SArray*      blockData;
5952
  SArray*      blockTbName;
5953
  SArray*      blockSchema;
5954

5955
  union {
5956
    struct {
5957
      int64_t sleepTime;
5958
    };
5959
    struct {
5960
      int32_t createTableNum;
5961
      SArray* createTableLen;
5962
      SArray* createTableReq;
5963
    };
5964
    struct {
5965
      int32_t len;
5966
      void*   rawData;
5967
    };
5968
  };
5969
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5970
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5971
  bool  timeout;
5972
} SMqDataRsp;
5973

5974
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5975
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5976
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5977
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5978
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5979

5980
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5981
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5982
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5983

5984
typedef struct SMqBatchMetaRsp {
5985
  SMqRspHead   head;  // not serialize
5986
  STqOffsetVal rspOffset;
5987
  SArray*      batchMetaLen;
5988
  SArray*      batchMetaReq;
5989
  void*        pMetaBuff;    // not serialize
5990
  uint32_t     metaBuffLen;  // not serialize
5991
} SMqBatchMetaRsp;
5992

5993
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5994
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5995
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5996
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5997

5998
typedef struct {
5999
  int32_t    code;
6000
  SArray*    topics;  // SArray<SMqSubTopicEp>
6001
} SMqAskEpRsp;
6002

6003
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6004
  int32_t tlen = 0;
7,764,032✔
6005
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6006
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,764,032✔
6007
  tlen += taosEncodeFixedI32(buf, sz);
7,763,318✔
6008
  for (int32_t i = 0; i < sz; i++) {
9,445,072✔
6009
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,682,822✔
6010
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,682,822✔
6011
  }
6012
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,762,250✔
6013

6014
  return tlen;
7,762,964✔
6015
}
6016

6017
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6018
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6019
  int32_t sz;
3,243,539✔
6020
  buf = taosDecodeFixedI32(buf, &sz);
3,317,146✔
6021
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,317,146✔
6022
  if (pRsp->topics == NULL) {
3,317,146✔
6023
    return NULL;
×
6024
  }
6025
  for (int32_t i = 0; i < sz; i++) {
4,110,285✔
6026
    SMqSubTopicEp topicEp;
780,178✔
6027
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
793,139✔
6028
    if (buf == NULL) {
793,139✔
6029
      return NULL;
×
6030
    }
6031
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,586,278✔
6032
      return NULL;
×
6033
    }
6034
  }
6035
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,317,146✔
6036

6037
  return buf;
3,317,146✔
6038
}
6039

6040
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6041
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,476,246✔
6042
}
9,475,554✔
6043

6044
typedef struct {
6045
  int32_t      vgId;
6046
  STqOffsetVal offset;
6047
  int64_t      rows;
6048
  int64_t      ever;
6049
} OffsetRows;
6050

6051
typedef struct {
6052
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6053
  SArray* offsetRows;
6054
} TopicOffsetRows;
6055

6056
typedef struct {
6057
  int64_t consumerId;
6058
  int32_t epoch;
6059
  SArray* topics;
6060
  int8_t  pollFlag;
6061
} SMqHbReq;
6062

6063
typedef struct {
6064
  char   topic[TSDB_TOPIC_FNAME_LEN];
6065
  int8_t noPrivilege;
6066
} STopicPrivilege;
6067

6068
typedef struct {
6069
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6070
  int32_t debugFlag;
6071
} SMqHbRsp;
6072

6073
typedef struct {
6074
  SMsgHead head;
6075
  int64_t  consumerId;
6076
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6077
} SMqSeekReq;
6078

6079
#define TD_AUTO_CREATE_TABLE 0x1
6080
typedef struct {
6081
  int64_t       suid;
6082
  int64_t       uid;
6083
  int32_t       sver;
6084
  uint32_t      nData;
6085
  uint8_t*      pData;
6086
  SVCreateTbReq cTbReq;
6087
} SVSubmitBlk;
6088

6089
typedef struct {
6090
  SMsgHead header;
6091
  uint64_t sId;
6092
  uint64_t queryId;
6093
  uint64_t clientId;
6094
  uint64_t taskId;
6095
  uint32_t sqlLen;
6096
  uint32_t phyLen;
6097
  char*    sql;
6098
  char*    msg;
6099
  int8_t   source;
6100
} SVDeleteReq;
6101

6102
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6103
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6104

6105
typedef struct {
6106
  int64_t affectedRows;
6107
} SVDeleteRsp;
6108

6109
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6110
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6111

6112
typedef struct SDeleteRes {
6113
  uint64_t suid;
6114
  SArray*  uidList;
6115
  int64_t  skey;
6116
  int64_t  ekey;
6117
  int64_t  affectedRows;
6118
  char     tableFName[TSDB_TABLE_NAME_LEN];
6119
  char     tsColName[TSDB_COL_NAME_LEN];
6120
  int64_t  ctimeMs;  // fill by vnode
6121
  int8_t   source;
6122
} SDeleteRes;
6123

6124
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6125
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6126

6127
typedef struct {
6128
  // int64_t uid;
6129
  char    tbname[TSDB_TABLE_NAME_LEN];
6130
  int64_t startTs;
6131
  int64_t endTs;
6132
} SSingleDeleteReq;
6133

6134
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6135
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6136

6137
typedef struct {
6138
  int64_t suid;
6139
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6140
  int64_t ctimeMs;     // fill by vnode
6141
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6142
} SBatchDeleteReq;
6143

6144
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6145
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6146
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6147

6148
typedef struct {
6149
  int32_t msgIdx;
6150
  int32_t msgType;
6151
  int32_t msgLen;
6152
  void*   msg;
6153
} SBatchMsg;
6154

6155
typedef struct {
6156
  SMsgHead header;
6157
  SArray*  pMsgs;  // SArray<SBatchMsg>
6158
} SBatchReq;
6159

6160
typedef struct {
6161
  int32_t reqType;
6162
  int32_t msgIdx;
6163
  int32_t msgLen;
6164
  int32_t rspCode;
6165
  void*   msg;
6166
} SBatchRspMsg;
6167

6168
typedef struct {
6169
  SArray* pRsps;  // SArray<SBatchRspMsg>
6170
} SBatchRsp;
6171

6172
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6173
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6174
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
94,374,644✔
6175
  if (NULL == msg) {
94,374,644✔
6176
    return;
×
6177
  }
6178
  SBatchMsg* pMsg = (SBatchMsg*)msg;
94,374,644✔
6179
  taosMemoryFree(pMsg->msg);
94,374,644✔
6180
}
6181

6182
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6183
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6184

6185
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
130,239,620✔
6186
  if (NULL == p) {
130,239,620✔
6187
    return;
×
6188
  }
6189

6190
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
130,239,620✔
6191
  taosMemoryFree(pRsp->msg);
130,239,620✔
6192
}
6193

6194
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6195
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6196
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6197
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6198
void    tDestroySMqHbReq(SMqHbReq* pReq);
6199

6200
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6201
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6202
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6203

6204
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6205
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6206

6207
#define TD_REQ_FROM_APP               0x0
6208
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6209
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6210
#define SUBMIT_REQ_FROM_FILE          0x4
6211
#define TD_REQ_FROM_TAOX              0x8
6212
#define TD_REQ_FROM_SML               0x10
6213
#define SUBMIT_REQUEST_VERSION        (2)
6214
#define SUBMIT_REQ_WITH_BLOB          0x10
6215
#define SUBMIT_REQ_SCHEMA_RES         0x20
6216
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6217

6218
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6219

6220
typedef struct {
6221
  int32_t        flags;
6222
  SVCreateTbReq* pCreateTbReq;
6223
  int64_t        suid;
6224
  int64_t        uid;
6225
  int32_t        sver;
6226
  union {
6227
    SArray* aRowP;
6228
    SArray* aCol;
6229
  };
6230
  int64_t   ctimeMs;
6231
  SBlobSet* pBlobSet;
6232
} SSubmitTbData;
6233

6234
typedef struct {
6235
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6236
  SArray* aSubmitBlobData;
6237
  bool    raw;
6238
} SSubmitReq2;
6239

6240
typedef struct {
6241
  SMsgHead header;
6242
  int64_t  version;
6243
  char     data[];  // SSubmitReq2
6244
} SSubmitReq2Msg;
6245

6246
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6247
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6248
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6249
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6250
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6251

6252
typedef struct {
6253
  int32_t affectedRows;
6254
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6255
} SSubmitRsp2;
6256

6257
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6258
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6259
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6260

6261
#define TSDB_MSG_FLG_ENCODE 0x1
6262
#define TSDB_MSG_FLG_DECODE 0x2
6263
#define TSDB_MSG_FLG_CMPT   0x3
6264

6265
typedef struct {
6266
  union {
6267
    struct {
6268
      void*   msgStr;
6269
      int32_t msgLen;
6270
      int64_t ver;
6271
    };
6272
    void* pDataBlock;
6273
  };
6274
} SPackedData;
6275

6276
typedef struct {
6277
  char     fullname[TSDB_VIEW_FNAME_LEN];
6278
  char     name[TSDB_VIEW_NAME_LEN];
6279
  char     dbFName[TSDB_DB_FNAME_LEN];
6280
  char*    querySql;
6281
  char*    sql;
6282
  int8_t   orReplace;
6283
  int8_t   precision;
6284
  int32_t  numOfCols;
6285
  SSchema* pSchema;
6286
} SCMCreateViewReq;
6287

6288
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6289
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6290
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6291

6292
typedef struct {
6293
  char   fullname[TSDB_VIEW_FNAME_LEN];
6294
  char   name[TSDB_VIEW_NAME_LEN];
6295
  char   dbFName[TSDB_DB_FNAME_LEN];
6296
  char*  sql;
6297
  int8_t igNotExists;
6298
} SCMDropViewReq;
6299

6300
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6301
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6302
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6303

6304
typedef struct {
6305
  char fullname[TSDB_VIEW_FNAME_LEN];
6306
} SViewMetaReq;
6307
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6308
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6309

6310
typedef struct {
6311
  char     name[TSDB_VIEW_NAME_LEN];
6312
  char     dbFName[TSDB_DB_FNAME_LEN];
6313
  char*    createUser;
6314
  int64_t  ownerId;
6315
  uint64_t dbId;
6316
  uint64_t viewId;
6317
  char*    querySql;
6318
  int8_t   precision;
6319
  int8_t   type;
6320
  int32_t  version;
6321
  int32_t  numOfCols;
6322
  SSchema* pSchema;
6323
} SViewMetaRsp;
6324
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6325
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6326
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6327
typedef struct {
6328
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6329
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6330
} STableTSMAInfoReq;
6331

6332
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6333
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6334

6335
typedef struct {
6336
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6337
  union {
6338
    uint8_t flags;
6339
    struct {
6340
      uint8_t withColName : 1;
6341
      uint8_t reserved : 7;
6342
    };
6343
  };
6344

6345
} SRsmaInfoReq;
6346

6347
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6348
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6349

6350
typedef struct {
6351
  int32_t  funcId;
6352
  col_id_t colId;
6353
} STableTSMAFuncInfo;
6354

6355
typedef struct {
6356
  char     name[TSDB_TABLE_NAME_LEN];
6357
  uint64_t tsmaId;
6358
  char     targetTb[TSDB_TABLE_NAME_LEN];
6359
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6360
  char     tb[TSDB_TABLE_NAME_LEN];
6361
  char     dbFName[TSDB_DB_FNAME_LEN];
6362
  uint64_t suid;
6363
  uint64_t destTbUid;
6364
  uint64_t dbId;
6365
  int32_t  version;
6366
  int64_t  interval;
6367
  int8_t   unit;
6368
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6369
  SArray*  pTags;      // SArray<SSchema>
6370
  SArray*  pUsedCols;  // SArray<SSchema>
6371
  char*    ast;
6372

6373
  int64_t streamUid;
6374
  int64_t reqTs;
6375
  int64_t rspTs;
6376
  int64_t delayDuration;  // ms
6377
  bool    fillHistoryFinished;
6378

6379
  void* streamAddr;  // for stream task, the address of the stream task
6380
} STableTSMAInfo;
6381

6382
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6383
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6384
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6385
void    tFreeTableTSMAInfo(void* p);
6386
void    tFreeAndClearTableTSMAInfo(void* p);
6387
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6388

6389
#define STSMAHbRsp            STableTSMAInfoRsp
6390
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6391
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6392
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6393

6394
typedef struct SDropCtbWithTsmaSingleVgReq {
6395
  SVgroupInfo vgInfo;
6396
  SArray*     pTbs;  // SVDropTbReq
6397
} SMDropTbReqsOnSingleVg;
6398

6399
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6400
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6401
void    tFreeSMDropTbReqOnSingleVg(void* p);
6402

6403
typedef struct SDropTbsReq {
6404
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6405
} SMDropTbsReq;
6406

6407
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6408
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6409
void    tFreeSMDropTbsReq(void*);
6410

6411
typedef struct SVFetchTtlExpiredTbsRsp {
6412
  SArray* pExpiredTbs;  // SVDropTbReq
6413
  int32_t vgId;
6414
} SVFetchTtlExpiredTbsRsp;
6415

6416
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6417
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6418

6419
void tFreeFetchTtlExpiredTbsRsp(void* p);
6420

6421
void setDefaultOptionsForField(SFieldWithOptions* field);
6422
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6423

6424
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6425
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6426

6427

6428
typedef struct {
6429
  char    id[TSDB_INSTANCE_ID_LEN];
6430
  char    type[TSDB_INSTANCE_TYPE_LEN];
6431
  char    desc[TSDB_INSTANCE_DESC_LEN];
6432
  int32_t expire;
6433
} SInstanceRegisterReq;
6434

6435
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6436
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6437

6438
typedef struct {
6439
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6440
} SInstanceListReq;
6441

6442
typedef struct {
6443
  int32_t count;
6444
  char**  ids;  // Array of instance IDs
6445
} SInstanceListRsp;
6446

6447
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6448
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6449
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6450
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6451

6452
#ifdef USE_MOUNT
6453
typedef struct {
6454
  char     mountName[TSDB_MOUNT_NAME_LEN];
6455
  int8_t   ignoreExist;
6456
  int16_t  nMounts;
6457
  int32_t* dnodeIds;
6458
  char**   mountPaths;
6459
  int32_t  sqlLen;
6460
  char*    sql;
6461
} SCreateMountReq;
6462

6463
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6464
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6465
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6466

6467
typedef struct {
6468
  char    mountName[TSDB_MOUNT_NAME_LEN];
6469
  int8_t  ignoreNotExists;
6470
  int32_t sqlLen;
6471
  char*   sql;
6472
} SDropMountReq;
6473

6474
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6475
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6476
void    tFreeSDropMountReq(SDropMountReq* pReq);
6477

6478
typedef struct {
6479
  char     mountName[TSDB_MOUNT_NAME_LEN];
6480
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6481
  int64_t  mountUid;
6482
  int32_t  dnodeId;
6483
  uint32_t valLen;
6484
  int8_t   ignoreExist;
6485
  void*    pVal;
6486
} SRetrieveMountPathReq;
6487

6488
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6489
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6490

6491
typedef struct {
6492
  // path
6493
  int32_t diskPrimary;
6494
  // vgInfo
6495
  int32_t  vgId;
6496
  int32_t  cacheLastSize;
6497
  int32_t  szPage;
6498
  int32_t  szCache;
6499
  uint64_t szBuf;
6500
  int8_t   cacheLast;
6501
  int8_t   standby;
6502
  int8_t   hashMethod;
6503
  uint32_t hashBegin;
6504
  uint32_t hashEnd;
6505
  int16_t  hashPrefix;
6506
  int16_t  hashSuffix;
6507
  int16_t  sttTrigger;
6508
  // syncInfo
6509
  int32_t replications;
6510
  // tsdbInfo
6511
  int8_t  precision;
6512
  int8_t  compression;
6513
  int8_t  slLevel;
6514
  int32_t daysPerFile;
6515
  int32_t keep0;
6516
  int32_t keep1;
6517
  int32_t keep2;
6518
  int32_t keepTimeOffset;
6519
  int32_t minRows;
6520
  int32_t maxRows;
6521
  int32_t tsdbPageSize;
6522
  int32_t ssChunkSize;
6523
  int32_t ssKeepLocal;
6524
  int8_t  ssCompact;
6525
  union {
6526
    uint8_t flags;
6527
    struct {
6528
      uint8_t isAudit : 1;
6529
      uint8_t allowDrop : 1;
6530
      uint8_t reserved : 6;
6531
    };
6532
  };
6533
  // walInfo
6534
  int32_t walFsyncPeriod;      // millisecond
6535
  int32_t walRetentionPeriod;  // secs
6536
  int32_t walRollPeriod;       // secs
6537
  int64_t walRetentionSize;
6538
  int64_t walSegSize;
6539
  int32_t walLevel;
6540
  // encryptInfo
6541
  int32_t encryptAlgorithm;
6542
  // SVState
6543
  int64_t committed;
6544
  int64_t commitID;
6545
  int64_t commitTerm;
6546
  // stats
6547
  int64_t numOfSTables;
6548
  int64_t numOfCTables;
6549
  int64_t numOfNTables;
6550
  // dbInfo
6551
  uint64_t dbId;
6552
} SMountVgInfo;
6553

6554
typedef struct {
6555
  SMCreateStbReq req;
6556
  SArray*        pColExts;  // element: column id
6557
  SArray*        pTagExts;  // element: tag id
6558
} SMountStbInfo;
6559

6560
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6561
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6562

6563
typedef struct {
6564
  char     dbName[TSDB_DB_FNAME_LEN];
6565
  uint64_t dbId;
6566
  SArray*  pVgs;   // SMountVgInfo
6567
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6568
} SMountDbInfo;
6569

6570
typedef struct {
6571
  // common fields
6572
  char     mountName[TSDB_MOUNT_NAME_LEN];
6573
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6574
  int8_t   ignoreExist;
6575
  int64_t  mountUid;
6576
  int64_t  clusterId;
6577
  int32_t  dnodeId;
6578
  uint32_t valLen;
6579
  void*    pVal;
6580

6581
  // response fields
6582
  SArray* pDbs;  // SMountDbInfo
6583

6584
  // memory fields, no serialized
6585
  SArray*   pDisks[TFS_MAX_TIERS];
6586
  TdFilePtr pFile;
6587
} SMountInfo;
6588

6589
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6590
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6591
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6592

6593
typedef struct {
6594
  SCreateVnodeReq createReq;
6595
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6596
  char            mountName[TSDB_MOUNT_NAME_LEN];
6597
  int64_t         mountId;
6598
  int32_t         diskPrimary;
6599
  int32_t         mountVgId;
6600
  int64_t         committed;
6601
  int64_t         commitID;
6602
  int64_t         commitTerm;
6603
  int64_t         numOfSTables;
6604
  int64_t         numOfCTables;
6605
  int64_t         numOfNTables;
6606
} SMountVnodeReq;
6607

6608
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6609
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6610
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6611

6612
#endif  // USE_MOUNT
6613

6614
#pragma pack(pop)
6615

6616
typedef struct {
6617
  char        db[TSDB_DB_FNAME_LEN];
6618
  STimeWindow timeRange;
6619
  int32_t     sqlLen;
6620
  char*       sql;
6621
  SArray*     vgroupIds;
6622
} SScanDbReq;
6623

6624
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6625
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6626
void    tFreeSScanDbReq(SScanDbReq* pReq);
6627

6628
typedef struct {
6629
  int32_t scanId;
6630
  int8_t  bAccepted;
6631
} SScanDbRsp;
6632

6633
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6634
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6635

6636
typedef struct {
6637
  int32_t scanId;
6638
  int32_t sqlLen;
6639
  char*   sql;
6640
} SKillScanReq;
6641

6642
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6643
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6644
void    tFreeSKillScanReq(SKillScanReq* pReq);
6645

6646
typedef struct {
6647
  int32_t scanId;
6648
  int32_t vgId;
6649
  int32_t dnodeId;
6650
} SVKillScanReq;
6651

6652
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6653
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6654

6655
typedef struct {
6656
  int32_t scanId;
6657
  int32_t vgId;
6658
  int32_t dnodeId;
6659
  int32_t numberFileset;
6660
  int32_t finished;
6661
  int32_t progress;
6662
  int64_t remainingTime;
6663
} SQueryScanProgressRsp;
6664

6665
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6666
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6667

6668
typedef struct {
6669
  int32_t scanId;
6670
  int32_t vgId;
6671
  int32_t dnodeId;
6672
} SQueryScanProgressReq;
6673

6674
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6675
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6676

6677
typedef struct {
6678
  int64_t     dbUid;
6679
  char        db[TSDB_DB_FNAME_LEN];
6680
  int64_t     scanStartTime;
6681
  STimeWindow tw;
6682
  int32_t     scanId;
6683
} SScanVnodeReq;
6684

6685
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6686
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6687

6688
#ifdef __cplusplus
6689
}
6690
#endif
6691

6692
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6693
 
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