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

taosdata / TDengine / #4907

30 Dec 2025 10:52AM UTC coverage: 65.541% (+0.03%) from 65.514%
#4907

push

travis-ci

web-flow
enh: drop multi-stream (#33962)

60 of 106 new or added lines in 4 files covered. (56.6%)

808 existing lines in 106 files now uncovered.

193920 of 295877 relevant lines covered (65.54%)

118520209.34 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;
68✔
106
}
107

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

110
static inline bool vnodeIsMsgBlock(tmsg_t type) {
883,027,807✔
111
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
843,405,353✔
112
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,726,433,160✔
113
         (type == TDMT_SYNC_CONFIG_CHANGE);
114
}
115

116
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,008,700,084✔
117
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,008,700,084✔
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) {
313,767✔
940
    return TSDB_CODE_INVALID_PARA;
×
941
  }
942
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
313,767✔
943
  if (pRef->pColRef == NULL) {
313,767✔
944
    return terrno;
×
945
  }
946
  pRef->nCols = nCols;
313,767✔
947
  for (int32_t i = 0; i < nCols; i++) {
3,972,102✔
948
    pRef->pColRef[i].hasRef = false;
3,658,335✔
949
    pRef->pColRef[i].id = (col_id_t)(i + 1);
3,658,335✔
950
  }
951
  return 0;
313,767✔
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)) {
3,574,935✔
980
    return TSDB_CODE_INVALID_PARA;
×
981
  }
982
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
3,574,935✔
983
  if (pCmpr->pColCmpr == NULL) {
3,574,935✔
984
    return terrno;
×
985
  }
986
  pCmpr->nCols = nCols;
3,574,935✔
987
  return 0;
3,574,935✔
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;
680,336,212✔
1016

1017
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
680,252,115✔
1018
  if (pSW == NULL) {
680,291,109✔
1019
    return NULL;
×
1020
  }
1021
  pSW->nCols = pSchemaWrapper->nCols;
680,291,109✔
1022
  pSW->version = pSchemaWrapper->version;
680,225,200✔
1023
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
680,252,535✔
1024
  if (pSW->pSchema == NULL) {
680,076,392✔
1025
    taosMemoryFree(pSW);
×
1026
    return NULL;
×
1027
  }
1028

1029
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
680,150,975✔
1030
  return pSW;
680,306,948✔
1031
}
1032

1033
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
304,457,349✔
1034
  if (pSchemaWrapper) {
1,857,269,046✔
1035
    taosMemoryFree(pSchemaWrapper->pSchema);
1,049,182,968✔
1036
    if (pSchemaWrapper->pRsma) {
1,049,067,435✔
1037
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,172✔
1038
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,172✔
1039
    }
1040
    taosMemoryFree(pSchemaWrapper);
1,049,011,083✔
1041
  }
1042
}
1,820,975,662✔
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) {
4,096,498✔
1055
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
4,096,498✔
1056
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
4,096,498✔
1057
  }
1058
}
4,096,498✔
1059

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

1070
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1071
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,101,457✔
1072
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,101,133✔
1073
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,101,133✔
1074
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,101,133✔
1075
  buf = taosDecodeStringTo(buf, pSchema->name);
1,101,133✔
1076
  return (void*)buf;
1,101,133✔
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));
19,904,796✔
1113
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
19,904,796✔
1114
  if (pColRef->hasRef) {
9,952,398✔
1115
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
10,753,008✔
1116
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
10,753,008✔
1117
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
10,753,008✔
1118
  }
1119
  return 0;
9,952,398✔
1120
}
1121

1122
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1123
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
12,467,138✔
1124
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
12,467,138✔
1125
  if (pColRef->hasRef) {
6,233,569✔
1126
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
3,531,180✔
1127
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
3,531,180✔
1128
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
3,531,180✔
1129
  }
1130

1131
  return 0;
6,233,569✔
1132
}
1133

1134
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1135
  int32_t tlen = 0;
397,268✔
1136
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
397,268✔
1137
  tlen += taosEncodeVariantI32(buf, pSW->version);
397,268✔
1138
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,799,812✔
1139
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
4,805,088✔
1140
  }
1141
  return tlen;
397,268✔
1142
}
1143

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

1153
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,275,819✔
1154
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,202,266✔
1155
    }
1156
  } else {
1157
    pSW->pSchema = NULL;
×
1158
  }
1159
  return (void*)buf;
174,686✔
1160
}
1161

1162
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1163
  if (pSW == NULL) {
478,968,640✔
1164
    return TSDB_CODE_INVALID_PARA;
×
1165
  }
1166
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
958,037,913✔
1167
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
958,049,618✔
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;
479,107,865✔
1172
}
1173

1174
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1175
  if (pSW == NULL) {
155,941,028✔
1176
    return TSDB_CODE_INVALID_PARA;
×
1177
  }
1178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
311,864,943✔
1179
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
311,855,126✔
1180

1181
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
155,931,211✔
1182
  if (pSW->pSchema == NULL) {
155,911,402✔
1183
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1184
  }
1185
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,492,313,604✔
1186
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1187
  }
1188

1189
  return 0;
155,959,222✔
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,629,573,682✔
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,629,993,199✔
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
  int8_t  ignoreNotExists;
1364
  int32_t sqlLen;
1365
  char*   sql;
1366
} SDropUserReq, SDropAcctReq;
1367

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1517

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

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

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

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

1537

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

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

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

1553
  int8_t negIpRanges;
1554
  int8_t negTimeRanges;
1555

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

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

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

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

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

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

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

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

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

1613
typedef struct {
1614
  int8_t alterType;
1615

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1741
typedef struct {
1742
  char user[TSDB_USER_LEN];
1743
} SGetUserAuthReq;
1744

1745
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1746
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1747

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

1769
  SUserSessCfg sessCfg;
1770
  int64_t      timeWhiteListVer;
1771
} SGetUserAuthRsp;
1772

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

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

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

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

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

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

1809

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

1816
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1817
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1818

1819

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

1826
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1827
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1828

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

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

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

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

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

1858

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

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

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

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

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

1893
typedef struct STimeWindow {
1894
  TSKEY skey;
1895
  TSKEY ekey;
1896
} STimeWindow;
1897

1898
typedef struct SQueryHint {
1899
  bool batchScan;
1900
} SQueryHint;
1901

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

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

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

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

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

1936
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1937

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

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

1969
typedef STableCfg STableCfgRsp;
1970

1971
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1972
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1973

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

1978
typedef struct {
1979
  SMsgHead header;
1980
  tb_uid_t suid;
1981
} SVSubTablesReq;
1982

1983
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1984
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1985

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

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

1995
typedef struct {
1996
  SMsgHead header;
1997
  tb_uid_t suid;
1998
} SVStbRefDbsReq;
1999

2000
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2001
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2002

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

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

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

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

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

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

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

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

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

2122
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2123
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2124

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

2130
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2131
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2132

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

2141
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2142
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2143

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

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

2170
typedef struct {
2171
  char db[TSDB_DB_FNAME_LEN];
2172
} SDbCfgReq;
2173

2174
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2175
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2176

2177
typedef struct {
2178
  char db[TSDB_DB_FNAME_LEN];
2179
} SSsMigrateDbReq;
2180

2181
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2182
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2183

2184
typedef struct {
2185
  int32_t ssMigrateId;
2186
  bool    bAccepted;
2187
} SSsMigrateDbRsp;
2188

2189
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2190
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2191

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

2197
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2198
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2199

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

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

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

2218
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2219
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2220

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

2228
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2229
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2230

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

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

2249
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2250
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2251

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

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

2263
// Request for TDMT_VND_KILL_SSMIGRATE
2264
typedef struct {
2265
  int32_t ssMigrateId;
2266
} SVnodeKillSsMigrateReq;
2267

2268
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2269
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2270

2271
typedef struct {
2272
  int32_t vgId;
2273
  int64_t keepVersion;
2274
} SMndSetVgroupKeepVersionReq;
2275

2276
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2277
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2278

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

2286
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2287
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2288

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

2346
typedef SDbCfgRsp SDbCfgInfo;
2347

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

2354
typedef struct {
2355
  int32_t rowNum;
2356
} SQnodeListReq;
2357

2358
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2359
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2360

2361
typedef struct {
2362
  int32_t rowNum;
2363
} SDnodeListReq;
2364

2365
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2366

2367
typedef struct {
2368
  int32_t useless;  // useless
2369
} SServerVerReq;
2370

2371
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2372
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2373

2374
typedef struct {
2375
  char ver[TSDB_VERSION_LEN];
2376
} SServerVerRsp;
2377

2378
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2379
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2380

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

2386
typedef struct {
2387
  SQueryNodeAddr addr;
2388
  uint64_t       load;
2389
} SQueryNodeLoad;
2390

2391
typedef struct {
2392
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2393
} SQnodeListRsp;
2394

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

2399

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

2411

2412

2413
typedef struct SDNodeAddr {
2414
  int32_t nodeId;  // dnodeId
2415
  SEpSet  epSet;
2416
} SDNodeAddr;
2417

2418
typedef struct {
2419
  SArray* dnodeList;  // SArray<SDNodeAddr>
2420
} SDnodeListRsp;
2421

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

2426
typedef struct {
2427
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2428
} STableTSMAInfoRsp;
2429

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

2439
typedef struct {
2440
  SArray* pArray;  // Array of SDbHbRsp
2441
} SDbHbBatchRsp;
2442

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

2447
typedef struct {
2448
  SArray* pArray;  // Array of SGetUserAuthRsp
2449
} SUserAuthBatchRsp;
2450

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

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

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

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

2478
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2479
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2480

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

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

2494
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2495
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2496

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

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

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

2521
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2522
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2523

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

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

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

2548
typedef struct {
2549
  int32_t funcVersion;
2550
  int64_t funcCreatedTime;
2551
} SFuncExtraInfo;
2552

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

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

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

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

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

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

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

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

2652
typedef struct {
2653
  int32_t vgId;
2654
  int64_t nTimeSeries;
2655
} SVnodeLoadLite;
2656

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

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

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

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

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

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

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

2726
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2727
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2728

2729
typedef enum {
2730
  MONITOR_TYPE_COUNTER = 0,
2731
  MONITOR_TYPE_SLOW_LOG = 1,
2732
} MONITOR_TYPE;
2733

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

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

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

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

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

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

2774
typedef struct {
2775
  int32_t dnodeId;
2776
  int64_t clusterId;
2777
} SDnodeCfg;
2778

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

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

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

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

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

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

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

2827
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2828
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2829

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

2847
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2848
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2849

2850
typedef struct {
2851
  int32_t reserved;
2852
} SMTimerReq;
2853

2854
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2855
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2856

2857
typedef struct SOrphanTask {
2858
  int64_t streamId;
2859
  int32_t taskId;
2860
  int32_t nodeId;
2861
} SOrphanTask;
2862

2863
typedef struct SMStreamDropOrphanMsg {
2864
  SArray* pList;  // SArray<SOrphanTask>
2865
} SMStreamDropOrphanMsg;
2866

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

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

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

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

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

2943
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2944
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2945

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

2959
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2960
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2961

2962
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2963
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2964

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

2973
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2974
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2975

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

2984
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2985
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2986

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

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

3012
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3013
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3014

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

3024
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3025
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3026

3027
typedef SVKillCompactReq SVKillRetentionReq;
3028

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

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

3050
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3051

3052
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3053
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3054

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

3081
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3082
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3083

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

3098
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3099
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3100

3101
typedef struct {
3102
  int32_t vgId;
3103
  int8_t  disable;
3104
} SDisableVnodeWriteReq;
3105

3106
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3107
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3108

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

3118
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3119
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3120

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

3131
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3132
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3133

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

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

3154
typedef struct {
3155
  int32_t     numOfVgroups;
3156
  SVgroupInfo vgroups[];
3157
} SVgroupsInfo;
3158

3159
typedef struct {
3160
  STableMetaRsp* pMeta;
3161
} SMAlterStbRsp;
3162

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

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

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

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

3181
typedef struct {
3182
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3183
} SViewHbRsp;
3184

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

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

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

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

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

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

3224
typedef struct {
3225
  SArray* variables;  // SArray<SVariablesInfo>
3226
} SShowVariablesRsp;
3227

3228
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3229
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3230

3231
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3232

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

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

3249
typedef struct {
3250
  int64_t       showId;
3251
  STableMetaRsp tableMeta;
3252
} SShowRsp, SVShowTablesRsp;
3253

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

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

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

3274
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3275
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3276

3277
#define RETRIEVE_TABLE_RSP_VERSION         0
3278
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3279
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3280

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

3300
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3301

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

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

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

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

3336
typedef struct {
3337
  int32_t           numOfPlans;
3338
  SExplainExecInfo* subplanInfo;
3339
} SExplainRsp;
3340

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3449
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3450
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3451

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

3459
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3460
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3461

3462
typedef struct {
3463
  int32_t nodeId;
3464
  SEpSet  epSet;
3465
} SNodeEpSet;
3466

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

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

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

3489
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3490
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3491

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

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

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

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

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

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

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

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

3537
typedef struct {
3538
  int32_t vgId;
3539
  int32_t hbSeq;
3540
} SVArbHbReqMember;
3541

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

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

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

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

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

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

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

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

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

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

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

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

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

3613
typedef struct {
3614
  int32_t dnodeId;
3615
  char*   token;
3616
} SMArbUpdateGroupMember;
3617

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

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

3636
typedef struct {
3637
  SArray* updateArray;  // SMArbUpdateGroup
3638
} SMArbUpdateGroupBatchReq;
3639

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

3644
typedef struct {
3645
  char queryStrId[TSDB_QUERY_ID_LEN];
3646
} SKillQueryReq;
3647

3648
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3649
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3650

3651
typedef struct {
3652
  uint32_t connId;
3653
} SKillConnReq;
3654

3655
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3656
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3657

3658
typedef struct {
3659
  int32_t transId;
3660
} SKillTransReq;
3661

3662
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3663
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3664

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

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

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

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

3689
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3690
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3691

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

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

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

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

3717
typedef struct {
3718
  int32_t vgId;
3719
} SForceBecomeFollowerReq;
3720

3721
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3722
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3723

3724
typedef struct {
3725
  int32_t vgId;
3726
  bool    force;
3727
} SSplitVgroupReq;
3728

3729
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3730
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3731

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

3740
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3741
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3742

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

3748
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3749
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3750

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

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

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

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

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

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

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

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

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

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

3838
typedef struct SColIdPair {
3839
  col_id_t  vtbColId;
3840
  col_id_t  orgColId;
3841
  SDataType type;
3842
} SColIdPair;
3843

3844
typedef struct SColIdSlotIdPair {
3845
  int32_t  vtbSlotId;
3846
  col_id_t orgColId;
3847
} SColIdSlotIdPair;
3848

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

3855
void destroySOrgTbInfo(void *info);
3856

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

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

3875
typedef struct STagScanOperatorParam {
3876
  tb_uid_t vcUid;
3877
} STagScanOperatorParam;
3878

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

3886
typedef struct SMergeOperatorParam {
3887
  int32_t         winNum;
3888
} SMergeOperatorParam;
3889

3890
typedef struct SAggOperatorParam {
3891
  bool            needCleanRes;
3892
} SAggOperatorParam;
3893

3894
typedef struct SExternalWindowOperatorParam {
3895
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3896
} SExternalWindowOperatorParam;
3897

3898
typedef struct SDynQueryCtrlOperatorParam {
3899
  STimeWindow    window;
3900
} SDynQueryCtrlOperatorParam;
3901

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

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

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

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

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

3942
typedef struct {
3943
  uint64_t queryId;
3944
  uint64_t taskId;
3945
  int8_t   action;
3946
} STaskAction;
3947

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

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

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

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

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

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

3983
typedef struct {
3984
  int32_t code;
3985
} STaskCancelRsp;
3986

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

3997
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3998
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3999

4000
typedef enum {
4001
  TASK_NOTIFY_FINISHED = 1,
4002
} ETaskNotifyType;
4003

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

4015
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4016
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4017

4018
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4019
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4020

4021
typedef struct {
4022
  int32_t code;
4023
} STaskDropRsp;
4024

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

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

4039
typedef struct SVgroupVer {
4040
  int32_t vgId;
4041
  int64_t ver;
4042
} SVgroupVer;
4043

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

4060
enum {
4061
  TOPIC_SUB_TYPE__DB = 1,
4062
  TOPIC_SUB_TYPE__TABLE,
4063
  TOPIC_SUB_TYPE__COLUMN,
4064
};
4065

4066
#define DEFAULT_MAX_POLL_INTERVAL  300000
4067
#define DEFAULT_SESSION_TIMEOUT    12000
4068
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4069
#define DEFAULT_MIN_POLL_ROWS      4096
4070

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

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

4087
typedef struct {
4088
  int64_t consumerId;
4089
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4090

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

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

4109
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4110
  int32_t tlen = 0;
626,444✔
4111
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
626,444✔
4112
  tlen += taosEncodeString(buf, pReq->cgroup);
626,444✔
4113
  tlen += taosEncodeString(buf, pReq->clientId);
626,444✔
4114

4115
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
626,444✔
4116
  tlen += taosEncodeFixedI32(buf, topicNum);
626,444✔
4117

4118
  for (int32_t i = 0; i < topicNum; i++) {
874,264✔
4119
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
495,640✔
4120
  }
4121

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

4133
  return tlen;
626,444✔
4134
}
4135

4136
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4137
  void* start = buf;
303,830✔
4138
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
303,830✔
4139
  buf = taosDecodeStringTo(buf, pReq->cgroup);
303,830✔
4140
  buf = taosDecodeStringTo(buf, pReq->clientId);
303,830✔
4141

4142
  int32_t topicNum = 0;
303,830✔
4143
  buf = taosDecodeFixedI32(buf, &topicNum);
303,830✔
4144

4145
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
303,830✔
4146
  if (pReq->topicNames == NULL) {
303,830✔
4147
    return terrno;
×
4148
  }
4149
  for (int32_t i = 0; i < topicNum; i++) {
443,166✔
4150
    char* name = NULL;
139,336✔
4151
    buf = taosDecodeString(buf, &name);
139,336✔
4152
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
278,672✔
4153
      return terrno;
×
4154
    }
4155
  }
4156

4157
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
303,830✔
4158
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
303,830✔
4159
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
303,830✔
4160
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
303,830✔
4161
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
303,830✔
4162
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
303,830✔
4163
  if ((char*)buf - (char*)start < len) {
303,830✔
4164
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
303,830✔
4165
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
303,830✔
4166
    buf = taosDecodeStringTo(buf, pReq->user);
303,830✔
4167
    buf = taosDecodeStringTo(buf, pReq->fqdn);
607,660✔
4168
  } else {
4169
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4170
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4171
  }
4172

4173
  return 0;
303,830✔
4174
}
4175

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

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

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

4210
typedef struct {
4211
  int64_t status;
4212
} SMVSubscribeRsp;
4213

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

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

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

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

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

4244
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4245
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4246

4247
typedef struct {
4248
  int8_t reserved;
4249
} SMDropCgroupRsp;
4250

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

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

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

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

4284
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4285
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4286

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

4306
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4307
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4308

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

4315
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4316
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4317

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

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

4355
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4356
  if (NULL == req) {
2,036,824,868✔
4357
    return;
1,978,856,707✔
4358
  }
4359

4360
  taosMemoryFreeClear(req->sql);
57,968,161✔
4361
  taosMemoryFreeClear(req->name);
57,968,464✔
4362
  taosMemoryFreeClear(req->comment);
57,970,637✔
4363
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
57,965,939✔
4364
    taosMemoryFreeClear(req->ctb.pTag);
54,170,205✔
4365
    taosMemoryFreeClear(req->ctb.stbName);
54,167,444✔
4366
    taosArrayDestroy(req->ctb.tagName);
54,178,310✔
4367
    req->ctb.tagName = NULL;
54,167,283✔
4368
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
3,792,299✔
4369
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
3,792,299✔
4370
  }
4371
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
57,961,099✔
4372
  taosMemoryFreeClear(req->pExtSchemas);
57,956,530✔
4373
  taosMemoryFreeClear(req->colRef.pColRef);
57,958,005✔
4374
}
4375

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

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

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

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

4398
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4399
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4400

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

4409
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4410
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4411

4412
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4413
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4414

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

4424
typedef struct {
4425
  int32_t code;
4426
} SVDropTbRsp;
4427

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

4436
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4437
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4438

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

4447
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4448
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4449

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

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

4505
typedef struct {
4506
  int32_t        code;
4507
  STableMetaRsp* pMeta;
4508
} SVAlterTbRsp;
4509

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

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

4528
typedef struct {
4529
  SMsgHead head;
4530
} SUpdateTagValRsp;
4531

4532
typedef struct {
4533
  SMsgHead head;
4534
} SVShowTablesReq;
4535

4536
typedef struct {
4537
  SMsgHead head;
4538
  int32_t  id;
4539
} SVShowTablesFetchReq;
4540

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

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

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

4563
typedef struct {
4564
  int64_t tscRid;
4565
  int8_t  connType;
4566
} SClientHbKey;
4567

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

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

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

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

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

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

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

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

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

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

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

4665
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
100,594,160✔
4666

4667
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4668
  void* pIter = taosHashIterate(info, NULL);
70,718,039✔
4669
  while (pIter != NULL) {
161,761,966✔
4670
    SKv* kv = (SKv*)pIter;
91,044,151✔
4671
    taosMemoryFreeClear(kv->value);
91,044,151✔
4672
    pIter = taosHashIterate(info, pIter);
91,044,151✔
4673
  }
4674
}
70,717,815✔
4675

4676
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
44,117,563✔
4677
  SQueryDesc* desc = (SQueryDesc*)pDesc;
44,117,563✔
4678
  if (desc->subDesc) {
44,117,563✔
4679
    taosArrayDestroy(desc->subDesc);
31,292,121✔
4680
    desc->subDesc = NULL;
31,290,690✔
4681
  }
4682
}
44,117,584✔
4683

4684
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
80,829,519✔
4685
  SClientHbReq* req = (SClientHbReq*)pReq;
83,374,436✔
4686
  if (req->query) {
83,374,436✔
4687
    if (req->query->queryDesc) {
80,829,519✔
4688
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
38,283,212✔
4689
    }
4690
    taosMemoryFreeClear(req->query);
80,829,519✔
4691
  }
4692

4693
  if (req->info) {
83,375,807✔
4694
    tFreeReqKvHash(req->info);
70,717,449✔
4695
    taosHashCleanup(req->info);
70,717,815✔
4696
    req->info = NULL;
70,717,831✔
4697
  }
4698
}
40,975,054✔
4699

4700
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4701
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4702

4703
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4704
  if (pReq == NULL) return;
35,709,735✔
4705
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
35,709,735✔
4706
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
35,709,735✔
4707
  taosMemoryFree(pReq);
35,709,735✔
4708
}
4709

4710
static FORCE_INLINE void tFreeClientKv(void* pKv) {
34,014,443✔
4711
  SKv* kv = (SKv*)pKv;
34,014,443✔
4712
  if (kv) {
34,014,443✔
4713
    taosMemoryFreeClear(kv->value);
34,014,443✔
4714
  }
4715
}
34,014,443✔
4716

4717
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
80,563,644✔
4718
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
80,563,644✔
4719
  if (rsp->query) {
80,563,644✔
4720
    taosArrayDestroy(rsp->query->pQnodeList);
80,562,512✔
4721
    taosMemoryFreeClear(rsp->query);
80,559,338✔
4722
  }
4723
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
80,566,787✔
4724
}
42,138,259✔
4725

4726
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4727
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
65,125,133✔
4728
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
65,125,133✔
4729
}
65,127,418✔
4730

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

4735
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4736
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
253,448,456✔
4737
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
253,449,108✔
4738
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
253,449,108✔
4739
  return 0;
126,724,258✔
4740
}
4741

4742
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4743
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
116,764,970✔
4744
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
116,764,970✔
4745
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
58,382,485✔
4746
  if (pKv->value == NULL) {
58,382,485✔
4747
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4748
  }
4749
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
58,382,485✔
4750
  return 0;
58,382,485✔
4751
}
4752

4753
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4754
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
313,785,658✔
4755
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
313,784,221✔
4756
  return 0;
156,893,775✔
4757
}
4758

4759
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4760
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
156,383,827✔
4761
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
156,386,998✔
4762
  return 0;
78,194,921✔
4763
}
4764

4765
typedef struct {
4766
  int32_t vgId;
4767
  // TODO stas
4768
} SMqReportVgInfo;
4769

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

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

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

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

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

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

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

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

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

4869
typedef struct {
4870
  int8_t reserved;
4871
} SMqVDeleteRsp;
4872

4873
typedef struct {
4874
  char**  name;
4875
  int32_t count;
4876
  int8_t igNotExists;
4877
} SMDropStreamReq;
4878

4879
typedef struct {
4880
  int8_t reserved;
4881
} SMDropStreamRsp;
4882

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

4890
typedef struct {
4891
  int8_t reserved;
4892
} SVDropStreamTaskRsp;
4893

4894
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4895
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4896
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4897

4898
typedef struct {
4899
  char*  name;
4900
  int8_t igNotExists;
4901
} SMPauseStreamReq;
4902

4903
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4904
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4905
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4906

4907
typedef struct {
4908
  char*  name;
4909
  int8_t igNotExists;
4910
  int8_t igUntreated;
4911
} SMResumeStreamReq;
4912

4913
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4914
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4915
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4916

4917
typedef struct {
4918
  char*       name;
4919
  int8_t      calcAll;
4920
  STimeWindow timeRange;
4921
} SMRecalcStreamReq;
4922

4923
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4924
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4925
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4926

4927
typedef struct SVndSetKeepVersionReq {
4928
  int64_t keepVersion;
4929
} SVndSetKeepVersionReq;
4930

4931
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4932
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4933

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

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

4960
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4961
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4962

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

4973
enum {
4974
  WITH_DATA = 0,
4975
  WITH_META = 1,
4976
  ONLY_META = 2,
4977
};
4978

4979
#define TQ_OFFSET_VERSION 1
4980

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

4997
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4998
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,334,452✔
4999
  pOffsetVal->uid = uid;
7,333,620✔
5000
  pOffsetVal->ts = ts;
7,334,452✔
5001
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,333,880✔
5002
    taosMemoryFree(pOffsetVal->primaryKey.pData);
276✔
5003
  }
5004
  pOffsetVal->primaryKey = primaryKey;
7,331,545✔
5005
}
7,331,879✔
5006

5007
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5008
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
38,815✔
5009
  pOffsetVal->uid = uid;
38,815✔
5010
}
38,815✔
5011

5012
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5013
  pOffsetVal->type = TMQ_OFFSET__LOG;
162,192,446✔
5014
  pOffsetVal->version = ver;
162,190,878✔
5015
}
162,171,039✔
5016

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

5024
typedef struct {
5025
  STqOffsetVal val;
5026
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5027
} STqOffset;
5028

5029
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5030
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5031
void    tDeleteSTqOffset(void* val);
5032

5033
typedef struct SMqVgOffset {
5034
  int64_t   consumerId;
5035
  STqOffset offset;
5036
} SMqVgOffset;
5037

5038
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5039
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5040

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

5075
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5076
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5077
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5078

5079
typedef struct {
5080
  char    name[TSDB_TABLE_FNAME_LEN];
5081
  int8_t  igNotExists;
5082
  char*   dropStreamReq;
5083
  int32_t dropStreamReqLen;
5084
} SMDropSmaReq;
5085

5086
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5087
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5088
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5089

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

5112
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5113
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5114
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5115

5116
typedef SMCreateRsmaReq SVCreateRsmaReq;
5117

5118
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5119
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5120
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5121

5122
typedef SMCreateRsmaReq SVAlterRsmaReq;
5123

5124
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5125
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5126
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5127

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

5140
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5141
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5142
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5143

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

5161
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5162
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5163
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5164

5165
typedef struct {
5166
  char   name[TSDB_TABLE_FNAME_LEN];
5167
  int8_t igNotExists;
5168
} SMDropRsmaReq;
5169

5170
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5171
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5172

5173
typedef struct {
5174
  char    name[TSDB_TABLE_NAME_LEN];
5175
  char    tbName[TSDB_TABLE_NAME_LEN];
5176
  int64_t uid;
5177
  int64_t tbUid;
5178
  int8_t  tbType;
5179
} SVDropRsmaReq;
5180

5181
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5182
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5183

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

5192
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5193
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5194

5195
typedef SMDropSmaReq SDropTagIndexReq;
5196

5197
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5198
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5199

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

5222
typedef STSma SVCreateTSmaReq;
5223

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

5230
typedef struct {
5231
  int64_t indexUid;
5232
  char    indexName[TSDB_INDEX_NAME_LEN];
5233
} SVDropTSmaReq;
5234

5235
typedef struct {
5236
  int tmp;  // TODO: to avoid compile error
5237
} SVCreateTSmaRsp, SVDropTSmaRsp;
5238

5239
#if 0
5240
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5241
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5242
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5243
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5244
#endif
5245

5246
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5247
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5248
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5249
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5250

5251
typedef struct {
5252
  int32_t number;
5253
  STSma*  tSma;
5254
} STSmaWrapper;
5255

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

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

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

5283
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5284
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5285

5286
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5287
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5288

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

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

5305
typedef struct {
5306
  int idx;
5307
} SMCreateFullTextReq;
5308

5309
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5310
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5311
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5312

5313
typedef struct {
5314
  char   name[TSDB_TABLE_FNAME_LEN];
5315
  int8_t igNotExists;
5316
} SMDropFullTextReq;
5317

5318
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5319
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5320

5321
typedef struct {
5322
  char indexFName[TSDB_INDEX_FNAME_LEN];
5323
} SUserIndexReq;
5324

5325
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5326
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5327

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

5337
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5338
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5339

5340
typedef struct {
5341
  char tbFName[TSDB_TABLE_FNAME_LEN];
5342
} STableIndexReq;
5343

5344
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5345
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5346

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

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

5368
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5369
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5370
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5371

5372
void tFreeSTableIndexInfo(void* pInfo);
5373

5374
typedef struct {
5375
  int8_t  mqMsgType;
5376
  int32_t code;
5377
  int32_t epoch;
5378
  int64_t consumerId;
5379
  int64_t walsver;
5380
  int64_t walever;
5381
} SMqRspHead;
5382

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

5401
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5402
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5403
void    tDestroySMqPollReq(SMqPollReq* pReq);
5404

5405
typedef struct {
5406
  int32_t vgId;
5407
  int64_t offset;
5408
  SEpSet  epSet;
5409
} SMqSubVgEp;
5410

5411
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5412
  int32_t tlen = 0;
2,324,796✔
5413
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,324,796✔
5414
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,324,796✔
5415
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,324,796✔
5416
  return tlen;
2,324,796✔
5417
}
5418

5419
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5420
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,165,581✔
5421
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,165,581✔
5422
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,165,581✔
5423
  return buf;
1,165,581✔
5424
}
5425

5426
typedef struct {
5427
  char           topic[TSDB_TOPIC_FNAME_LEN];
5428
  char           db[TSDB_DB_FNAME_LEN];
5429
  SArray*        vgs;  // SArray<SMqSubVgEp>
5430
} SMqSubTopicEp;
5431

5432
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5433
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5434
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5435

5436
typedef struct {
5437
  SMqRspHead   head;
5438
  STqOffsetVal rspOffset;
5439
  int16_t      resMsgType;
5440
  int32_t      metaRspLen;
5441
  void*        metaRsp;
5442
} SMqMetaRsp;
5443

5444
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5445
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5446
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5447

5448
#define MQ_DATA_RSP_VERSION 100
5449

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

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

5480
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5481
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5482
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5483
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5484
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5485

5486
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5487
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5488
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5489

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

5499
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5500
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5501
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5502
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5503

5504
typedef struct {
5505
  int32_t    code;
5506
  SArray*    topics;  // SArray<SMqSubTopicEp>
5507
} SMqAskEpRsp;
5508

5509
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5510
  int32_t tlen = 0;
15,278,344✔
5511
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5512
  int32_t sz = taosArrayGetSize(pRsp->topics);
15,278,344✔
5513
  tlen += taosEncodeFixedI32(buf, sz);
15,278,344✔
5514
  for (int32_t i = 0; i < sz; i++) {
17,192,272✔
5515
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,913,928✔
5516
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,913,928✔
5517
  }
5518
  tlen += taosEncodeFixedI32(buf, pRsp->code);
15,278,344✔
5519

5520
  return tlen;
15,277,399✔
5521
}
5522

5523
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5524
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5525
  int32_t sz;
3,829,909✔
5526
  buf = taosDecodeFixedI32(buf, &sz);
3,915,498✔
5527
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,915,498✔
5528
  if (pRsp->topics == NULL) {
3,915,498✔
UNCOV
5529
    return NULL;
×
5530
  }
5531
  for (int32_t i = 0; i < sz; i++) {
4,889,607✔
5532
    SMqSubTopicEp topicEp;
959,900✔
5533
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
974,109✔
5534
    if (buf == NULL) {
974,109✔
UNCOV
5535
      return NULL;
×
5536
    }
5537
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,948,218✔
UNCOV
5538
      return NULL;
×
5539
    }
5540
  }
5541
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,915,498✔
5542

5543
  return buf;
3,915,498✔
5544
}
5545

5546
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5547
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
14,567,019✔
5548
}
14,567,019✔
5549

5550
typedef struct {
5551
  int32_t      vgId;
5552
  STqOffsetVal offset;
5553
  int64_t      rows;
5554
  int64_t      ever;
5555
} OffsetRows;
5556

5557
typedef struct {
5558
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5559
  SArray* offsetRows;
5560
} TopicOffsetRows;
5561

5562
typedef struct {
5563
  int64_t consumerId;
5564
  int32_t epoch;
5565
  SArray* topics;
5566
  int8_t  pollFlag;
5567
} SMqHbReq;
5568

5569
typedef struct {
5570
  char   topic[TSDB_TOPIC_FNAME_LEN];
5571
  int8_t noPrivilege;
5572
} STopicPrivilege;
5573

5574
typedef struct {
5575
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5576
  int32_t debugFlag;
5577
} SMqHbRsp;
5578

5579
typedef struct {
5580
  SMsgHead head;
5581
  int64_t  consumerId;
5582
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5583
} SMqSeekReq;
5584

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

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

5608
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5609
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5610

5611
typedef struct {
5612
  int64_t affectedRows;
5613
} SVDeleteRsp;
5614

5615
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5616
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5617

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

5630
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5631
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5632

5633
typedef struct {
5634
  // int64_t uid;
5635
  char    tbname[TSDB_TABLE_NAME_LEN];
5636
  int64_t startTs;
5637
  int64_t endTs;
5638
} SSingleDeleteReq;
5639

5640
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5641
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5642

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

5650
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5651
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5652
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5653

5654
typedef struct {
5655
  int32_t msgIdx;
5656
  int32_t msgType;
5657
  int32_t msgLen;
5658
  void*   msg;
5659
} SBatchMsg;
5660

5661
typedef struct {
5662
  SMsgHead header;
5663
  SArray*  pMsgs;  // SArray<SBatchMsg>
5664
} SBatchReq;
5665

5666
typedef struct {
5667
  int32_t reqType;
5668
  int32_t msgIdx;
5669
  int32_t msgLen;
5670
  int32_t rspCode;
5671
  void*   msg;
5672
} SBatchRspMsg;
5673

5674
typedef struct {
5675
  SArray* pRsps;  // SArray<SBatchRspMsg>
5676
} SBatchRsp;
5677

5678
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5679
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5680
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
86,926,929✔
5681
  if (NULL == msg) {
86,926,929✔
UNCOV
5682
    return;
×
5683
  }
5684
  SBatchMsg* pMsg = (SBatchMsg*)msg;
86,926,929✔
5685
  taosMemoryFree(pMsg->msg);
86,926,929✔
5686
}
5687

5688
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5689
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5690

5691
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
118,691,898✔
5692
  if (NULL == p) {
118,691,898✔
UNCOV
5693
    return;
×
5694
  }
5695

5696
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
118,691,898✔
5697
  taosMemoryFree(pRsp->msg);
118,691,898✔
5698
}
5699

5700
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5701
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5702
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5703
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5704
void    tDestroySMqHbReq(SMqHbReq* pReq);
5705

5706
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5707
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5708
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5709

5710
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5711
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5712

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

5724
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5725

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

5740
typedef struct {
5741
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5742
  SArray* aSubmitBlobData;
5743
  bool    raw;
5744
} SSubmitReq2;
5745

5746
typedef struct {
5747
  SMsgHead header;
5748
  int64_t  version;
5749
  char     data[];  // SSubmitReq2
5750
} SSubmitReq2Msg;
5751

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

5758
typedef struct {
5759
  int32_t affectedRows;
5760
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5761
} SSubmitRsp2;
5762

5763
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5764
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5765
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5766

5767
#define TSDB_MSG_FLG_ENCODE 0x1
5768
#define TSDB_MSG_FLG_DECODE 0x2
5769
#define TSDB_MSG_FLG_CMPT   0x3
5770

5771
typedef struct {
5772
  union {
5773
    struct {
5774
      void*   msgStr;
5775
      int32_t msgLen;
5776
      int64_t ver;
5777
    };
5778
    void* pDataBlock;
5779
  };
5780
} SPackedData;
5781

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

5794
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5795
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5796
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5797

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

5806
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5807
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5808
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5809

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

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

5838
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5839
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5840

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

5851
} SRsmaInfoReq;
5852

5853
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5854
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5855

5856
typedef struct {
5857
  int32_t  funcId;
5858
  col_id_t colId;
5859
} STableTSMAFuncInfo;
5860

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

5879
  int64_t streamUid;
5880
  int64_t reqTs;
5881
  int64_t rspTs;
5882
  int64_t delayDuration;  // ms
5883
  bool    fillHistoryFinished;
5884

5885
  void* streamAddr;  // for stream task, the address of the stream task
5886
} STableTSMAInfo;
5887

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

5895
#define STSMAHbRsp            STableTSMAInfoRsp
5896
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5897
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5898
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5899

5900
typedef struct SDropCtbWithTsmaSingleVgReq {
5901
  SVgroupInfo vgInfo;
5902
  SArray*     pTbs;  // SVDropTbReq
5903
} SMDropTbReqsOnSingleVg;
5904

5905
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5906
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5907
void    tFreeSMDropTbReqOnSingleVg(void* p);
5908

5909
typedef struct SDropTbsReq {
5910
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5911
} SMDropTbsReq;
5912

5913
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5914
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5915
void    tFreeSMDropTbsReq(void*);
5916

5917
typedef struct SVFetchTtlExpiredTbsRsp {
5918
  SArray* pExpiredTbs;  // SVDropTbReq
5919
  int32_t vgId;
5920
} SVFetchTtlExpiredTbsRsp;
5921

5922
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5923
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5924

5925
void tFreeFetchTtlExpiredTbsRsp(void* p);
5926

5927
void setDefaultOptionsForField(SFieldWithOptions* field);
5928
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5929

5930
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5931
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5932

5933
typedef struct {
5934
  char    id[TSDB_INSTANCE_ID_LEN];
5935
  char    type[TSDB_INSTANCE_TYPE_LEN];
5936
  char    desc[TSDB_INSTANCE_DESC_LEN];
5937
  int32_t expire;
5938
} SInstanceRegisterReq;
5939

5940
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5941
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5942

5943
typedef struct {
5944
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5945
} SInstanceListReq;
5946

5947
typedef struct {
5948
  int32_t count;
5949
  char**  ids;  // Array of instance IDs
5950
} SInstanceListRsp;
5951

5952
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5953
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5954
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5955
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5956

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

5968
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5969
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5970
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5971

5972
typedef struct {
5973
  char    mountName[TSDB_MOUNT_NAME_LEN];
5974
  int8_t  ignoreNotExists;
5975
  int32_t sqlLen;
5976
  char*   sql;
5977
} SDropMountReq;
5978

5979
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5980
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5981
void    tFreeSDropMountReq(SDropMountReq* pReq);
5982

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

5993
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5994
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5995

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

6051
typedef struct {
6052
  SMCreateStbReq req;
6053
  SArray*        pColExts;  // element: column id
6054
  SArray*        pTagExts;  // element: tag id
6055
} SMountStbInfo;
6056

6057
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6058
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6059

6060
typedef struct {
6061
  char     dbName[TSDB_DB_FNAME_LEN];
6062
  uint64_t dbId;
6063
  SArray*  pVgs;   // SMountVgInfo
6064
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6065
} SMountDbInfo;
6066

6067
typedef struct {
6068
  // common fields
6069
  char     mountName[TSDB_MOUNT_NAME_LEN];
6070
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6071
  int8_t   ignoreExist;
6072
  int64_t  mountUid;
6073
  int64_t  clusterId;
6074
  int32_t  dnodeId;
6075
  uint32_t valLen;
6076
  void*    pVal;
6077

6078
  // response fields
6079
  SArray* pDbs;  // SMountDbInfo
6080

6081
  // memory fields, no serialized
6082
  SArray*   pDisks[TFS_MAX_TIERS];
6083
  TdFilePtr pFile;
6084
} SMountInfo;
6085

6086
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6087
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6088
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6089

6090
typedef struct {
6091
  SCreateVnodeReq createReq;
6092
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6093
  char            mountName[TSDB_MOUNT_NAME_LEN];
6094
  int64_t         mountId;
6095
  int32_t         diskPrimary;
6096
  int32_t         mountVgId;
6097
  int64_t         committed;
6098
  int64_t         commitID;
6099
  int64_t         commitTerm;
6100
  int64_t         numOfSTables;
6101
  int64_t         numOfCTables;
6102
  int64_t         numOfNTables;
6103
} SMountVnodeReq;
6104

6105
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6106
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6107
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6108

6109
#endif  // USE_MOUNT
6110

6111
#pragma pack(pop)
6112

6113
typedef struct {
6114
  char        db[TSDB_DB_FNAME_LEN];
6115
  STimeWindow timeRange;
6116
  int32_t     sqlLen;
6117
  char*       sql;
6118
  SArray*     vgroupIds;
6119
} SScanDbReq;
6120

6121
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6122
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6123
void    tFreeSScanDbReq(SScanDbReq* pReq);
6124

6125
typedef struct {
6126
  int32_t scanId;
6127
  int8_t  bAccepted;
6128
} SScanDbRsp;
6129

6130
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6131
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6132

6133
typedef struct {
6134
  int32_t scanId;
6135
  int32_t sqlLen;
6136
  char*   sql;
6137
} SKillScanReq;
6138

6139
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6140
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6141
void    tFreeSKillScanReq(SKillScanReq* pReq);
6142

6143
typedef struct {
6144
  int32_t scanId;
6145
  int32_t vgId;
6146
  int32_t dnodeId;
6147
} SVKillScanReq;
6148

6149
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6150
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6151

6152
typedef struct {
6153
  int32_t scanId;
6154
  int32_t vgId;
6155
  int32_t dnodeId;
6156
  int32_t numberFileset;
6157
  int32_t finished;
6158
  int32_t progress;
6159
  int64_t remainingTime;
6160
} SQueryScanProgressRsp;
6161

6162
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6163
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6164

6165
typedef struct {
6166
  int32_t scanId;
6167
  int32_t vgId;
6168
  int32_t dnodeId;
6169
} SQueryScanProgressReq;
6170

6171
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6172
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6173

6174
typedef struct {
6175
  int64_t     dbUid;
6176
  char        db[TSDB_DB_FNAME_LEN];
6177
  int64_t     scanStartTime;
6178
  STimeWindow tw;
6179
  int32_t     scanId;
6180
} SScanVnodeReq;
6181

6182
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6183
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6184

6185
#ifdef __cplusplus
6186
}
6187
#endif
6188

6189
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6190
 
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