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

taosdata / TDengine / #4905

29 Dec 2025 02:08PM UTC coverage: 65.423% (-0.3%) from 65.734%
#4905

push

travis-ci

web-flow
enh: sign connect request (#34067)

23 of 29 new or added lines in 4 files covered. (79.31%)

11614 existing lines in 186 files now uncovered.

193476 of 295730 relevant lines covered (65.42%)

115752566.53 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include "taosdef.h"
20
#include "taoserror.h"
21
#include "tarray.h"
22
#include "tcoding.h"
23
#include "tcol.h"
24
#include "tencode.h"
25
#include "thash.h"
26
#include "tlist.h"
27
#include "tname.h"
28
#include "tpriv.h"
29
#include "trow.h"
30
#include "tuuid.h"
31

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

36
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
37

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

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

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

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

66
typedef uint16_t tmsg_t;
67

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

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

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

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

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

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

110
static inline bool vnodeIsMsgBlock(tmsg_t type) {
924,591,927✔
111
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
876,303,889✔
112
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,800,895,816✔
113
         (type == TDMT_SYNC_CONFIG_CHANGE);
114
}
115

116
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,055,890,109✔
117
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,055,890,109✔
118
}
119

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

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

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

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

215
typedef enum {
216
  TSDB_OPTR_NORMAL = 0,  // default
217
  TSDB_OPTR_SSMIGRATE = 1,
218
  TSDB_OPTR_ROLLUP = 2,
219
} ETsdbOpType;
220

221
typedef enum {
222
  TSDB_TRIGGER_MANUAL = 0,  // default
223
  TSDB_TRIGGER_AUTO = 1,
224
} ETriggerType;
225

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

245
#define TSDB_FILL_NONE        0
246
#define TSDB_FILL_NULL        1
247
#define TSDB_FILL_NULL_F      2
248
#define TSDB_FILL_SET_VALUE   3
249
#define TSDB_FILL_SET_VALUE_F 4
250
#define TSDB_FILL_LINEAR      5
251
#define TSDB_FILL_PREV        6
252
#define TSDB_FILL_NEXT        7
253
#define TSDB_FILL_NEAR        8
254

255

256
#define TSDB_ALTER_USER_BASIC_INFO             1
257
// these definitions start from 5 is to keep compatible with old versions
258
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
259
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
260

261

262
#define TSDB_ALTER_ROLE_LOCK            0x1
263
#define TSDB_ALTER_ROLE_ROLE            0x2
264
#define TSDB_ALTER_ROLE_PRIVILEGES      0x3
265
#define TSDB_ALTER_ROLE_MAX             0x4 // increase according to actual use
266

267
#define TSDB_ALTER_RSMA_FUNCTION        0x1
268

269
#define TSDB_KILL_MSG_LEN 30
270

271
#define TSDB_TABLE_NUM_UNIT 100000
272

273
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
274
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
275
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
276

277
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
278
#define TSDB_COL_TAG    0x1u  // the tag column type
279
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
280
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
281
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
282

283
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
284
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
285
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
286
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
287

288
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
289
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
290
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
291
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
292
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
293

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

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

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

484
  // show statement nodes
485
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
486
  QUERY_NODE_SHOW_DNODES_STMT = 400,
487
  QUERY_NODE_SHOW_MNODES_STMT,
488
  QUERY_NODE_SHOW_MODULES_STMT,
489
  QUERY_NODE_SHOW_QNODES_STMT,
490
  QUERY_NODE_SHOW_SNODES_STMT,
491
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
492
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
493
  QUERY_NODE_SHOW_CLUSTER_STMT,
494
  QUERY_NODE_SHOW_DATABASES_STMT,
495
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
496
  QUERY_NODE_SHOW_INDEXES_STMT,
497
  QUERY_NODE_SHOW_STABLES_STMT,
498
  QUERY_NODE_SHOW_STREAMS_STMT,
499
  QUERY_NODE_SHOW_TABLES_STMT,
500
  QUERY_NODE_SHOW_TAGS_STMT,
501
  QUERY_NODE_SHOW_USERS_STMT,
502
  QUERY_NODE_SHOW_USERS_FULL_STMT,
503
  QUERY_NODE_SHOW_LICENCES_STMT,
504
  QUERY_NODE_SHOW_VGROUPS_STMT,
505
  QUERY_NODE_SHOW_TOPICS_STMT,
506
  QUERY_NODE_SHOW_CONSUMERS_STMT,
507
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
508
  QUERY_NODE_SHOW_QUERIES_STMT,
509
  QUERY_NODE_SHOW_APPS_STMT,
510
  QUERY_NODE_SHOW_VARIABLES_STMT,
511
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
512
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
513
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
514
  QUERY_NODE_SHOW_VNODES_STMT,
515
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
516
  QUERY_NODE_SHOW_VIEWS_STMT,
517
  QUERY_NODE_SHOW_COMPACTS_STMT,
518
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
519
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
520
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
521
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
522
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
523
  QUERY_NODE_SHOW_TSMAS_STMT,
524
  QUERY_NODE_SHOW_ANODES_STMT,
525
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
526
  QUERY_NODE_SHOW_USAGE_STMT,
527
  QUERY_NODE_SHOW_FILESETS_STMT,
528
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
529
  QUERY_NODE_SHOW_VTABLES_STMT,
530
  QUERY_NODE_SHOW_BNODES_STMT,
531
  QUERY_NODE_SHOW_MOUNTS_STMT,
532
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
533
  QUERY_NODE_SHOW_SCANS_STMT,
534
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
535
  QUERY_NODE_SHOW_RSMAS_STMT,
536
  QUERY_NODE_SHOW_RETENTIONS_STMT,
537
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
538
  QUERY_NODE_SHOW_INSTANCES_STMT,
539
  QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT,
540
  QUERY_NODE_SHOW_TOKENS_STMT,
541
  QUERY_NODE_SHOW_ENCRYPT_STATUS_STMT,
542
  QUERY_NODE_SHOW_ROLES_STMT,
543
  QUERY_NODE_SHOW_ROLE_PRIVILEGES_STMT,
544
  QUERY_NODE_SHOW_ROLE_COL_PRIVILEGES_STMT,
545

546
  // logic plan node
547
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
548
  QUERY_NODE_LOGIC_PLAN_JOIN,
549
  QUERY_NODE_LOGIC_PLAN_AGG,
550
  QUERY_NODE_LOGIC_PLAN_PROJECT,
551
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
552
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
553
  QUERY_NODE_LOGIC_PLAN_MERGE,
554
  QUERY_NODE_LOGIC_PLAN_WINDOW,
555
  QUERY_NODE_LOGIC_PLAN_FILL,
556
  QUERY_NODE_LOGIC_PLAN_SORT,
557
  QUERY_NODE_LOGIC_PLAN_PARTITION,
558
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
559
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
560
  QUERY_NODE_LOGIC_SUBPLAN,
561
  QUERY_NODE_LOGIC_PLAN,
562
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
563
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
564
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
565
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
566
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
567

568
  // physical plan node
569
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
570
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
571
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
572
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
573
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
574
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
575
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
576
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
577
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
578
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
579
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
580
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
581
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
582
  QUERY_NODE_PHYSICAL_PLAN_SORT,
583
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
584
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
585
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
586
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
587
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
588
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
589
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
590
  QUERY_NODE_PHYSICAL_PLAN_FILL,
591
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
592
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
593
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
594
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
595
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
596
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
597
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
598
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
599
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
600
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
601
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
602
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
603
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
604
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
605
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
606
  QUERY_NODE_PHYSICAL_SUBPLAN,
607
  QUERY_NODE_PHYSICAL_PLAN,
608
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
609
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
610
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
611
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
612
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
613
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
614
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
615
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
616
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
617
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
618
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
619
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
620
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
621
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
622
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
623
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
624
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
625
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
626
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
627
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
628
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
629
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
630
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
631
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
632
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
633
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
634
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
635
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
636
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
637
} ENodeType;
638

639
typedef struct {
640
  int32_t     vgId;
641
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
642
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
643
  const char* dbFName;
644
  const char* tbName;
645
} SBuildTableInput;
646

647
typedef struct {
648
  char    db[TSDB_DB_FNAME_LEN];
649
  int64_t dbId;
650
  int32_t vgVersion;
651
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
652
  int64_t stateTs;
653
} SBuildUseDBInput;
654

655
typedef struct SField {
656
  char    name[TSDB_COL_NAME_LEN];
657
  uint8_t type;
658
  int8_t  flags;
659
  int32_t bytes;
660
} SField;
661

662
typedef struct SFieldWithOptions {
663
  char     name[TSDB_COL_NAME_LEN];
664
  uint8_t  type;
665
  int8_t   flags;
666
  int32_t  bytes;
667
  uint32_t compress;
668
  STypeMod typeMod;
669
} SFieldWithOptions;
670

671
typedef struct SRetention {
672
  int64_t freq;
673
  int64_t keep;
674
  int8_t  freqUnit;
675
  int8_t  keepUnit;
676
} SRetention;
677

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

680
#pragma pack(push, 1)
681
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
682
typedef struct SEp {
683
  char     fqdn[TSDB_FQDN_LEN];
684
  uint16_t port;
685
} SEp;
686

687
typedef struct {
688
  int32_t contLen;
689
  int32_t vgId;
690
} SMsgHead;
691

692
// Submit message for one table
693
typedef struct SSubmitBlk {
694
  int64_t uid;        // table unique id
695
  int64_t suid;       // stable id
696
  int32_t sversion;   // data schema version
697
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
698
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
699
  int32_t numOfRows;  // total number of rows in current submit block
700
  char    data[];
701
} SSubmitBlk;
702

703
// Submit message for this TSDB
704
typedef struct {
705
  SMsgHead header;
706
  int64_t  version;
707
  int32_t  length;
708
  int32_t  numOfBlocks;
709
  char     blocks[];
710
} SSubmitReq;
711

712
typedef struct {
713
  int32_t totalLen;
714
  int32_t len;
715
  STSRow* row;
716
} SSubmitBlkIter;
717

718
typedef struct {
719
  int32_t totalLen;
720
  int32_t len;
721
  // head of SSubmitBlk
722
  int64_t uid;        // table unique id
723
  int64_t suid;       // stable id
724
  int32_t sversion;   // data schema version
725
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
726
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
727
  int32_t numOfRows;  // total number of rows in current submit block
728
  // head of SSubmitBlk
729
  int32_t     numOfBlocks;
730
  const void* pMsg;
731
} SSubmitMsgIter;
732

733
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
734
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
735
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
736
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
737
// for debug
738
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
739

740
typedef struct {
741
  bool     hasRef;
742
  col_id_t id;
743
  char     refDbName[TSDB_DB_NAME_LEN];
744
  char     refTableName[TSDB_TABLE_NAME_LEN];
745
  char     refColName[TSDB_COL_NAME_LEN];
746
} SColRef;
747

748
typedef struct {
749
  int32_t  nCols;
750
  int32_t  version;
751
  SColRef* pColRef;
752
} SColRefWrapper;
753

754
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
755
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
756
typedef struct {
757
  int32_t vgId;
758
  SColRef colRef;
759
} SColRefEx;
760

761
typedef struct {
762
  int16_t colId;
763
  char    refDbName[TSDB_DB_NAME_LEN];
764
  char    refTableName[TSDB_TABLE_NAME_LEN];
765
  char    refColName[TSDB_COL_NAME_LEN];
766
} SRefColInfo;
767

768
typedef struct SVCTableRefCols {
769
  uint64_t     uid;
770
  int32_t      numOfSrcTbls;
771
  int32_t      numOfColRefs;
772
  SRefColInfo* refCols;
773
} SVCTableRefCols;
774

775
typedef struct SVCTableMergeInfo {
776
  uint64_t uid;
777
  int32_t  numOfSrcTbls;
778
} SVCTableMergeInfo;
779

780
typedef struct {
781
  int32_t    nCols;
782
  SColRefEx* pColRefEx;
783
} SColRefExWrapper;
784

785
struct SSchema {
786
  int8_t   type;
787
  int8_t   flags;
788
  col_id_t colId;
789
  int32_t  bytes;
790
  char     name[TSDB_COL_NAME_LEN];
791
};
792
struct SSchemaExt {
793
  col_id_t colId;
794
  uint32_t compress;
795
  STypeMod typeMod;
796
};
797

798
struct SSchemaRsma {
799
  int64_t    interval[2];
800
  int32_t    nFuncs;
801
  int8_t     tbType;
802
  tb_uid_t   tbUid;
803
  func_id_t* funcIds;
804
  char       tbName[TSDB_TABLE_NAME_LEN];
805
};
806

807
struct SSchema2 {
808
  int8_t   type;
809
  int8_t   flags;
810
  col_id_t colId;
811
  int32_t  bytes;
812
  char     name[TSDB_COL_NAME_LEN];
813
  uint32_t compress;
814
};
815

816
typedef struct {
817
  char        tbName[TSDB_TABLE_NAME_LEN];
818
  char        stbName[TSDB_TABLE_NAME_LEN];
819
  char        dbFName[TSDB_DB_FNAME_LEN];
820
  int64_t     dbId;
821
  int32_t     numOfTags;
822
  int32_t     numOfColumns;
823
  int8_t      precision;
824
  int8_t      tableType;
825
  int32_t     sversion;
826
  int32_t     tversion;
827
  int32_t     rversion;
828
  uint64_t    suid;
829
  uint64_t    tuid;
830
  int32_t     vgId;
831
  int8_t      sysInfo;
832
  int64_t     ownerId;
833
  SSchema*    pSchemas;
834
  SSchemaExt* pSchemaExt;
835
  int8_t      virtualStb;
836
  int32_t     numOfColRefs;
837
  SColRef*    pColRefs;
838
} STableMetaRsp;
839

840
typedef struct {
841
  int32_t        code;
842
  int64_t        uid;
843
  char*          tblFName;
844
  int32_t        numOfRows;
845
  int32_t        affectedRows;
846
  int64_t        sver;
847
  STableMetaRsp* pMeta;
848
} SSubmitBlkRsp;
849

850
typedef struct {
851
  int32_t numOfRows;
852
  int32_t affectedRows;
853
  int32_t nBlocks;
854
  union {
855
    SArray*        pArray;
856
    SSubmitBlkRsp* pBlocks;
857
  };
858
} SSubmitRsp;
859

860
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
861
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
862
// void    tFreeSSubmitBlkRsp(void* param);
863
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
864

865
#define COL_SMA_ON       ((int8_t)0x1)
866
#define COL_IDX_ON       ((int8_t)0x2)
867
#define COL_IS_KEY       ((int8_t)0x4)
868
#define COL_SET_NULL     ((int8_t)0x10)
869
#define COL_SET_VAL      ((int8_t)0x20)
870
#define COL_IS_SYSINFO   ((int8_t)0x40)
871
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
872
#define COL_REF_BY_STM   ((int8_t)0x08)
873

874
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
875
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
876

877
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
878
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
879
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
880

881
#define SSCHMEA_SET_IDX_ON(s) \
882
  do {                        \
883
    (s)->flags |= COL_IDX_ON; \
884
  } while (0)
885

886
#define SSCHMEA_SET_IDX_OFF(s)   \
887
  do {                           \
888
    (s)->flags &= (~COL_IDX_ON); \
889
  } while (0)
890

891
#define SSCHEMA_SET_TYPE_MOD(s)     \
892
  do {                              \
893
    (s)->flags |= COL_HAS_TYPE_MOD; \
894
  } while (0)
895

896
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
897

898
#define SSCHMEA_TYPE(s)  ((s)->type)
899
#define SSCHMEA_FLAGS(s) ((s)->flags)
900
#define SSCHMEA_COLID(s) ((s)->colId)
901
#define SSCHMEA_BYTES(s) ((s)->bytes)
902
#define SSCHMEA_NAME(s)  ((s)->name)
903

904
typedef struct {
905
  bool    tsEnableMonitor;
906
  int32_t tsMonitorInterval;
907
  int32_t tsSlowLogThreshold;
908
  int32_t tsSlowLogMaxLen;
909
  int32_t tsSlowLogScope;
910
  int32_t tsSlowLogThresholdTest;  // Obsolete
911
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
912
} SMonitorParas;
913

914
typedef struct {
915
  STypeMod typeMod;
916
} SExtSchema;
917

918
bool hasExtSchema(const SExtSchema* pExtSchema);
919

920
typedef struct {
921
  int32_t      nCols;
922
  int32_t      version;
923
  SSchema*     pSchema;
924
  SSchemaRsma* pRsma;
925
} SSchemaWrapper;
926

927
typedef struct {
928
  col_id_t id;
929
  uint32_t alg;
930
} SColCmpr;
931

932
typedef struct {
933
  int32_t   nCols;
934
  int32_t   version;
935
  SColCmpr* pColCmpr;
936
} SColCmprWrapper;
937

938
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
939
  if (pRef->pColRef) {
266,823✔
UNCOV
940
    return TSDB_CODE_INVALID_PARA;
×
941
  }
942
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
266,823✔
943
  if (pRef->pColRef == NULL) {
266,823✔
UNCOV
944
    return terrno;
×
945
  }
946
  pRef->nCols = nCols;
266,823✔
947
  for (int32_t i = 0; i < nCols; i++) {
72,379,307✔
948
    pRef->pColRef[i].hasRef = false;
72,112,484✔
949
    pRef->pColRef[i].id = (col_id_t)(i + 1);
72,112,484✔
950
  }
951
  return 0;
266,823✔
952
}
953

954
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
955
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
956
    terrno = TSDB_CODE_INVALID_PARA;
957
    return NULL;
958
  }
959

960
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
961
  if (pDstWrapper == NULL) {
962
    return NULL;
963
  }
964
  pDstWrapper->nCols = pSrcWrapper->nCols;
965
  pDstWrapper->version = pSrcWrapper->version;
966

967
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
968
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
969
  if (pDstWrapper->pColCmpr == NULL) {
970
    taosMemoryFree(pDstWrapper);
971
    return NULL;
972
  }
973
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
974

975
  return pDstWrapper;
976
}
977

978
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
979
  if (!(!pCmpr->pColCmpr)) {
12,025,697✔
UNCOV
980
    return TSDB_CODE_INVALID_PARA;
×
981
  }
982
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
12,025,697✔
983
  if (pCmpr->pColCmpr == NULL) {
12,025,697✔
UNCOV
984
    return terrno;
×
985
  }
986
  pCmpr->nCols = nCols;
12,025,697✔
987
  return 0;
12,025,697✔
988
}
989

990
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
991
  pCmpr->nCols = pSchema->nCols;
992
  if (!(!pCmpr->pColCmpr)) {
993
    return TSDB_CODE_INVALID_PARA;
994
  }
995
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
996
  if (pCmpr->pColCmpr == NULL) {
997
    return terrno;
998
  }
999
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1000
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1001
    SSchema*  pColSchema = &pSchema->pSchema[i];
1002
    pColCmpr->id = pColSchema->colId;
1003
    pColCmpr->alg = 0;
1004
  }
1005
  return 0;
1006
}
1007

1008
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1009
  if (pWrapper == NULL) return;
1010

1011
  taosMemoryFreeClear(pWrapper->pColCmpr);
1012
  taosMemoryFreeClear(pWrapper);
1013
}
1014
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1015
  if (pSchemaWrapper->pSchema == NULL) return NULL;
689,226,978✔
1016

1017
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
689,339,487✔
1018
  if (pSW == NULL) {
688,996,147✔
UNCOV
1019
    return NULL;
×
1020
  }
1021
  pSW->nCols = pSchemaWrapper->nCols;
688,996,147✔
1022
  pSW->version = pSchemaWrapper->version;
689,020,740✔
1023
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
689,129,017✔
1024
  if (pSW->pSchema == NULL) {
688,442,977✔
UNCOV
1025
    taosMemoryFree(pSW);
×
UNCOV
1026
    return NULL;
×
1027
  }
1028

1029
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
688,550,119✔
1030
  return pSW;
689,244,091✔
1031
}
1032

1033
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
274,181,758✔
1034
  if (pSchemaWrapper) {
1,940,388,845✔
1035
    taosMemoryFree(pSchemaWrapper->pSchema);
1,097,010,150✔
1036
    if (pSchemaWrapper->pRsma) {
1,096,613,482✔
1037
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
25,308✔
1038
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
25,308✔
1039
    }
1040
    taosMemoryFree(pSchemaWrapper);
1,096,702,291✔
1041
  }
1042
}
1,900,965,245✔
1043

1044
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1045
  if (pSchemaWrapper) {
1046
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1047
    if (pSchemaWrapper->pRsma) {
1048
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1049
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1050
    }
1051
  }
1052
}
1053

1054
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
3,478,217✔
1055
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
3,478,217✔
1056
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
3,478,217✔
1057
  }
1058
}
3,478,217✔
1059

1060
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1061
  int32_t tlen = 0;
2,431,082✔
1062
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,432,378✔
1063
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,431,082✔
1064
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,431,082✔
1065
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,431,082✔
1066
  tlen += taosEncodeString(buf, pSchema->name);
2,431,082✔
1067
  return tlen;
2,431,082✔
1068
}
1069

1070
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1071
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,125,000✔
1072
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,124,676✔
1073
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,124,676✔
1074
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,124,676✔
1075
  buf = taosDecodeStringTo(buf, pSchema->name);
1,124,676✔
1076
  return (void*)buf;
1,124,676✔
1077
}
1078

1079
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1080
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1081
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1082
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1083
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1084
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1085
  return 0;
2,147,483,647✔
1086
}
1087

1088
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1089
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1090
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1091
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1092
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1093
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1094
  return 0;
2,147,483,647✔
1095
}
1096

1097
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1098
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1099
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1100
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1101
  return 0;
2,147,483,647✔
1102
}
1103

1104
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1105
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1106
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1107
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1108
  return 0;
2,147,483,647✔
1109
}
1110

1111
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1112
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
362,438,928✔
1113
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
362,438,928✔
1114
  if (pColRef->hasRef) {
181,219,464✔
1115
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
216,270,724✔
1116
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
216,270,724✔
1117
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
216,270,724✔
1118
  }
1119
  return 0;
181,219,464✔
1120
}
1121

1122
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1123
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
182,075,826✔
1124
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
182,075,826✔
1125
  if (pColRef->hasRef) {
91,037,913✔
1126
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
54,366,786✔
1127
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
54,366,786✔
1128
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
54,366,786✔
1129
  }
1130

1131
  return 0;
91,037,913✔
1132
}
1133

1134
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1135
  int32_t tlen = 0;
399,228✔
1136
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
399,228✔
1137
  tlen += taosEncodeVariantI32(buf, pSW->version);
399,228✔
1138
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,830,310✔
1139
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
4,862,164✔
1140
  }
1141
  return tlen;
399,228✔
1142
}
1143

1144
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1145
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
177,973✔
1146
  buf = taosDecodeVariantI32(buf, &pSW->version);
177,973✔
1147
  if (pSW->nCols > 0) {
177,973✔
1148
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
177,973✔
1149
    if (pSW->pSchema == NULL) {
177,973✔
UNCOV
1150
      return NULL;
×
1151
    }
1152

1153
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,302,649✔
1154
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,249,352✔
1155
    }
1156
  } else {
UNCOV
1157
    pSW->pSchema = NULL;
×
1158
  }
1159
  return (void*)buf;
177,973✔
1160
}
1161

1162
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1163
  if (pSW == NULL) {
451,271,154✔
UNCOV
1164
    return TSDB_CODE_INVALID_PARA;
×
1165
  }
1166
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
902,633,559✔
1167
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
902,593,511✔
1168
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1169
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1170
  }
1171
  return 0;
451,437,788✔
1172
}
1173

1174
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1175
  if (pSW == NULL) {
178,130,415✔
UNCOV
1176
    return TSDB_CODE_INVALID_PARA;
×
1177
  }
1178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
356,189,556✔
1179
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
356,183,858✔
1180

1181
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
178,124,717✔
1182
  if (pSW->pSchema == NULL) {
178,067,138✔
UNCOV
1183
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1184
  }
1185
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,559,197,483✔
1186
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1187
  }
1188

1189
  return 0;
178,182,882✔
1190
}
1191

1192
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1194
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1195

1196
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1197
  if (pSW->pSchema == NULL) {
1,744,989,978✔
UNCOV
1198
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1199
  }
1200
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1201
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1202
  }
1203

1204
  return 0;
1,745,978,130✔
1205
}
1206

1207
typedef struct {
1208
  char     name[TSDB_TABLE_FNAME_LEN];
1209
  int8_t   igExists;
1210
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1211
  int8_t   reserved[6];
1212
  tb_uid_t suid;
1213
  int64_t  delay1;
1214
  int64_t  delay2;
1215
  int64_t  watermark1;
1216
  int64_t  watermark2;
1217
  int32_t  ttl;
1218
  int32_t  colVer;
1219
  int32_t  tagVer;
1220
  int32_t  numOfColumns;
1221
  int32_t  numOfTags;
1222
  int32_t  numOfFuncs;
1223
  int32_t  commentLen;
1224
  int32_t  ast1Len;
1225
  int32_t  ast2Len;
1226
  SArray*  pColumns;  // array of SFieldWithOptions
1227
  SArray*  pTags;     // array of SField
1228
  SArray*  pFuncs;
1229
  char*    pComment;
1230
  char*    pAst1;
1231
  char*    pAst2;
1232
  int64_t  deleteMark1;
1233
  int64_t  deleteMark2;
1234
  int32_t  sqlLen;
1235
  char*    sql;
1236
  int64_t  keep;
1237
  int8_t   virtualStb;
1238
} SMCreateStbReq;
1239

1240
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1241
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1242
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1243

1244
typedef struct {
1245
  STableMetaRsp* pMeta;
1246
} SMCreateStbRsp;
1247

1248
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1249
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1250
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1251

1252
typedef struct {
1253
  char     name[TSDB_TABLE_FNAME_LEN];
1254
  int8_t   igNotExists;
1255
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1256
  int8_t   reserved[6];
1257
  tb_uid_t suid;
1258
  int32_t  sqlLen;
1259
  char*    sql;
1260
} SMDropStbReq;
1261

1262
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1263
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1264
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1265

1266
typedef struct {
1267
  char    name[TSDB_TABLE_FNAME_LEN];
1268
  int8_t  alterType;
1269
  int32_t numOfFields;
1270
  SArray* pFields;
1271
  int32_t ttl;
1272
  int32_t commentLen;
1273
  char*   comment;
1274
  int32_t sqlLen;
1275
  char*   sql;
1276
  int64_t keep;
1277
  SArray* pTypeMods;
1278
} SMAlterStbReq;
1279

1280
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1281
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1282
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1283

1284
typedef struct SEpSet {
1285
  int8_t inUse;
1286
  int8_t numOfEps;
1287
  SEp    eps[TSDB_MAX_REPLICA];
1288
} SEpSet;
1289

1290
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1291
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1292
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1293
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1294

1295
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1296
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1297

1298
typedef struct {
1299
  int8_t  connType;
1300
  int32_t pid;
1301
  int32_t totpCode;
1302
  char    app[TSDB_APP_NAME_LEN];
1303
  char    db[TSDB_DB_NAME_LEN];
1304
  char    user[TSDB_USER_LEN];
1305
  char    passwd[TSDB_PASSWORD_LEN];
1306
  char    token[TSDB_TOKEN_LEN];
1307
  int64_t startTime;
1308
  int64_t connectTime;
1309
  char    sVer[TSDB_VERSION_LEN];
1310
  char    signature[20]; // SHA1 produces a 20-byte signature
1311
} SConnectReq;
1312

1313
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1314
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1315
void    tSignConnectReq(SConnectReq* pReq);
1316
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1317

1318
typedef struct {
1319
  int64_t       clusterId;
1320
  int32_t       acctId;
1321
  uint32_t      connId;
1322
  int32_t       dnodeNum;
1323
  int8_t        superUser;
1324
  int8_t        sysInfo;
1325
  int8_t        connType;
1326
  int8_t        enableAuditDelete;
1327
  SEpSet        epSet;
1328
  int32_t       svrTimestamp;
1329
  int32_t       passVer;
1330
  int32_t       authVer;
1331
  char          sVer[TSDB_VERSION_LEN];
1332
  char          sDetailVer[128];
1333
  int64_t       whiteListVer;
1334
  int64_t       timeWhiteListVer;
1335
  int64_t       userId;
1336
  SMonitorParas monitorParas;
1337
  char          user[TSDB_USER_LEN];
1338
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1339
  int8_t        enableAuditSelect;
1340
  int8_t        enableAuditInsert;
1341
  int8_t        auditLevel;
1342
} SConnectRsp;
1343

1344
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1345
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1346

1347
typedef struct {
1348
  char    user[TSDB_USER_LEN];
1349
  char    pass[TSDB_PASSWORD_LEN];
1350
  int32_t maxUsers;
1351
  int32_t maxDbs;
1352
  int32_t maxTimeSeries;
1353
  int32_t maxStreams;
1354
  int32_t accessState;  // Configured only by command
1355
  int64_t maxStorage;
1356
} SCreateAcctReq, SAlterAcctReq;
1357

1358
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1359
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1360

1361
typedef struct {
1362
  char    user[TSDB_USER_LEN];
1363
  int32_t sqlLen;
1364
  char*   sql;
1365
} SDropUserReq, SDropAcctReq;
1366

1367
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1368
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1369
void    tFreeSDropUserReq(SDropUserReq* pReq);
1370

1371
typedef struct {
1372
  char name[TSDB_ROLE_LEN];
1373
  union {
1374
    uint8_t flag;
1375
    struct {
1376
      uint8_t ignoreExists : 1;
1377
      uint8_t reserve : 7;
1378
    };
1379
  };
1380
  int32_t sqlLen;
1381
  char*   sql;
1382
} SCreateRoleReq;
1383

1384
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1385
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1386
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1387

1388
typedef struct {
1389
  char name[TSDB_ROLE_LEN];
1390
  union {
1391
    uint8_t flag;
1392
    struct {
1393
      uint8_t ignoreNotExists : 1;
1394
      uint8_t reserve : 7;
1395
    };
1396
  };
1397
  int32_t sqlLen;
1398
  char*   sql;
1399
} SDropRoleReq;
1400

1401
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1402
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1403
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1404

1405
typedef struct {
1406
  SPrivSet privSet;
1407
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1408
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1409
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1410
  // delete can only specify conditions by cond and cannot specify columns
1411
  char*    cond;     // for table privileges
1412
  int32_t  condLen;  // for table privileges
1413
} SPrivSetReqArgs;
1414

1415
typedef struct {
1416
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1417
  uint8_t objType;    // db, table, view, rsma, etc.
1418
  union {
1419
    uint32_t flag;
1420
    struct {
1421
      uint32_t lock : 1;     // lock or unlock role
1422
      uint32_t add : 1;      // add or remove
1423
      uint32_t sysPriv : 1;  // system or object privileges
1424
      uint32_t objLevel : 2;
1425
      uint32_t reserve : 27;
1426
    };
1427
  };
1428
  union {
1429
    SPrivSetReqArgs privileges;
1430
    char            roleName[TSDB_ROLE_LEN];
1431
  };
1432
  char    principal[TSDB_ROLE_LEN];      // role or user name
1433
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db or topic
1434
  char    tblName[TSDB_TABLE_NAME_LEN];
1435
  int32_t sqlLen;
1436
  char*   sql;
1437
} SAlterRoleReq;
1438

1439
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1440
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1441
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1442

1443
typedef struct {
1444
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1445
  int32_t sqlLen;
1446
  char*   sql;
1447
} SDropEncryptAlgrReq;
1448

1449
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1450
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1451
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1452

1453
typedef struct SIpV4Range {
1454
  uint32_t ip;
1455
  uint32_t mask;
1456
} SIpV4Range;
1457

1458
typedef struct SIpv6Range {
1459
  uint64_t addr[2];
1460
  uint32_t mask;
1461
} SIpV6Range;
1462

1463
typedef struct {
1464
  int8_t type;   // 0: IPv4, 1: IPv6
1465
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1466
  union {
1467
    SIpV4Range ipV4;
1468
    SIpV6Range ipV6;
1469
  };
1470
} SIpRange;
1471

1472
typedef struct {
1473
  int32_t    num;
1474
  SIpV4Range pIpRange[];
1475
} SIpWhiteList;
1476

1477
typedef struct {
1478
  int32_t  num;
1479
  SIpRange pIpRanges[];
1480
} SIpWhiteListDual;
1481

1482
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1483
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1484
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1485
int32_t           createDefaultIp6Range(SIpRange* pRange);
1486
int32_t           createDefaultIp4Range(SIpRange* pRange);
1487

1488
typedef struct {
1489
  int32_t sessPerUser;
1490
  int32_t sessConnTime;
1491
  int32_t sessConnIdleTime;
1492
  int32_t sessMaxConcurrency;
1493
  int32_t sessMaxCallVnodeNum;
1494
} SUserSessCfg;
1495

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

1500
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1501
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1502
typedef struct {
1503
  int16_t year;
1504
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1505
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1506
  int8_t hour;
1507
  int8_t minute;
1508
  int8_t neg;   // this is a negative entry
1509
  int32_t duration; // duration in minute
1510
} SDateTimeRange;
1511

1512
bool isValidDateTimeRange(SDateTimeRange* pRange);
1513
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1514
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1515

1516

1517
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1518
typedef struct {
1519
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1520
  bool neg;         // this is a negative entry
1521
  int32_t duration; // duration in seconds
1522
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1523
} SDateTimeWhiteListItem;
1524

1525
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1526
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1527

1528
typedef struct {
1529
  int32_t num;
1530
  SDateTimeWhiteListItem ranges[];
1531
} SDateTimeWhiteList;
1532

1533
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1534
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1535

1536

1537
typedef struct {
1538
  int8_t createType;
1539
  int8_t superUser;  // denote if it is a super user or not
1540
  int8_t ignoreExists;
1541

1542
  char   user[TSDB_USER_LEN];
1543
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1544
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1545

1546
  int8_t sysInfo;
1547
  int8_t createDb;
1548
  int8_t isImport;
1549
  int8_t changepass;
1550
  int8_t enable;
1551

1552
  int8_t negIpRanges;
1553
  int8_t negTimeRanges;
1554

1555
  int32_t sessionPerUser;
1556
  int32_t connectTime;
1557
  int32_t connectIdleTime;
1558
  int32_t callPerSession;
1559
  int32_t vnodePerCall;
1560
  int32_t failedLoginAttempts;
1561
  int32_t passwordLifeTime;
1562
  int32_t passwordReuseTime;
1563
  int32_t passwordReuseMax;
1564
  int32_t passwordLockTime;
1565
  int32_t passwordGraceTime;
1566
  int32_t inactiveAccountTime;
1567
  int32_t allowTokenNum;
1568

1569
  int32_t         numIpRanges;
1570
  SIpRange*       pIpDualRanges;
1571
  int32_t         numTimeRanges;
1572
  SDateTimeRange* pTimeRanges;
1573

1574
  int32_t sqlLen;
1575
  char*   sql;
1576
} SCreateUserReq;
1577

1578
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1579
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1580
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1581

1582
typedef struct {
1583
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1584
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1585
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1586
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1587
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1588
  int32_t sqlLen;
1589
  char*   sql;
1590
} SCreateEncryptAlgrReq;
1591

1592
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1593
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1594
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1595

1596
typedef struct {
1597
  int32_t dnodeId;
1598
  int64_t analVer;
1599
} SRetrieveAnalyticsAlgoReq;
1600

1601
typedef struct {
1602
  int64_t   ver;
1603
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1604
} SRetrieveAnalyticAlgoRsp;
1605

1606
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1607
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1608
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1609
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1610
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1611

1612
typedef struct {
1613
  int8_t alterType;
1614

1615
  int8_t isView;
1616
  
1617
  int8_t hasPassword;
1618
  int8_t hasTotpseed;
1619
  int8_t hasEnable;
1620
  int8_t hasSysinfo;
1621
  int8_t hasCreatedb;
1622
  int8_t hasChangepass;
1623
  int8_t hasSessionPerUser;
1624
  int8_t hasConnectTime;
1625
  int8_t hasConnectIdleTime;
1626
  int8_t hasCallPerSession;
1627
  int8_t hasVnodePerCall;
1628
  int8_t hasFailedLoginAttempts;
1629
  int8_t hasPasswordLifeTime;
1630
  int8_t hasPasswordReuseTime;
1631
  int8_t hasPasswordReuseMax;
1632
  int8_t hasPasswordLockTime;
1633
  int8_t hasPasswordGraceTime;
1634
  int8_t hasInactiveAccountTime;
1635
  int8_t hasAllowTokenNum;
1636

1637
  int8_t enable;
1638
  int8_t sysinfo;
1639
  int8_t createdb;
1640
  int8_t changepass;
1641

1642
  char   user[TSDB_USER_LEN];
1643
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1644
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1645
  int32_t sessionPerUser;
1646
  int32_t connectTime;
1647
  int32_t connectIdleTime;
1648
  int32_t callPerSession;
1649
  int32_t vnodePerCall;
1650
  int32_t failedLoginAttempts;
1651
  int32_t passwordLifeTime;
1652
  int32_t passwordReuseTime;
1653
  int32_t passwordReuseMax;
1654
  int32_t passwordLockTime;
1655
  int32_t passwordGraceTime;
1656
  int32_t inactiveAccountTime;
1657
  int32_t allowTokenNum;
1658

1659
  int32_t         numIpRanges;
1660
  int32_t         numTimeRanges;
1661
  int32_t         numDropIpRanges;
1662
  int32_t         numDropTimeRanges;
1663
  SIpRange*       pIpRanges;
1664
  SDateTimeRange* pTimeRanges;
1665
  SIpRange*       pDropIpRanges;
1666
  SDateTimeRange* pDropTimeRanges;
1667
  SPrivSet        privileges;
1668

1669
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1670
  char        tabName[TSDB_TABLE_NAME_LEN];
1671
  char*       tagCond;
1672
  int32_t     tagCondLen;
1673
  int32_t     sqlLen;
1674
  char*       sql;
1675
} SAlterUserReq;
1676

1677
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1678
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1679
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1680

1681
typedef struct {
1682
  char    name[TSDB_TOKEN_NAME_LEN];
1683
  char    user[TSDB_USER_LEN];
1684
  int8_t  enable;
1685
  int8_t  ignoreExists;
1686
  int32_t ttl;
1687
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1688
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1689

1690
  int32_t sqlLen;
1691
  char*   sql;
1692
} SCreateTokenReq;
1693

1694
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1695
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1696
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1697

1698
typedef struct {
1699
  char name[TSDB_TOKEN_NAME_LEN];
1700
  char user[TSDB_USER_LEN];
1701
  char token[TSDB_TOKEN_LEN];
1702
} SCreateTokenRsp;
1703

1704
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1705
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1706
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1707

1708
typedef struct {
1709
  char    name[TSDB_TOKEN_NAME_LEN];
1710

1711
  int8_t hasEnable;
1712
  int8_t hasTtl;
1713
  int8_t hasProvider;
1714
  int8_t hasExtraInfo;
1715

1716
  int8_t  enable;
1717
  int32_t ttl;
1718
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1719
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1720

1721
  int32_t     sqlLen;
1722
  char*       sql;
1723
} SAlterTokenReq;
1724

1725
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1726
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1727
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1728

1729
typedef struct {
1730
  char    name[TSDB_TOKEN_NAME_LEN];
1731
  int32_t sqlLen;
1732
  char*   sql;
1733
} SDropTokenReq;
1734

1735
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1736
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1737
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1738

1739
typedef struct {
1740
  char user[TSDB_USER_LEN];
1741
} SGetUserAuthReq;
1742

1743
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1744
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1745

1746
typedef struct {
1747
  char      user[TSDB_USER_LEN];
1748
  int64_t   userId;
1749
  int32_t   version;
1750
  int32_t   passVer;
1751
  int8_t    superAuth;
1752
  int8_t    sysInfo;
1753
  int8_t    enable;
1754
  int8_t    dropped;
1755
  SPrivSet  sysPrivs;
1756
  SHashObj* objPrivs;
1757
  // SHashObj* createdDbs;
1758
  SHashObj* selectTbs;
1759
  SHashObj* insertTbs;
1760
  SHashObj* deleteTbs;
1761
  // SHashObj* readViews;
1762
  // SHashObj* writeViews;
1763
  // SHashObj* alterViews;
1764
  // SHashObj* useDbs;
1765
  int64_t   whiteListVer;
1766

1767
  SUserSessCfg sessCfg;
1768
  int64_t      timeWhiteListVer;
1769
} SGetUserAuthRsp;
1770

1771
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1772
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1773
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1774

1775
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1776
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1777
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1778
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1779

1780
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1781
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1782
typedef struct {
1783
  int64_t ver;
1784
  char    user[TSDB_USER_LEN];
1785
  int32_t numOfRange;
1786
  union {
1787
    SIpV4Range* pIpRanges;
1788
    SIpRange*   pIpDualRanges;
1789
  };
1790
} SUpdateUserIpWhite;
1791

1792
typedef struct {
1793
  int64_t             ver;
1794
  int                 numOfUser;
1795
  SUpdateUserIpWhite* pUserIpWhite;
1796
} SUpdateIpWhite;
1797

1798
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1799
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1800
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1801
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1802

1803
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1804
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1805
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1806

1807

1808
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1809
// corresponding response struct is different.
1810
typedef struct {
1811
  int64_t ver;
1812
} SRetrieveWhiteListReq;
1813

1814
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1815
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1816

1817

1818
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1819
// corresponding response struct is different.
1820
typedef struct {
1821
  char user[TSDB_USER_LEN];
1822
} SGetUserWhiteListReq;
1823

1824
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1825
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1826

1827
typedef struct {
1828
  char    user[TSDB_USER_LEN];
1829
  int32_t numWhiteLists;
1830
  union {
1831
    SIpV4Range* pWhiteLists;
1832
    SIpRange*   pWhiteListsDual;
1833
  };
1834
} SGetUserIpWhiteListRsp;
1835

1836
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1837
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1838
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1839
void    tIpRangeSetDefaultMask(SIpRange* range);
1840

1841
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1842
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1843
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1844

1845
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1846
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1847
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1848

1849
typedef struct {
1850
  int64_t ver;
1851
  char    user[TSDB_USER_LEN];
1852
  int32_t numWhiteLists;
1853
  SDateTimeWhiteListItem* pWhiteLists;
1854
} SUserDateTimeWhiteList;
1855

1856

1857
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1858
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1859
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1860
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1861

1862
typedef struct {
1863
  int64_t             ver;
1864
  int                 numOfUser;
1865
  SUserDateTimeWhiteList *pUsers;
1866
} SRetrieveDateTimeWhiteListRsp;
1867

1868
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1869
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1870
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1871
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1872

1873
/*
1874
 * for client side struct, only column id, type, bytes are necessary
1875
 * But for data in vnode side, we need all the following information.
1876
 */
1877
typedef struct {
1878
  union {
1879
    col_id_t colId;
1880
    int16_t  slotId;
1881
  };
1882

1883
  uint8_t precision;
1884
  uint8_t scale;
1885
  int32_t bytes;
1886
  int8_t  type;
1887
  uint8_t pk;
1888
  bool    noData;
1889
} SColumnInfo;
1890

1891
typedef struct STimeWindow {
1892
  TSKEY skey;
1893
  TSKEY ekey;
1894
} STimeWindow;
1895

1896
typedef struct SQueryHint {
1897
  bool batchScan;
1898
} SQueryHint;
1899

1900
typedef struct {
1901
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1902
  int32_t tsLen;          // total length of ts comp block
1903
  int32_t tsNumOfBlocks;  // ts comp block numbers
1904
  int32_t tsOrder;        // ts comp block order
1905
} STsBufInfo;
1906

1907
typedef struct {
1908
  void*       timezone;
1909
  char        intervalUnit;
1910
  char        slidingUnit;
1911
  char        offsetUnit;
1912
  int8_t      precision;
1913
  int64_t     interval;
1914
  int64_t     sliding;
1915
  int64_t     offset;
1916
  STimeWindow timeRange;
1917
} SInterval;
1918

1919
typedef struct STbVerInfo {
1920
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1921
  int32_t sversion;
1922
  int32_t tversion;
1923
  int32_t rversion;  // virtual table's column ref's version
1924
} STbVerInfo;
1925

1926
typedef struct {
1927
  int32_t code;
1928
  int64_t affectedRows;
1929
  SArray* tbVerInfo;  // STbVerInfo
1930
} SQueryTableRsp;
1931

1932
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1933

1934
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1935

1936
typedef struct {
1937
  SMsgHead header;
1938
  char     dbFName[TSDB_DB_FNAME_LEN];
1939
  char     tbName[TSDB_TABLE_NAME_LEN];
1940
} STableCfgReq;
1941

1942
typedef struct {
1943
  char        tbName[TSDB_TABLE_NAME_LEN];
1944
  char        stbName[TSDB_TABLE_NAME_LEN];
1945
  char        dbFName[TSDB_DB_FNAME_LEN];
1946
  int32_t     numOfTags;
1947
  int32_t     numOfColumns;
1948
  int8_t      tableType;
1949
  int64_t     delay1;
1950
  int64_t     delay2;
1951
  int64_t     watermark1;
1952
  int64_t     watermark2;
1953
  int32_t     ttl;
1954
  int32_t     keep;
1955
  int64_t     ownerId;
1956
  SArray*     pFuncs;
1957
  int32_t     commentLen;
1958
  char*       pComment;
1959
  SSchema*    pSchemas;
1960
  int32_t     tagsLen;
1961
  char*       pTags;
1962
  SSchemaExt* pSchemaExt;
1963
  int8_t      virtualStb;
1964
  SColRef*    pColRefs;
1965
} STableCfg;
1966

1967
typedef STableCfg STableCfgRsp;
1968

1969
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1970
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1971

1972
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1973
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1974
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1975

1976
typedef struct {
1977
  SMsgHead header;
1978
  tb_uid_t suid;
1979
} SVSubTablesReq;
1980

1981
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1982
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1983

1984
typedef struct {
1985
  int32_t vgId;
1986
  SArray* pTables;  // SArray<SVCTableRefCols*>
1987
} SVSubTablesRsp;
1988

1989
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1990
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1991
void    tDestroySVSubTablesRsp(void* rsp);
1992

1993
typedef struct {
1994
  SMsgHead header;
1995
  tb_uid_t suid;
1996
} SVStbRefDbsReq;
1997

1998
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1999
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2000

2001
typedef struct {
2002
  int32_t vgId;
2003
  SArray* pDbs;  // SArray<char* (db name)>
2004
} SVStbRefDbsRsp;
2005

2006
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2007
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2008
void    tDestroySVStbRefDbsRsp(void* rsp);
2009

2010
typedef struct {
2011
  char    db[TSDB_DB_FNAME_LEN];
2012
  int32_t numOfVgroups;
2013
  int32_t numOfStables;  // single_stable
2014
  int32_t buffer;        // MB
2015
  int32_t pageSize;
2016
  int32_t pages;
2017
  int32_t cacheLastSize;
2018
  int32_t daysPerFile;
2019
  int32_t daysToKeep0;
2020
  int32_t daysToKeep1;
2021
  int32_t daysToKeep2;
2022
  int32_t keepTimeOffset;
2023
  int32_t minRows;
2024
  int32_t maxRows;
2025
  int32_t walFsyncPeriod;
2026
  int8_t  walLevel;
2027
  int8_t  precision;  // time resolution
2028
  int8_t  compression;
2029
  int8_t  replications;
2030
  int8_t  strict;
2031
  int8_t  cacheLast;
2032
  int8_t  schemaless;
2033
  int8_t  ignoreExist;
2034
  int32_t numOfRetensions;
2035
  SArray* pRetensions;  // SRetention
2036
  int32_t walRetentionPeriod;
2037
  int64_t walRetentionSize;
2038
  int32_t walRollPeriod;
2039
  int64_t walSegmentSize;
2040
  int32_t sstTrigger;
2041
  int16_t hashPrefix;
2042
  int16_t hashSuffix;
2043
  int32_t ssChunkSize;
2044
  int32_t ssKeepLocal;
2045
  int8_t  ssCompact;
2046
  int32_t tsdbPageSize;
2047
  int32_t sqlLen;
2048
  char*   sql;
2049
  int8_t  withArbitrator;
2050
  int8_t  encryptAlgorithm;
2051
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2052
  // 1. add auto-compact parameters
2053
  int32_t compactInterval;    // minutes
2054
  int32_t compactStartTime;   // minutes
2055
  int32_t compactEndTime;     // minutes
2056
  int8_t  compactTimeOffset;  // hour
2057
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2058
  int8_t  isAudit;
2059
} SCreateDbReq;
2060

2061
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2062
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2063
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2064

2065
typedef struct {
2066
  char    db[TSDB_DB_FNAME_LEN];
2067
  int32_t buffer;
2068
  int32_t pageSize;
2069
  int32_t pages;
2070
  int32_t cacheLastSize;
2071
  int32_t daysPerFile;
2072
  int32_t daysToKeep0;
2073
  int32_t daysToKeep1;
2074
  int32_t daysToKeep2;
2075
  int32_t keepTimeOffset;
2076
  int32_t walFsyncPeriod;
2077
  int8_t  walLevel;
2078
  int8_t  strict;
2079
  int8_t  cacheLast;
2080
  int8_t  replications;
2081
  int32_t sstTrigger;
2082
  int32_t minRows;
2083
  int32_t walRetentionPeriod;
2084
  int32_t walRetentionSize;
2085
  int32_t ssKeepLocal;
2086
  int8_t  ssCompact;
2087
  int32_t sqlLen;
2088
  char*   sql;
2089
  int8_t  withArbitrator;
2090
  // 1. add auto-compact parameters
2091
  int32_t compactInterval;
2092
  int32_t compactStartTime;
2093
  int32_t compactEndTime;
2094
  int8_t  compactTimeOffset;
2095
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2096
  int8_t  isAudit;
2097
} SAlterDbReq;
2098

2099
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2100
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2101
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2102

2103
typedef struct {
2104
  char    db[TSDB_DB_FNAME_LEN];
2105
  int8_t  ignoreNotExists;
2106
  int8_t  force;
2107
  int32_t sqlLen;
2108
  char*   sql;
2109
} SDropDbReq;
2110

2111
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2112
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2113
void    tFreeSDropDbReq(SDropDbReq* pReq);
2114

2115
typedef struct {
2116
  char    db[TSDB_DB_FNAME_LEN];
2117
  int64_t uid;
2118
} SDropDbRsp;
2119

2120
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2121
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2122

2123
typedef struct {
2124
  char    name[TSDB_MOUNT_NAME_LEN];
2125
  int64_t uid;
2126
} SDropMountRsp;
2127

2128
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2129
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2130

2131
typedef struct {
2132
  char    db[TSDB_DB_FNAME_LEN];
2133
  int64_t dbId;
2134
  int32_t vgVersion;
2135
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2136
  int64_t stateTs;     // ms
2137
} SUseDbReq;
2138

2139
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2140
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2141

2142
typedef struct {
2143
  char    db[TSDB_DB_FNAME_LEN];
2144
  int64_t uid;
2145
  int32_t vgVersion;
2146
  int32_t vgNum;
2147
  int16_t hashPrefix;
2148
  int16_t hashSuffix;
2149
  int8_t  hashMethod;
2150
  union {
2151
    uint8_t flags;
2152
    struct {
2153
      uint8_t isMount : 1;  // TS-5868
2154
      uint8_t padding : 7;
2155
    };
2156
  };
2157
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2158
  int32_t errCode;
2159
  int64_t stateTs;  // ms
2160
} SUseDbRsp;
2161

2162
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2163
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2164
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2165
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2166
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2167

2168
typedef struct {
2169
  char db[TSDB_DB_FNAME_LEN];
2170
} SDbCfgReq;
2171

2172
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2173
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2174

2175
typedef struct {
2176
  char db[TSDB_DB_FNAME_LEN];
2177
} SSsMigrateDbReq;
2178

2179
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2180
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2181

2182
typedef struct {
2183
  int32_t ssMigrateId;
2184
  bool    bAccepted;
2185
} SSsMigrateDbRsp;
2186

2187
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2188
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2189

2190
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2191
typedef struct {
2192
  int32_t ssMigrateId;
2193
} SListSsMigrateFileSetsReq;
2194

2195
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2196
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2197

2198
typedef struct {
2199
  int32_t ssMigrateId;
2200
  int32_t vgId;       // vgroup id
2201
  SArray* pFileSets;  // SArray<int32_t>
2202
} SListSsMigrateFileSetsRsp;
2203

2204
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2205
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2206
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2207

2208
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2209
typedef struct {
2210
  int32_t ssMigrateId;
2211
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2212
  int32_t fid;
2213
  int64_t startTimeSec;
2214
} SSsMigrateFileSetReq;
2215

2216
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2217
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2218

2219
typedef struct {
2220
  int32_t ssMigrateId;
2221
  int32_t nodeId;  // node id of the leader vnode
2222
  int32_t vgId;
2223
  int32_t fid;
2224
} SSsMigrateFileSetRsp;
2225

2226
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2227
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2228

2229
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2230
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2231
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2232
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2233
#define SSMIGRATE_FILESET_STATE_FAILED      4
2234

2235
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2236
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2237
// while as a request, the 'state' field is not used.
2238
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2239
typedef struct {
2240
  int32_t ssMigrateId;  // ss migrate id
2241
  int32_t nodeId;       // node id of the leader vnode
2242
  int32_t vgId;         // vgroup id
2243
  int32_t fid;          // file set id
2244
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2245
} SSsMigrateProgress;
2246

2247
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2248
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2249

2250
// Request for TDMT_MND_KILL_SSMIGRATE
2251
typedef struct {
2252
  int32_t ssMigrateId;
2253
  int32_t sqlLen;
2254
  char*   sql;
2255
} SKillSsMigrateReq;
2256

2257
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2258
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2259
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2260

2261
// Request for TDMT_VND_KILL_SSMIGRATE
2262
typedef struct {
2263
  int32_t ssMigrateId;
2264
} SVnodeKillSsMigrateReq;
2265

2266
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2267
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2268

2269
typedef struct {
2270
  int32_t vgId;
2271
  int64_t keepVersion;
2272
} SMndSetVgroupKeepVersionReq;
2273

2274
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2275
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2276

2277
typedef struct {
2278
  int32_t timestampSec;
2279
  int32_t ttlDropMaxCount;
2280
  int32_t nUids;
2281
  SArray* pTbUids;
2282
} SVDropTtlTableReq;
2283

2284
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2285
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2286

2287
typedef struct {
2288
  char    db[TSDB_DB_FNAME_LEN];
2289
  int64_t dbId;
2290
  int64_t ownerId;
2291
  int32_t cfgVersion;
2292
  int32_t numOfVgroups;
2293
  int32_t numOfStables;
2294
  int32_t buffer;
2295
  int32_t cacheSize;
2296
  int32_t pageSize;
2297
  int32_t pages;
2298
  int32_t daysPerFile;
2299
  int32_t daysToKeep0;
2300
  int32_t daysToKeep1;
2301
  int32_t daysToKeep2;
2302
  int32_t keepTimeOffset;
2303
  int32_t minRows;
2304
  int32_t maxRows;
2305
  int32_t walFsyncPeriod;
2306
  int16_t hashPrefix;
2307
  int16_t hashSuffix;
2308
  int8_t  hashMethod;
2309
  int8_t  walLevel;
2310
  int8_t  precision;
2311
  int8_t  compression;
2312
  int8_t  replications;
2313
  int8_t  strict;
2314
  int8_t  cacheLast;
2315
  int8_t  encryptAlgr;
2316
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2317
  int32_t ssChunkSize;
2318
  int32_t ssKeepLocal;
2319
  int8_t  ssCompact;
2320
  union {
2321
    uint8_t flags;
2322
    struct {
2323
      uint8_t isMount : 1;  // TS-5868
2324
      uint8_t padding : 7;
2325
    };
2326
  };
2327
  int8_t  compactTimeOffset;
2328
  int32_t compactInterval;
2329
  int32_t compactStartTime;
2330
  int32_t compactEndTime;
2331
  int32_t tsdbPageSize;
2332
  int32_t walRetentionPeriod;
2333
  int32_t walRollPeriod;
2334
  int64_t walRetentionSize;
2335
  int64_t walSegmentSize;
2336
  int32_t numOfRetensions;
2337
  SArray* pRetensions;
2338
  int8_t  schemaless;
2339
  int16_t sstTrigger;
2340
  int8_t  withArbitrator;
2341
  int8_t  isAudit;
2342
} SDbCfgRsp;
2343

2344
typedef SDbCfgRsp SDbCfgInfo;
2345

2346
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2347
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2348
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2349
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2350
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2351

2352
typedef struct {
2353
  int32_t rowNum;
2354
} SQnodeListReq;
2355

2356
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2357
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2358

2359
typedef struct {
2360
  int32_t rowNum;
2361
} SDnodeListReq;
2362

2363
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2364

2365
typedef struct {
2366
  int32_t useless;  // useless
2367
} SServerVerReq;
2368

2369
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2370
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2371

2372
typedef struct {
2373
  char ver[TSDB_VERSION_LEN];
2374
} SServerVerRsp;
2375

2376
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2377
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2378

2379
typedef struct SQueryNodeAddr {
2380
  int32_t nodeId;  // vgId or qnodeId
2381
  SEpSet  epSet;
2382
} SQueryNodeAddr;
2383

2384
typedef struct {
2385
  SQueryNodeAddr addr;
2386
  uint64_t       load;
2387
} SQueryNodeLoad;
2388

2389
typedef struct {
2390
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2391
} SQnodeListRsp;
2392

2393
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2394
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2395
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2396

2397

2398
typedef struct SDownstreamSourceNode {
2399
  ENodeType      type;
2400
  SQueryNodeAddr addr;
2401
  uint64_t       clientId;
2402
  uint64_t       taskId;
2403
  uint64_t       sId;
2404
  int32_t        execId;
2405
  int32_t        fetchMsgType;
2406
  bool           localExec;
2407
} SDownstreamSourceNode;
2408

2409

2410

2411
typedef struct SDNodeAddr {
2412
  int32_t nodeId;  // dnodeId
2413
  SEpSet  epSet;
2414
} SDNodeAddr;
2415

2416
typedef struct {
2417
  SArray* dnodeList;  // SArray<SDNodeAddr>
2418
} SDnodeListRsp;
2419

2420
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2421
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2422
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2423

2424
typedef struct {
2425
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2426
} STableTSMAInfoRsp;
2427

2428
typedef struct {
2429
  SUseDbRsp*         useDbRsp;
2430
  SDbCfgRsp*         cfgRsp;
2431
  STableTSMAInfoRsp* pTsmaRsp;
2432
  int32_t            dbTsmaVersion;
2433
  char               db[TSDB_DB_FNAME_LEN];
2434
  int64_t            dbId;
2435
} SDbHbRsp;
2436

2437
typedef struct {
2438
  SArray* pArray;  // Array of SDbHbRsp
2439
} SDbHbBatchRsp;
2440

2441
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2442
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2443
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2444

2445
typedef struct {
2446
  SArray* pArray;  // Array of SGetUserAuthRsp
2447
} SUserAuthBatchRsp;
2448

2449
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2450
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2451
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2452

2453
typedef struct {
2454
  char        db[TSDB_DB_FNAME_LEN];
2455
  STimeWindow timeRange;
2456
  int32_t     sqlLen;
2457
  char*       sql;
2458
  SArray*     vgroupIds;
2459
  int32_t     compactId;
2460
  int8_t      metaOnly;
2461
  int8_t      force;
2462
} SCompactDbReq;
2463

2464
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2465
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2466
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2467

2468
typedef struct {
2469
  union {
2470
    int32_t compactId;
2471
    int32_t id;
2472
  };
2473
  int8_t bAccepted;
2474
} SCompactDbRsp;
2475

2476
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2477
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2478

2479
typedef struct {
2480
  union {
2481
    int32_t compactId;
2482
    int32_t id;
2483
  };
2484
  int32_t sqlLen;
2485
  char*   sql;
2486
} SKillCompactReq;
2487

2488
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2489
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2490
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2491

2492
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2493
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2494

2495
typedef struct {
2496
  char    name[TSDB_FUNC_NAME_LEN];
2497
  int8_t  igExists;
2498
  int8_t  funcType;
2499
  int8_t  scriptType;
2500
  int8_t  outputType;
2501
  int32_t outputLen;
2502
  int32_t bufSize;
2503
  int32_t codeLen;
2504
  int64_t signature;
2505
  char*   pComment;
2506
  char*   pCode;
2507
  int8_t  orReplace;
2508
} SCreateFuncReq;
2509

2510
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2511
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2512
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2513

2514
typedef struct {
2515
  char   name[TSDB_FUNC_NAME_LEN];
2516
  int8_t igNotExists;
2517
} SDropFuncReq;
2518

2519
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2520
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2521

2522
typedef struct {
2523
  int32_t numOfFuncs;
2524
  bool    ignoreCodeComment;
2525
  SArray* pFuncNames;
2526
} SRetrieveFuncReq;
2527

2528
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2529
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2530
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2531

2532
typedef struct {
2533
  char    name[TSDB_FUNC_NAME_LEN];
2534
  int8_t  funcType;
2535
  int8_t  scriptType;
2536
  int8_t  outputType;
2537
  int32_t outputLen;
2538
  int32_t bufSize;
2539
  int64_t signature;
2540
  int32_t commentSize;
2541
  int32_t codeSize;
2542
  char*   pComment;
2543
  char*   pCode;
2544
} SFuncInfo;
2545

2546
typedef struct {
2547
  int32_t funcVersion;
2548
  int64_t funcCreatedTime;
2549
} SFuncExtraInfo;
2550

2551
typedef struct {
2552
  int32_t numOfFuncs;
2553
  SArray* pFuncInfos;
2554
  SArray* pFuncExtraInfos;
2555
} SRetrieveFuncRsp;
2556

2557
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2558
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2559
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2560
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2561

2562
typedef struct {
2563
  int32_t       statusInterval;
2564
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2565
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2566
  char          locale[TD_LOCALE_LEN];      // tsLocale
2567
  char          charset[TD_LOCALE_LEN];     // tsCharset
2568
  int8_t        ttlChangeOnWrite;
2569
  int8_t        enableWhiteList;
2570
  int8_t        encryptionKeyStat;
2571
  uint32_t      encryptionKeyChksum;
2572
  SMonitorParas monitorParas;
2573
  int32_t       statusIntervalMs;
2574
} SClusterCfg;
2575

2576
typedef struct {
2577
  int32_t openVnodes;
2578
  int32_t dropVnodes;
2579
  int32_t totalVnodes;
2580
  int32_t masterNum;
2581
  int64_t numOfSelectReqs;
2582
  int64_t numOfInsertReqs;
2583
  int64_t numOfInsertSuccessReqs;
2584
  int64_t numOfBatchInsertReqs;
2585
  int64_t numOfBatchInsertSuccessReqs;
2586
  int64_t errors;
2587
} SVnodesStat;
2588

2589
typedef struct {
2590
  int32_t vgId;
2591
  int8_t  syncState;
2592
  int8_t  syncRestore;
2593
  int64_t syncTerm;
2594
  int64_t roleTimeMs;
2595
  int64_t startTimeMs;
2596
  int8_t  syncCanRead;
2597
  int64_t cacheUsage;
2598
  int64_t numOfTables;
2599
  int64_t numOfTimeSeries;
2600
  int64_t totalStorage;
2601
  int64_t compStorage;
2602
  int64_t pointsWritten;
2603
  int64_t numOfSelectReqs;
2604
  int64_t numOfInsertReqs;
2605
  int64_t numOfInsertSuccessReqs;
2606
  int64_t numOfBatchInsertReqs;
2607
  int64_t numOfBatchInsertSuccessReqs;
2608
  int32_t numOfCachedTables;
2609
  int32_t learnerProgress;  // use one reservered
2610
  int64_t syncAppliedIndex;
2611
  int64_t syncCommitIndex;
2612
  int64_t bufferSegmentUsed;
2613
  int64_t bufferSegmentSize;
2614
} SVnodeLoad;
2615

2616
typedef struct {
2617
  int64_t total_requests;
2618
  int64_t total_rows;
2619
  int64_t total_bytes;
2620
  double  write_size;
2621
  double  cache_hit_ratio;
2622
  int64_t rpc_queue_wait;
2623
  int64_t preprocess_time;
2624

2625
  int64_t memory_table_size;
2626
  int64_t commit_count;
2627
  int64_t merge_count;
2628
  double  commit_time;
2629
  double  merge_time;
2630
  int64_t block_commit_time;
2631
  int64_t memtable_wait_time;
2632
} SVnodeMetrics;
2633

2634
typedef struct {
2635
  int32_t     vgId;
2636
  int64_t     numOfTables;
2637
  int64_t     memSize;
2638
  int64_t     l1Size;
2639
  int64_t     l2Size;
2640
  int64_t     l3Size;
2641
  int64_t     cacheSize;
2642
  int64_t     walSize;
2643
  int64_t     metaSize;
2644
  int64_t     rawDataSize;
2645
  int64_t     ssSize;
2646
  const char* dbname;
2647
  int8_t      estimateRawData;
2648
} SDbSizeStatisInfo;
2649

2650
typedef struct {
2651
  int32_t vgId;
2652
  int64_t nTimeSeries;
2653
} SVnodeLoadLite;
2654

2655
typedef struct {
2656
  int8_t  syncState;
2657
  int64_t syncTerm;
2658
  int8_t  syncRestore;
2659
  int64_t roleTimeMs;
2660
} SMnodeLoad;
2661

2662
typedef struct {
2663
  int32_t dnodeId;
2664
  int64_t numOfProcessedQuery;
2665
  int64_t numOfProcessedCQuery;
2666
  int64_t numOfProcessedFetch;
2667
  int64_t numOfProcessedDrop;
2668
  int64_t numOfProcessedNotify;
2669
  int64_t numOfProcessedHb;
2670
  int64_t numOfProcessedDelete;
2671
  int64_t cacheDataSize;
2672
  int64_t numOfQueryInQueue;
2673
  int64_t numOfFetchInQueue;
2674
  int64_t timeInQueryQueue;
2675
  int64_t timeInFetchQueue;
2676
} SQnodeLoad;
2677

2678
typedef struct {
2679
  int32_t     sver;      // software version
2680
  int64_t     dnodeVer;  // dnode table version in sdb
2681
  int32_t     dnodeId;
2682
  int64_t     clusterId;
2683
  int64_t     rebootTime;
2684
  int64_t     updateTime;
2685
  float       numOfCores;
2686
  int32_t     numOfSupportVnodes;
2687
  int32_t     numOfDiskCfg;
2688
  int64_t     memTotal;
2689
  int64_t     memAvail;
2690
  char        dnodeEp[TSDB_EP_LEN];
2691
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2692
  SMnodeLoad  mload;
2693
  SQnodeLoad  qload;
2694
  SClusterCfg clusterCfg;
2695
  SArray*     pVloads;  // array of SVnodeLoad
2696
  int32_t     statusSeq;
2697
  int64_t     ipWhiteVer;
2698
  int64_t     timeWhiteVer;
2699
  int64_t     analVer;
2700
  int64_t     timestamp;
2701
  char        auditDB[TSDB_DB_FNAME_LEN];
2702
  char        auditToken[TSDB_TOKEN_LEN];
2703
} SStatusReq;
2704

2705
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2706
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2707
void    tFreeSStatusReq(SStatusReq* pReq);
2708

2709
typedef struct {
2710
  int32_t forceReadConfig;
2711
  int32_t cver;
2712
  SArray* array;
2713
} SConfigReq;
2714

2715
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2716
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2717
void    tFreeSConfigReq(SConfigReq* pReq);
2718

2719
typedef struct {
2720
  int32_t dnodeId;
2721
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2722
} SDnodeInfoReq;
2723

2724
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2725
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2726

2727
typedef enum {
2728
  MONITOR_TYPE_COUNTER = 0,
2729
  MONITOR_TYPE_SLOW_LOG = 1,
2730
} MONITOR_TYPE;
2731

2732
typedef struct {
2733
  int32_t      contLen;
2734
  char*        pCont;
2735
  MONITOR_TYPE type;
2736
} SStatisReq;
2737

2738
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2739
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2740
void    tFreeSStatisReq(SStatisReq* pReq);
2741

2742
typedef struct {
2743
  char    db[TSDB_DB_FNAME_LEN];
2744
  char    table[TSDB_TABLE_NAME_LEN];
2745
  char    operation[AUDIT_OPERATION_LEN];
2746
  int32_t sqlLen;
2747
  char*   pSql;
2748
  double  duration;
2749
  int64_t affectedRows;
2750
} SAuditReq;
2751
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2752
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2753
void    tFreeSAuditReq(SAuditReq* pReq);
2754

2755
typedef struct {
2756
  SArray* auditArr;
2757
} SBatchAuditReq;
2758
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2759
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2760
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2761

2762
typedef struct {
2763
  int32_t dnodeId;
2764
  int64_t clusterId;
2765
  SArray* pVloads;
2766
} SNotifyReq;
2767

2768
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2769
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2770
void    tFreeSNotifyReq(SNotifyReq* pReq);
2771

2772
typedef struct {
2773
  int32_t dnodeId;
2774
  int64_t clusterId;
2775
} SDnodeCfg;
2776

2777
typedef struct {
2778
  int32_t id;
2779
  int8_t  isMnode;
2780
  SEp     ep;
2781
} SDnodeEp;
2782

2783
typedef struct {
2784
  int32_t id;
2785
  int8_t  isMnode;
2786
  int8_t  offlineReason;
2787
  SEp     ep;
2788
  char    active[TSDB_ACTIVE_KEY_LEN];
2789
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2790
} SDnodeInfo;
2791

2792
typedef struct {
2793
  int64_t   dnodeVer;
2794
  SDnodeCfg dnodeCfg;
2795
  SArray*   pDnodeEps;  // Array of SDnodeEp
2796
  int32_t   statusSeq;
2797
  int64_t   ipWhiteVer;
2798
  int64_t   analVer;
2799
  int64_t   timeWhiteVer;
2800
  char      auditDB[TSDB_DB_FNAME_LEN];
2801
  char      auditToken[TSDB_TOKEN_LEN];
2802
} SStatusRsp;
2803

2804
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2805
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2806
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2807

2808
typedef struct {
2809
  int32_t forceReadConfig;
2810
  int32_t isConifgVerified;
2811
  int32_t isVersionVerified;
2812
  int32_t cver;
2813
  SArray* array;
2814
} SConfigRsp;
2815

2816
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2817
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2818
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2819

2820
typedef struct {
2821
  int32_t dnodeId;
2822
  int32_t keyVersion;  // Local key version
2823
} SKeySyncReq;
2824

2825
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2826
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2827

2828
typedef struct {
2829
  int32_t keyVersion;        // mnode's key version
2830
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2831
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2832
  char    svrKey[129];       // Server key (if needUpdate)
2833
  char    dbKey[129];        // Database key (if needUpdate)
2834
  char    cfgKey[129];       // Config key (if needUpdate)
2835
  char    metaKey[129];      // Metadata key (if needUpdate)
2836
  char    dataKey[129];      // Data key (if needUpdate)
2837
  int32_t algorithm;         // Encryption algorithm for master keys
2838
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2839
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2840
  int64_t createTime;        // Key creation time
2841
  int64_t svrKeyUpdateTime;  // Server key update time
2842
  int64_t dbKeyUpdateTime;   // Database key update time
2843
} SKeySyncRsp;
2844

2845
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2846
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2847

2848
typedef struct {
2849
  int32_t reserved;
2850
} SMTimerReq;
2851

2852
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2853
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2854

2855
typedef struct SOrphanTask {
2856
  int64_t streamId;
2857
  int32_t taskId;
2858
  int32_t nodeId;
2859
} SOrphanTask;
2860

2861
typedef struct SMStreamDropOrphanMsg {
2862
  SArray* pList;  // SArray<SOrphanTask>
2863
} SMStreamDropOrphanMsg;
2864

2865
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2866
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2867
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2868

2869
typedef struct {
2870
  int32_t  id;
2871
  uint16_t port;                 // node sync Port
2872
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2873
} SReplica;
2874

2875
typedef struct {
2876
  int32_t  vgId;
2877
  char     db[TSDB_DB_FNAME_LEN];
2878
  int64_t  dbUid;
2879
  int32_t  vgVersion;
2880
  int32_t  numOfStables;
2881
  int32_t  buffer;
2882
  int32_t  pageSize;
2883
  int32_t  pages;
2884
  int32_t  cacheLastSize;
2885
  int32_t  daysPerFile;
2886
  int32_t  daysToKeep0;
2887
  int32_t  daysToKeep1;
2888
  int32_t  daysToKeep2;
2889
  int32_t  keepTimeOffset;
2890
  int32_t  minRows;
2891
  int32_t  maxRows;
2892
  int32_t  walFsyncPeriod;
2893
  uint32_t hashBegin;
2894
  uint32_t hashEnd;
2895
  int8_t   hashMethod;
2896
  int8_t   walLevel;
2897
  int8_t   precision;
2898
  int8_t   compression;
2899
  int8_t   strict;
2900
  int8_t   cacheLast;
2901
  int8_t   isTsma;
2902
  int8_t   replica;
2903
  int8_t   selfIndex;
2904
  SReplica replicas[TSDB_MAX_REPLICA];
2905
  int32_t  numOfRetensions;
2906
  SArray*  pRetensions;  // SRetention
2907
  void*    pTsma;
2908
  int32_t  walRetentionPeriod;
2909
  int64_t  walRetentionSize;
2910
  int32_t  walRollPeriod;
2911
  int64_t  walSegmentSize;
2912
  int16_t  sstTrigger;
2913
  int16_t  hashPrefix;
2914
  int16_t  hashSuffix;
2915
  int32_t  tsdbPageSize;
2916
  int32_t  ssChunkSize;
2917
  int32_t  ssKeepLocal;
2918
  int8_t   ssCompact;
2919
  int64_t  reserved[6];
2920
  int8_t   learnerReplica;
2921
  int8_t   learnerSelfIndex;
2922
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2923
  int32_t  changeVersion;
2924
  int8_t   encryptAlgorithm;
2925
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2926
} SCreateVnodeReq;
2927

2928
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2929
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2930
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2931

2932
typedef struct {
2933
  union {
2934
    int32_t compactId;
2935
    int32_t id;
2936
  };
2937
  int32_t vgId;
2938
  int32_t dnodeId;
2939
} SQueryCompactProgressReq;
2940

2941
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2942
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2943

2944
typedef struct {
2945
  union {
2946
    int32_t compactId;
2947
    int32_t id;
2948
  };
2949
  int32_t vgId;
2950
  int32_t dnodeId;
2951
  int32_t numberFileset;
2952
  int32_t finished;
2953
  int32_t progress;
2954
  int64_t remainingTime;
2955
} SQueryCompactProgressRsp;
2956

2957
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2958
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2959

2960
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2961
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2962

2963
typedef struct {
2964
  int32_t vgId;
2965
  int32_t dnodeId;
2966
  int64_t dbUid;
2967
  char    db[TSDB_DB_FNAME_LEN];
2968
  int64_t reserved[8];
2969
} SDropVnodeReq;
2970

2971
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2972
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2973

2974
typedef struct {
2975
  char    colName[TSDB_COL_NAME_LEN];
2976
  char    stb[TSDB_TABLE_FNAME_LEN];
2977
  int64_t stbUid;
2978
  int64_t dbUid;
2979
  int64_t reserved[8];
2980
} SDropIndexReq;
2981

2982
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2983
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2984

2985
typedef struct {
2986
  int64_t dbUid;
2987
  char    db[TSDB_DB_FNAME_LEN];
2988
  union {
2989
    int64_t compactStartTime;
2990
    int64_t startTime;
2991
  };
2992

2993
  STimeWindow tw;
2994
  union {
2995
    int32_t compactId;
2996
    int32_t id;
2997
  };
2998
  int8_t metaOnly;
2999
  union {
3000
    uint16_t flags;
3001
    struct {
3002
      uint16_t optrType : 3;     // ETsdbOpType
3003
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3004
      uint16_t reserved : 12;
3005
    };
3006
  };
3007
  int8_t force;  // force compact
3008
} SCompactVnodeReq;
3009

3010
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3011
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3012

3013
typedef struct {
3014
  union {
3015
    int32_t compactId;
3016
    int32_t taskId;
3017
  };
3018
  int32_t vgId;
3019
  int32_t dnodeId;
3020
} SVKillCompactReq;
3021

3022
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3023
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3024

3025
typedef SVKillCompactReq SVKillRetentionReq;
3026

3027
typedef struct {
3028
  char        db[TSDB_DB_FNAME_LEN];
3029
  int32_t     maxSpeed;
3030
  int32_t     sqlLen;
3031
  char*       sql;
3032
  SArray*     vgroupIds;
3033
  STimeWindow tw;  // unit is second
3034
  union {
3035
    uint32_t flags;
3036
    struct {
3037
      uint32_t optrType : 3;     // ETsdbOpType
3038
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3039
      uint32_t reserved : 28;
3040
    };
3041
  };
3042
} STrimDbReq;
3043

3044
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3045
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3046
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3047

3048
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3049

3050
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3051
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3052

3053
typedef struct {
3054
  int32_t vgVersion;
3055
  int32_t buffer;
3056
  int32_t pageSize;
3057
  int32_t pages;
3058
  int32_t cacheLastSize;
3059
  int32_t daysPerFile;
3060
  int32_t daysToKeep0;
3061
  int32_t daysToKeep1;
3062
  int32_t daysToKeep2;
3063
  int32_t keepTimeOffset;
3064
  int32_t walFsyncPeriod;
3065
  int8_t  walLevel;
3066
  int8_t  strict;
3067
  int8_t  cacheLast;
3068
  int64_t reserved[7];
3069
  // 1st modification
3070
  int16_t sttTrigger;
3071
  int32_t minRows;
3072
  // 2nd modification
3073
  int32_t walRetentionPeriod;
3074
  int32_t walRetentionSize;
3075
  int32_t ssKeepLocal;
3076
  int8_t  ssCompact;
3077
} SAlterVnodeConfigReq;
3078

3079
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3080
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3081

3082
typedef struct {
3083
  int32_t  vgId;
3084
  int8_t   strict;
3085
  int8_t   selfIndex;
3086
  int8_t   replica;
3087
  SReplica replicas[TSDB_MAX_REPLICA];
3088
  int64_t  reserved[8];
3089
  int8_t   learnerSelfIndex;
3090
  int8_t   learnerReplica;
3091
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3092
  int32_t  changeVersion;
3093
  int32_t  electBaseLine;
3094
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3095

3096
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3097
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3098

3099
typedef struct {
3100
  int32_t vgId;
3101
  int8_t  disable;
3102
} SDisableVnodeWriteReq;
3103

3104
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3105
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3106

3107
typedef struct {
3108
  int32_t  srcVgId;
3109
  int32_t  dstVgId;
3110
  uint32_t hashBegin;
3111
  uint32_t hashEnd;
3112
  int32_t  changeVersion;
3113
  int32_t  reserved;
3114
} SAlterVnodeHashRangeReq;
3115

3116
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3117
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3118

3119
#define REQ_OPT_TBNAME 0x0
3120
#define REQ_OPT_TBUID  0x01
3121
typedef struct {
3122
  SMsgHead header;
3123
  char     dbFName[TSDB_DB_FNAME_LEN];
3124
  char     tbName[TSDB_TABLE_NAME_LEN];
3125
  uint8_t  option;
3126
  uint8_t  autoCreateCtb;
3127
} STableInfoReq;
3128

3129
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3130
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3131

3132
typedef struct {
3133
  int8_t  metaClone;  // create local clone of the cached table meta
3134
  int32_t numOfVgroups;
3135
  int32_t numOfTables;
3136
  int32_t numOfUdfs;
3137
  char    tableNames[];
3138
} SMultiTableInfoReq;
3139

3140
// todo refactor
3141
typedef struct SVgroupInfo {
3142
  int32_t  vgId;
3143
  uint32_t hashBegin;
3144
  uint32_t hashEnd;
3145
  SEpSet   epSet;
3146
  union {
3147
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3148
    int32_t taskId;      // used in stream
3149
  };
3150
} SVgroupInfo;
3151

3152
typedef struct {
3153
  int32_t     numOfVgroups;
3154
  SVgroupInfo vgroups[];
3155
} SVgroupsInfo;
3156

3157
typedef struct {
3158
  STableMetaRsp* pMeta;
3159
} SMAlterStbRsp;
3160

3161
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3162
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3163
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3164

3165
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3166
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3167
void    tFreeSTableMetaRsp(void* pRsp);
3168
void    tFreeSTableIndexRsp(void* info);
3169

3170
typedef struct {
3171
  SArray* pMetaRsp;   // Array of STableMetaRsp
3172
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3173
} SSTbHbRsp;
3174

3175
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3176
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3177
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3178

3179
typedef struct {
3180
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3181
} SViewHbRsp;
3182

3183
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3184
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3185
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3186

3187
typedef struct {
3188
  int32_t numOfTables;
3189
  int32_t numOfVgroup;
3190
  int32_t numOfUdf;
3191
  int32_t contLen;
3192
  int8_t  compressed;  // denote if compressed or not
3193
  int32_t rawLen;      // size before compress
3194
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3195
  char    meta[];
3196
} SMultiTableMeta;
3197

3198
typedef struct {
3199
  int32_t dataLen;
3200
  char    name[TSDB_TABLE_FNAME_LEN];
3201
  char*   data;
3202
} STagData;
3203

3204
typedef struct {
3205
  int32_t  opType;
3206
  uint32_t valLen;
3207
  char*    val;
3208
} SShowVariablesReq;
3209

3210
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3211
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3212
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3213

3214
typedef struct {
3215
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3216
  char value[TSDB_CONFIG_PATH_LEN + 1];
3217
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3218
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3219
  char info[TSDB_CONFIG_INFO_LEN + 1];
3220
} SVariablesInfo;
3221

3222
typedef struct {
3223
  SArray* variables;  // SArray<SVariablesInfo>
3224
} SShowVariablesRsp;
3225

3226
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3227
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3228

3229
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3230

3231
/*
3232
 * sql: show tables like '%a_%'
3233
 * payload is the query condition, e.g., '%a_%'
3234
 * payloadLen is the length of payload
3235
 */
3236
typedef struct {
3237
  int32_t type;
3238
  char    db[TSDB_DB_FNAME_LEN];
3239
  int32_t payloadLen;
3240
  char*   payload;
3241
} SShowReq;
3242

3243
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3244
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3245
void tFreeSShowReq(SShowReq* pReq);
3246

3247
typedef struct {
3248
  int64_t       showId;
3249
  STableMetaRsp tableMeta;
3250
} SShowRsp, SVShowTablesRsp;
3251

3252
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3253
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3254
// void    tFreeSShowRsp(SShowRsp* pRsp);
3255

3256
typedef struct {
3257
  char    db[TSDB_DB_FNAME_LEN];
3258
  char    tb[TSDB_TABLE_NAME_LEN];
3259
  char    user[TSDB_USER_LEN];
3260
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3261
  int64_t showId;
3262
  int64_t compactId;  // for compact
3263
  bool    withFull;   // for show users full
3264
} SRetrieveTableReq;
3265

3266
typedef struct SSysTableSchema {
3267
  int8_t   type;
3268
  col_id_t colId;
3269
  int32_t  bytes;
3270
} SSysTableSchema;
3271

3272
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3273
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3274

3275
#define RETRIEVE_TABLE_RSP_VERSION         0
3276
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3277
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3278

3279
typedef struct {
3280
  int64_t useconds;
3281
  int8_t  completed;  // all results are returned to client
3282
  int8_t  precision;
3283
  int8_t  compressed;
3284
  int8_t  streamBlockType;
3285
  int32_t payloadLen;
3286
  int32_t compLen;
3287
  int32_t numOfBlocks;
3288
  int64_t numOfRows;  // from int32_t change to int64_t
3289
  int64_t numOfCols;
3290
  int64_t skey;
3291
  int64_t ekey;
3292
  int64_t version;                         // for stream
3293
  TSKEY   watermark;                       // for stream
3294
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3295
  char    data[];
3296
} SRetrieveTableRsp;
3297

3298
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3299

3300
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3301
  do {                                          \
3302
    ((int32_t*)(_p))[0] = (_compLen);           \
3303
    ((int32_t*)(_p))[1] = (_fullLen);           \
3304
  } while (0);
3305

3306
typedef struct {
3307
  int64_t version;
3308
  int64_t numOfRows;
3309
  int8_t  compressed;
3310
  int8_t  precision;
3311
  char    data[];
3312
} SRetrieveTableRspForTmq;
3313

3314
typedef struct {
3315
  int64_t handle;
3316
  int64_t useconds;
3317
  int8_t  completed;  // all results are returned to client
3318
  int8_t  precision;
3319
  int8_t  compressed;
3320
  int32_t compLen;
3321
  int32_t numOfRows;
3322
  int32_t fullLen;
3323
  char    data[];
3324
} SRetrieveMetaTableRsp;
3325

3326
typedef struct SExplainExecInfo {
3327
  double   startupCost;
3328
  double   totalCost;
3329
  uint64_t numOfRows;
3330
  uint32_t verboseLen;
3331
  void*    verboseInfo;
3332
} SExplainExecInfo;
3333

3334
typedef struct {
3335
  int32_t           numOfPlans;
3336
  SExplainExecInfo* subplanInfo;
3337
} SExplainRsp;
3338

3339
typedef struct {
3340
  SExplainRsp rsp;
3341
  uint64_t    qId;
3342
  uint64_t    cId;
3343
  uint64_t    tId;
3344
  int64_t     rId;
3345
  int32_t     eId;
3346
} SExplainLocalRsp;
3347

3348
typedef struct STableScanAnalyzeInfo {
3349
  uint64_t totalRows;
3350
  uint64_t totalCheckedRows;
3351
  uint32_t totalBlocks;
3352
  uint32_t loadBlocks;
3353
  uint32_t loadBlockStatis;
3354
  uint32_t skipBlocks;
3355
  uint32_t filterOutBlocks;
3356
  double   elapsedTime;
3357
  double   filterTime;
3358
} STableScanAnalyzeInfo;
3359

3360
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3361
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3362
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3363

3364
typedef struct {
3365
  char    config[TSDB_DNODE_CONFIG_LEN];
3366
  char    value[TSDB_CLUSTER_VALUE_LEN];
3367
  int32_t sqlLen;
3368
  char*   sql;
3369
} SMCfgClusterReq;
3370

3371
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3372
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3373
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3374

3375
typedef struct {
3376
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3377
  int32_t port;
3378
  int32_t sqlLen;
3379
  char*   sql;
3380
} SCreateDnodeReq;
3381

3382
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3383
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3384
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3385

3386
typedef struct {
3387
  int32_t dnodeId;
3388
  char    fqdn[TSDB_FQDN_LEN];
3389
  int32_t port;
3390
  int8_t  force;
3391
  int8_t  unsafe;
3392
  int32_t sqlLen;
3393
  char*   sql;
3394
} SDropDnodeReq;
3395

3396
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3397
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3398
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3399

3400
enum {
3401
  RESTORE_TYPE__ALL = 1,
3402
  RESTORE_TYPE__MNODE,
3403
  RESTORE_TYPE__VNODE,
3404
  RESTORE_TYPE__QNODE,
3405
};
3406

3407
typedef struct {
3408
  int32_t dnodeId;
3409
  int8_t  restoreType;
3410
  int32_t sqlLen;
3411
  char*   sql;
3412
} SRestoreDnodeReq;
3413

3414
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3415
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3416
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3417

3418
typedef struct {
3419
  int32_t dnodeId;
3420
  char    config[TSDB_DNODE_CONFIG_LEN];
3421
  char    value[TSDB_DNODE_VALUE_LEN];
3422
  int32_t sqlLen;
3423
  char*   sql;
3424
} SMCfgDnodeReq;
3425

3426
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3427
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3428
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3429

3430
typedef struct {
3431
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3432
  char    newKey[ENCRYPT_KEY_LEN + 1];
3433
  int32_t sqlLen;
3434
  char*   sql;
3435
} SMAlterEncryptKeyReq;
3436

3437
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3438
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3439
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3440

3441
typedef struct {
3442
  char    config[TSDB_DNODE_CONFIG_LEN];
3443
  char    value[TSDB_DNODE_VALUE_LEN];
3444
  int32_t version;
3445
} SDCfgDnodeReq;
3446

3447
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3448
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3449

3450
typedef struct {
3451
  int32_t dnodeId;
3452
  int32_t sqlLen;
3453
  char*   sql;
3454
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3455
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3456

3457
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3458
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3459

3460
typedef struct {
3461
  int32_t nodeId;
3462
  SEpSet  epSet;
3463
} SNodeEpSet;
3464

3465
typedef struct {
3466
  int32_t    snodeId;
3467
  SNodeEpSet leaders[2];
3468
  SNodeEpSet replica;
3469
  int32_t    sqlLen;
3470
  char*      sql;
3471
} SDCreateSnodeReq;
3472

3473
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3474
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3475
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3476

3477
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3478
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3479
typedef struct {
3480
  int8_t   replica;
3481
  SReplica replicas[TSDB_MAX_REPLICA];
3482
  int8_t   learnerReplica;
3483
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3484
  int64_t  lastIndex;
3485
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3486

3487
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3488
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3489

3490
typedef struct {
3491
  int32_t urlLen;
3492
  int32_t sqlLen;
3493
  char*   url;
3494
  char*   sql;
3495
} SMCreateAnodeReq;
3496

3497
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3498
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3499
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3500

3501
typedef struct {
3502
  int32_t anodeId;
3503
  int32_t sqlLen;
3504
  char*   sql;
3505
} SMDropAnodeReq, SMUpdateAnodeReq;
3506

3507
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3508
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3509
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3510
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3511
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3512
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3513

3514
typedef struct {
3515
  int32_t dnodeId;
3516
  int32_t bnodeProto;
3517
  int32_t sqlLen;
3518
  char*   sql;
3519
} SMCreateBnodeReq, SDCreateBnodeReq;
3520

3521
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3522
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3523
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3524

3525
typedef struct {
3526
  int32_t dnodeId;
3527
  int32_t sqlLen;
3528
  char*   sql;
3529
} SMDropBnodeReq, SDDropBnodeReq;
3530

3531
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3532
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3533
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3534

3535
typedef struct {
3536
  int32_t vgId;
3537
  int32_t hbSeq;
3538
} SVArbHbReqMember;
3539

3540
typedef struct {
3541
  int32_t dnodeId;
3542
  char*   arbToken;
3543
  int64_t arbTerm;
3544
  SArray* hbMembers;  // SVArbHbReqMember
3545
} SVArbHeartBeatReq;
3546

3547
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3548
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3549
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3550

3551
typedef struct {
3552
  int32_t vgId;
3553
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3554
  int32_t hbSeq;
3555
} SVArbHbRspMember;
3556

3557
typedef struct {
3558
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3559
  int32_t dnodeId;
3560
  SArray* hbMembers;  // SVArbHbRspMember
3561
} SVArbHeartBeatRsp;
3562

3563
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3564
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3565
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3566

3567
typedef struct {
3568
  char*   arbToken;
3569
  int64_t arbTerm;
3570
  char*   member0Token;
3571
  char*   member1Token;
3572
} SVArbCheckSyncReq;
3573

3574
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3575
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3576
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3577

3578
typedef struct {
3579
  char*   arbToken;
3580
  char*   member0Token;
3581
  char*   member1Token;
3582
  int32_t vgId;
3583
  int32_t errCode;
3584
} SVArbCheckSyncRsp;
3585

3586
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3587
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3588
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3589

3590
typedef struct {
3591
  char*   arbToken;
3592
  int64_t arbTerm;
3593
  char*   memberToken;
3594
  int8_t  force;
3595
} SVArbSetAssignedLeaderReq;
3596

3597
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3598
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3599
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3600

3601
typedef struct {
3602
  char*   arbToken;
3603
  char*   memberToken;
3604
  int32_t vgId;
3605
} SVArbSetAssignedLeaderRsp;
3606

3607
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3608
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3609
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3610

3611
typedef struct {
3612
  int32_t dnodeId;
3613
  char*   token;
3614
} SMArbUpdateGroupMember;
3615

3616
typedef struct {
3617
  int32_t dnodeId;
3618
  char*   token;
3619
  int8_t  acked;
3620
} SMArbUpdateGroupAssigned;
3621

3622
typedef struct {
3623
  int32_t                  vgId;
3624
  int64_t                  dbUid;
3625
  SMArbUpdateGroupMember   members[2];
3626
  int8_t                   isSync;
3627
  int8_t                   assignedAcked;
3628
  SMArbUpdateGroupAssigned assignedLeader;
3629
  int64_t                  version;
3630
  int32_t                  code;
3631
  int64_t                  updateTimeMs;
3632
} SMArbUpdateGroup;
3633

3634
typedef struct {
3635
  SArray* updateArray;  // SMArbUpdateGroup
3636
} SMArbUpdateGroupBatchReq;
3637

3638
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3639
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3640
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3641

3642
typedef struct {
3643
  char queryStrId[TSDB_QUERY_ID_LEN];
3644
} SKillQueryReq;
3645

3646
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3647
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3648

3649
typedef struct {
3650
  uint32_t connId;
3651
} SKillConnReq;
3652

3653
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3654
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3655

3656
typedef struct {
3657
  int32_t transId;
3658
} SKillTransReq;
3659

3660
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3661
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3662

3663
typedef struct {
3664
  int32_t useless;  // useless
3665
  int32_t sqlLen;
3666
  char*   sql;
3667
} SBalanceVgroupReq;
3668

3669
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3670
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3671
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3672

3673
typedef struct {
3674
  int32_t useless;  // useless
3675
  int32_t sqlLen;
3676
  char*   sql;
3677
} SAssignLeaderReq;
3678

3679
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3680
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3681
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3682
typedef struct {
3683
  int32_t vgId1;
3684
  int32_t vgId2;
3685
} SMergeVgroupReq;
3686

3687
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3688
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3689

3690
typedef struct {
3691
  int32_t vgId;
3692
  int32_t dnodeId1;
3693
  int32_t dnodeId2;
3694
  int32_t dnodeId3;
3695
  int32_t sqlLen;
3696
  char*   sql;
3697
} SRedistributeVgroupReq;
3698

3699
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3700
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3701
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3702

3703
typedef struct {
3704
  int32_t reserved;
3705
  int32_t vgId;
3706
  int32_t sqlLen;
3707
  char*   sql;
3708
  char    db[TSDB_DB_FNAME_LEN];
3709
} SBalanceVgroupLeaderReq;
3710

3711
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3712
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3713
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3714

3715
typedef struct {
3716
  int32_t vgId;
3717
} SForceBecomeFollowerReq;
3718

3719
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3720
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3721

3722
typedef struct {
3723
  int32_t vgId;
3724
  bool    force;
3725
} SSplitVgroupReq;
3726

3727
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3728
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3729

3730
typedef struct {
3731
  char user[TSDB_USER_LEN];
3732
  char spi;
3733
  char encrypt;
3734
  char secret[TSDB_PASSWORD_LEN];
3735
  char ckey[TSDB_PASSWORD_LEN];
3736
} SAuthReq, SAuthRsp;
3737

3738
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3739
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3740

3741
typedef struct {
3742
  int32_t statusCode;
3743
  char    details[1024];
3744
} SServerStatusRsp;
3745

3746
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3747
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3748

3749
/**
3750
 * The layout of the query message payload is as following:
3751
 * +--------------------+---------------------------------+
3752
 * |Sql statement       | Physical plan                   |
3753
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3754
 * +--------------------+---------------------------------+
3755
 */
3756
typedef struct SSubQueryMsg {
3757
  SMsgHead header;
3758
  uint64_t sId;
3759
  uint64_t queryId;
3760
  uint64_t clientId;
3761
  uint64_t taskId;
3762
  int64_t  refId;
3763
  int32_t  execId;
3764
  int32_t  msgMask;
3765
  int8_t   taskType;
3766
  int8_t   explain;
3767
  int8_t   needFetch;
3768
  int8_t   compress;
3769
  uint32_t sqlLen;
3770
  char*    sql;
3771
  uint32_t msgLen;
3772
  char*    msg;
3773
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
3774
} SSubQueryMsg;
3775

3776
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3777
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3778
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3779

3780
typedef struct {
3781
  SMsgHead header;
3782
  uint64_t sId;
3783
  uint64_t queryId;
3784
  uint64_t taskId;
3785
} SSinkDataReq;
3786

3787
typedef struct {
3788
  SMsgHead header;
3789
  uint64_t sId;
3790
  uint64_t queryId;
3791
  uint64_t clientId;
3792
  uint64_t taskId;
3793
  int32_t  execId;
3794
} SQueryContinueReq;
3795

3796
typedef struct {
3797
  SMsgHead header;
3798
  uint64_t sId;
3799
  uint64_t queryId;
3800
  uint64_t taskId;
3801
} SResReadyReq;
3802

3803
typedef struct {
3804
  int32_t code;
3805
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3806
  int32_t sversion;
3807
  int32_t tversion;
3808
} SResReadyRsp;
3809

3810
typedef struct SOperatorParam {
3811
  int32_t opType;
3812
  int32_t downstreamIdx;
3813
  void*   value;
3814
  SArray* pChildren;  // SArray<SOperatorParam*>
3815
  bool    reUse;
3816
} SOperatorParam;
3817

3818
typedef struct SColIdNameKV {
3819
  col_id_t colId;
3820
  char     colName[TSDB_COL_NAME_LEN];
3821
} SColIdNameKV;
3822

3823
#define COL_MASK_ON   ((int8_t)0x1)
3824
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
3825
#define COL_SET_MASK_ON(c)     \
3826
  do {                         \
3827
    (c)->flags |= COL_MASK_ON; \
3828
  } while (0)
3829

3830
typedef struct SColNameFlag {
3831
  col_id_t colId;
3832
  char     colName[TSDB_COL_NAME_LEN];
3833
  int8_t   flags;  // 0x01: COL_MASK_ON
3834
} SColNameFlag;
3835

3836
typedef struct SColIdPair {
3837
  col_id_t  vtbColId;
3838
  col_id_t  orgColId;
3839
  SDataType type;
3840
} SColIdPair;
3841

3842
typedef struct SColIdSlotIdPair {
3843
  int32_t  vtbSlotId;
3844
  col_id_t orgColId;
3845
} SColIdSlotIdPair;
3846

3847
typedef struct SOrgTbInfo {
3848
  int32_t vgId;
3849
  char    tbName[TSDB_TABLE_FNAME_LEN];
3850
  SArray* colMap;  // SArray<SColIdNameKV>
3851
} SOrgTbInfo;
3852

3853
void destroySOrgTbInfo(void *info);
3854

3855
typedef enum {
3856
  DYN_TYPE_STB_JOIN = 1,
3857
  DYN_TYPE_VSTB_SINGLE_SCAN,
3858
  DYN_TYPE_VSTB_BATCH_SCAN,
3859
} ETableScanDynType;
3860

3861
typedef struct STableScanOperatorParam {
3862
  bool              tableSeq;
3863
  bool              isNewParam;
3864
  uint64_t          groupid;
3865
  SArray*           pUidList;
3866
  SOrgTbInfo*       pOrgTbInfo;
3867
  SArray*           pBatchTbInfo;  // SArray<SOrgTbInfo>
3868
  SArray*           pTagList;
3869
  STimeWindow       window;
3870
  ETableScanDynType type;
3871
} STableScanOperatorParam;
3872

3873
typedef struct STagScanOperatorParam {
3874
  tb_uid_t vcUid;
3875
} STagScanOperatorParam;
3876

3877
typedef struct SVTableScanOperatorParam {
3878
  uint64_t        uid;
3879
  STimeWindow     window;
3880
  SOperatorParam* pTagScanOp;
3881
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3882
} SVTableScanOperatorParam;
3883

3884
typedef struct SMergeOperatorParam {
3885
  int32_t         winNum;
3886
} SMergeOperatorParam;
3887

3888
typedef struct SAggOperatorParam {
3889
  bool            needCleanRes;
3890
} SAggOperatorParam;
3891

3892
typedef struct SExternalWindowOperatorParam {
3893
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3894
} SExternalWindowOperatorParam;
3895

3896
typedef struct SDynQueryCtrlOperatorParam {
3897
  STimeWindow    window;
3898
} SDynQueryCtrlOperatorParam;
3899

3900
struct SStreamRuntimeFuncInfo;
3901
typedef struct {
3902
  SMsgHead        header;
3903
  uint64_t        sId;
3904
  uint64_t        queryId;
3905
  uint64_t        clientId;
3906
  uint64_t        taskId;
3907
  int32_t         execId;
3908
  SOperatorParam* pOpParam;
3909

3910
  // used for new-stream
3911
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3912
  bool                           reset;
3913
  bool                           dynTbname;
3914
  // used for new-stream
3915
} SResFetchReq;
3916

3917
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3918
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3919
void    tDestroySResFetchReq(SResFetchReq* pReq);
3920
typedef struct {
3921
  SMsgHead header;
3922
  uint64_t clientId;
3923
} SSchTasksStatusReq;
3924

3925
typedef struct {
3926
  uint64_t queryId;
3927
  uint64_t clientId;
3928
  uint64_t taskId;
3929
  int64_t  refId;
3930
  int32_t  subJobId;
3931
  int32_t  execId;
3932
  int8_t   status;
3933
} STaskStatus;
3934

3935
typedef struct {
3936
  int64_t refId;
3937
  SArray* taskStatus;  // SArray<STaskStatus>
3938
} SSchedulerStatusRsp;
3939

3940
typedef struct {
3941
  uint64_t queryId;
3942
  uint64_t taskId;
3943
  int8_t   action;
3944
} STaskAction;
3945

3946
typedef struct SQueryNodeEpId {
3947
  int32_t nodeId;  // vgId or qnodeId
3948
  SEp     ep;
3949
} SQueryNodeEpId;
3950

3951
typedef struct {
3952
  SMsgHead       header;
3953
  uint64_t       clientId;
3954
  SQueryNodeEpId epId;
3955
  SArray*        taskAction;  // SArray<STaskAction>
3956
} SSchedulerHbReq;
3957

3958
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3959
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3960
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3961

3962
typedef struct {
3963
  SQueryNodeEpId epId;
3964
  SArray*        taskStatus;  // SArray<STaskStatus>
3965
} SSchedulerHbRsp;
3966

3967
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3968
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3969
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3970

3971
typedef struct {
3972
  SMsgHead header;
3973
  uint64_t sId;
3974
  uint64_t queryId;
3975
  uint64_t clientId;
3976
  uint64_t taskId;
3977
  int64_t  refId;
3978
  int32_t  execId;
3979
} STaskCancelReq;
3980

3981
typedef struct {
3982
  int32_t code;
3983
} STaskCancelRsp;
3984

3985
typedef struct {
3986
  SMsgHead header;
3987
  uint64_t sId;
3988
  uint64_t queryId;
3989
  uint64_t clientId;
3990
  uint64_t taskId;
3991
  int64_t  refId;
3992
  int32_t  execId;
3993
} STaskDropReq;
3994

3995
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3996
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3997

3998
typedef enum {
3999
  TASK_NOTIFY_FINISHED = 1,
4000
} ETaskNotifyType;
4001

4002
typedef struct {
4003
  SMsgHead        header;
4004
  uint64_t        sId;
4005
  uint64_t        queryId;
4006
  uint64_t        clientId;
4007
  uint64_t        taskId;
4008
  int64_t         refId;
4009
  int32_t         execId;
4010
  ETaskNotifyType type;
4011
} STaskNotifyReq;
4012

4013
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4014
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4015

4016
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4017
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4018

4019
typedef struct {
4020
  int32_t code;
4021
} STaskDropRsp;
4022

4023
#define STREAM_TRIGGER_AT_ONCE                 1
4024
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4025
#define STREAM_TRIGGER_MAX_DELAY               3
4026
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4027
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4028

4029
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4030
#define STREAM_FILL_HISTORY_ON        1
4031
#define STREAM_FILL_HISTORY_OFF       0
4032
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4033
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4034
#define STREAM_CREATE_STABLE_TRUE     1
4035
#define STREAM_CREATE_STABLE_FALSE    0
4036

4037
typedef struct SVgroupVer {
4038
  int32_t vgId;
4039
  int64_t ver;
4040
} SVgroupVer;
4041

4042
typedef struct STaskNotifyEventStat {
4043
  int64_t notifyEventAddTimes;     // call times of add function
4044
  int64_t notifyEventAddElems;     // elements added by add function
4045
  double  notifyEventAddCostSec;   // time cost of add function
4046
  int64_t notifyEventPushTimes;    // call times of push function
4047
  int64_t notifyEventPushElems;    // elements pushed by push function
4048
  double  notifyEventPushCostSec;  // time cost of push function
4049
  int64_t notifyEventPackTimes;    // call times of pack function
4050
  int64_t notifyEventPackElems;    // elements packed by pack function
4051
  double  notifyEventPackCostSec;  // time cost of pack function
4052
  int64_t notifyEventSendTimes;    // call times of send function
4053
  int64_t notifyEventSendElems;    // elements sent by send function
4054
  double  notifyEventSendCostSec;  // time cost of send function
4055
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4056
} STaskNotifyEventStat;
4057

4058
enum {
4059
  TOPIC_SUB_TYPE__DB = 1,
4060
  TOPIC_SUB_TYPE__TABLE,
4061
  TOPIC_SUB_TYPE__COLUMN,
4062
};
4063

4064
#define DEFAULT_MAX_POLL_INTERVAL  300000
4065
#define DEFAULT_SESSION_TIMEOUT    12000
4066
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4067
#define DEFAULT_MIN_POLL_ROWS      4096
4068

4069
typedef struct {
4070
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4071
  int8_t igExists;
4072
  int8_t subType;
4073
  int8_t withMeta;
4074
  char*  sql;
4075
  char   subDbName[TSDB_DB_FNAME_LEN];
4076
  char*  ast;
4077
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4078
  int8_t reload;
4079
} SCMCreateTopicReq;
4080

4081
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4082
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4083
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4084

4085
typedef struct {
4086
  int64_t consumerId;
4087
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4088

4089
typedef struct {
4090
  int64_t consumerId;
4091
  char    cgroup[TSDB_CGROUP_LEN];
4092
  char    clientId[TSDB_CLIENT_ID_LEN];
4093
  char    user[TSDB_USER_LEN];
4094
  char    fqdn[TSDB_FQDN_LEN];
4095
  SArray* topicNames;  // SArray<char**>
4096

4097
  int8_t  withTbName;
4098
  int8_t  autoCommit;
4099
  int32_t autoCommitInterval;
4100
  int8_t  resetOffsetCfg;
4101
  int8_t  enableReplay;
4102
  int8_t  enableBatchMeta;
4103
  int32_t sessionTimeoutMs;
4104
  int32_t maxPollIntervalMs;
4105
} SCMSubscribeReq;
4106

4107
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4108
  int32_t tlen = 0;
661,550✔
4109
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
661,550✔
4110
  tlen += taosEncodeString(buf, pReq->cgroup);
661,550✔
4111
  tlen += taosEncodeString(buf, pReq->clientId);
661,550✔
4112

4113
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
661,550✔
4114
  tlen += taosEncodeFixedI32(buf, topicNum);
661,550✔
4115

4116
  for (int32_t i = 0; i < topicNum; i++) {
922,820✔
4117
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
522,540✔
4118
  }
4119

4120
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
661,550✔
4121
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
661,550✔
4122
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
661,550✔
4123
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
661,550✔
4124
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
661,550✔
4125
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
661,550✔
4126
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
661,550✔
4127
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
661,550✔
4128
  tlen += taosEncodeString(buf, pReq->user);
661,550✔
4129
  tlen += taosEncodeString(buf, pReq->fqdn);
661,550✔
4130

4131
  return tlen;
661,550✔
4132
}
4133

4134
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4135
  void* start = buf;
333,035✔
4136
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
333,035✔
4137
  buf = taosDecodeStringTo(buf, pReq->cgroup);
333,035✔
4138
  buf = taosDecodeStringTo(buf, pReq->clientId);
333,035✔
4139

4140
  int32_t topicNum = 0;
333,035✔
4141
  buf = taosDecodeFixedI32(buf, &topicNum);
333,035✔
4142

4143
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
333,035✔
4144
  if (pReq->topicNames == NULL) {
333,035✔
UNCOV
4145
    return terrno;
×
4146
  }
4147
  for (int32_t i = 0; i < topicNum; i++) {
483,843✔
4148
    char* name = NULL;
150,808✔
4149
    buf = taosDecodeString(buf, &name);
150,808✔
4150
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
301,616✔
UNCOV
4151
      return terrno;
×
4152
    }
4153
  }
4154

4155
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
333,035✔
4156
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
333,035✔
4157
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
333,035✔
4158
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
333,035✔
4159
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
333,035✔
4160
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
333,035✔
4161
  if ((char*)buf - (char*)start < len) {
333,035✔
4162
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
333,035✔
4163
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
333,035✔
4164
    buf = taosDecodeStringTo(buf, pReq->user);
333,035✔
4165
    buf = taosDecodeStringTo(buf, pReq->fqdn);
666,070✔
4166
  } else {
UNCOV
4167
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4168
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4169
  }
4170

4171
  return 0;
333,035✔
4172
}
4173

4174
typedef struct {
4175
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4176
  SArray* removedConsumers;  // SArray<int64_t>
4177
  SArray* newConsumers;      // SArray<int64_t>
4178
} SMqRebInfo;
4179

4180
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4181
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
310,130✔
4182
  if (pRebInfo == NULL) {
310,130✔
UNCOV
4183
    return NULL;
×
4184
  }
4185
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
310,130✔
4186
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
310,130✔
4187
  if (pRebInfo->removedConsumers == NULL) {
310,130✔
UNCOV
4188
    goto _err;
×
4189
  }
4190
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
310,130✔
4191
  if (pRebInfo->newConsumers == NULL) {
310,130✔
UNCOV
4192
    goto _err;
×
4193
  }
4194
  return pRebInfo;
310,130✔
UNCOV
4195
_err:
×
UNCOV
4196
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4197
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4198
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4199
  return NULL;
×
4200
}
4201

4202
typedef struct {
4203
  int64_t streamId;
4204
  int64_t checkpointId;
4205
  char    streamName[TSDB_STREAM_FNAME_LEN];
4206
} SMStreamDoCheckpointMsg;
4207

4208
typedef struct {
4209
  int64_t status;
4210
} SMVSubscribeRsp;
4211

4212
typedef struct {
4213
  char    name[TSDB_TOPIC_FNAME_LEN];
4214
  int8_t  igNotExists;
4215
  int32_t sqlLen;
4216
  char*   sql;
4217
  int8_t  force;
4218
} SMDropTopicReq;
4219

4220
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4221
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4222
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4223

4224
typedef struct {
4225
  char    name[TSDB_TOPIC_FNAME_LEN];
4226
  int8_t  igNotExists;
4227
  int32_t sqlLen;
4228
  char*   sql;
4229
} SMReloadTopicReq;
4230

4231
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4232
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4233
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4234

4235
typedef struct {
4236
  char   topic[TSDB_TOPIC_FNAME_LEN];
4237
  char   cgroup[TSDB_CGROUP_LEN];
4238
  int8_t igNotExists;
4239
  int8_t force;
4240
} SMDropCgroupReq;
4241

4242
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4243
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4244

4245
typedef struct {
4246
  int8_t reserved;
4247
} SMDropCgroupRsp;
4248

4249
typedef struct {
4250
  char    name[TSDB_TABLE_FNAME_LEN];
4251
  int8_t  alterType;
4252
  SSchema schema;
4253
} SAlterTopicReq;
4254

4255
typedef struct {
4256
  SMsgHead head;
4257
  char     name[TSDB_TABLE_FNAME_LEN];
4258
  int64_t  tuid;
4259
  int32_t  sverson;
4260
  int32_t  execLen;
4261
  char*    executor;
4262
  int32_t  sqlLen;
4263
  char*    sql;
4264
} SDCreateTopicReq;
4265

4266
typedef struct {
4267
  SMsgHead head;
4268
  char     name[TSDB_TABLE_FNAME_LEN];
4269
  int64_t  tuid;
4270
} SDDropTopicReq;
4271

4272
typedef struct {
4273
  char*      name;
4274
  int64_t    uid;
4275
  int64_t    interval[2];
4276
  int8_t     intervalUnit;
4277
  int16_t    nFuncs;
4278
  col_id_t*  funcColIds;  // column ids specified by user
4279
  func_id_t* funcIds;     // function ids specified by user
4280
} SRSmaParam;
4281

4282
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4283
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4284

4285
// TDMT_VND_CREATE_STB ==============
4286
typedef struct SVCreateStbReq {
4287
  char*           name;
4288
  tb_uid_t        suid;
4289
  int8_t          rollup;
4290
  SSchemaWrapper  schemaRow;
4291
  SSchemaWrapper  schemaTag;
4292
  SRSmaParam      rsmaParam;
4293
  int32_t         alterOriDataLen;
4294
  void*           alterOriData;
4295
  int8_t          source;
4296
  int8_t          colCmpred;
4297
  SColCmprWrapper colCmpr;
4298
  int64_t         keep;
4299
  int64_t         ownerId;
4300
  SExtSchema*     pExtSchemas;
4301
  int8_t          virtualStb;
4302
} SVCreateStbReq;
4303

4304
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4305
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4306

4307
// TDMT_VND_DROP_STB ==============
4308
typedef struct SVDropStbReq {
4309
  char*    name;
4310
  tb_uid_t suid;
4311
} SVDropStbReq;
4312

4313
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4314
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4315

4316
// TDMT_VND_CREATE_TABLE ==============
4317
#define TD_CREATE_IF_NOT_EXISTS       0x1
4318
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4319
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4320
typedef struct SVCreateTbReq {
4321
  int32_t  flags;
4322
  char*    name;
4323
  tb_uid_t uid;
4324
  int64_t  btime;
4325
  int32_t  ttl;
4326
  int32_t  commentLen;
4327
  char*    comment;
4328
  int8_t   type;
4329
  union {
4330
    struct {
4331
      char*    stbName;  // super table name
4332
      uint8_t  tagNum;
4333
      tb_uid_t suid;
4334
      SArray*  tagName;
4335
      uint8_t* pTag;
4336
    } ctb;
4337
    struct {
4338
      SSchemaWrapper schemaRow;
4339
    } ntb;
4340
  };
4341
  int32_t         sqlLen;
4342
  char*           sql;
4343
  SColCmprWrapper colCmpr;
4344
  SExtSchema*     pExtSchemas;
4345
  SColRefWrapper  colRef;  // col reference for virtual table
4346
} SVCreateTbReq;
4347

4348
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4349
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4350
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4351
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4352

4353
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4354
  if (NULL == req) {
2,125,115,110✔
4355
    return;
2,059,742,993✔
4356
  }
4357

4358
  taosMemoryFreeClear(req->sql);
65,372,117✔
4359
  taosMemoryFreeClear(req->name);
65,371,512✔
4360
  taosMemoryFreeClear(req->comment);
65,375,948✔
4361
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
65,375,107✔
4362
    taosMemoryFreeClear(req->ctb.pTag);
53,168,334✔
4363
    taosMemoryFreeClear(req->ctb.stbName);
53,169,896✔
4364
    taosArrayDestroy(req->ctb.tagName);
53,164,415✔
4365
    req->ctb.tagName = NULL;
53,138,251✔
4366
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
12,212,165✔
4367
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
12,212,165✔
4368
  }
4369
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
65,355,535✔
4370
  taosMemoryFreeClear(req->pExtSchemas);
65,379,563✔
4371
  taosMemoryFreeClear(req->colRef.pColRef);
65,380,986✔
4372
}
4373

4374
typedef struct {
4375
  int32_t nReqs;
4376
  union {
4377
    SVCreateTbReq* pReqs;
4378
    SArray*        pArray;
4379
  };
4380
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4381
} SVCreateTbBatchReq;
4382

4383
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4384
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4385
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4386

4387
typedef struct {
4388
  int32_t        code;
4389
  STableMetaRsp* pMeta;
4390
} SVCreateTbRsp, SVUpdateTbRsp;
4391

4392
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4393
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4394
void tFreeSVCreateTbRsp(void* param);
4395

4396
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4397
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4398

4399
typedef struct {
4400
  int32_t nRsps;
4401
  union {
4402
    SVCreateTbRsp* pRsps;
4403
    SArray*        pArray;
4404
  };
4405
} SVCreateTbBatchRsp;
4406

4407
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4408
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4409

4410
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4411
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4412

4413
// TDMT_VND_DROP_TABLE =================
4414
typedef struct {
4415
  char*    name;
4416
  uint64_t suid;  // for tmq in wal format
4417
  int64_t  uid;
4418
  int8_t   igNotExists;
4419
  int8_t   isVirtual;
4420
} SVDropTbReq;
4421

4422
typedef struct {
4423
  int32_t code;
4424
} SVDropTbRsp;
4425

4426
typedef struct {
4427
  int32_t nReqs;
4428
  union {
4429
    SVDropTbReq* pReqs;
4430
    SArray*      pArray;
4431
  };
4432
} SVDropTbBatchReq;
4433

4434
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4435
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4436

4437
typedef struct {
4438
  int32_t nRsps;
4439
  union {
4440
    SVDropTbRsp* pRsps;
4441
    SArray*      pArray;
4442
  };
4443
} SVDropTbBatchRsp;
4444

4445
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4446
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4447

4448
// TDMT_VND_ALTER_TABLE =====================
4449
typedef struct SMultiTagUpateVal {
4450
  char*    tagName;
4451
  int32_t  colId;
4452
  int8_t   tagType;
4453
  int8_t   tagFree;
4454
  uint32_t nTagVal;
4455
  uint8_t* pTagVal;
4456
  int8_t   isNull;
4457
  SArray*  pTagArray;
4458
} SMultiTagUpateVal;
4459
typedef struct SVAlterTbReq {
4460
  char*   tbName;
4461
  int8_t  action;
4462
  char*   colName;
4463
  int32_t colId;
4464
  // TSDB_ALTER_TABLE_ADD_COLUMN
4465
  int8_t  type;
4466
  int8_t  flags;
4467
  int32_t bytes;
4468
  // TSDB_ALTER_TABLE_DROP_COLUMN
4469
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4470
  int8_t   colModType;
4471
  int32_t  colModBytes;
4472
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4473
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4474
  int8_t   isNull;
4475
  int8_t   tagType;
4476
  int8_t   tagFree;
4477
  uint32_t nTagVal;
4478
  uint8_t* pTagVal;
4479
  SArray*  pTagArray;
4480
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4481
  int8_t   updateTTL;
4482
  int32_t  newTTL;
4483
  int32_t  newCommentLen;
4484
  char*    newComment;
4485
  int64_t  ctimeMs;    // fill by vnode
4486
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4487
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4488
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4489
  // for Add column
4490
  STypeMod typeMod;
4491
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4492
  char* refDbName;
4493
  char* refTbName;
4494
  char* refColName;
4495
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4496
} SVAlterTbReq;
4497

4498
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4499
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4500
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4501
void    tfreeMultiTagUpateVal(void* pMultiTag);
4502

4503
typedef struct {
4504
  int32_t        code;
4505
  STableMetaRsp* pMeta;
4506
} SVAlterTbRsp;
4507

4508
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4509
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4510
// ======================
4511

4512
typedef struct {
4513
  SMsgHead head;
4514
  int64_t  uid;
4515
  int32_t  tid;
4516
  int16_t  tversion;
4517
  int16_t  colId;
4518
  int8_t   type;
4519
  int16_t  bytes;
4520
  int32_t  tagValLen;
4521
  int16_t  numOfTags;
4522
  int32_t  schemaLen;
4523
  char     data[];
4524
} SUpdateTagValReq;
4525

4526
typedef struct {
4527
  SMsgHead head;
4528
} SUpdateTagValRsp;
4529

4530
typedef struct {
4531
  SMsgHead head;
4532
} SVShowTablesReq;
4533

4534
typedef struct {
4535
  SMsgHead head;
4536
  int32_t  id;
4537
} SVShowTablesFetchReq;
4538

4539
typedef struct {
4540
  int64_t useconds;
4541
  int8_t  completed;  // all results are returned to client
4542
  int8_t  precision;
4543
  int8_t  compressed;
4544
  int32_t compLen;
4545
  int32_t numOfRows;
4546
  char    data[];
4547
} SVShowTablesFetchRsp;
4548

4549
typedef struct {
4550
  int64_t consumerId;
4551
  int32_t epoch;
4552
  char    cgroup[TSDB_CGROUP_LEN];
4553
} SMqAskEpReq;
4554

4555
typedef struct {
4556
  int32_t key;
4557
  int32_t valueLen;
4558
  void*   value;
4559
} SKv;
4560

4561
typedef struct {
4562
  int64_t tscRid;
4563
  int8_t  connType;
4564
} SClientHbKey;
4565

4566
typedef struct {
4567
  int64_t tid;
4568
  char    status[TSDB_JOB_STATUS_LEN];
4569
} SQuerySubDesc;
4570

4571
typedef struct {
4572
  char     sql[TSDB_SHOW_SQL_LEN];
4573
  uint64_t queryId;
4574
  int64_t  useconds;
4575
  int64_t  stime;  // timestamp precision ms
4576
  int64_t  reqRid;
4577
  bool     stableQuery;
4578
  bool     isSubQuery;
4579
  char     fqdn[TSDB_FQDN_LEN];
4580
  int32_t  subPlanNum;
4581
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4582
} SQueryDesc;
4583

4584
typedef struct {
4585
  uint32_t connId;
4586
  SArray*  queryDesc;  // SArray<SQueryDesc>
4587
} SQueryHbReqBasic;
4588

4589
typedef struct {
4590
  uint32_t connId;
4591
  uint64_t killRid;
4592
  int32_t  totalDnodes;
4593
  int32_t  onlineDnodes;
4594
  int8_t   killConnection;
4595
  int8_t   align[3];
4596
  SEpSet   epSet;
4597
  SArray*  pQnodeList;
4598
} SQueryHbRspBasic;
4599

4600
typedef struct SAppClusterSummary {
4601
  uint64_t numOfInsertsReq;
4602
  uint64_t numOfInsertRows;
4603
  uint64_t insertElapsedTime;
4604
  uint64_t insertBytes;  // submit to tsdb since launched.
4605

4606
  uint64_t fetchBytes;
4607
  uint64_t numOfQueryReq;
4608
  uint64_t queryElapsedTime;
4609
  uint64_t numOfSlowQueries;
4610
  uint64_t totalRequests;
4611
  uint64_t currentRequests;  // the number of SRequestObj
4612
} SAppClusterSummary;
4613

4614
typedef struct {
4615
  int64_t            appId;
4616
  int32_t            pid;
4617
  char               name[TSDB_APP_NAME_LEN];
4618
  int64_t            startTime;
4619
  SAppClusterSummary summary;
4620
} SAppHbReq;
4621

4622
typedef struct {
4623
  SClientHbKey      connKey;
4624
  int64_t           clusterId;
4625
  SAppHbReq         app;
4626
  SQueryHbReqBasic* query;
4627
  SHashObj*         info;  // hash<Skv.key, Skv>
4628
  char              user[TSDB_USER_LEN];
4629
  char              tokenName[TSDB_TOKEN_NAME_LEN];
4630
  char              userApp[TSDB_APP_NAME_LEN];
4631
  uint32_t          userIp;
4632
  SIpRange          userDualIp;
4633
  char              sVer[TSDB_VERSION_LEN];
4634
  char              cInfo[CONNECTOR_INFO_LEN];
4635
} SClientHbReq;
4636

4637
typedef struct {
4638
  int64_t reqId;
4639
  SArray* reqs;  // SArray<SClientHbReq>
4640
  int64_t ipWhiteListVer;
4641
} SClientHbBatchReq;
4642

4643
typedef struct {
4644
  SClientHbKey      connKey;
4645
  int32_t           status;
4646
  SQueryHbRspBasic* query;
4647
  SArray*           info;  // Array<Skv>
4648
} SClientHbRsp;
4649

4650
typedef struct {
4651
  int64_t       reqId;
4652
  int64_t       rspId;
4653
  int32_t       svrTimestamp;
4654
  SArray*       rsps;  // SArray<SClientHbRsp>
4655
  SMonitorParas monitorParas;
4656
  int8_t        enableAuditDelete;
4657
  int8_t        enableStrongPass;
4658
  int8_t        enableAuditSelect;
4659
  int8_t        enableAuditInsert;
4660
  int8_t        auditLevel;
4661
} SClientHbBatchRsp;
4662

4663
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
60,861,112✔
4664

4665
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4666
  void* pIter = taosHashIterate(info, NULL);
42,373,570✔
4667
  while (pIter != NULL) {
98,099,863✔
4668
    SKv* kv = (SKv*)pIter;
55,725,245✔
4669
    taosMemoryFreeClear(kv->value);
55,725,245✔
4670
    pIter = taosHashIterate(info, pIter);
55,725,245✔
4671
  }
4672
}
42,374,618✔
4673

4674
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
27,066,466✔
4675
  SQueryDesc* desc = (SQueryDesc*)pDesc;
27,066,466✔
4676
  if (desc->subDesc) {
27,066,466✔
4677
    taosArrayDestroy(desc->subDesc);
19,205,571✔
4678
    desc->subDesc = NULL;
19,203,132✔
4679
  }
4680
}
27,065,516✔
4681

4682
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
48,537,216✔
4683
  SClientHbReq* req = (SClientHbReq*)pReq;
50,594,101✔
4684
  if (req->query) {
50,594,101✔
4685
    if (req->query->queryDesc) {
48,537,216✔
4686
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
22,194,359✔
4687
    }
4688
    taosMemoryFreeClear(req->query);
48,537,060✔
4689
  }
4690

4691
  if (req->info) {
50,594,544✔
4692
    tFreeReqKvHash(req->info);
42,374,618✔
4693
    taosHashCleanup(req->info);
42,374,618✔
4694
    req->info = NULL;
42,373,054✔
4695
  }
4696
}
25,477,870✔
4697

4698
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4699
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4700

4701
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4702
  if (pReq == NULL) return;
21,065,532✔
4703
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
21,065,532✔
4704
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
21,065,532✔
4705
  taosMemoryFree(pReq);
21,065,532✔
4706
}
4707

4708
static FORCE_INLINE void tFreeClientKv(void* pKv) {
20,780,362✔
4709
  SKv* kv = (SKv*)pKv;
20,780,362✔
4710
  if (kv) {
20,780,362✔
4711
    taosMemoryFreeClear(kv->value);
20,780,362✔
4712
  }
4713
}
20,779,713✔
4714

4715
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
48,358,619✔
4716
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
48,358,619✔
4717
  if (rsp->query) {
48,358,619✔
4718
    taosArrayDestroy(rsp->query->pQnodeList);
48,350,971✔
4719
    taosMemoryFreeClear(rsp->query);
48,346,217✔
4720
  }
4721
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
48,363,274✔
4722
}
24,940,590✔
4723

4724
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4725
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
40,491,800✔
4726
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
40,491,800✔
4727
}
40,496,931✔
4728

4729
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4730
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4731
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4732

4733
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4734
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
150,611,429✔
4735
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
150,611,584✔
4736
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
150,612,181✔
4737
  return 0;
75,306,274✔
4738
}
4739

4740
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4741
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
73,268,023✔
4742
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
73,268,106✔
4743
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
36,634,053✔
4744
  if (pKv->value == NULL) {
36,633,688✔
UNCOV
4745
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4746
  }
4747
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
36,633,970✔
4748
  return 0;
36,633,970✔
4749
}
4750

4751
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4752
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
187,978,185✔
4753
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
187,972,812✔
4754
  return 0;
93,987,413✔
4755
}
4756

4757
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4758
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
93,650,200✔
4759
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
93,657,050✔
4760
  return 0;
46,830,392✔
4761
}
4762

4763
typedef struct {
4764
  int32_t vgId;
4765
  // TODO stas
4766
} SMqReportVgInfo;
4767

4768
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4769
  int32_t tlen = 0;
4770
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4771
  return tlen;
4772
}
4773

4774
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4775
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4776
  return buf;
4777
}
4778

4779
typedef struct {
4780
  int32_t epoch;
4781
  int64_t topicUid;
4782
  char    name[TSDB_TOPIC_FNAME_LEN];
4783
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4784
} SMqTopicInfo;
4785

4786
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4787
  int32_t tlen = 0;
4788
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4789
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4790
  tlen += taosEncodeString(buf, pTopicInfo->name);
4791
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4792
  tlen += taosEncodeFixedI32(buf, sz);
4793
  for (int32_t i = 0; i < sz; i++) {
4794
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4795
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4796
  }
4797
  return tlen;
4798
}
4799

4800
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4801
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4802
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4803
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4804
  int32_t sz;
4805
  buf = taosDecodeFixedI32(buf, &sz);
4806
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4807
    return NULL;
4808
  }
4809
  for (int32_t i = 0; i < sz; i++) {
4810
    SMqReportVgInfo vgInfo;
4811
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4812
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4813
      return NULL;
4814
    }
4815
  }
4816
  return buf;
4817
}
4818

4819
typedef struct {
4820
  int32_t status;  // ask hb endpoint
4821
  int32_t epoch;
4822
  int64_t consumerId;
4823
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4824
} SMqReportReq;
4825

4826
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4827
  int32_t tlen = 0;
4828
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4829
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4830
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4831
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4832
  tlen += taosEncodeFixedI32(buf, sz);
4833
  for (int32_t i = 0; i < sz; i++) {
4834
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4835
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4836
  }
4837
  return tlen;
4838
}
4839

4840
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4841
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4842
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4843
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4844
  int32_t sz;
4845
  buf = taosDecodeFixedI32(buf, &sz);
4846
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4847
    return NULL;
4848
  }
4849
  for (int32_t i = 0; i < sz; i++) {
4850
    SMqTopicInfo topicInfo;
4851
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4852
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4853
      return NULL;
4854
    }
4855
  }
4856
  return buf;
4857
}
4858

4859
typedef struct {
4860
  SMsgHead head;
4861
  int64_t  leftForVer;
4862
  int32_t  vgId;
4863
  int64_t  consumerId;
4864
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4865
} SMqVDeleteReq;
4866

4867
typedef struct {
4868
  int8_t reserved;
4869
} SMqVDeleteRsp;
4870

4871
typedef struct {
4872
  char*  name;
4873
  int8_t igNotExists;
4874
} SMDropStreamReq;
4875

4876
typedef struct {
4877
  int8_t reserved;
4878
} SMDropStreamRsp;
4879

4880
typedef struct {
4881
  SMsgHead head;
4882
  int64_t  resetRelHalt;  // reset related stream task halt status
4883
  int64_t  streamId;
4884
  int32_t  taskId;
4885
} SVDropStreamTaskReq;
4886

4887
typedef struct {
4888
  int8_t reserved;
4889
} SVDropStreamTaskRsp;
4890

4891
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4892
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4893
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4894

4895
typedef struct {
4896
  char*  name;
4897
  int8_t igNotExists;
4898
} SMPauseStreamReq;
4899

4900
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4901
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4902
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4903

4904
typedef struct {
4905
  char*  name;
4906
  int8_t igNotExists;
4907
  int8_t igUntreated;
4908
} SMResumeStreamReq;
4909

4910
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4911
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4912
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4913

4914
typedef struct {
4915
  char*       name;
4916
  int8_t      calcAll;
4917
  STimeWindow timeRange;
4918
} SMRecalcStreamReq;
4919

4920
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4921
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4922
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4923

4924
typedef struct SVndSetKeepVersionReq {
4925
  int64_t keepVersion;
4926
} SVndSetKeepVersionReq;
4927

4928
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4929
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4930

4931
typedef struct SVUpdateCheckpointInfoReq {
4932
  SMsgHead head;
4933
  int64_t  streamId;
4934
  int32_t  taskId;
4935
  int64_t  checkpointId;
4936
  int64_t  checkpointVer;
4937
  int64_t  checkpointTs;
4938
  int32_t  transId;
4939
  int64_t  hStreamId;  // add encode/decode
4940
  int64_t  hTaskId;
4941
  int8_t   dropRelHTask;
4942
} SVUpdateCheckpointInfoReq;
4943

4944
typedef struct {
4945
  int64_t leftForVer;
4946
  int32_t vgId;
4947
  int64_t oldConsumerId;
4948
  int64_t newConsumerId;
4949
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4950
  int8_t  subType;
4951
  int8_t  withMeta;
4952
  char*   qmsg;  // SubPlanToString
4953
  SSchemaWrapper schema;
4954
  int64_t suid;
4955
} SMqRebVgReq;
4956

4957
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4958
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4959

4960
// tqOffset
4961
enum {
4962
  TMQ_OFFSET__RESET_NONE = -3,
4963
  TMQ_OFFSET__RESET_EARLIEST = -2,
4964
  TMQ_OFFSET__RESET_LATEST = -1,
4965
  TMQ_OFFSET__LOG = 1,
4966
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4967
  TMQ_OFFSET__SNAPSHOT_META = 3,
4968
};
4969

4970
enum {
4971
  WITH_DATA = 0,
4972
  WITH_META = 1,
4973
  ONLY_META = 2,
4974
};
4975

4976
#define TQ_OFFSET_VERSION 1
4977

4978
typedef struct {
4979
  int8_t type;
4980
  union {
4981
    // snapshot
4982
    struct {
4983
      int64_t uid;
4984
      int64_t ts;
4985
      SValue  primaryKey;
4986
    };
4987
    // log
4988
    struct {
4989
      int64_t version;
4990
    };
4991
  };
4992
} STqOffsetVal;
4993

4994
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4995
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,122,818✔
4996
  pOffsetVal->uid = uid;
7,123,427✔
4997
  pOffsetVal->ts = ts;
7,122,212✔
4998
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,123,987✔
4999
    taosMemoryFree(pOffsetVal->primaryKey.pData);
273✔
5000
  }
5001
  pOffsetVal->primaryKey = primaryKey;
7,125,835✔
5002
}
7,121,963✔
5003

5004
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5005
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
38,160✔
5006
  pOffsetVal->uid = uid;
38,160✔
5007
}
38,160✔
5008

5009
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5010
  pOffsetVal->type = TMQ_OFFSET__LOG;
111,471,283✔
5011
  pOffsetVal->version = ver;
111,469,260✔
5012
}
111,467,739✔
5013

5014
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5015
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5016
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5017
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5018
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5019
void    tOffsetDestroy(void* pVal);
5020

5021
typedef struct {
5022
  STqOffsetVal val;
5023
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5024
} STqOffset;
5025

5026
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5027
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5028
void    tDeleteSTqOffset(void* val);
5029

5030
typedef struct SMqVgOffset {
5031
  int64_t   consumerId;
5032
  STqOffset offset;
5033
} SMqVgOffset;
5034

5035
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5036
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5037

5038
typedef struct {
5039
  char    name[TSDB_TABLE_FNAME_LEN];
5040
  char    stb[TSDB_TABLE_FNAME_LEN];
5041
  int8_t  igExists;
5042
  int8_t  intervalUnit;
5043
  int8_t  slidingUnit;
5044
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5045
  int32_t dstVgId;   // for stream
5046
  int64_t interval;
5047
  int64_t offset;
5048
  int64_t sliding;
5049
  int64_t maxDelay;
5050
  int64_t watermark;
5051
  int32_t exprLen;        // strlen + 1
5052
  int32_t tagsFilterLen;  // strlen + 1
5053
  int32_t sqlLen;         // strlen + 1
5054
  int32_t astLen;         // strlen + 1
5055
  char*   expr;
5056
  char*   tagsFilter;
5057
  char*   sql;
5058
  char*   ast;
5059
  int64_t deleteMark;
5060
  int64_t lastTs;
5061
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5062
  SArray* pVgroupVerList;
5063
  int8_t  recursiveTsma;
5064
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5065
  char*   createStreamReq;
5066
  int32_t streamReqLen;
5067
  char*   dropStreamReq;
5068
  int32_t dropStreamReqLen;
5069
  int64_t uid;
5070
} SMCreateSmaReq;
5071

5072
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5073
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5074
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5075

5076
typedef struct {
5077
  char    name[TSDB_TABLE_FNAME_LEN];
5078
  int8_t  igNotExists;
5079
  char*   dropStreamReq;
5080
  int32_t dropStreamReqLen;
5081
} SMDropSmaReq;
5082

5083
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5084
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5085
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5086

5087
typedef struct {
5088
  char name[TSDB_TABLE_NAME_LEN];
5089
  union {
5090
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5091
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5092
  };
5093
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5094
  union {
5095
    int8_t igExists;   // used by mnode
5096
    int8_t alterType;  // used by vnode
5097
  };
5098
  int8_t     intervalUnit;
5099
  int16_t    nFuncs;       // number of functions specified by user
5100
  col_id_t*  funcColIds;   // column ids specified by user
5101
  func_id_t* funcIds;      // function ids specified by user
5102
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5103
  int64_t    tbUid;
5104
  int64_t    uid;     // rsma uid
5105
  int32_t    sqlLen;  // strlen + 1
5106
  char*      sql;
5107
} SMCreateRsmaReq;
5108

5109
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5110
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5111
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5112

5113
typedef SMCreateRsmaReq SVCreateRsmaReq;
5114

5115
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5116
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5117
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5118

5119
typedef SMCreateRsmaReq SVAlterRsmaReq;
5120

5121
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5122
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5123
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5124

5125
typedef struct {
5126
  char       name[TSDB_TABLE_NAME_LEN];
5127
  int8_t     alterType;
5128
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5129
  int8_t     igNotExists;
5130
  int16_t    nFuncs;      // number of functions specified by user
5131
  col_id_t*  funcColIds;  // column ids specified by user
5132
  func_id_t* funcIds;     // function ids specified by user
5133
  int32_t    sqlLen;      // strlen + 1
5134
  char*      sql;
5135
} SMAlterRsmaReq;
5136

5137
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5138
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5139
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5140

5141
typedef struct {
5142
  int64_t    id;
5143
  char       name[TSDB_TABLE_NAME_LEN];
5144
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5145
  int64_t    ownerId;
5146
  int32_t    code;
5147
  int32_t    version;
5148
  int8_t     tbType;
5149
  int8_t     intervalUnit;
5150
  col_id_t   nFuncs;
5151
  col_id_t   nColNames;
5152
  int64_t    interval[2];
5153
  col_id_t*  funcColIds;
5154
  func_id_t* funcIds;
5155
  SArray*    colNames;
5156
} SRsmaInfoRsp;
5157

5158
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5159
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5160
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5161

5162
typedef struct {
5163
  char   name[TSDB_TABLE_FNAME_LEN];
5164
  int8_t igNotExists;
5165
} SMDropRsmaReq;
5166

5167
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5168
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5169

5170
typedef struct {
5171
  char    name[TSDB_TABLE_NAME_LEN];
5172
  char    tbName[TSDB_TABLE_NAME_LEN];
5173
  int64_t uid;
5174
  int64_t tbUid;
5175
  int8_t  tbType;
5176
} SVDropRsmaReq;
5177

5178
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5179
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5180

5181
typedef struct {
5182
  char   dbFName[TSDB_DB_FNAME_LEN];
5183
  char   stbName[TSDB_TABLE_NAME_LEN];
5184
  char   colName[TSDB_COL_NAME_LEN];
5185
  char   idxName[TSDB_INDEX_FNAME_LEN];
5186
  int8_t idxType;
5187
} SCreateTagIndexReq;
5188

5189
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5190
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5191

5192
typedef SMDropSmaReq SDropTagIndexReq;
5193

5194
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5195
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5196

5197
typedef struct {
5198
  int8_t         version;       // for compatibility(default 0)
5199
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5200
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5201
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5202
  int32_t        dstVgId;
5203
  char           indexName[TSDB_INDEX_NAME_LEN];
5204
  int32_t        exprLen;
5205
  int32_t        tagsFilterLen;
5206
  int64_t        indexUid;
5207
  tb_uid_t       tableUid;  // super/child/common table uid
5208
  tb_uid_t       dstTbUid;  // for dstVgroup
5209
  int64_t        interval;
5210
  int64_t        offset;  // use unit by precision of DB
5211
  int64_t        sliding;
5212
  char*          dstTbName;  // for dstVgroup
5213
  char*          expr;       // sma expression
5214
  char*          tagsFilter;
5215
  SSchemaWrapper schemaRow;  // for dstVgroup
5216
  SSchemaWrapper schemaTag;  // for dstVgroup
5217
} STSma;                     // Time-range-wise SMA
5218

5219
typedef STSma SVCreateTSmaReq;
5220

5221
typedef struct {
5222
  int8_t  type;  // 0 status report, 1 update data
5223
  int64_t indexUid;
5224
  int64_t skey;  // start TS key of interval/sliding window
5225
} STSmaMsg;
5226

5227
typedef struct {
5228
  int64_t indexUid;
5229
  char    indexName[TSDB_INDEX_NAME_LEN];
5230
} SVDropTSmaReq;
5231

5232
typedef struct {
5233
  int tmp;  // TODO: to avoid compile error
5234
} SVCreateTSmaRsp, SVDropTSmaRsp;
5235

5236
#if 0
5237
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5238
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5239
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5240
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5241
#endif
5242

5243
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5244
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5245
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5246
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5247

5248
typedef struct {
5249
  int32_t number;
5250
  STSma*  tSma;
5251
} STSmaWrapper;
5252

5253
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5254
  if (pSma) {
×
UNCOV
5255
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5256
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5257
    taosMemoryFreeClear(pSma->tagsFilter);
×
5258
  }
UNCOV
5259
}
×
5260

5261
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5262
  if (pSW) {
×
UNCOV
5263
    if (pSW->tSma) {
×
UNCOV
5264
      if (deepCopy) {
×
UNCOV
5265
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5266
          tDestroyTSma(pSW->tSma + i);
×
5267
        }
5268
      }
UNCOV
5269
      taosMemoryFreeClear(pSW->tSma);
×
5270
    }
5271
  }
UNCOV
5272
}
×
5273

5274
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5275
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5276
  taosMemoryFreeClear(pSW);
×
UNCOV
5277
  return NULL;
×
5278
}
5279

5280
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5281
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5282

5283
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5284
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5285

UNCOV
5286
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5287
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5288
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5289
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5290
  }
UNCOV
5291
  return 0;
×
5292
}
5293

UNCOV
5294
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5295
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5296
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5297
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5298
  }
UNCOV
5299
  return 0;
×
5300
}
5301

5302
typedef struct {
5303
  int idx;
5304
} SMCreateFullTextReq;
5305

5306
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5307
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5308
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5309

5310
typedef struct {
5311
  char   name[TSDB_TABLE_FNAME_LEN];
5312
  int8_t igNotExists;
5313
} SMDropFullTextReq;
5314

5315
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5316
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5317

5318
typedef struct {
5319
  char indexFName[TSDB_INDEX_FNAME_LEN];
5320
} SUserIndexReq;
5321

5322
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5323
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5324

5325
typedef struct {
5326
  char dbFName[TSDB_DB_FNAME_LEN];
5327
  char tblFName[TSDB_TABLE_FNAME_LEN];
5328
  char colName[TSDB_COL_NAME_LEN];
5329
  char owner[TSDB_USER_LEN];
5330
  char indexType[TSDB_INDEX_TYPE_LEN];
5331
  char indexExts[TSDB_INDEX_EXTS_LEN];
5332
} SUserIndexRsp;
5333

5334
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5335
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5336

5337
typedef struct {
5338
  char tbFName[TSDB_TABLE_FNAME_LEN];
5339
} STableIndexReq;
5340

5341
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5342
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5343

5344
typedef struct {
5345
  int8_t  intervalUnit;
5346
  int8_t  slidingUnit;
5347
  int64_t interval;
5348
  int64_t offset;
5349
  int64_t sliding;
5350
  int64_t dstTbUid;
5351
  int32_t dstVgId;
5352
  SEpSet  epSet;
5353
  char*   expr;
5354
} STableIndexInfo;
5355

5356
typedef struct {
5357
  char     tbName[TSDB_TABLE_NAME_LEN];
5358
  char     dbFName[TSDB_DB_FNAME_LEN];
5359
  uint64_t suid;
5360
  int32_t  version;
5361
  int32_t  indexSize;
5362
  SArray*  pIndex;  // STableIndexInfo
5363
} STableIndexRsp;
5364

5365
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5366
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5367
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5368

5369
void tFreeSTableIndexInfo(void* pInfo);
5370

5371
typedef struct {
5372
  int8_t  mqMsgType;
5373
  int32_t code;
5374
  int32_t epoch;
5375
  int64_t consumerId;
5376
  int64_t walsver;
5377
  int64_t walever;
5378
} SMqRspHead;
5379

5380
typedef struct {
5381
  SMsgHead     head;
5382
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5383
  int8_t       withTbName;
5384
  int8_t       useSnapshot;
5385
  int32_t      epoch;
5386
  uint64_t     reqId;
5387
  int64_t      consumerId;
5388
  int64_t      timeout;
5389
  STqOffsetVal reqOffset;
5390
  int8_t       enableReplay;
5391
  int8_t       sourceExcluded;
5392
  int8_t       rawData;
5393
  int32_t      minPollRows;
5394
  int8_t       enableBatchMeta;
5395
  SHashObj*    uidHash;  // to find if uid is duplicated
5396
} SMqPollReq;
5397

5398
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5399
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5400
void    tDestroySMqPollReq(SMqPollReq* pReq);
5401

5402
typedef struct {
5403
  int32_t vgId;
5404
  int64_t offset;
5405
  SEpSet  epSet;
5406
} SMqSubVgEp;
5407

5408
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5409
  int32_t tlen = 0;
2,257,440✔
5410
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,257,440✔
5411
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,257,440✔
5412
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,257,440✔
5413
  return tlen;
2,257,440✔
5414
}
5415

5416
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5417
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,119,668✔
5418
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,119,668✔
5419
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,119,668✔
5420
  return buf;
1,119,668✔
5421
}
5422

5423
typedef struct {
5424
  char           topic[TSDB_TOPIC_FNAME_LEN];
5425
  char           db[TSDB_DB_FNAME_LEN];
5426
  SArray*        vgs;  // SArray<SMqSubVgEp>
5427
} SMqSubTopicEp;
5428

5429
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5430
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5431
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5432

5433
typedef struct {
5434
  SMqRspHead   head;
5435
  STqOffsetVal rspOffset;
5436
  int16_t      resMsgType;
5437
  int32_t      metaRspLen;
5438
  void*        metaRsp;
5439
} SMqMetaRsp;
5440

5441
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5442
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5443
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5444

5445
#define MQ_DATA_RSP_VERSION 100
5446

5447
typedef struct {
5448
  SMqRspHead   head;
5449
  STqOffsetVal rspOffset;
5450
  STqOffsetVal reqOffset;
5451
  int32_t      blockNum;
5452
  int8_t       withTbName;
5453
  int8_t       withSchema;
5454
  SArray*      blockDataLen;
5455
  SArray*      blockData;
5456
  SArray*      blockTbName;
5457
  SArray*      blockSchema;
5458

5459
  union {
5460
    struct {
5461
      int64_t sleepTime;
5462
    };
5463
    struct {
5464
      int32_t createTableNum;
5465
      SArray* createTableLen;
5466
      SArray* createTableReq;
5467
    };
5468
    struct {
5469
      int32_t len;
5470
      void*   rawData;
5471
    };
5472
  };
5473
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5474
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5475
} SMqDataRsp;
5476

5477
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5478
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5479
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5480
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5481
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5482

5483
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5484
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5485
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5486

5487
typedef struct SMqBatchMetaRsp {
5488
  SMqRspHead   head;  // not serialize
5489
  STqOffsetVal rspOffset;
5490
  SArray*      batchMetaLen;
5491
  SArray*      batchMetaReq;
5492
  void*        pMetaBuff;    // not serialize
5493
  uint32_t     metaBuffLen;  // not serialize
5494
} SMqBatchMetaRsp;
5495

5496
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5497
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5498
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5499
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5500

5501
typedef struct {
5502
  int32_t    code;
5503
  SArray*    topics;  // SArray<SMqSubTopicEp>
5504
} SMqAskEpRsp;
5505

5506
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5507
  int32_t tlen = 0;
7,350,248✔
5508
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5509
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,350,248✔
5510
  tlen += taosEncodeFixedI32(buf, sz);
7,350,248✔
5511
  for (int32_t i = 0; i < sz; i++) {
9,138,424✔
5512
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,788,176✔
5513
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,788,176✔
5514
  }
5515
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,350,248✔
5516

5517
  return tlen;
7,350,248✔
5518
}
5519

5520
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5521
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5522
  int32_t sz;
3,318,918✔
5523
  buf = taosDecodeFixedI32(buf, &sz);
3,398,946✔
5524
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,398,946✔
5525
  if (pRsp->topics == NULL) {
3,398,946✔
UNCOV
5526
    return NULL;
×
5527
  }
5528
  for (int32_t i = 0; i < sz; i++) {
4,302,806✔
5529
    SMqSubTopicEp topicEp;
889,856✔
5530
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
903,860✔
5531
    if (buf == NULL) {
903,860✔
UNCOV
5532
      return NULL;
×
5533
    }
5534
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,807,720✔
UNCOV
5535
      return NULL;
×
5536
    }
5537
  }
5538
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,398,946✔
5539

5540
  return buf;
3,398,946✔
5541
}
5542

5543
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5544
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,503,647✔
5545
}
9,503,319✔
5546

5547
typedef struct {
5548
  int32_t      vgId;
5549
  STqOffsetVal offset;
5550
  int64_t      rows;
5551
  int64_t      ever;
5552
} OffsetRows;
5553

5554
typedef struct {
5555
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5556
  SArray* offsetRows;
5557
} TopicOffsetRows;
5558

5559
typedef struct {
5560
  int64_t consumerId;
5561
  int32_t epoch;
5562
  SArray* topics;
5563
  int8_t  pollFlag;
5564
} SMqHbReq;
5565

5566
typedef struct {
5567
  char   topic[TSDB_TOPIC_FNAME_LEN];
5568
  int8_t noPrivilege;
5569
} STopicPrivilege;
5570

5571
typedef struct {
5572
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5573
  int32_t debugFlag;
5574
} SMqHbRsp;
5575

5576
typedef struct {
5577
  SMsgHead head;
5578
  int64_t  consumerId;
5579
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5580
} SMqSeekReq;
5581

5582
#define TD_AUTO_CREATE_TABLE 0x1
5583
typedef struct {
5584
  int64_t       suid;
5585
  int64_t       uid;
5586
  int32_t       sver;
5587
  uint32_t      nData;
5588
  uint8_t*      pData;
5589
  SVCreateTbReq cTbReq;
5590
} SVSubmitBlk;
5591

5592
typedef struct {
5593
  SMsgHead header;
5594
  uint64_t sId;
5595
  uint64_t queryId;
5596
  uint64_t clientId;
5597
  uint64_t taskId;
5598
  uint32_t sqlLen;
5599
  uint32_t phyLen;
5600
  char*    sql;
5601
  char*    msg;
5602
  int8_t   source;
5603
} SVDeleteReq;
5604

5605
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5606
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5607

5608
typedef struct {
5609
  int64_t affectedRows;
5610
} SVDeleteRsp;
5611

5612
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5613
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5614

5615
typedef struct SDeleteRes {
5616
  uint64_t suid;
5617
  SArray*  uidList;
5618
  int64_t  skey;
5619
  int64_t  ekey;
5620
  int64_t  affectedRows;
5621
  char     tableFName[TSDB_TABLE_NAME_LEN];
5622
  char     tsColName[TSDB_COL_NAME_LEN];
5623
  int64_t  ctimeMs;  // fill by vnode
5624
  int8_t   source;
5625
} SDeleteRes;
5626

5627
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5628
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5629

5630
typedef struct {
5631
  // int64_t uid;
5632
  char    tbname[TSDB_TABLE_NAME_LEN];
5633
  int64_t startTs;
5634
  int64_t endTs;
5635
} SSingleDeleteReq;
5636

5637
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5638
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5639

5640
typedef struct {
5641
  int64_t suid;
5642
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5643
  int64_t ctimeMs;     // fill by vnode
5644
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5645
} SBatchDeleteReq;
5646

5647
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5648
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5649
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5650

5651
typedef struct {
5652
  int32_t msgIdx;
5653
  int32_t msgType;
5654
  int32_t msgLen;
5655
  void*   msg;
5656
} SBatchMsg;
5657

5658
typedef struct {
5659
  SMsgHead header;
5660
  SArray*  pMsgs;  // SArray<SBatchMsg>
5661
} SBatchReq;
5662

5663
typedef struct {
5664
  int32_t reqType;
5665
  int32_t msgIdx;
5666
  int32_t msgLen;
5667
  int32_t rspCode;
5668
  void*   msg;
5669
} SBatchRspMsg;
5670

5671
typedef struct {
5672
  SArray* pRsps;  // SArray<SBatchRspMsg>
5673
} SBatchRsp;
5674

5675
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5676
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5677
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
81,531,020✔
5678
  if (NULL == msg) {
81,531,020✔
UNCOV
5679
    return;
×
5680
  }
5681
  SBatchMsg* pMsg = (SBatchMsg*)msg;
81,531,020✔
5682
  taosMemoryFree(pMsg->msg);
81,531,020✔
5683
}
5684

5685
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5686
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5687

5688
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
108,314,858✔
5689
  if (NULL == p) {
108,314,858✔
UNCOV
5690
    return;
×
5691
  }
5692

5693
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
108,314,858✔
5694
  taosMemoryFree(pRsp->msg);
108,314,858✔
5695
}
5696

5697
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5698
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5699
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5700
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5701
void    tDestroySMqHbReq(SMqHbReq* pReq);
5702

5703
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5704
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5705
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5706

5707
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5708
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5709

5710
#define TD_REQ_FROM_APP               0x0
5711
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5712
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5713
#define SUBMIT_REQ_FROM_FILE          0x4
5714
#define TD_REQ_FROM_TAOX              0x8
5715
#define TD_REQ_FROM_SML               0x10
5716
#define SUBMIT_REQUEST_VERSION        (2)
5717
#define SUBMIT_REQ_WITH_BLOB          0x10
5718
#define SUBMIT_REQ_SCHEMA_RES         0x20
5719
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5720

5721
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5722

5723
typedef struct {
5724
  int32_t        flags;
5725
  SVCreateTbReq* pCreateTbReq;
5726
  int64_t        suid;
5727
  int64_t        uid;
5728
  int32_t        sver;
5729
  union {
5730
    SArray* aRowP;
5731
    SArray* aCol;
5732
  };
5733
  int64_t   ctimeMs;
5734
  SBlobSet* pBlobSet;
5735
} SSubmitTbData;
5736

5737
typedef struct {
5738
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5739
  SArray* aSubmitBlobData;
5740
  bool    raw;
5741
} SSubmitReq2;
5742

5743
typedef struct {
5744
  SMsgHead header;
5745
  int64_t  version;
5746
  char     data[];  // SSubmitReq2
5747
} SSubmitReq2Msg;
5748

5749
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5750
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5751
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5752
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5753
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5754

5755
typedef struct {
5756
  int32_t affectedRows;
5757
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5758
} SSubmitRsp2;
5759

5760
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5761
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5762
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5763

5764
#define TSDB_MSG_FLG_ENCODE 0x1
5765
#define TSDB_MSG_FLG_DECODE 0x2
5766
#define TSDB_MSG_FLG_CMPT   0x3
5767

5768
typedef struct {
5769
  union {
5770
    struct {
5771
      void*   msgStr;
5772
      int32_t msgLen;
5773
      int64_t ver;
5774
    };
5775
    void* pDataBlock;
5776
  };
5777
} SPackedData;
5778

5779
typedef struct {
5780
  char     fullname[TSDB_VIEW_FNAME_LEN];
5781
  char     name[TSDB_VIEW_NAME_LEN];
5782
  char     dbFName[TSDB_DB_FNAME_LEN];
5783
  char*    querySql;
5784
  char*    sql;
5785
  int8_t   orReplace;
5786
  int8_t   precision;
5787
  int32_t  numOfCols;
5788
  SSchema* pSchema;
5789
} SCMCreateViewReq;
5790

5791
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5792
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5793
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5794

5795
typedef struct {
5796
  char   fullname[TSDB_VIEW_FNAME_LEN];
5797
  char   name[TSDB_VIEW_NAME_LEN];
5798
  char   dbFName[TSDB_DB_FNAME_LEN];
5799
  char*  sql;
5800
  int8_t igNotExists;
5801
} SCMDropViewReq;
5802

5803
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5804
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5805
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5806

5807
typedef struct {
5808
  char fullname[TSDB_VIEW_FNAME_LEN];
5809
} SViewMetaReq;
5810
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5811
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5812

5813
typedef struct {
5814
  char     name[TSDB_VIEW_NAME_LEN];
5815
  char     dbFName[TSDB_DB_FNAME_LEN];
5816
  char*    createUser;
5817
  int64_t  ownerId;
5818
  uint64_t dbId;
5819
  uint64_t viewId;
5820
  char*    querySql;
5821
  int8_t   precision;
5822
  int8_t   type;
5823
  int32_t  version;
5824
  int32_t  numOfCols;
5825
  SSchema* pSchema;
5826
} SViewMetaRsp;
5827
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5828
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5829
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5830
typedef struct {
5831
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5832
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5833
} STableTSMAInfoReq;
5834

5835
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5836
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5837

5838
typedef struct {
5839
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5840
  union {
5841
    uint8_t flags;
5842
    struct {
5843
      uint8_t withColName : 1;
5844
      uint8_t reserved : 7;
5845
    };
5846
  };
5847

5848
} SRsmaInfoReq;
5849

5850
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5851
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5852

5853
typedef struct {
5854
  int32_t  funcId;
5855
  col_id_t colId;
5856
} STableTSMAFuncInfo;
5857

5858
typedef struct {
5859
  char     name[TSDB_TABLE_NAME_LEN];
5860
  uint64_t tsmaId;
5861
  char     targetTb[TSDB_TABLE_NAME_LEN];
5862
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5863
  char     tb[TSDB_TABLE_NAME_LEN];
5864
  char     dbFName[TSDB_DB_FNAME_LEN];
5865
  uint64_t suid;
5866
  uint64_t destTbUid;
5867
  uint64_t dbId;
5868
  int32_t  version;
5869
  int64_t  interval;
5870
  int8_t   unit;
5871
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5872
  SArray*  pTags;      // SArray<SSchema>
5873
  SArray*  pUsedCols;  // SArray<SSchema>
5874
  char*    ast;
5875

5876
  int64_t streamUid;
5877
  int64_t reqTs;
5878
  int64_t rspTs;
5879
  int64_t delayDuration;  // ms
5880
  bool    fillHistoryFinished;
5881

5882
  void* streamAddr;  // for stream task, the address of the stream task
5883
} STableTSMAInfo;
5884

5885
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5886
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5887
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5888
void    tFreeTableTSMAInfo(void* p);
5889
void    tFreeAndClearTableTSMAInfo(void* p);
5890
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5891

5892
#define STSMAHbRsp            STableTSMAInfoRsp
5893
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5894
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5895
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5896

5897
typedef struct SDropCtbWithTsmaSingleVgReq {
5898
  SVgroupInfo vgInfo;
5899
  SArray*     pTbs;  // SVDropTbReq
5900
} SMDropTbReqsOnSingleVg;
5901

5902
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5903
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5904
void    tFreeSMDropTbReqOnSingleVg(void* p);
5905

5906
typedef struct SDropTbsReq {
5907
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5908
} SMDropTbsReq;
5909

5910
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5911
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5912
void    tFreeSMDropTbsReq(void*);
5913

5914
typedef struct SVFetchTtlExpiredTbsRsp {
5915
  SArray* pExpiredTbs;  // SVDropTbReq
5916
  int32_t vgId;
5917
} SVFetchTtlExpiredTbsRsp;
5918

5919
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5920
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5921

5922
void tFreeFetchTtlExpiredTbsRsp(void* p);
5923

5924
void setDefaultOptionsForField(SFieldWithOptions* field);
5925
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5926

5927
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5928
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5929

5930
typedef struct {
5931
  char    id[TSDB_INSTANCE_ID_LEN];
5932
  char    type[TSDB_INSTANCE_TYPE_LEN];
5933
  char    desc[TSDB_INSTANCE_DESC_LEN];
5934
  int32_t expire;
5935
} SInstanceRegisterReq;
5936

5937
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5938
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5939

5940
typedef struct {
5941
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5942
} SInstanceListReq;
5943

5944
typedef struct {
5945
  int32_t count;
5946
  char**  ids;  // Array of instance IDs
5947
} SInstanceListRsp;
5948

5949
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5950
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5951
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5952
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5953

5954
#ifdef USE_MOUNT
5955
typedef struct {
5956
  char     mountName[TSDB_MOUNT_NAME_LEN];
5957
  int8_t   ignoreExist;
5958
  int16_t  nMounts;
5959
  int32_t* dnodeIds;
5960
  char**   mountPaths;
5961
  int32_t  sqlLen;
5962
  char*    sql;
5963
} SCreateMountReq;
5964

5965
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5966
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5967
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5968

5969
typedef struct {
5970
  char    mountName[TSDB_MOUNT_NAME_LEN];
5971
  int8_t  ignoreNotExists;
5972
  int32_t sqlLen;
5973
  char*   sql;
5974
} SDropMountReq;
5975

5976
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5977
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5978
void    tFreeSDropMountReq(SDropMountReq* pReq);
5979

5980
typedef struct {
5981
  char     mountName[TSDB_MOUNT_NAME_LEN];
5982
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5983
  int64_t  mountUid;
5984
  int32_t  dnodeId;
5985
  uint32_t valLen;
5986
  int8_t   ignoreExist;
5987
  void*    pVal;
5988
} SRetrieveMountPathReq;
5989

5990
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5991
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5992

5993
typedef struct {
5994
  // path
5995
  int32_t diskPrimary;
5996
  // vgInfo
5997
  int32_t  vgId;
5998
  int32_t  cacheLastSize;
5999
  int32_t  szPage;
6000
  int32_t  szCache;
6001
  uint64_t szBuf;
6002
  int8_t   cacheLast;
6003
  int8_t   standby;
6004
  int8_t   hashMethod;
6005
  uint32_t hashBegin;
6006
  uint32_t hashEnd;
6007
  int16_t  hashPrefix;
6008
  int16_t  hashSuffix;
6009
  int16_t  sttTrigger;
6010
  // syncInfo
6011
  int32_t replications;
6012
  // tsdbInfo
6013
  int8_t  precision;
6014
  int8_t  compression;
6015
  int8_t  slLevel;
6016
  int32_t daysPerFile;
6017
  int32_t keep0;
6018
  int32_t keep1;
6019
  int32_t keep2;
6020
  int32_t keepTimeOffset;
6021
  int32_t minRows;
6022
  int32_t maxRows;
6023
  int32_t tsdbPageSize;
6024
  int32_t ssChunkSize;
6025
  int32_t ssKeepLocal;
6026
  int8_t  ssCompact;
6027
  // walInfo
6028
  int32_t walFsyncPeriod;      // millisecond
6029
  int32_t walRetentionPeriod;  // secs
6030
  int32_t walRollPeriod;       // secs
6031
  int64_t walRetentionSize;
6032
  int64_t walSegSize;
6033
  int32_t walLevel;
6034
  // encryptInfo
6035
  int32_t encryptAlgorithm;
6036
  // SVState
6037
  int64_t committed;
6038
  int64_t commitID;
6039
  int64_t commitTerm;
6040
  // stats
6041
  int64_t numOfSTables;
6042
  int64_t numOfCTables;
6043
  int64_t numOfNTables;
6044
  // dbInfo
6045
  uint64_t dbId;
6046
} SMountVgInfo;
6047

6048
typedef struct {
6049
  SMCreateStbReq req;
6050
  SArray*        pColExts;  // element: column id
6051
  SArray*        pTagExts;  // element: tag id
6052
} SMountStbInfo;
6053

6054
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6055
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6056

6057
typedef struct {
6058
  char     dbName[TSDB_DB_FNAME_LEN];
6059
  uint64_t dbId;
6060
  SArray*  pVgs;   // SMountVgInfo
6061
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6062
} SMountDbInfo;
6063

6064
typedef struct {
6065
  // common fields
6066
  char     mountName[TSDB_MOUNT_NAME_LEN];
6067
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6068
  int8_t   ignoreExist;
6069
  int64_t  mountUid;
6070
  int64_t  clusterId;
6071
  int32_t  dnodeId;
6072
  uint32_t valLen;
6073
  void*    pVal;
6074

6075
  // response fields
6076
  SArray* pDbs;  // SMountDbInfo
6077

6078
  // memory fields, no serialized
6079
  SArray*   pDisks[TFS_MAX_TIERS];
6080
  TdFilePtr pFile;
6081
} SMountInfo;
6082

6083
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6084
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6085
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6086

6087
typedef struct {
6088
  SCreateVnodeReq createReq;
6089
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6090
  char            mountName[TSDB_MOUNT_NAME_LEN];
6091
  int64_t         mountId;
6092
  int32_t         diskPrimary;
6093
  int32_t         mountVgId;
6094
  int64_t         committed;
6095
  int64_t         commitID;
6096
  int64_t         commitTerm;
6097
  int64_t         numOfSTables;
6098
  int64_t         numOfCTables;
6099
  int64_t         numOfNTables;
6100
} SMountVnodeReq;
6101

6102
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6103
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6104
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6105

6106
#endif  // USE_MOUNT
6107

6108
#pragma pack(pop)
6109

6110
typedef struct {
6111
  char        db[TSDB_DB_FNAME_LEN];
6112
  STimeWindow timeRange;
6113
  int32_t     sqlLen;
6114
  char*       sql;
6115
  SArray*     vgroupIds;
6116
} SScanDbReq;
6117

6118
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6119
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6120
void    tFreeSScanDbReq(SScanDbReq* pReq);
6121

6122
typedef struct {
6123
  int32_t scanId;
6124
  int8_t  bAccepted;
6125
} SScanDbRsp;
6126

6127
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6128
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6129

6130
typedef struct {
6131
  int32_t scanId;
6132
  int32_t sqlLen;
6133
  char*   sql;
6134
} SKillScanReq;
6135

6136
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6137
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6138
void    tFreeSKillScanReq(SKillScanReq* pReq);
6139

6140
typedef struct {
6141
  int32_t scanId;
6142
  int32_t vgId;
6143
  int32_t dnodeId;
6144
} SVKillScanReq;
6145

6146
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6147
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6148

6149
typedef struct {
6150
  int32_t scanId;
6151
  int32_t vgId;
6152
  int32_t dnodeId;
6153
  int32_t numberFileset;
6154
  int32_t finished;
6155
  int32_t progress;
6156
  int64_t remainingTime;
6157
} SQueryScanProgressRsp;
6158

6159
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6160
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6161

6162
typedef struct {
6163
  int32_t scanId;
6164
  int32_t vgId;
6165
  int32_t dnodeId;
6166
} SQueryScanProgressReq;
6167

6168
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6169
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6170

6171
typedef struct {
6172
  int64_t     dbUid;
6173
  char        db[TSDB_DB_FNAME_LEN];
6174
  int64_t     scanStartTime;
6175
  STimeWindow tw;
6176
  int32_t     scanId;
6177
} SScanVnodeReq;
6178

6179
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6180
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6181

6182
#ifdef __cplusplus
6183
}
6184
#endif
6185

6186
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6187
 
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