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

taosdata / TDengine / #4912

04 Jan 2026 09:05AM UTC coverage: 64.888% (-0.1%) from 65.028%
#4912

push

travis-ci

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

1206 of 4524 new or added lines in 22 files covered. (26.66%)

5351 existing lines in 123 files now uncovered.

194856 of 300296 relevant lines covered (64.89%)

118198896.2 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

37
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
38

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
946,029,580✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
896,167,225✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,842,196,805✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

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

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

261

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

267

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

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

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

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

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

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

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

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

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

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

557
  // logic plan node
558
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
559
  QUERY_NODE_LOGIC_PLAN_JOIN,
560
  QUERY_NODE_LOGIC_PLAN_AGG,
561
  QUERY_NODE_LOGIC_PLAN_PROJECT,
562
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
563
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
564
  QUERY_NODE_LOGIC_PLAN_MERGE,
565
  QUERY_NODE_LOGIC_PLAN_WINDOW,
566
  QUERY_NODE_LOGIC_PLAN_FILL,
567
  QUERY_NODE_LOGIC_PLAN_SORT,
568
  QUERY_NODE_LOGIC_PLAN_PARTITION,
569
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
570
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
571
  QUERY_NODE_LOGIC_SUBPLAN,
572
  QUERY_NODE_LOGIC_PLAN,
573
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
574
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
575
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
576
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
577
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
578

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

669
} ENodeType;
670

671
typedef struct {
672
  int32_t     vgId;
673
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
674
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
675
  const char* dbFName;
676
  const char* tbName;
677
} SBuildTableInput;
678

679
typedef struct {
680
  char    db[TSDB_DB_FNAME_LEN];
681
  int64_t dbId;
682
  int32_t vgVersion;
683
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
684
  int64_t stateTs;
685
} SBuildUseDBInput;
686

687
typedef struct SField {
688
  char    name[TSDB_COL_NAME_LEN];
689
  uint8_t type;
690
  int8_t  flags;
691
  int32_t bytes;
692
} SField;
693

694
typedef struct SFieldWithOptions {
695
  char     name[TSDB_COL_NAME_LEN];
696
  uint8_t  type;
697
  int8_t   flags;
698
  int32_t  bytes;
699
  uint32_t compress;
700
  STypeMod typeMod;
701
} SFieldWithOptions;
702

703
typedef struct SRetention {
704
  int64_t freq;
705
  int64_t keep;
706
  int8_t  freqUnit;
707
  int8_t  keepUnit;
708
} SRetention;
709

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

712
#pragma pack(push, 1)
713
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
714
typedef struct SEp {
715
  char     fqdn[TSDB_FQDN_LEN];
716
  uint16_t port;
717
} SEp;
718

719
typedef struct {
720
  int32_t contLen;
721
  int32_t vgId;
722
} SMsgHead;
723

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

735
// Submit message for this TSDB
736
typedef struct {
737
  SMsgHead header;
738
  int64_t  version;
739
  int32_t  length;
740
  int32_t  numOfBlocks;
741
  char     blocks[];
742
} SSubmitReq;
743

744
typedef struct {
745
  int32_t totalLen;
746
  int32_t len;
747
  STSRow* row;
748
} SSubmitBlkIter;
749

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

765
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
766
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
767
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
768
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
769
// for debug
770
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
771

772
typedef struct {
773
  bool     hasRef;
774
  col_id_t id;
775
  char     refDbName[TSDB_DB_NAME_LEN];
776
  char     refTableName[TSDB_TABLE_NAME_LEN];
777
  char     refColName[TSDB_COL_NAME_LEN];
778
} SColRef;
779

780
typedef struct {
781
  int32_t  nCols;
782
  int32_t  version;
783
  SColRef* pColRef;
784
} SColRefWrapper;
785

786
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
787
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
788
typedef struct {
789
  int32_t vgId;
790
  SColRef colRef;
791
} SColRefEx;
792

793
typedef struct {
794
  int16_t colId;
795
  char    refDbName[TSDB_DB_NAME_LEN];
796
  char    refTableName[TSDB_TABLE_NAME_LEN];
797
  char    refColName[TSDB_COL_NAME_LEN];
798
} SRefColInfo;
799

800
typedef struct SVCTableRefCols {
801
  uint64_t     uid;
802
  int32_t      numOfSrcTbls;
803
  int32_t      numOfColRefs;
804
  SRefColInfo* refCols;
805
} SVCTableRefCols;
806

807
typedef struct SVCTableMergeInfo {
808
  uint64_t uid;
809
  int32_t  numOfSrcTbls;
810
} SVCTableMergeInfo;
811

812
typedef struct {
813
  int32_t    nCols;
814
  SColRefEx* pColRefEx;
815
} SColRefExWrapper;
816

817
struct SSchema {
818
  int8_t   type;
819
  int8_t   flags;
820
  col_id_t colId;
821
  int32_t  bytes;
822
  char     name[TSDB_COL_NAME_LEN];
823
};
824
struct SSchemaExt {
825
  col_id_t colId;
826
  uint32_t compress;
827
  STypeMod typeMod;
828
};
829

830
struct SSchemaRsma {
831
  int64_t    interval[2];
832
  int32_t    nFuncs;
833
  int8_t     tbType;
834
  tb_uid_t   tbUid;
835
  func_id_t* funcIds;
836
  char       tbName[TSDB_TABLE_NAME_LEN];
837
};
838

839
struct SSchema2 {
840
  int8_t   type;
841
  int8_t   flags;
842
  col_id_t colId;
843
  int32_t  bytes;
844
  char     name[TSDB_COL_NAME_LEN];
845
  uint32_t compress;
846
};
847

848
typedef struct {
849
  char        tbName[TSDB_TABLE_NAME_LEN];
850
  char        stbName[TSDB_TABLE_NAME_LEN];
851
  char        dbFName[TSDB_DB_FNAME_LEN];
852
  int64_t     dbId;
853
  int32_t     numOfTags;
854
  int32_t     numOfColumns;
855
  int8_t      precision;
856
  int8_t      tableType;
857
  int32_t     sversion;
858
  int32_t     tversion;
859
  int32_t     rversion;
860
  uint64_t    suid;
861
  uint64_t    tuid;
862
  int32_t     vgId;
863
  int8_t      sysInfo;
864
  int64_t     ownerId;
865
  SSchema*    pSchemas;
866
  SSchemaExt* pSchemaExt;
867
  int8_t      virtualStb;
868
  int32_t     numOfColRefs;
869
  SColRef*    pColRefs;
870
} STableMetaRsp;
871

872
typedef struct {
873
  int32_t        code;
874
  int64_t        uid;
875
  char*          tblFName;
876
  int32_t        numOfRows;
877
  int32_t        affectedRows;
878
  int64_t        sver;
879
  STableMetaRsp* pMeta;
880
} SSubmitBlkRsp;
881

882
typedef struct {
883
  int32_t numOfRows;
884
  int32_t affectedRows;
885
  int32_t nBlocks;
886
  union {
887
    SArray*        pArray;
888
    SSubmitBlkRsp* pBlocks;
889
  };
890
} SSubmitRsp;
891

892
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
893
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
894
// void    tFreeSSubmitBlkRsp(void* param);
895
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
896

897
#define COL_SMA_ON       ((int8_t)0x1)
898
#define COL_IDX_ON       ((int8_t)0x2)
899
#define COL_IS_KEY       ((int8_t)0x4)
900
#define COL_SET_NULL     ((int8_t)0x10)
901
#define COL_SET_VAL      ((int8_t)0x20)
902
#define COL_IS_SYSINFO   ((int8_t)0x40)
903
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
904
#define COL_REF_BY_STM   ((int8_t)0x08)
905

906
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
907
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
908

909
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
910
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
911
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
912

913
#define SSCHMEA_SET_IDX_ON(s) \
914
  do {                        \
915
    (s)->flags |= COL_IDX_ON; \
916
  } while (0)
917

918
#define SSCHMEA_SET_IDX_OFF(s)   \
919
  do {                           \
920
    (s)->flags &= (~COL_IDX_ON); \
921
  } while (0)
922

923
#define SSCHEMA_SET_TYPE_MOD(s)     \
924
  do {                              \
925
    (s)->flags |= COL_HAS_TYPE_MOD; \
926
  } while (0)
927

928
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
929

930
#define SSCHMEA_TYPE(s)  ((s)->type)
931
#define SSCHMEA_FLAGS(s) ((s)->flags)
932
#define SSCHMEA_COLID(s) ((s)->colId)
933
#define SSCHMEA_BYTES(s) ((s)->bytes)
934
#define SSCHMEA_NAME(s)  ((s)->name)
935

936
typedef struct {
937
  bool    tsEnableMonitor;
938
  int32_t tsMonitorInterval;
939
  int32_t tsSlowLogThreshold;
940
  int32_t tsSlowLogMaxLen;
941
  int32_t tsSlowLogScope;
942
  int32_t tsSlowLogThresholdTest;  // Obsolete
943
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
944
} SMonitorParas;
945

946
typedef struct {
947
  STypeMod typeMod;
948
} SExtSchema;
949

950
bool hasExtSchema(const SExtSchema* pExtSchema);
951

952
typedef struct {
953
  int32_t      nCols;
954
  int32_t      version;
955
  SSchema*     pSchema;
956
  SSchemaRsma* pRsma;
957
} SSchemaWrapper;
958

959
typedef struct {
960
  col_id_t id;
961
  uint32_t alg;
962
} SColCmpr;
963

964
typedef struct {
965
  int32_t   nCols;
966
  int32_t   version;
967
  SColCmpr* pColCmpr;
968
} SColCmprWrapper;
969

970
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
971
  if (pRef->pColRef) {
265,211✔
UNCOV
972
    return TSDB_CODE_INVALID_PARA;
×
973
  }
974
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
265,211✔
975
  if (pRef->pColRef == NULL) {
265,211✔
UNCOV
976
    return terrno;
×
977
  }
978
  pRef->nCols = nCols;
265,211✔
979
  for (int32_t i = 0; i < nCols; i++) {
91,710,572✔
980
    pRef->pColRef[i].hasRef = false;
91,445,361✔
981
    pRef->pColRef[i].id = (col_id_t)(i + 1);
91,445,361✔
982
  }
983
  return 0;
265,211✔
984
}
985

986
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
987
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
988
    terrno = TSDB_CODE_INVALID_PARA;
989
    return NULL;
990
  }
991

992
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
993
  if (pDstWrapper == NULL) {
994
    return NULL;
995
  }
996
  pDstWrapper->nCols = pSrcWrapper->nCols;
997
  pDstWrapper->version = pSrcWrapper->version;
998

999
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1000
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1001
  if (pDstWrapper->pColCmpr == NULL) {
1002
    taosMemoryFree(pDstWrapper);
1003
    return NULL;
1004
  }
1005
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1006

1007
  return pDstWrapper;
1008
}
1009

1010
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1011
  if (!(!pCmpr->pColCmpr)) {
14,509,674✔
UNCOV
1012
    return TSDB_CODE_INVALID_PARA;
×
1013
  }
1014
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
14,509,674✔
1015
  if (pCmpr->pColCmpr == NULL) {
14,509,674✔
UNCOV
1016
    return terrno;
×
1017
  }
1018
  pCmpr->nCols = nCols;
14,509,674✔
1019
  return 0;
14,509,674✔
1020
}
1021

1022
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1023
  pCmpr->nCols = pSchema->nCols;
1024
  if (!(!pCmpr->pColCmpr)) {
1025
    return TSDB_CODE_INVALID_PARA;
1026
  }
1027
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1028
  if (pCmpr->pColCmpr == NULL) {
1029
    return terrno;
1030
  }
1031
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1032
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1033
    SSchema*  pColSchema = &pSchema->pSchema[i];
1034
    pColCmpr->id = pColSchema->colId;
1035
    pColCmpr->alg = 0;
1036
  }
1037
  return 0;
1038
}
1039

1040
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1041
  if (pWrapper == NULL) return;
1042

1043
  taosMemoryFreeClear(pWrapper->pColCmpr);
1044
  taosMemoryFreeClear(pWrapper);
1045
}
1046
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1047
  if (pSchemaWrapper->pSchema == NULL) return NULL;
736,188,588✔
1048

1049
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
735,864,375✔
1050
  if (pSW == NULL) {
735,830,288✔
UNCOV
1051
    return NULL;
×
1052
  }
1053
  pSW->nCols = pSchemaWrapper->nCols;
735,830,288✔
1054
  pSW->version = pSchemaWrapper->version;
735,790,874✔
1055
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
736,116,969✔
1056
  if (pSW->pSchema == NULL) {
735,658,183✔
UNCOV
1057
    taosMemoryFree(pSW);
×
UNCOV
1058
    return NULL;
×
1059
  }
1060

1061
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
735,313,463✔
1062
  return pSW;
736,179,895✔
1063
}
1064

1065
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
292,680,385✔
1066
  if (pSchemaWrapper) {
2,090,753,605✔
1067
    taosMemoryFree(pSchemaWrapper->pSchema);
1,184,068,248✔
1068
    if (pSchemaWrapper->pRsma) {
1,183,772,981✔
1069
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
25,452✔
1070
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
25,452✔
1071
    }
1072
    taosMemoryFree(pSchemaWrapper);
1,183,847,062✔
1073
  }
1074
}
2,050,616,763✔
1075

1076
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1077
  if (pSchemaWrapper) {
1078
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1079
    if (pSchemaWrapper->pRsma) {
1080
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1081
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1082
    }
1083
  }
1084
}
1085

1086
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
3,502,167✔
1087
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
3,502,167✔
1088
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
3,502,167✔
1089
  }
1090
}
3,502,167✔
1091

1092
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1093
  int32_t tlen = 0;
2,481,616✔
1094
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,482,912✔
1095
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,481,616✔
1096
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,481,616✔
1097
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,481,616✔
1098
  tlen += taosEncodeString(buf, pSchema->name);
2,481,616✔
1099
  return tlen;
2,481,616✔
1100
}
1101

1102
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1103
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,123,150✔
1104
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,122,826✔
1105
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,122,826✔
1106
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,122,826✔
1107
  buf = taosDecodeStringTo(buf, pSchema->name);
1,122,826✔
1108
  return (void*)buf;
1,122,826✔
1109
}
1110

1111
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1112
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1113
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1114
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1115
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1116
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1117
  return 0;
2,147,483,647✔
1118
}
1119

1120
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1121
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1122
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1123
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1124
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1125
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1126
  return 0;
2,147,483,647✔
1127
}
1128

1129
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1130
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1131
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1132
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1133
  return 0;
2,147,483,647✔
1134
}
1135

1136
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1137
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1138
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1139
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1140
  return 0;
2,147,483,647✔
1141
}
1142

1143
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1144
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
471,542,176✔
1145
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
471,542,176✔
1146
  if (pColRef->hasRef) {
235,771,088✔
1147
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
281,753,352✔
1148
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
281,753,352✔
1149
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
281,753,352✔
1150
  }
1151
  return 0;
235,771,088✔
1152
}
1153

1154
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1155
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
237,063,718✔
1156
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
237,063,718✔
1157
  if (pColRef->hasRef) {
118,531,859✔
1158
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
70,878,237✔
1159
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
70,878,237✔
1160
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
70,878,237✔
1161
  }
1162

1163
  return 0;
118,531,859✔
1164
}
1165

1166
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1167
  int32_t tlen = 0;
410,316✔
1168
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
410,316✔
1169
  tlen += taosEncodeVariantI32(buf, pSW->version);
410,316✔
1170
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,891,932✔
1171
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
4,963,232✔
1172
  }
1173
  return tlen;
410,316✔
1174
}
1175

1176
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1177
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
178,823✔
1178
  buf = taosDecodeVariantI32(buf, &pSW->version);
178,823✔
1179
  if (pSW->nCols > 0) {
178,823✔
1180
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
178,823✔
1181
    if (pSW->pSchema == NULL) {
178,823✔
UNCOV
1182
      return NULL;
×
1183
    }
1184

1185
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,301,649✔
1186
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,245,652✔
1187
    }
1188
  } else {
UNCOV
1189
    pSW->pSchema = NULL;
×
1190
  }
1191
  return (void*)buf;
178,823✔
1192
}
1193

1194
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1195
  if (pSW == NULL) {
489,707,302✔
UNCOV
1196
    return TSDB_CODE_INVALID_PARA;
×
1197
  }
1198
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
979,393,891✔
1199
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
979,293,255✔
1200
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1201
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1202
  }
1203
  return 0;
489,820,367✔
1204
}
1205

1206
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1207
  if (pSW == NULL) {
191,893,333✔
UNCOV
1208
    return TSDB_CODE_INVALID_PARA;
×
1209
  }
1210
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
383,743,188✔
1211
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
383,717,669✔
1212

1213
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
191,867,814✔
1214
  if (pSW->pSchema == NULL) {
191,816,139✔
UNCOV
1215
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1216
  }
1217
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,654,317,027✔
1218
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1219
  }
1220

1221
  return 0;
191,910,745✔
1222
}
1223

1224
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1225
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1226
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1227

1228
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1229
  if (pSW->pSchema == NULL) {
1,858,055,640✔
UNCOV
1230
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1231
  }
1232
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1233
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1234
  }
1235

1236
  return 0;
1,859,242,908✔
1237
}
1238

1239
typedef struct {
1240
  char     name[TSDB_TABLE_FNAME_LEN];
1241
  int8_t   igExists;
1242
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1243
  int8_t   reserved[6];
1244
  tb_uid_t suid;
1245
  int64_t  delay1;
1246
  int64_t  delay2;
1247
  int64_t  watermark1;
1248
  int64_t  watermark2;
1249
  int32_t  ttl;
1250
  int32_t  colVer;
1251
  int32_t  tagVer;
1252
  int32_t  numOfColumns;
1253
  int32_t  numOfTags;
1254
  int32_t  numOfFuncs;
1255
  int32_t  commentLen;
1256
  int32_t  ast1Len;
1257
  int32_t  ast2Len;
1258
  SArray*  pColumns;  // array of SFieldWithOptions
1259
  SArray*  pTags;     // array of SField
1260
  SArray*  pFuncs;
1261
  char*    pComment;
1262
  char*    pAst1;
1263
  char*    pAst2;
1264
  int64_t  deleteMark1;
1265
  int64_t  deleteMark2;
1266
  int32_t  sqlLen;
1267
  char*    sql;
1268
  int64_t  keep;
1269
  int8_t   virtualStb;
1270
} SMCreateStbReq;
1271

1272
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1273
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1274
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1275

1276
typedef struct {
1277
  STableMetaRsp* pMeta;
1278
} SMCreateStbRsp;
1279

1280
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1281
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1282
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1283

1284
typedef struct {
1285
  char     name[TSDB_TABLE_FNAME_LEN];
1286
  int8_t   igNotExists;
1287
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1288
  int8_t   reserved[6];
1289
  tb_uid_t suid;
1290
  int32_t  sqlLen;
1291
  char*    sql;
1292
} SMDropStbReq;
1293

1294
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1295
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1296
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1297

1298
typedef struct {
1299
  char    name[TSDB_TABLE_FNAME_LEN];
1300
  int8_t  alterType;
1301
  int32_t numOfFields;
1302
  SArray* pFields;
1303
  int32_t ttl;
1304
  int32_t commentLen;
1305
  char*   comment;
1306
  int32_t sqlLen;
1307
  char*   sql;
1308
  int64_t keep;
1309
  SArray* pTypeMods;
1310
} SMAlterStbReq;
1311

1312
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1313
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1314
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1315

1316
typedef struct SEpSet {
1317
  int8_t inUse;
1318
  int8_t numOfEps;
1319
  SEp    eps[TSDB_MAX_REPLICA];
1320
} SEpSet;
1321

1322
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1323
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1324
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1325
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1326

1327
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1328
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1329

1330
typedef struct {
1331
  int8_t  connType;
1332
  int32_t pid;
1333
  int32_t totpCode;
1334
  char    app[TSDB_APP_NAME_LEN];
1335
  char    db[TSDB_DB_NAME_LEN];
1336
  char    user[TSDB_USER_LEN];
1337
  char    passwd[TSDB_PASSWORD_LEN];
1338
  char    token[TSDB_TOKEN_LEN];
1339
  int64_t startTime;
1340
  int64_t connectTime;
1341
  char    sVer[TSDB_VERSION_LEN];
1342
  char    signature[20]; // SHA1 produces a 20-byte signature
1343
} SConnectReq;
1344

1345
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1346
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1347
void    tSignConnectReq(SConnectReq* pReq);
1348
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1349

1350
typedef struct {
1351
  int64_t       clusterId;
1352
  int32_t       acctId;
1353
  uint32_t      connId;
1354
  int32_t       dnodeNum;
1355
  int8_t        superUser;
1356
  int8_t        sysInfo;
1357
  int8_t        connType;
1358
  int8_t        enableAuditDelete;
1359
  SEpSet        epSet;
1360
  int32_t       svrTimestamp;
1361
  int32_t       passVer;
1362
  int32_t       authVer;
1363
  char          sVer[TSDB_VERSION_LEN];
1364
  char          sDetailVer[128];
1365
  int64_t       whiteListVer;
1366
  int64_t       timeWhiteListVer;
1367
  int64_t       userId;
1368
  SMonitorParas monitorParas;
1369
  char          user[TSDB_USER_LEN];
1370
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1371
  int8_t        enableAuditSelect;
1372
  int8_t        enableAuditInsert;
1373
  int8_t        auditLevel;
1374
} SConnectRsp;
1375

1376
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1377
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1378

1379
typedef struct {
1380
  char    user[TSDB_USER_LEN];
1381
  char    pass[TSDB_PASSWORD_LEN];
1382
  int32_t maxUsers;
1383
  int32_t maxDbs;
1384
  int32_t maxTimeSeries;
1385
  int32_t maxStreams;
1386
  int32_t accessState;  // Configured only by command
1387
  int64_t maxStorage;
1388
} SCreateAcctReq, SAlterAcctReq;
1389

1390
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1391
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1392

1393
typedef struct {
1394
  char    user[TSDB_USER_LEN];
1395
  int8_t  ignoreNotExists;
1396
  int32_t sqlLen;
1397
  char*   sql;
1398
} SDropUserReq, SDropAcctReq;
1399

1400
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1401
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1402
void    tFreeSDropUserReq(SDropUserReq* pReq);
1403

1404
typedef struct {
1405
  char name[TSDB_ROLE_LEN];
1406
  union {
1407
    uint8_t flag;
1408
    struct {
1409
      uint8_t ignoreExists : 1;
1410
      uint8_t reserve : 7;
1411
    };
1412
  };
1413
  int32_t sqlLen;
1414
  char*   sql;
1415
} SCreateRoleReq;
1416

1417
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1418
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1419
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1420

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

1434
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1435
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1436
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1437

1438
typedef struct {
1439
  SPrivSet privSet;
1440
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1441
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1442
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1443
  // delete can only specify conditions by cond and cannot specify columns
1444
  char*    cond;     // for table privileges
1445
  int32_t  condLen;  // for table privileges
1446
} SPrivSetReqArgs;
1447

1448
typedef struct {
1449
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1450
  uint8_t objType;    // db, table, view, rsma, etc.
1451
  union {
1452
    uint32_t flag;
1453
    struct {
1454
      uint32_t lock : 1;     // lock or unlock role
1455
      uint32_t add : 1;      // add or remove
1456
      uint32_t sysPriv : 1;  // system or object privileges
1457
      uint32_t objLevel : 2;
1458
      uint32_t reserve : 27;
1459
    };
1460
  };
1461
  union {
1462
    SPrivSetReqArgs privileges;
1463
    char            roleName[TSDB_ROLE_LEN];
1464
  };
1465
  char    principal[TSDB_ROLE_LEN];      // role or user name
1466
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db or topic
1467
  char    tblName[TSDB_TABLE_NAME_LEN];
1468
  int32_t sqlLen;
1469
  char*   sql;
1470
} SAlterRoleReq;
1471

1472
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1473
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1474
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1475

1476
typedef struct {
1477
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1478
  int32_t sqlLen;
1479
  char*   sql;
1480
} SDropEncryptAlgrReq;
1481

1482
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1483
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1484
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1485

1486
typedef struct SIpV4Range {
1487
  uint32_t ip;
1488
  uint32_t mask;
1489
} SIpV4Range;
1490

1491
typedef struct SIpv6Range {
1492
  uint64_t addr[2];
1493
  uint32_t mask;
1494
} SIpV6Range;
1495

1496
typedef struct {
1497
  int8_t type;   // 0: IPv4, 1: IPv6
1498
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1499
  union {
1500
    SIpV4Range ipV4;
1501
    SIpV6Range ipV6;
1502
  };
1503
} SIpRange;
1504

1505
typedef struct {
1506
  int32_t    num;
1507
  SIpV4Range pIpRange[];
1508
} SIpWhiteList;
1509

1510
typedef struct {
1511
  int32_t  num;
1512
  SIpRange pIpRanges[];
1513
} SIpWhiteListDual;
1514

1515
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1516
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1517
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1518
int32_t           createDefaultIp6Range(SIpRange* pRange);
1519
int32_t           createDefaultIp4Range(SIpRange* pRange);
1520

1521
typedef struct {
1522
  int32_t sessPerUser;
1523
  int32_t sessConnTime;
1524
  int32_t sessConnIdleTime;
1525
  int32_t sessMaxConcurrency;
1526
  int32_t sessMaxCallVnodeNum;
1527
} SUserSessCfg;
1528

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

1533
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1534
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1535
typedef struct {
1536
  int16_t year;
1537
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1538
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1539
  int8_t hour;
1540
  int8_t minute;
1541
  int8_t neg;   // this is a negative entry
1542
  int32_t duration; // duration in minute
1543
} SDateTimeRange;
1544

1545
bool isValidDateTimeRange(SDateTimeRange* pRange);
1546
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1547
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1548

1549
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1550
typedef struct {
1551
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1552
  bool neg;         // this is a negative entry
1553
  int32_t duration; // duration in seconds
1554
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1555
} SDateTimeWhiteListItem;
1556

1557
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1558
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1559

1560
typedef struct {
1561
  int32_t num;
1562
  SDateTimeWhiteListItem ranges[];
1563
} SDateTimeWhiteList;
1564

1565
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1566
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1567

1568

1569
typedef struct {
1570
  int8_t createType;
1571
  int8_t superUser;  // denote if it is a super user or not
1572
  int8_t ignoreExists;
1573

1574
  char   user[TSDB_USER_LEN];
1575
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1576
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1577

1578
  int8_t sysInfo;
1579
  int8_t createDb;
1580
  int8_t isImport;
1581
  int8_t changepass;
1582
  int8_t enable;
1583

1584
  int8_t negIpRanges;
1585
  int8_t negTimeRanges;
1586

1587
  int32_t sessionPerUser;
1588
  int32_t connectTime;
1589
  int32_t connectIdleTime;
1590
  int32_t callPerSession;
1591
  int32_t vnodePerCall;
1592
  int32_t failedLoginAttempts;
1593
  int32_t passwordLifeTime;
1594
  int32_t passwordReuseTime;
1595
  int32_t passwordReuseMax;
1596
  int32_t passwordLockTime;
1597
  int32_t passwordGraceTime;
1598
  int32_t inactiveAccountTime;
1599
  int32_t allowTokenNum;
1600

1601
  int32_t         numIpRanges;
1602
  SIpRange*       pIpDualRanges;
1603
  int32_t         numTimeRanges;
1604
  SDateTimeRange* pTimeRanges;
1605

1606
  int32_t sqlLen;
1607
  char*   sql;
1608
} SCreateUserReq;
1609

1610
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1611
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1612
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1613

1614
typedef struct {
1615
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1616
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1617
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1618
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1619
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1620
  int32_t sqlLen;
1621
  char*   sql;
1622
} SCreateEncryptAlgrReq;
1623

1624
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1625
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1626
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1627

1628
typedef struct {
1629
  int32_t dnodeId;
1630
  int64_t analVer;
1631
} SRetrieveAnalyticsAlgoReq;
1632

1633
typedef struct {
1634
  int64_t   ver;
1635
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1636
} SRetrieveAnalyticAlgoRsp;
1637

1638
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1639
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1640
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1641
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1642
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1643

1644
typedef struct {
1645
  int8_t alterType;
1646

1647
  int8_t isView;
1648

1649
  int8_t hasPassword;
1650
  int8_t hasTotpseed;
1651
  int8_t hasEnable;
1652
  int8_t hasSysinfo;
1653
  int8_t hasCreatedb;
1654
  int8_t hasChangepass;
1655
  int8_t hasSessionPerUser;
1656
  int8_t hasConnectTime;
1657
  int8_t hasConnectIdleTime;
1658
  int8_t hasCallPerSession;
1659
  int8_t hasVnodePerCall;
1660
  int8_t hasFailedLoginAttempts;
1661
  int8_t hasPasswordLifeTime;
1662
  int8_t hasPasswordReuseTime;
1663
  int8_t hasPasswordReuseMax;
1664
  int8_t hasPasswordLockTime;
1665
  int8_t hasPasswordGraceTime;
1666
  int8_t hasInactiveAccountTime;
1667
  int8_t hasAllowTokenNum;
1668

1669
  int8_t enable;
1670
  int8_t sysinfo;
1671
  int8_t createdb;
1672
  int8_t changepass;
1673

1674
  char   user[TSDB_USER_LEN];
1675
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1676
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1677
  int32_t sessionPerUser;
1678
  int32_t connectTime;
1679
  int32_t connectIdleTime;
1680
  int32_t callPerSession;
1681
  int32_t vnodePerCall;
1682
  int32_t failedLoginAttempts;
1683
  int32_t passwordLifeTime;
1684
  int32_t passwordReuseTime;
1685
  int32_t passwordReuseMax;
1686
  int32_t passwordLockTime;
1687
  int32_t passwordGraceTime;
1688
  int32_t inactiveAccountTime;
1689
  int32_t allowTokenNum;
1690

1691
  int32_t         numIpRanges;
1692
  int32_t         numTimeRanges;
1693
  int32_t         numDropIpRanges;
1694
  int32_t         numDropTimeRanges;
1695
  SIpRange*       pIpRanges;
1696
  SDateTimeRange* pTimeRanges;
1697
  SIpRange*       pDropIpRanges;
1698
  SDateTimeRange* pDropTimeRanges;
1699
  SPrivSet        privileges;
1700

1701
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1702
  char        tabName[TSDB_TABLE_NAME_LEN];
1703
  char*       tagCond;
1704
  int32_t     tagCondLen;
1705
  int32_t     sqlLen;
1706
  char*       sql;
1707
} SAlterUserReq;
1708

1709
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1710
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1711
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1712

1713
typedef struct {
1714
  char    name[TSDB_TOKEN_NAME_LEN];
1715
  char    user[TSDB_USER_LEN];
1716
  int8_t  enable;
1717
  int8_t  ignoreExists;
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
} SCreateTokenReq;
1725

1726
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1727
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1728
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1729

1730
typedef struct {
1731
  char name[TSDB_TOKEN_NAME_LEN];
1732
  char user[TSDB_USER_LEN];
1733
  char token[TSDB_TOKEN_LEN];
1734
} SCreateTokenRsp;
1735

1736
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1737
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1738
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1739

1740
typedef struct {
1741
  char    name[TSDB_TOKEN_NAME_LEN];
1742

1743
  int8_t hasEnable;
1744
  int8_t hasTtl;
1745
  int8_t hasProvider;
1746
  int8_t hasExtraInfo;
1747

1748
  int8_t  enable;
1749
  int32_t ttl;
1750
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1751
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1752

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

1757
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1758
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1759
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1760

1761
typedef struct {
1762
  char    name[TSDB_TOKEN_NAME_LEN];
1763
  int8_t  ignoreNotExists;
1764
  int32_t sqlLen;
1765
  char*   sql;
1766
} SDropTokenReq;
1767

1768
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1769
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1770
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1771

1772
typedef struct {
1773
  char user[TSDB_USER_LEN];
1774
} SGetUserAuthReq;
1775

1776
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1777
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1778

1779
typedef struct {
1780
  char      user[TSDB_USER_LEN];
1781
  int64_t   userId;
1782
  int32_t   version;
1783
  int32_t   passVer;
1784
  int8_t    superAuth;
1785
  int8_t    sysInfo;
1786
  int8_t    enable;
1787
  int8_t    dropped;
1788
  SPrivSet  sysPrivs;
1789
  SHashObj* objPrivs;
1790
  // SHashObj* createdDbs;
1791
  SHashObj* selectTbs;
1792
  SHashObj* insertTbs;
1793
  SHashObj* deleteTbs;
1794
  // SHashObj* readViews;
1795
  // SHashObj* writeViews;
1796
  // SHashObj* alterViews;
1797
  // SHashObj* useDbs;
1798
  int64_t   whiteListVer;
1799

1800
  SUserSessCfg sessCfg;
1801
  int64_t      timeWhiteListVer;
1802
} SGetUserAuthRsp;
1803

1804
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1805
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1806
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1807

1808
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1809
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1810
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1811
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1812

1813
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1814
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1815
typedef struct {
1816
  int64_t ver;
1817
  char    user[TSDB_USER_LEN];
1818
  int32_t numOfRange;
1819
  union {
1820
    SIpV4Range* pIpRanges;
1821
    SIpRange*   pIpDualRanges;
1822
  };
1823
} SUpdateUserIpWhite;
1824

1825
typedef struct {
1826
  int64_t             ver;
1827
  int                 numOfUser;
1828
  SUpdateUserIpWhite* pUserIpWhite;
1829
} SUpdateIpWhite;
1830

1831
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1832
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1833
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1834
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1835

1836
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1837
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1838
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1839

1840

1841
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1842
// corresponding response struct is different.
1843
typedef struct {
1844
  int64_t ver;
1845
} SRetrieveWhiteListReq;
1846

1847
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1848
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1849

1850

1851
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1852
// corresponding response struct is different.
1853
typedef struct {
1854
  char user[TSDB_USER_LEN];
1855
} SGetUserWhiteListReq;
1856

1857
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1858
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1859

1860
typedef struct {
1861
  char    user[TSDB_USER_LEN];
1862
  int32_t numWhiteLists;
1863
  union {
1864
    SIpV4Range* pWhiteLists;
1865
    SIpRange*   pWhiteListsDual;
1866
  };
1867
} SGetUserIpWhiteListRsp;
1868

1869
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1870
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1871
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1872
void    tIpRangeSetDefaultMask(SIpRange* range);
1873

1874
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1875
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1876
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1877

1878
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1879
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1880
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1881

1882
typedef struct {
1883
  int64_t ver;
1884
  char    user[TSDB_USER_LEN];
1885
  int32_t numWhiteLists;
1886
  SDateTimeWhiteListItem* pWhiteLists;
1887
} SUserDateTimeWhiteList;
1888

1889

1890
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1891
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1892
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1893
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1894

1895
typedef struct {
1896
  int64_t             ver;
1897
  int                 numOfUser;
1898
  SUserDateTimeWhiteList *pUsers;
1899
} SRetrieveDateTimeWhiteListRsp;
1900

1901
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1902
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1903
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1904
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1905

1906
/*
1907
 * for client side struct, only column id, type, bytes are necessary
1908
 * But for data in vnode side, we need all the following information.
1909
 */
1910
typedef struct {
1911
  union {
1912
    col_id_t colId;
1913
    int16_t  slotId;
1914
  };
1915

1916
  uint8_t precision;
1917
  uint8_t scale;
1918
  int32_t bytes;
1919
  int8_t  type;
1920
  uint8_t pk;
1921
  bool    noData;
1922
} SColumnInfo;
1923

1924
typedef struct STimeWindow {
1925
  TSKEY skey;
1926
  TSKEY ekey;
1927
} STimeWindow;
1928

1929
typedef struct SQueryHint {
1930
  bool batchScan;
1931
} SQueryHint;
1932

1933
typedef struct {
1934
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1935
  int32_t tsLen;          // total length of ts comp block
1936
  int32_t tsNumOfBlocks;  // ts comp block numbers
1937
  int32_t tsOrder;        // ts comp block order
1938
} STsBufInfo;
1939

1940
typedef struct {
1941
  void*       timezone;
1942
  char        intervalUnit;
1943
  char        slidingUnit;
1944
  char        offsetUnit;
1945
  int8_t      precision;
1946
  int64_t     interval;
1947
  int64_t     sliding;
1948
  int64_t     offset;
1949
  STimeWindow timeRange;
1950
} SInterval;
1951

1952
typedef struct STbVerInfo {
1953
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1954
  int32_t sversion;
1955
  int32_t tversion;
1956
  int32_t rversion;  // virtual table's column ref's version
1957
} STbVerInfo;
1958

1959
typedef struct {
1960
  int32_t code;
1961
  int64_t affectedRows;
1962
  SArray* tbVerInfo;  // STbVerInfo
1963
} SQueryTableRsp;
1964

1965
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1966

1967
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1968

1969
typedef struct {
1970
  SMsgHead header;
1971
  char     dbFName[TSDB_DB_FNAME_LEN];
1972
  char     tbName[TSDB_TABLE_NAME_LEN];
1973
} STableCfgReq;
1974

1975
typedef struct {
1976
  char        tbName[TSDB_TABLE_NAME_LEN];
1977
  char        stbName[TSDB_TABLE_NAME_LEN];
1978
  char        dbFName[TSDB_DB_FNAME_LEN];
1979
  int32_t     numOfTags;
1980
  int32_t     numOfColumns;
1981
  int8_t      tableType;
1982
  int64_t     delay1;
1983
  int64_t     delay2;
1984
  int64_t     watermark1;
1985
  int64_t     watermark2;
1986
  int32_t     ttl;
1987
  int32_t     keep;
1988
  int64_t     ownerId;
1989
  SArray*     pFuncs;
1990
  int32_t     commentLen;
1991
  char*       pComment;
1992
  SSchema*    pSchemas;
1993
  int32_t     tagsLen;
1994
  char*       pTags;
1995
  SSchemaExt* pSchemaExt;
1996
  int8_t      virtualStb;
1997
  SColRef*    pColRefs;
1998
} STableCfg;
1999

2000
typedef STableCfg STableCfgRsp;
2001

2002
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2003
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2004

2005
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2006
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2007
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2008

2009
typedef struct {
2010
  SMsgHead header;
2011
  tb_uid_t suid;
2012
} SVSubTablesReq;
2013

2014
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2015
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2016

2017
typedef struct {
2018
  int32_t vgId;
2019
  SArray* pTables;  // SArray<SVCTableRefCols*>
2020
} SVSubTablesRsp;
2021

2022
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2023
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2024
void    tDestroySVSubTablesRsp(void* rsp);
2025

2026
typedef struct {
2027
  SMsgHead header;
2028
  tb_uid_t suid;
2029
} SVStbRefDbsReq;
2030

2031
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2032
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2033

2034
typedef struct {
2035
  int32_t vgId;
2036
  SArray* pDbs;  // SArray<char* (db name)>
2037
} SVStbRefDbsRsp;
2038

2039
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2040
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2041
void    tDestroySVStbRefDbsRsp(void* rsp);
2042

2043
typedef struct {
2044
  char    db[TSDB_DB_FNAME_LEN];
2045
  int32_t numOfVgroups;
2046
  int32_t numOfStables;  // single_stable
2047
  int32_t buffer;        // MB
2048
  int32_t pageSize;
2049
  int32_t pages;
2050
  int32_t cacheLastSize;
2051
  int32_t daysPerFile;
2052
  int32_t daysToKeep0;
2053
  int32_t daysToKeep1;
2054
  int32_t daysToKeep2;
2055
  int32_t keepTimeOffset;
2056
  int32_t minRows;
2057
  int32_t maxRows;
2058
  int32_t walFsyncPeriod;
2059
  int8_t  walLevel;
2060
  int8_t  precision;  // time resolution
2061
  int8_t  compression;
2062
  int8_t  replications;
2063
  int8_t  strict;
2064
  int8_t  cacheLast;
2065
  int8_t  schemaless;
2066
  int8_t  ignoreExist;
2067
  int32_t numOfRetensions;
2068
  SArray* pRetensions;  // SRetention
2069
  int32_t walRetentionPeriod;
2070
  int64_t walRetentionSize;
2071
  int32_t walRollPeriod;
2072
  int64_t walSegmentSize;
2073
  int32_t sstTrigger;
2074
  int16_t hashPrefix;
2075
  int16_t hashSuffix;
2076
  int32_t ssChunkSize;
2077
  int32_t ssKeepLocal;
2078
  int8_t  ssCompact;
2079
  int32_t tsdbPageSize;
2080
  int32_t sqlLen;
2081
  char*   sql;
2082
  int8_t  withArbitrator;
2083
  int8_t  encryptAlgorithm;
2084
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2085
  // 1. add auto-compact parameters
2086
  int32_t compactInterval;    // minutes
2087
  int32_t compactStartTime;   // minutes
2088
  int32_t compactEndTime;     // minutes
2089
  int8_t  compactTimeOffset;  // hour
2090
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2091
  int8_t  isAudit;
2092
} SCreateDbReq;
2093

2094
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2095
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2096
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2097

2098
typedef struct {
2099
  char    db[TSDB_DB_FNAME_LEN];
2100
  int32_t buffer;
2101
  int32_t pageSize;
2102
  int32_t pages;
2103
  int32_t cacheLastSize;
2104
  int32_t daysPerFile;
2105
  int32_t daysToKeep0;
2106
  int32_t daysToKeep1;
2107
  int32_t daysToKeep2;
2108
  int32_t keepTimeOffset;
2109
  int32_t walFsyncPeriod;
2110
  int8_t  walLevel;
2111
  int8_t  strict;
2112
  int8_t  cacheLast;
2113
  int8_t  replications;
2114
  int32_t sstTrigger;
2115
  int32_t minRows;
2116
  int32_t walRetentionPeriod;
2117
  int32_t walRetentionSize;
2118
  int32_t ssKeepLocal;
2119
  int8_t  ssCompact;
2120
  int32_t sqlLen;
2121
  char*   sql;
2122
  int8_t  withArbitrator;
2123
  // 1. add auto-compact parameters
2124
  int32_t compactInterval;
2125
  int32_t compactStartTime;
2126
  int32_t compactEndTime;
2127
  int8_t  compactTimeOffset;
2128
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2129
  int8_t  isAudit;
2130
} SAlterDbReq;
2131

2132
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2133
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2134
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2135

2136
typedef struct {
2137
  char    db[TSDB_DB_FNAME_LEN];
2138
  int8_t  ignoreNotExists;
2139
  int8_t  force;
2140
  int32_t sqlLen;
2141
  char*   sql;
2142
} SDropDbReq;
2143

2144
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2145
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2146
void    tFreeSDropDbReq(SDropDbReq* pReq);
2147

2148
typedef struct {
2149
  char    db[TSDB_DB_FNAME_LEN];
2150
  int64_t uid;
2151
} SDropDbRsp;
2152

2153
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2154
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2155

2156
typedef struct {
2157
  char    name[TSDB_MOUNT_NAME_LEN];
2158
  int64_t uid;
2159
} SDropMountRsp;
2160

2161
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2162
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2163

2164
typedef struct {
2165
  char    db[TSDB_DB_FNAME_LEN];
2166
  int64_t dbId;
2167
  int32_t vgVersion;
2168
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2169
  int64_t stateTs;     // ms
2170
} SUseDbReq;
2171

2172
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2173
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2174

2175
typedef struct {
2176
  char    db[TSDB_DB_FNAME_LEN];
2177
  int64_t uid;
2178
  int32_t vgVersion;
2179
  int32_t vgNum;
2180
  int16_t hashPrefix;
2181
  int16_t hashSuffix;
2182
  int8_t  hashMethod;
2183
  union {
2184
    uint8_t flags;
2185
    struct {
2186
      uint8_t isMount : 1;  // TS-5868
2187
      uint8_t padding : 7;
2188
    };
2189
  };
2190
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2191
  int32_t errCode;
2192
  int64_t stateTs;  // ms
2193
} SUseDbRsp;
2194

2195
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2196
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2197
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2198
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2199
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2200

2201
typedef struct {
2202
  char db[TSDB_DB_FNAME_LEN];
2203
} SDbCfgReq;
2204

2205
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2206
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2207

2208
typedef struct {
2209
  char db[TSDB_DB_FNAME_LEN];
2210
} SSsMigrateDbReq;
2211

2212
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2213
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2214

2215
typedef struct {
2216
  int32_t ssMigrateId;
2217
  bool    bAccepted;
2218
} SSsMigrateDbRsp;
2219

2220
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2221
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2222

2223
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2224
typedef struct {
2225
  int32_t ssMigrateId;
2226
} SListSsMigrateFileSetsReq;
2227

2228
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2229
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2230

2231
typedef struct {
2232
  int32_t ssMigrateId;
2233
  int32_t vgId;       // vgroup id
2234
  SArray* pFileSets;  // SArray<int32_t>
2235
} SListSsMigrateFileSetsRsp;
2236

2237
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2238
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2239
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2240

2241
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2242
typedef struct {
2243
  int32_t ssMigrateId;
2244
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2245
  int32_t fid;
2246
  int64_t startTimeSec;
2247
} SSsMigrateFileSetReq;
2248

2249
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2250
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2251

2252
typedef struct {
2253
  int32_t ssMigrateId;
2254
  int32_t nodeId;  // node id of the leader vnode
2255
  int32_t vgId;
2256
  int32_t fid;
2257
} SSsMigrateFileSetRsp;
2258

2259
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2260
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2261

2262
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2263
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2264
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2265
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2266
#define SSMIGRATE_FILESET_STATE_FAILED      4
2267

2268
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2269
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2270
// while as a request, the 'state' field is not used.
2271
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2272
typedef struct {
2273
  int32_t ssMigrateId;  // ss migrate id
2274
  int32_t nodeId;       // node id of the leader vnode
2275
  int32_t vgId;         // vgroup id
2276
  int32_t fid;          // file set id
2277
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2278
} SSsMigrateProgress;
2279

2280
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2281
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2282

2283
// Request for TDMT_MND_KILL_SSMIGRATE
2284
typedef struct {
2285
  int32_t ssMigrateId;
2286
  int32_t sqlLen;
2287
  char*   sql;
2288
} SKillSsMigrateReq;
2289

2290
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2291
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2292
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2293

2294
// Request for TDMT_VND_KILL_SSMIGRATE
2295
typedef struct {
2296
  int32_t ssMigrateId;
2297
} SVnodeKillSsMigrateReq;
2298

2299
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2300
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2301

2302
typedef struct {
2303
  int32_t vgId;
2304
  int64_t keepVersion;
2305
} SMndSetVgroupKeepVersionReq;
2306

2307
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2308
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2309

2310
typedef struct {
2311
  int32_t timestampSec;
2312
  int32_t ttlDropMaxCount;
2313
  int32_t nUids;
2314
  SArray* pTbUids;
2315
} SVDropTtlTableReq;
2316

2317
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2318
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2319

2320
typedef struct {
2321
  char    db[TSDB_DB_FNAME_LEN];
2322
  int64_t dbId;
2323
  int64_t ownerId;
2324
  int32_t cfgVersion;
2325
  int32_t numOfVgroups;
2326
  int32_t numOfStables;
2327
  int32_t buffer;
2328
  int32_t cacheSize;
2329
  int32_t pageSize;
2330
  int32_t pages;
2331
  int32_t daysPerFile;
2332
  int32_t daysToKeep0;
2333
  int32_t daysToKeep1;
2334
  int32_t daysToKeep2;
2335
  int32_t keepTimeOffset;
2336
  int32_t minRows;
2337
  int32_t maxRows;
2338
  int32_t walFsyncPeriod;
2339
  int16_t hashPrefix;
2340
  int16_t hashSuffix;
2341
  int8_t  hashMethod;
2342
  int8_t  walLevel;
2343
  int8_t  precision;
2344
  int8_t  compression;
2345
  int8_t  replications;
2346
  int8_t  strict;
2347
  int8_t  cacheLast;
2348
  int8_t  encryptAlgr;
2349
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2350
  int32_t ssChunkSize;
2351
  int32_t ssKeepLocal;
2352
  int8_t  ssCompact;
2353
  union {
2354
    uint8_t flags;
2355
    struct {
2356
      uint8_t isMount : 1;  // TS-5868
2357
      uint8_t padding : 7;
2358
    };
2359
  };
2360
  int8_t  compactTimeOffset;
2361
  int32_t compactInterval;
2362
  int32_t compactStartTime;
2363
  int32_t compactEndTime;
2364
  int32_t tsdbPageSize;
2365
  int32_t walRetentionPeriod;
2366
  int32_t walRollPeriod;
2367
  int64_t walRetentionSize;
2368
  int64_t walSegmentSize;
2369
  int32_t numOfRetensions;
2370
  SArray* pRetensions;
2371
  int8_t  schemaless;
2372
  int16_t sstTrigger;
2373
  int8_t  withArbitrator;
2374
  int8_t  isAudit;
2375
} SDbCfgRsp;
2376

2377
typedef SDbCfgRsp SDbCfgInfo;
2378

2379
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2380
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2381
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2382
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2383
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2384

2385
typedef struct {
2386
  int32_t rowNum;
2387
} SQnodeListReq;
2388

2389
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2390
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2391

2392
typedef struct {
2393
  int32_t rowNum;
2394
} SDnodeListReq;
2395

2396
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2397

2398
typedef struct {
2399
  int32_t useless;  // useless
2400
} SServerVerReq;
2401

2402
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2403
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2404

2405
typedef struct {
2406
  char ver[TSDB_VERSION_LEN];
2407
} SServerVerRsp;
2408

2409
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2410
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2411

2412
typedef struct SQueryNodeAddr {
2413
  int32_t nodeId;  // vgId or qnodeId
2414
  SEpSet  epSet;
2415
} SQueryNodeAddr;
2416

2417
typedef struct {
2418
  SQueryNodeAddr addr;
2419
  uint64_t       load;
2420
} SQueryNodeLoad;
2421

2422
typedef struct {
2423
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2424
} SQnodeListRsp;
2425

2426
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2427
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2428
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2429

2430

2431
typedef struct SDownstreamSourceNode {
2432
  ENodeType      type;
2433
  SQueryNodeAddr addr;
2434
  uint64_t       clientId;
2435
  uint64_t       taskId;
2436
  uint64_t       sId;
2437
  int32_t        execId;
2438
  int32_t        fetchMsgType;
2439
  bool           localExec;
2440
} SDownstreamSourceNode;
2441

2442

2443

2444
typedef struct SDNodeAddr {
2445
  int32_t nodeId;  // dnodeId
2446
  SEpSet  epSet;
2447
} SDNodeAddr;
2448

2449
typedef struct {
2450
  SArray* dnodeList;  // SArray<SDNodeAddr>
2451
} SDnodeListRsp;
2452

2453
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2454
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2455
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2456

2457
typedef struct {
2458
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2459
} STableTSMAInfoRsp;
2460

2461
typedef struct {
2462
  SUseDbRsp*         useDbRsp;
2463
  SDbCfgRsp*         cfgRsp;
2464
  STableTSMAInfoRsp* pTsmaRsp;
2465
  int32_t            dbTsmaVersion;
2466
  char               db[TSDB_DB_FNAME_LEN];
2467
  int64_t            dbId;
2468
} SDbHbRsp;
2469

2470
typedef struct {
2471
  SArray* pArray;  // Array of SDbHbRsp
2472
} SDbHbBatchRsp;
2473

2474
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2475
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2476
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2477

2478
typedef struct {
2479
  SArray* pArray;  // Array of SGetUserAuthRsp
2480
} SUserAuthBatchRsp;
2481

2482
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2483
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2484
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2485

2486
typedef struct {
2487
  char        db[TSDB_DB_FNAME_LEN];
2488
  STimeWindow timeRange;
2489
  int32_t     sqlLen;
2490
  char*       sql;
2491
  SArray*     vgroupIds;
2492
  int32_t     compactId;
2493
  int8_t      metaOnly;
2494
  int8_t      force;
2495
} SCompactDbReq;
2496

2497
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2498
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2499
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2500

2501
typedef struct {
2502
  union {
2503
    int32_t compactId;
2504
    int32_t id;
2505
  };
2506
  int8_t bAccepted;
2507
} SCompactDbRsp;
2508

2509
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2510
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2511

2512
typedef struct {
2513
  union {
2514
    int32_t compactId;
2515
    int32_t id;
2516
  };
2517
  int32_t sqlLen;
2518
  char*   sql;
2519
} SKillCompactReq;
2520

2521
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2522
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2523
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2524

2525
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2526
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2527

2528
typedef struct {
2529
  char    name[TSDB_FUNC_NAME_LEN];
2530
  int8_t  igExists;
2531
  int8_t  funcType;
2532
  int8_t  scriptType;
2533
  int8_t  outputType;
2534
  int32_t outputLen;
2535
  int32_t bufSize;
2536
  int32_t codeLen;
2537
  int64_t signature;
2538
  char*   pComment;
2539
  char*   pCode;
2540
  int8_t  orReplace;
2541
} SCreateFuncReq;
2542

2543
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2544
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2545
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2546

2547
typedef struct {
2548
  char   name[TSDB_FUNC_NAME_LEN];
2549
  int8_t igNotExists;
2550
} SDropFuncReq;
2551

2552
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2553
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2554

2555
typedef struct {
2556
  int32_t numOfFuncs;
2557
  bool    ignoreCodeComment;
2558
  SArray* pFuncNames;
2559
} SRetrieveFuncReq;
2560

2561
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2562
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2563
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2564

2565
typedef struct {
2566
  char    name[TSDB_FUNC_NAME_LEN];
2567
  int8_t  funcType;
2568
  int8_t  scriptType;
2569
  int8_t  outputType;
2570
  int32_t outputLen;
2571
  int32_t bufSize;
2572
  int64_t signature;
2573
  int32_t commentSize;
2574
  int32_t codeSize;
2575
  char*   pComment;
2576
  char*   pCode;
2577
} SFuncInfo;
2578

2579
typedef struct {
2580
  int32_t funcVersion;
2581
  int64_t funcCreatedTime;
2582
} SFuncExtraInfo;
2583

2584
typedef struct {
2585
  int32_t numOfFuncs;
2586
  SArray* pFuncInfos;
2587
  SArray* pFuncExtraInfos;
2588
} SRetrieveFuncRsp;
2589

2590
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2591
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2592
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2593
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2594

2595
typedef struct {
2596
  int32_t       statusInterval;
2597
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2598
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2599
  char          locale[TD_LOCALE_LEN];      // tsLocale
2600
  char          charset[TD_LOCALE_LEN];     // tsCharset
2601
  int8_t        ttlChangeOnWrite;
2602
  int8_t        enableWhiteList;
2603
  int8_t        encryptionKeyStat;
2604
  uint32_t      encryptionKeyChksum;
2605
  SMonitorParas monitorParas;
2606
  int32_t       statusIntervalMs;
2607
} SClusterCfg;
2608

2609
typedef struct {
2610
  int32_t openVnodes;
2611
  int32_t dropVnodes;
2612
  int32_t totalVnodes;
2613
  int32_t masterNum;
2614
  int64_t numOfSelectReqs;
2615
  int64_t numOfInsertReqs;
2616
  int64_t numOfInsertSuccessReqs;
2617
  int64_t numOfBatchInsertReqs;
2618
  int64_t numOfBatchInsertSuccessReqs;
2619
  int64_t errors;
2620
} SVnodesStat;
2621

2622
typedef struct {
2623
  int32_t vgId;
2624
  int8_t  syncState;
2625
  int8_t  syncRestore;
2626
  int64_t syncTerm;
2627
  int64_t roleTimeMs;
2628
  int64_t startTimeMs;
2629
  int8_t  syncCanRead;
2630
  int64_t cacheUsage;
2631
  int64_t numOfTables;
2632
  int64_t numOfTimeSeries;
2633
  int64_t totalStorage;
2634
  int64_t compStorage;
2635
  int64_t pointsWritten;
2636
  int64_t numOfSelectReqs;
2637
  int64_t numOfInsertReqs;
2638
  int64_t numOfInsertSuccessReqs;
2639
  int64_t numOfBatchInsertReqs;
2640
  int64_t numOfBatchInsertSuccessReqs;
2641
  int32_t numOfCachedTables;
2642
  int32_t learnerProgress;  // use one reservered
2643
  int64_t syncAppliedIndex;
2644
  int64_t syncCommitIndex;
2645
  int64_t bufferSegmentUsed;
2646
  int64_t bufferSegmentSize;
2647
} SVnodeLoad;
2648

2649
typedef struct {
2650
  int64_t total_requests;
2651
  int64_t total_rows;
2652
  int64_t total_bytes;
2653
  double  write_size;
2654
  double  cache_hit_ratio;
2655
  int64_t rpc_queue_wait;
2656
  int64_t preprocess_time;
2657

2658
  int64_t memory_table_size;
2659
  int64_t commit_count;
2660
  int64_t merge_count;
2661
  double  commit_time;
2662
  double  merge_time;
2663
  int64_t block_commit_time;
2664
  int64_t memtable_wait_time;
2665
} SVnodeMetrics;
2666

2667
typedef struct {
2668
  int32_t     vgId;
2669
  int64_t     numOfTables;
2670
  int64_t     memSize;
2671
  int64_t     l1Size;
2672
  int64_t     l2Size;
2673
  int64_t     l3Size;
2674
  int64_t     cacheSize;
2675
  int64_t     walSize;
2676
  int64_t     metaSize;
2677
  int64_t     rawDataSize;
2678
  int64_t     ssSize;
2679
  const char* dbname;
2680
  int8_t      estimateRawData;
2681
} SDbSizeStatisInfo;
2682

2683
typedef struct {
2684
  int32_t vgId;
2685
  int64_t nTimeSeries;
2686
} SVnodeLoadLite;
2687

2688
typedef struct {
2689
  int8_t  syncState;
2690
  int64_t syncTerm;
2691
  int8_t  syncRestore;
2692
  int64_t roleTimeMs;
2693
} SMnodeLoad;
2694

2695
typedef struct {
2696
  int32_t dnodeId;
2697
  int64_t numOfProcessedQuery;
2698
  int64_t numOfProcessedCQuery;
2699
  int64_t numOfProcessedFetch;
2700
  int64_t numOfProcessedDrop;
2701
  int64_t numOfProcessedNotify;
2702
  int64_t numOfProcessedHb;
2703
  int64_t numOfProcessedDelete;
2704
  int64_t cacheDataSize;
2705
  int64_t numOfQueryInQueue;
2706
  int64_t numOfFetchInQueue;
2707
  int64_t timeInQueryQueue;
2708
  int64_t timeInFetchQueue;
2709
} SQnodeLoad;
2710

2711
typedef struct {
2712
  int32_t     sver;      // software version
2713
  int64_t     dnodeVer;  // dnode table version in sdb
2714
  int32_t     dnodeId;
2715
  int64_t     clusterId;
2716
  int64_t     rebootTime;
2717
  int64_t     updateTime;
2718
  float       numOfCores;
2719
  int32_t     numOfSupportVnodes;
2720
  int32_t     numOfDiskCfg;
2721
  int64_t     memTotal;
2722
  int64_t     memAvail;
2723
  char        dnodeEp[TSDB_EP_LEN];
2724
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2725
  SMnodeLoad  mload;
2726
  SQnodeLoad  qload;
2727
  SClusterCfg clusterCfg;
2728
  SArray*     pVloads;  // array of SVnodeLoad
2729
  int32_t     statusSeq;
2730
  int64_t     ipWhiteVer;
2731
  int64_t     timeWhiteVer;
2732
  int64_t     analVer;
2733
  int64_t     timestamp;
2734
  char        auditDB[TSDB_DB_FNAME_LEN];
2735
  char        auditToken[TSDB_TOKEN_LEN];
2736
} SStatusReq;
2737

2738
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2739
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2740
void    tFreeSStatusReq(SStatusReq* pReq);
2741

2742
typedef struct {
2743
  int32_t forceReadConfig;
2744
  int32_t cver;
2745
  SArray* array;
2746
} SConfigReq;
2747

2748
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2749
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2750
void    tFreeSConfigReq(SConfigReq* pReq);
2751

2752
typedef struct {
2753
  int32_t dnodeId;
2754
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2755
} SDnodeInfoReq;
2756

2757
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2758
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2759

2760
typedef enum {
2761
  MONITOR_TYPE_COUNTER = 0,
2762
  MONITOR_TYPE_SLOW_LOG = 1,
2763
} MONITOR_TYPE;
2764

2765
typedef struct {
2766
  int32_t      contLen;
2767
  char*        pCont;
2768
  MONITOR_TYPE type;
2769
} SStatisReq;
2770

2771
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2772
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2773
void    tFreeSStatisReq(SStatisReq* pReq);
2774

2775
typedef struct {
2776
  char    db[TSDB_DB_FNAME_LEN];
2777
  char    table[TSDB_TABLE_NAME_LEN];
2778
  char    operation[AUDIT_OPERATION_LEN];
2779
  int32_t sqlLen;
2780
  char*   pSql;
2781
  double  duration;
2782
  int64_t affectedRows;
2783
} SAuditReq;
2784
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2785
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2786
void    tFreeSAuditReq(SAuditReq* pReq);
2787

2788
typedef struct {
2789
  SArray* auditArr;
2790
} SBatchAuditReq;
2791
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2792
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2793
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2794

2795
typedef struct {
2796
  int32_t dnodeId;
2797
  int64_t clusterId;
2798
  SArray* pVloads;
2799
} SNotifyReq;
2800

2801
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2802
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2803
void    tFreeSNotifyReq(SNotifyReq* pReq);
2804

2805
typedef struct {
2806
  int32_t dnodeId;
2807
  int64_t clusterId;
2808
} SDnodeCfg;
2809

2810
typedef struct {
2811
  int32_t id;
2812
  int8_t  isMnode;
2813
  SEp     ep;
2814
} SDnodeEp;
2815

2816
typedef struct {
2817
  int32_t id;
2818
  int8_t  isMnode;
2819
  int8_t  offlineReason;
2820
  SEp     ep;
2821
  char    active[TSDB_ACTIVE_KEY_LEN];
2822
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2823
} SDnodeInfo;
2824

2825
typedef struct {
2826
  int64_t   dnodeVer;
2827
  SDnodeCfg dnodeCfg;
2828
  SArray*   pDnodeEps;  // Array of SDnodeEp
2829
  int32_t   statusSeq;
2830
  int64_t   ipWhiteVer;
2831
  int64_t   analVer;
2832
  int64_t   timeWhiteVer;
2833
  char      auditDB[TSDB_DB_FNAME_LEN];
2834
  char      auditToken[TSDB_TOKEN_LEN];
2835
} SStatusRsp;
2836

2837
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2838
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2839
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2840

2841
typedef struct {
2842
  int32_t forceReadConfig;
2843
  int32_t isConifgVerified;
2844
  int32_t isVersionVerified;
2845
  int32_t cver;
2846
  SArray* array;
2847
} SConfigRsp;
2848

2849
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2850
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2851
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2852

2853
typedef struct {
2854
  int32_t dnodeId;
2855
  int32_t keyVersion;  // Local key version
2856
} SKeySyncReq;
2857

2858
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2859
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2860

2861
typedef struct {
2862
  int32_t keyVersion;        // mnode's key version
2863
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2864
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2865
  char    svrKey[129];       // Server key (if needUpdate)
2866
  char    dbKey[129];        // Database key (if needUpdate)
2867
  char    cfgKey[129];       // Config key (if needUpdate)
2868
  char    metaKey[129];      // Metadata key (if needUpdate)
2869
  char    dataKey[129];      // Data key (if needUpdate)
2870
  int32_t algorithm;         // Encryption algorithm for master keys
2871
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2872
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2873
  int64_t createTime;        // Key creation time
2874
  int64_t svrKeyUpdateTime;  // Server key update time
2875
  int64_t dbKeyUpdateTime;   // Database key update time
2876
} SKeySyncRsp;
2877

2878
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2879
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2880

2881
typedef struct {
2882
  int32_t reserved;
2883
} SMTimerReq;
2884

2885
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2886
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2887

2888
typedef struct SOrphanTask {
2889
  int64_t streamId;
2890
  int32_t taskId;
2891
  int32_t nodeId;
2892
} SOrphanTask;
2893

2894
typedef struct SMStreamDropOrphanMsg {
2895
  SArray* pList;  // SArray<SOrphanTask>
2896
} SMStreamDropOrphanMsg;
2897

2898
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2899
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2900
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2901

2902
typedef struct {
2903
  int32_t  id;
2904
  uint16_t port;                 // node sync Port
2905
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2906
} SReplica;
2907

2908
typedef struct {
2909
  int32_t  vgId;
2910
  char     db[TSDB_DB_FNAME_LEN];
2911
  int64_t  dbUid;
2912
  int32_t  vgVersion;
2913
  int32_t  numOfStables;
2914
  int32_t  buffer;
2915
  int32_t  pageSize;
2916
  int32_t  pages;
2917
  int32_t  cacheLastSize;
2918
  int32_t  daysPerFile;
2919
  int32_t  daysToKeep0;
2920
  int32_t  daysToKeep1;
2921
  int32_t  daysToKeep2;
2922
  int32_t  keepTimeOffset;
2923
  int32_t  minRows;
2924
  int32_t  maxRows;
2925
  int32_t  walFsyncPeriod;
2926
  uint32_t hashBegin;
2927
  uint32_t hashEnd;
2928
  int8_t   hashMethod;
2929
  int8_t   walLevel;
2930
  int8_t   precision;
2931
  int8_t   compression;
2932
  int8_t   strict;
2933
  int8_t   cacheLast;
2934
  int8_t   isTsma;
2935
  int8_t   replica;
2936
  int8_t   selfIndex;
2937
  SReplica replicas[TSDB_MAX_REPLICA];
2938
  int32_t  numOfRetensions;
2939
  SArray*  pRetensions;  // SRetention
2940
  void*    pTsma;
2941
  int32_t  walRetentionPeriod;
2942
  int64_t  walRetentionSize;
2943
  int32_t  walRollPeriod;
2944
  int64_t  walSegmentSize;
2945
  int16_t  sstTrigger;
2946
  int16_t  hashPrefix;
2947
  int16_t  hashSuffix;
2948
  int32_t  tsdbPageSize;
2949
  int32_t  ssChunkSize;
2950
  int32_t  ssKeepLocal;
2951
  int8_t   ssCompact;
2952
  int64_t  reserved[6];
2953
  int8_t   learnerReplica;
2954
  int8_t   learnerSelfIndex;
2955
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2956
  int32_t  changeVersion;
2957
  int8_t   encryptAlgorithm;
2958
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2959
} SCreateVnodeReq;
2960

2961
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2962
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2963
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2964

2965
typedef struct {
2966
  union {
2967
    int32_t compactId;
2968
    int32_t id;
2969
  };
2970
  int32_t vgId;
2971
  int32_t dnodeId;
2972
} SQueryCompactProgressReq;
2973

2974
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2975
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2976

2977
typedef struct {
2978
  union {
2979
    int32_t compactId;
2980
    int32_t id;
2981
  };
2982
  int32_t vgId;
2983
  int32_t dnodeId;
2984
  int32_t numberFileset;
2985
  int32_t finished;
2986
  int32_t progress;
2987
  int64_t remainingTime;
2988
} SQueryCompactProgressRsp;
2989

2990
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2991
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2992

2993
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2994
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2995

2996
typedef struct {
2997
  int32_t vgId;
2998
  int32_t dnodeId;
2999
  int64_t dbUid;
3000
  char    db[TSDB_DB_FNAME_LEN];
3001
  int64_t reserved[8];
3002
} SDropVnodeReq;
3003

3004
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3005
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3006

3007
typedef struct {
3008
  char    colName[TSDB_COL_NAME_LEN];
3009
  char    stb[TSDB_TABLE_FNAME_LEN];
3010
  int64_t stbUid;
3011
  int64_t dbUid;
3012
  int64_t reserved[8];
3013
} SDropIndexReq;
3014

3015
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3016
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3017

3018
typedef struct {
3019
  int64_t dbUid;
3020
  char    db[TSDB_DB_FNAME_LEN];
3021
  union {
3022
    int64_t compactStartTime;
3023
    int64_t startTime;
3024
  };
3025

3026
  STimeWindow tw;
3027
  union {
3028
    int32_t compactId;
3029
    int32_t id;
3030
  };
3031
  int8_t metaOnly;
3032
  union {
3033
    uint16_t flags;
3034
    struct {
3035
      uint16_t optrType : 3;     // ETsdbOpType
3036
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3037
      uint16_t reserved : 12;
3038
    };
3039
  };
3040
  int8_t force;  // force compact
3041
} SCompactVnodeReq;
3042

3043
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3044
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3045

3046
typedef struct {
3047
  union {
3048
    int32_t compactId;
3049
    int32_t taskId;
3050
  };
3051
  int32_t vgId;
3052
  int32_t dnodeId;
3053
} SVKillCompactReq;
3054

3055
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3056
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3057

3058
typedef SVKillCompactReq SVKillRetentionReq;
3059

3060
typedef struct {
3061
  char        db[TSDB_DB_FNAME_LEN];
3062
  int32_t     maxSpeed;
3063
  int32_t     sqlLen;
3064
  char*       sql;
3065
  SArray*     vgroupIds;
3066
  STimeWindow tw;  // unit is second
3067
  union {
3068
    uint32_t flags;
3069
    struct {
3070
      uint32_t optrType : 3;     // ETsdbOpType
3071
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3072
      uint32_t reserved : 28;
3073
    };
3074
  };
3075
} STrimDbReq;
3076

3077
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3078
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3079
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3080

3081
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3082

3083
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3084
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3085

3086
typedef struct {
3087
  int32_t vgVersion;
3088
  int32_t buffer;
3089
  int32_t pageSize;
3090
  int32_t pages;
3091
  int32_t cacheLastSize;
3092
  int32_t daysPerFile;
3093
  int32_t daysToKeep0;
3094
  int32_t daysToKeep1;
3095
  int32_t daysToKeep2;
3096
  int32_t keepTimeOffset;
3097
  int32_t walFsyncPeriod;
3098
  int8_t  walLevel;
3099
  int8_t  strict;
3100
  int8_t  cacheLast;
3101
  int64_t reserved[7];
3102
  // 1st modification
3103
  int16_t sttTrigger;
3104
  int32_t minRows;
3105
  // 2nd modification
3106
  int32_t walRetentionPeriod;
3107
  int32_t walRetentionSize;
3108
  int32_t ssKeepLocal;
3109
  int8_t  ssCompact;
3110
} SAlterVnodeConfigReq;
3111

3112
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3113
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3114

3115
typedef struct {
3116
  int32_t  vgId;
3117
  int8_t   strict;
3118
  int8_t   selfIndex;
3119
  int8_t   replica;
3120
  SReplica replicas[TSDB_MAX_REPLICA];
3121
  int64_t  reserved[8];
3122
  int8_t   learnerSelfIndex;
3123
  int8_t   learnerReplica;
3124
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3125
  int32_t  changeVersion;
3126
  int32_t  electBaseLine;
3127
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3128

3129
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3130
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3131

3132
typedef struct {
3133
  int32_t vgId;
3134
  int8_t  disable;
3135
} SDisableVnodeWriteReq;
3136

3137
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3138
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3139

3140
typedef struct {
3141
  int32_t  srcVgId;
3142
  int32_t  dstVgId;
3143
  uint32_t hashBegin;
3144
  uint32_t hashEnd;
3145
  int32_t  changeVersion;
3146
  int32_t  reserved;
3147
} SAlterVnodeHashRangeReq;
3148

3149
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3150
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3151

3152
#define REQ_OPT_TBNAME 0x0
3153
#define REQ_OPT_TBUID  0x01
3154
typedef struct {
3155
  SMsgHead header;
3156
  char     dbFName[TSDB_DB_FNAME_LEN];
3157
  char     tbName[TSDB_TABLE_NAME_LEN];
3158
  uint8_t  option;
3159
  uint8_t  autoCreateCtb;
3160
} STableInfoReq;
3161

3162
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3163
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3164

3165
typedef struct {
3166
  int8_t  metaClone;  // create local clone of the cached table meta
3167
  int32_t numOfVgroups;
3168
  int32_t numOfTables;
3169
  int32_t numOfUdfs;
3170
  char    tableNames[];
3171
} SMultiTableInfoReq;
3172

3173
// todo refactor
3174
typedef struct SVgroupInfo {
3175
  int32_t  vgId;
3176
  uint32_t hashBegin;
3177
  uint32_t hashEnd;
3178
  SEpSet   epSet;
3179
  union {
3180
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3181
    int32_t taskId;      // used in stream
3182
  };
3183
} SVgroupInfo;
3184

3185
typedef struct {
3186
  int32_t     numOfVgroups;
3187
  SVgroupInfo vgroups[];
3188
} SVgroupsInfo;
3189

3190
typedef struct {
3191
  STableMetaRsp* pMeta;
3192
} SMAlterStbRsp;
3193

3194
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3195
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3196
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3197

3198
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3199
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3200
void    tFreeSTableMetaRsp(void* pRsp);
3201
void    tFreeSTableIndexRsp(void* info);
3202

3203
typedef struct {
3204
  SArray* pMetaRsp;   // Array of STableMetaRsp
3205
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3206
} SSTbHbRsp;
3207

3208
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3209
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3210
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3211

3212
typedef struct {
3213
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3214
} SViewHbRsp;
3215

3216
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3217
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3218
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3219

3220
typedef struct {
3221
  int32_t numOfTables;
3222
  int32_t numOfVgroup;
3223
  int32_t numOfUdf;
3224
  int32_t contLen;
3225
  int8_t  compressed;  // denote if compressed or not
3226
  int32_t rawLen;      // size before compress
3227
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3228
  char    meta[];
3229
} SMultiTableMeta;
3230

3231
typedef struct {
3232
  int32_t dataLen;
3233
  char    name[TSDB_TABLE_FNAME_LEN];
3234
  char*   data;
3235
} STagData;
3236

3237
typedef struct {
3238
  int32_t  opType;
3239
  uint32_t valLen;
3240
  char*    val;
3241
} SShowVariablesReq;
3242

3243
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3244
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3245
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3246

3247
typedef struct {
3248
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3249
  char value[TSDB_CONFIG_PATH_LEN + 1];
3250
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3251
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3252
  char info[TSDB_CONFIG_INFO_LEN + 1];
3253
} SVariablesInfo;
3254

3255
typedef struct {
3256
  SArray* variables;  // SArray<SVariablesInfo>
3257
} SShowVariablesRsp;
3258

3259
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3260
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3261

3262
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3263

3264
/*
3265
 * sql: show tables like '%a_%'
3266
 * payload is the query condition, e.g., '%a_%'
3267
 * payloadLen is the length of payload
3268
 */
3269
typedef struct {
3270
  int32_t type;
3271
  char    db[TSDB_DB_FNAME_LEN];
3272
  int32_t payloadLen;
3273
  char*   payload;
3274
} SShowReq;
3275

3276
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3277
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3278
void tFreeSShowReq(SShowReq* pReq);
3279

3280
typedef struct {
3281
  int64_t       showId;
3282
  STableMetaRsp tableMeta;
3283
} SShowRsp, SVShowTablesRsp;
3284

3285
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3286
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3287
// void    tFreeSShowRsp(SShowRsp* pRsp);
3288

3289
typedef struct {
3290
  char    db[TSDB_DB_FNAME_LEN];
3291
  char    tb[TSDB_TABLE_NAME_LEN];
3292
  char    user[TSDB_USER_LEN];
3293
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3294
  int64_t showId;
3295
  int64_t compactId;  // for compact
3296
  bool    withFull;   // for show users full
3297
} SRetrieveTableReq;
3298

3299
typedef struct SSysTableSchema {
3300
  int8_t   type;
3301
  col_id_t colId;
3302
  int32_t  bytes;
3303
} SSysTableSchema;
3304

3305
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3306
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3307

3308
#define RETRIEVE_TABLE_RSP_VERSION         0
3309
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3310
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3311

3312
typedef struct {
3313
  int64_t useconds;
3314
  int8_t  completed;  // all results are returned to client
3315
  int8_t  precision;
3316
  int8_t  compressed;
3317
  int8_t  streamBlockType;
3318
  int32_t payloadLen;
3319
  int32_t compLen;
3320
  int32_t numOfBlocks;
3321
  int64_t numOfRows;  // from int32_t change to int64_t
3322
  int64_t numOfCols;
3323
  int64_t skey;
3324
  int64_t ekey;
3325
  int64_t version;                         // for stream
3326
  TSKEY   watermark;                       // for stream
3327
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3328
  char    data[];
3329
} SRetrieveTableRsp;
3330

3331
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3332

3333
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3334
  do {                                          \
3335
    ((int32_t*)(_p))[0] = (_compLen);           \
3336
    ((int32_t*)(_p))[1] = (_fullLen);           \
3337
  } while (0);
3338

3339
typedef struct {
3340
  int64_t version;
3341
  int64_t numOfRows;
3342
  int8_t  compressed;
3343
  int8_t  precision;
3344
  char    data[];
3345
} SRetrieveTableRspForTmq;
3346

3347
typedef struct {
3348
  int64_t handle;
3349
  int64_t useconds;
3350
  int8_t  completed;  // all results are returned to client
3351
  int8_t  precision;
3352
  int8_t  compressed;
3353
  int32_t compLen;
3354
  int32_t numOfRows;
3355
  int32_t fullLen;
3356
  char    data[];
3357
} SRetrieveMetaTableRsp;
3358

3359
typedef struct SExplainExecInfo {
3360
  double   startupCost;
3361
  double   totalCost;
3362
  uint64_t numOfRows;
3363
  uint32_t verboseLen;
3364
  void*    verboseInfo;
3365
} SExplainExecInfo;
3366

3367
typedef struct {
3368
  int32_t           numOfPlans;
3369
  SExplainExecInfo* subplanInfo;
3370
} SExplainRsp;
3371

3372
typedef struct {
3373
  SExplainRsp rsp;
3374
  uint64_t    qId;
3375
  uint64_t    cId;
3376
  uint64_t    tId;
3377
  int64_t     rId;
3378
  int32_t     eId;
3379
} SExplainLocalRsp;
3380

3381
typedef struct STableScanAnalyzeInfo {
3382
  uint64_t totalRows;
3383
  uint64_t totalCheckedRows;
3384
  uint32_t totalBlocks;
3385
  uint32_t loadBlocks;
3386
  uint32_t loadBlockStatis;
3387
  uint32_t skipBlocks;
3388
  uint32_t filterOutBlocks;
3389
  double   elapsedTime;
3390
  double   filterTime;
3391
} STableScanAnalyzeInfo;
3392

3393
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3394
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3395
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3396

3397
typedef struct {
3398
  char    config[TSDB_DNODE_CONFIG_LEN];
3399
  char    value[TSDB_CLUSTER_VALUE_LEN];
3400
  int32_t sqlLen;
3401
  char*   sql;
3402
} SMCfgClusterReq;
3403

3404
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3405
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3406
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3407

3408
typedef struct {
3409
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3410
  int32_t port;
3411
  int32_t sqlLen;
3412
  char*   sql;
3413
} SCreateDnodeReq;
3414

3415
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3416
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3417
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3418

3419
typedef struct {
3420
  int32_t dnodeId;
3421
  char    fqdn[TSDB_FQDN_LEN];
3422
  int32_t port;
3423
  int8_t  force;
3424
  int8_t  unsafe;
3425
  int32_t sqlLen;
3426
  char*   sql;
3427
} SDropDnodeReq;
3428

3429
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3430
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3431
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3432

3433
enum {
3434
  RESTORE_TYPE__ALL = 1,
3435
  RESTORE_TYPE__MNODE,
3436
  RESTORE_TYPE__VNODE,
3437
  RESTORE_TYPE__QNODE,
3438
};
3439

3440
typedef struct {
3441
  int32_t dnodeId;
3442
  int8_t  restoreType;
3443
  int32_t sqlLen;
3444
  char*   sql;
3445
} SRestoreDnodeReq;
3446

3447
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3448
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3449
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3450

3451
typedef struct {
3452
  int32_t dnodeId;
3453
  char    config[TSDB_DNODE_CONFIG_LEN];
3454
  char    value[TSDB_DNODE_VALUE_LEN];
3455
  int32_t sqlLen;
3456
  char*   sql;
3457
} SMCfgDnodeReq;
3458

3459
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3460
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3461
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3462

3463
typedef struct {
3464
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3465
  char    newKey[ENCRYPT_KEY_LEN + 1];
3466
  int32_t sqlLen;
3467
  char*   sql;
3468
} SMAlterEncryptKeyReq;
3469

3470
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3471
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3472
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3473

3474
typedef struct {
3475
  char    config[TSDB_DNODE_CONFIG_LEN];
3476
  char    value[TSDB_DNODE_VALUE_LEN];
3477
  int32_t version;
3478
} SDCfgDnodeReq;
3479

3480
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3481
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3482

3483
typedef struct {
3484
  int32_t dnodeId;
3485
  int32_t sqlLen;
3486
  char*   sql;
3487
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3488
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3489

3490
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3491
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3492

3493
typedef struct {
3494
  int32_t nodeId;
3495
  SEpSet  epSet;
3496
} SNodeEpSet;
3497

3498
typedef struct {
3499
  int32_t    snodeId;
3500
  SNodeEpSet leaders[2];
3501
  SNodeEpSet replica;
3502
  int32_t    sqlLen;
3503
  char*      sql;
3504
} SDCreateSnodeReq;
3505

3506
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3507
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3508
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3509

3510
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3511
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3512
typedef struct {
3513
  int8_t   replica;
3514
  SReplica replicas[TSDB_MAX_REPLICA];
3515
  int8_t   learnerReplica;
3516
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3517
  int64_t  lastIndex;
3518
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3519

3520
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3521
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3522

3523
typedef struct {
3524
  int32_t urlLen;
3525
  int32_t sqlLen;
3526
  char*   url;
3527
  char*   sql;
3528
} SMCreateAnodeReq;
3529

3530
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3531
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3532
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3533

3534
typedef struct {
3535
  int32_t anodeId;
3536
  int32_t sqlLen;
3537
  char*   sql;
3538
} SMDropAnodeReq, SMUpdateAnodeReq;
3539

3540
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3541
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3542
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3543
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3544
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3545
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3546

3547
typedef struct {
3548
  int32_t dnodeId;
3549
  int32_t bnodeProto;
3550
  int32_t sqlLen;
3551
  char*   sql;
3552
} SMCreateBnodeReq, SDCreateBnodeReq;
3553

3554
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3555
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3556
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3557

3558
typedef struct {
3559
  int32_t dnodeId;
3560
  int32_t sqlLen;
3561
  char*   sql;
3562
} SMDropBnodeReq, SDDropBnodeReq;
3563

3564
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3565
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3566
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3567

3568
typedef struct {
3569
  int32_t sqlLen;
3570
  int32_t urlLen;
3571
  int32_t userLen;
3572
  int32_t passLen;
3573
  int32_t passIsMd5;
3574
  char*   sql;
3575
  char*   url;
3576
  char*   user;
3577
  char*   pass;
3578
} SMCreateXnodeReq, SDCreateXnodeReq;
3579

3580
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3581
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3582
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3583

3584
typedef struct {
3585
  int32_t xnodeId;
3586
  int32_t force;
3587
  int32_t urlLen;
3588
  int32_t sqlLen;
3589
  char*   url;
3590
  char*   sql;
3591
} SMDropXnodeReq, SMUpdateXnodeReq, SDDropXnodeReq;
3592

3593
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3594
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3595
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3596
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3597
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3598
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3599

3600
typedef struct {
3601
  int32_t xnodeId;
3602
  int32_t sqlLen;
3603
  char*   sql;
3604
} SMDrainXnodeReq;
3605
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3606
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3607
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3608

3609
typedef struct {
3610
  bool        shouldFree;
3611
  int32_t     len;
3612
  const char* ptr;
3613
} CowStr;
3614
/**
3615
 * @brief Create a CowStr object.
3616
 *
3617
 * @param len: length of the string.
3618
 * @param ptr: pointer to the string input.
3619
 * @param shouldClone: whether to clone the string.
3620
 * @return CowStr object.
3621
 */
3622
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3623
/**
3624
 * @brief Set a CowStr object with given string.
3625
 *
3626
 * @param cow: pointer to the CowStr object.
3627
 * @param len: length of the string.
3628
 * @param ptr: pointer to the string input.
3629
 * @param shouldFree: whether to free the string.
3630
 */
3631
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3632
/**
3633
 * @brief Clone a CowStr object without copy the string.
3634
 *
3635
 * @param cow: pointer to the CowStr object.
3636
 * @return CowStr object.
3637
 */
3638
CowStr xCloneRefCowStr(CowStr* cow);
3639
/**
3640
 * @brief Convert a CowStr object to a string.
3641
 *
3642
 * @param cow: pointer to the CowStr object.
3643
 */
3644
char* xCowStrToStr(CowStr* cow);
3645
/**
3646
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3647
 *
3648
 * @param cow: pointer to the CowStr object.
3649
 */
3650
void xFreeCowStr(CowStr* cow);
3651
/**
3652
 * @brief Encode and push a CowStr object into the encoder.
3653
 *
3654
 * @param encoder
3655
 * @param cow
3656
 * @return int32_t
3657
 */
3658
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3659
/**
3660
 * @brief Decode a CowStr from the encoder.
3661
 *
3662
 * @param decoder
3663
 * @param cow
3664
 * @param shouldClone
3665
 * @return int32_t
3666
 */
3667
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3668

3669
typedef enum {
3670
  XNODE_TASK_SOURCE_DSN = 1,
3671
  XNODE_TASK_SOURCE_DATABASE,
3672
  XNODE_TASK_SOURCE_TOPIC,
3673
} ENodeXTaskSourceType;
3674

3675
typedef enum {
3676
  XNODE_TASK_SINK_DSN = 1,
3677
  XNODE_TASK_SINK_DATABASE,
3678
} ENodeXTaskSinkType;
3679

3680
typedef struct {
3681
  ENodeXTaskSourceType type;
3682
  CowStr               cstr;
3683
} xTaskSource;
3684
/**
3685
 * @brief Deallocate a xTaskSource object.
3686
 *
3687
 * @param source ptr
3688
 */
3689
void xFreeTaskSource(xTaskSource* source);
3690
/**
3691
 * @brief Create a xTaskSource object with cloned source string.
3692
 *
3693
 * @param sourceType: source type.
3694
 * @param len: length of source string.
3695
 * @param source: source string ptr.
3696
 * @return xTaskSource object
3697
 */
3698
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3699
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3700
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3701
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3702
const char* xGetTaskSourceStr(xTaskSource* source);
3703
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3704
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3705

3706
typedef struct {
3707
  ENodeXTaskSinkType type;
3708
  CowStr             cstr;
3709
} xTaskSink;
3710
/**
3711
 * @brief Deallocate a xTaskSink object.
3712
 *
3713
 * @param sink ptr
3714
 */
3715
void xFreeTaskSink(xTaskSink* sink);
3716
/**
3717
 * @brief Create a xTaskSink object with cloned name string.
3718
 *
3719
 * @param sinkType: sink type.
3720
 * @param len: length of sink string.
3721
 * @param ptr: sink string ptr.
3722
 * @return xTaskSink object
3723
 */
3724
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3725
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3726
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3727
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3728
const char* xGetTaskSinkStr(xTaskSink* sink);
3729
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3730
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3731

3732
typedef struct {
3733
  int32_t via;
3734
  CowStr  parser;
3735
  // CowStr  reason;
3736
  CowStr  trigger;
3737
  CowStr  health;
3738
  int32_t optionsNum;
3739
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3740
} xTaskOptions;
3741
/**
3742
 * @brief Deallocate a xTaskOptions object.
3743
 *
3744
 * @param options ptr
3745
 */
3746
void    xFreeTaskOptions(xTaskOptions* options);
3747
void    printXnodeTaskOptions(xTaskOptions* options);
3748
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3749
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3750

3751
typedef struct {
3752
  int32_t sqlLen;
3753
  char*   sql;
3754
  int32_t      xnodeId;
3755
  CowStr       name;
3756
  xTaskSource  source;
3757
  xTaskSink    sink;
3758
  xTaskOptions options;
3759
} SMCreateXnodeTaskReq;
3760
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3761
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3762
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3763

3764
typedef struct {
3765
  int32_t     tid;
3766
  CowStr      name;
3767
  int32_t     via;
3768
  int32_t     xnodeId;
3769
  CowStr      status;
3770
  xTaskSource source;
3771
  xTaskSink   sink;
3772
  CowStr      parser;
3773
  CowStr      reason;
3774
  CowStr      updateName;
3775
  int32_t     sqlLen;
3776
  char*       sql;
3777
} SMUpdateXnodeTaskReq;
3778
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3779
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3780
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3781

3782
typedef struct {
3783
  int32_t tid;
3784
  bool    force;
3785
  int32_t nameLen;
3786
  int32_t sqlLen;
3787
  char*   name;
3788
  char*   sql;
3789
} SMDropXnodeTaskReq;
3790
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3791
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3792
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3793

3794
typedef struct {
3795
  int32_t tid;
3796
  CowStr  name;
3797
  int32_t sqlLen;
3798
  char*   sql;
3799
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3800
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3801
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3802
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3803

3804
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3805
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3806
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3807

3808
typedef struct {
3809
  int32_t tid;
3810
  int32_t via;
3811
  int32_t xnodeId;
3812
  CowStr  status;
3813
  int32_t configLen;
3814
  int32_t reasonLen;
3815
  int32_t sqlLen;
3816
  char*   config;
3817
  char*   reason;
3818
  char*   sql;
3819
} SMCreateXnodeJobReq;
3820
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3821
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3822
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3823

3824
typedef struct {
3825
  int32_t jid;
3826
  int32_t via;
3827
  int32_t xnodeId;
3828
  CowStr  status;
3829
  int32_t configLen;
3830
  int32_t reasonLen;
3831
  int32_t sqlLen;
3832
  char*   config;
3833
  char*   reason;
3834
  char*   sql;
3835
} SMUpdateXnodeJobReq;
3836
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3837
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3838
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3839

3840
typedef struct {
3841
  int32_t jid;
3842
  int32_t xnodeId;
3843
  int32_t sqlLen;
3844
  char*   sql;
3845
} SMRebalanceXnodeJobReq;
3846
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3847
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3848
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3849

3850
typedef struct {
3851
  CowStr  ast;
3852
  int32_t sqlLen;
3853
  char*   sql;
3854
} SMRebalanceXnodeJobsWhereReq;
3855
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3856
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3857
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3858

3859
typedef struct {
3860
  int32_t jid;
3861
  int32_t tid;
3862
  int32_t sqlLen;
3863
  char*   sql;
3864
} SMDropXnodeJobReq;
3865
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3866
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3867
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3868

3869
typedef struct {
3870
  int32_t vgId;
3871
  int32_t hbSeq;
3872
} SVArbHbReqMember;
3873

3874
typedef struct {
3875
  int32_t dnodeId;
3876
  char*   arbToken;
3877
  int64_t arbTerm;
3878
  SArray* hbMembers;  // SVArbHbReqMember
3879
} SVArbHeartBeatReq;
3880

3881
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3882
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3883
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3884

3885
typedef struct {
3886
  int32_t vgId;
3887
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3888
  int32_t hbSeq;
3889
} SVArbHbRspMember;
3890

3891
typedef struct {
3892
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3893
  int32_t dnodeId;
3894
  SArray* hbMembers;  // SVArbHbRspMember
3895
} SVArbHeartBeatRsp;
3896

3897
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3898
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3899
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3900

3901
typedef struct {
3902
  char*   arbToken;
3903
  int64_t arbTerm;
3904
  char*   member0Token;
3905
  char*   member1Token;
3906
} SVArbCheckSyncReq;
3907

3908
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3909
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3910
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3911

3912
typedef struct {
3913
  char*   arbToken;
3914
  char*   member0Token;
3915
  char*   member1Token;
3916
  int32_t vgId;
3917
  int32_t errCode;
3918
} SVArbCheckSyncRsp;
3919

3920
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3921
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3922
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3923

3924
typedef struct {
3925
  char*   arbToken;
3926
  int64_t arbTerm;
3927
  char*   memberToken;
3928
  int8_t  force;
3929
} SVArbSetAssignedLeaderReq;
3930

3931
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3932
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3933
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3934

3935
typedef struct {
3936
  char*   arbToken;
3937
  char*   memberToken;
3938
  int32_t vgId;
3939
} SVArbSetAssignedLeaderRsp;
3940

3941
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3942
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3943
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3944

3945
typedef struct {
3946
  int32_t dnodeId;
3947
  char*   token;
3948
} SMArbUpdateGroupMember;
3949

3950
typedef struct {
3951
  int32_t dnodeId;
3952
  char*   token;
3953
  int8_t  acked;
3954
} SMArbUpdateGroupAssigned;
3955

3956
typedef struct {
3957
  int32_t                  vgId;
3958
  int64_t                  dbUid;
3959
  SMArbUpdateGroupMember   members[2];
3960
  int8_t                   isSync;
3961
  int8_t                   assignedAcked;
3962
  SMArbUpdateGroupAssigned assignedLeader;
3963
  int64_t                  version;
3964
  int32_t                  code;
3965
  int64_t                  updateTimeMs;
3966
} SMArbUpdateGroup;
3967

3968
typedef struct {
3969
  SArray* updateArray;  // SMArbUpdateGroup
3970
} SMArbUpdateGroupBatchReq;
3971

3972
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3973
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3974
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3975

3976
typedef struct {
3977
  char queryStrId[TSDB_QUERY_ID_LEN];
3978
} SKillQueryReq;
3979

3980
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3981
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3982

3983
typedef struct {
3984
  uint32_t connId;
3985
} SKillConnReq;
3986

3987
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3988
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3989

3990
typedef struct {
3991
  int32_t transId;
3992
} SKillTransReq;
3993

3994
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3995
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3996

3997
typedef struct {
3998
  int32_t useless;  // useless
3999
  int32_t sqlLen;
4000
  char*   sql;
4001
} SBalanceVgroupReq;
4002

4003
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4004
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4005
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4006

4007
typedef struct {
4008
  int32_t useless;  // useless
4009
  int32_t sqlLen;
4010
  char*   sql;
4011
} SAssignLeaderReq;
4012

4013
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4014
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4015
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4016
typedef struct {
4017
  int32_t vgId1;
4018
  int32_t vgId2;
4019
} SMergeVgroupReq;
4020

4021
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4022
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4023

4024
typedef struct {
4025
  int32_t vgId;
4026
  int32_t dnodeId1;
4027
  int32_t dnodeId2;
4028
  int32_t dnodeId3;
4029
  int32_t sqlLen;
4030
  char*   sql;
4031
} SRedistributeVgroupReq;
4032

4033
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4034
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4035
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4036

4037
typedef struct {
4038
  int32_t reserved;
4039
  int32_t vgId;
4040
  int32_t sqlLen;
4041
  char*   sql;
4042
  char    db[TSDB_DB_FNAME_LEN];
4043
} SBalanceVgroupLeaderReq;
4044

4045
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4046
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4047
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4048

4049
typedef struct {
4050
  int32_t vgId;
4051
} SForceBecomeFollowerReq;
4052

4053
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4054
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4055

4056
typedef struct {
4057
  int32_t vgId;
4058
  bool    force;
4059
} SSplitVgroupReq;
4060

4061
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4062
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4063

4064
typedef struct {
4065
  char user[TSDB_USER_LEN];
4066
  char spi;
4067
  char encrypt;
4068
  char secret[TSDB_PASSWORD_LEN];
4069
  char ckey[TSDB_PASSWORD_LEN];
4070
} SAuthReq, SAuthRsp;
4071

4072
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4073
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4074

4075
typedef struct {
4076
  int32_t statusCode;
4077
  char    details[1024];
4078
} SServerStatusRsp;
4079

4080
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4081
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4082

4083
/**
4084
 * The layout of the query message payload is as following:
4085
 * +--------------------+---------------------------------+
4086
 * |Sql statement       | Physical plan                   |
4087
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4088
 * +--------------------+---------------------------------+
4089
 */
4090
typedef struct SSubQueryMsg {
4091
  SMsgHead header;
4092
  uint64_t sId;
4093
  uint64_t queryId;
4094
  uint64_t clientId;
4095
  uint64_t taskId;
4096
  int64_t  refId;
4097
  int32_t  execId;
4098
  int32_t  msgMask;
4099
  int8_t   taskType;
4100
  int8_t   explain;
4101
  int8_t   needFetch;
4102
  int8_t   compress;
4103
  uint32_t sqlLen;
4104
  char*    sql;
4105
  uint32_t msgLen;
4106
  char*    msg;
4107
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4108
} SSubQueryMsg;
4109

4110
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4111
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4112
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4113

4114
typedef struct {
4115
  SMsgHead header;
4116
  uint64_t sId;
4117
  uint64_t queryId;
4118
  uint64_t taskId;
4119
} SSinkDataReq;
4120

4121
typedef struct {
4122
  SMsgHead header;
4123
  uint64_t sId;
4124
  uint64_t queryId;
4125
  uint64_t clientId;
4126
  uint64_t taskId;
4127
  int32_t  execId;
4128
} SQueryContinueReq;
4129

4130
typedef struct {
4131
  SMsgHead header;
4132
  uint64_t sId;
4133
  uint64_t queryId;
4134
  uint64_t taskId;
4135
} SResReadyReq;
4136

4137
typedef struct {
4138
  int32_t code;
4139
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4140
  int32_t sversion;
4141
  int32_t tversion;
4142
} SResReadyRsp;
4143

4144
typedef struct SOperatorParam {
4145
  int32_t opType;
4146
  int32_t downstreamIdx;
4147
  void*   value;
4148
  SArray* pChildren;  // SArray<SOperatorParam*>
4149
  bool    reUse;
4150
} SOperatorParam;
4151

4152
typedef struct SColIdNameKV {
4153
  col_id_t colId;
4154
  char     colName[TSDB_COL_NAME_LEN];
4155
} SColIdNameKV;
4156

4157
#define COL_MASK_ON   ((int8_t)0x1)
4158
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4159
#define COL_SET_MASK_ON(c)     \
4160
  do {                         \
4161
    (c)->flags |= COL_MASK_ON; \
4162
  } while (0)
4163

4164
typedef struct SColNameFlag {
4165
  col_id_t colId;
4166
  char     colName[TSDB_COL_NAME_LEN];
4167
  int8_t   flags;  // 0x01: COL_MASK_ON
4168
} SColNameFlag;
4169

4170
typedef struct SColIdPair {
4171
  col_id_t  vtbColId;
4172
  col_id_t  orgColId;
4173
  SDataType type;
4174
} SColIdPair;
4175

4176
typedef struct SColIdSlotIdPair {
4177
  int32_t  vtbSlotId;
4178
  col_id_t orgColId;
4179
} SColIdSlotIdPair;
4180

4181
typedef struct SOrgTbInfo {
4182
  int32_t vgId;
4183
  char    tbName[TSDB_TABLE_FNAME_LEN];
4184
  SArray* colMap;  // SArray<SColIdNameKV>
4185
} SOrgTbInfo;
4186

4187
void destroySOrgTbInfo(void *info);
4188

4189
typedef enum {
4190
  DYN_TYPE_STB_JOIN = 1,
4191
  DYN_TYPE_VSTB_SINGLE_SCAN,
4192
  DYN_TYPE_VSTB_BATCH_SCAN,
4193
} ETableScanDynType;
4194

4195
typedef struct STableScanOperatorParam {
4196
  bool              tableSeq;
4197
  bool              isNewParam;
4198
  uint64_t          groupid;
4199
  SArray*           pUidList;
4200
  SOrgTbInfo*       pOrgTbInfo;
4201
  SArray*           pBatchTbInfo;  // SArray<SOrgTbInfo>
4202
  SArray*           pTagList;
4203
  STimeWindow       window;
4204
  ETableScanDynType type;
4205
} STableScanOperatorParam;
4206

4207
typedef struct STagScanOperatorParam {
4208
  tb_uid_t vcUid;
4209
} STagScanOperatorParam;
4210

4211
typedef struct SVTableScanOperatorParam {
4212
  uint64_t        uid;
4213
  STimeWindow     window;
4214
  SOperatorParam* pTagScanOp;
4215
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4216
} SVTableScanOperatorParam;
4217

4218
typedef struct SMergeOperatorParam {
4219
  int32_t         winNum;
4220
} SMergeOperatorParam;
4221

4222
typedef struct SAggOperatorParam {
4223
  bool            needCleanRes;
4224
} SAggOperatorParam;
4225

4226
typedef struct SExternalWindowOperatorParam {
4227
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4228
} SExternalWindowOperatorParam;
4229

4230
typedef struct SDynQueryCtrlOperatorParam {
4231
  STimeWindow    window;
4232
} SDynQueryCtrlOperatorParam;
4233

4234
struct SStreamRuntimeFuncInfo;
4235
typedef struct {
4236
  SMsgHead        header;
4237
  uint64_t        sId;
4238
  uint64_t        queryId;
4239
  uint64_t        clientId;
4240
  uint64_t        taskId;
4241
  int32_t         execId;
4242
  SOperatorParam* pOpParam;
4243

4244
  // used for new-stream
4245
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4246
  bool                           reset;
4247
  bool                           dynTbname;
4248
  // used for new-stream
4249
} SResFetchReq;
4250

4251
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4252
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4253
void    tDestroySResFetchReq(SResFetchReq* pReq);
4254
typedef struct {
4255
  SMsgHead header;
4256
  uint64_t clientId;
4257
} SSchTasksStatusReq;
4258

4259
typedef struct {
4260
  uint64_t queryId;
4261
  uint64_t clientId;
4262
  uint64_t taskId;
4263
  int64_t  refId;
4264
  int32_t  subJobId;
4265
  int32_t  execId;
4266
  int8_t   status;
4267
} STaskStatus;
4268

4269
typedef struct {
4270
  int64_t refId;
4271
  SArray* taskStatus;  // SArray<STaskStatus>
4272
} SSchedulerStatusRsp;
4273

4274
typedef struct {
4275
  uint64_t queryId;
4276
  uint64_t taskId;
4277
  int8_t   action;
4278
} STaskAction;
4279

4280
typedef struct SQueryNodeEpId {
4281
  int32_t nodeId;  // vgId or qnodeId
4282
  SEp     ep;
4283
} SQueryNodeEpId;
4284

4285
typedef struct {
4286
  SMsgHead       header;
4287
  uint64_t       clientId;
4288
  SQueryNodeEpId epId;
4289
  SArray*        taskAction;  // SArray<STaskAction>
4290
} SSchedulerHbReq;
4291

4292
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4293
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4294
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4295

4296
typedef struct {
4297
  SQueryNodeEpId epId;
4298
  SArray*        taskStatus;  // SArray<STaskStatus>
4299
} SSchedulerHbRsp;
4300

4301
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4302
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4303
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4304

4305
typedef struct {
4306
  SMsgHead header;
4307
  uint64_t sId;
4308
  uint64_t queryId;
4309
  uint64_t clientId;
4310
  uint64_t taskId;
4311
  int64_t  refId;
4312
  int32_t  execId;
4313
} STaskCancelReq;
4314

4315
typedef struct {
4316
  int32_t code;
4317
} STaskCancelRsp;
4318

4319
typedef struct {
4320
  SMsgHead header;
4321
  uint64_t sId;
4322
  uint64_t queryId;
4323
  uint64_t clientId;
4324
  uint64_t taskId;
4325
  int64_t  refId;
4326
  int32_t  execId;
4327
} STaskDropReq;
4328

4329
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4330
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4331

4332
typedef enum {
4333
  TASK_NOTIFY_FINISHED = 1,
4334
} ETaskNotifyType;
4335

4336
typedef struct {
4337
  SMsgHead        header;
4338
  uint64_t        sId;
4339
  uint64_t        queryId;
4340
  uint64_t        clientId;
4341
  uint64_t        taskId;
4342
  int64_t         refId;
4343
  int32_t         execId;
4344
  ETaskNotifyType type;
4345
} STaskNotifyReq;
4346

4347
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4348
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4349

4350
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4351
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4352

4353
typedef struct {
4354
  int32_t code;
4355
} STaskDropRsp;
4356

4357
#define STREAM_TRIGGER_AT_ONCE                 1
4358
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4359
#define STREAM_TRIGGER_MAX_DELAY               3
4360
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4361
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4362

4363
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4364
#define STREAM_FILL_HISTORY_ON        1
4365
#define STREAM_FILL_HISTORY_OFF       0
4366
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4367
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4368
#define STREAM_CREATE_STABLE_TRUE     1
4369
#define STREAM_CREATE_STABLE_FALSE    0
4370

4371
typedef struct SVgroupVer {
4372
  int32_t vgId;
4373
  int64_t ver;
4374
} SVgroupVer;
4375

4376
typedef struct STaskNotifyEventStat {
4377
  int64_t notifyEventAddTimes;     // call times of add function
4378
  int64_t notifyEventAddElems;     // elements added by add function
4379
  double  notifyEventAddCostSec;   // time cost of add function
4380
  int64_t notifyEventPushTimes;    // call times of push function
4381
  int64_t notifyEventPushElems;    // elements pushed by push function
4382
  double  notifyEventPushCostSec;  // time cost of push function
4383
  int64_t notifyEventPackTimes;    // call times of pack function
4384
  int64_t notifyEventPackElems;    // elements packed by pack function
4385
  double  notifyEventPackCostSec;  // time cost of pack function
4386
  int64_t notifyEventSendTimes;    // call times of send function
4387
  int64_t notifyEventSendElems;    // elements sent by send function
4388
  double  notifyEventSendCostSec;  // time cost of send function
4389
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4390
} STaskNotifyEventStat;
4391

4392
enum {
4393
  TOPIC_SUB_TYPE__DB = 1,
4394
  TOPIC_SUB_TYPE__TABLE,
4395
  TOPIC_SUB_TYPE__COLUMN,
4396
};
4397

4398
#define DEFAULT_MAX_POLL_INTERVAL  300000
4399
#define DEFAULT_SESSION_TIMEOUT    12000
4400
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4401
#define DEFAULT_MIN_POLL_ROWS      4096
4402

4403
typedef struct {
4404
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4405
  int8_t igExists;
4406
  int8_t subType;
4407
  int8_t withMeta;
4408
  char*  sql;
4409
  char   subDbName[TSDB_DB_FNAME_LEN];
4410
  char*  ast;
4411
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4412
  int8_t reload;
4413
} SCMCreateTopicReq;
4414

4415
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4416
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4417
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4418

4419
typedef struct {
4420
  int64_t consumerId;
4421
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4422

4423
typedef struct {
4424
  int64_t consumerId;
4425
  char    cgroup[TSDB_CGROUP_LEN];
4426
  char    clientId[TSDB_CLIENT_ID_LEN];
4427
  char    user[TSDB_USER_LEN];
4428
  char    fqdn[TSDB_FQDN_LEN];
4429
  SArray* topicNames;  // SArray<char**>
4430

4431
  int8_t  withTbName;
4432
  int8_t  autoCommit;
4433
  int32_t autoCommitInterval;
4434
  int8_t  resetOffsetCfg;
4435
  int8_t  enableReplay;
4436
  int8_t  enableBatchMeta;
4437
  int32_t sessionTimeoutMs;
4438
  int32_t maxPollIntervalMs;
4439
} SCMSubscribeReq;
4440

4441
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4442
  int32_t tlen = 0;
641,838✔
4443
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
641,838✔
4444
  tlen += taosEncodeString(buf, pReq->cgroup);
641,838✔
4445
  tlen += taosEncodeString(buf, pReq->clientId);
641,838✔
4446

4447
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
641,838✔
4448
  tlen += taosEncodeFixedI32(buf, topicNum);
641,838✔
4449

4450
  for (int32_t i = 0; i < topicNum; i++) {
895,268✔
4451
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
506,860✔
4452
  }
4453

4454
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
641,838✔
4455
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
641,838✔
4456
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
641,838✔
4457
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
641,838✔
4458
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
641,838✔
4459
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
641,838✔
4460
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
641,838✔
4461
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
641,838✔
4462
  tlen += taosEncodeString(buf, pReq->user);
641,838✔
4463
  tlen += taosEncodeString(buf, pReq->fqdn);
641,838✔
4464

4465
  return tlen;
641,838✔
4466
}
4467

4468
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4469
  void* start = buf;
330,742✔
4470
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
330,742✔
4471
  buf = taosDecodeStringTo(buf, pReq->cgroup);
330,742✔
4472
  buf = taosDecodeStringTo(buf, pReq->clientId);
330,742✔
4473

4474
  int32_t topicNum = 0;
330,742✔
4475
  buf = taosDecodeFixedI32(buf, &topicNum);
330,742✔
4476

4477
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
330,742✔
4478
  if (pReq->topicNames == NULL) {
330,742✔
UNCOV
4479
    return terrno;
×
4480
  }
4481
  for (int32_t i = 0; i < topicNum; i++) {
480,334✔
4482
    char* name = NULL;
149,592✔
4483
    buf = taosDecodeString(buf, &name);
149,592✔
4484
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
299,184✔
UNCOV
4485
      return terrno;
×
4486
    }
4487
  }
4488

4489
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
330,742✔
4490
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
330,742✔
4491
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
330,742✔
4492
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
330,742✔
4493
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
330,742✔
4494
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
330,742✔
4495
  if ((char*)buf - (char*)start < len) {
330,742✔
4496
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
330,742✔
4497
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
330,742✔
4498
    buf = taosDecodeStringTo(buf, pReq->user);
330,742✔
4499
    buf = taosDecodeStringTo(buf, pReq->fqdn);
661,484✔
4500
  } else {
UNCOV
4501
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4502
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4503
  }
4504

4505
  return 0;
330,742✔
4506
}
4507

4508
typedef struct {
4509
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4510
  SArray* removedConsumers;  // SArray<int64_t>
4511
  SArray* newConsumers;      // SArray<int64_t>
4512
} SMqRebInfo;
4513

4514
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4515
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
307,294✔
4516
  if (pRebInfo == NULL) {
307,294✔
UNCOV
4517
    return NULL;
×
4518
  }
4519
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
307,294✔
4520
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
307,294✔
4521
  if (pRebInfo->removedConsumers == NULL) {
307,294✔
UNCOV
4522
    goto _err;
×
4523
  }
4524
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
307,294✔
4525
  if (pRebInfo->newConsumers == NULL) {
307,294✔
UNCOV
4526
    goto _err;
×
4527
  }
4528
  return pRebInfo;
307,294✔
UNCOV
4529
_err:
×
UNCOV
4530
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4531
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4532
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4533
  return NULL;
×
4534
}
4535

4536
typedef struct {
4537
  int64_t streamId;
4538
  int64_t checkpointId;
4539
  char    streamName[TSDB_STREAM_FNAME_LEN];
4540
} SMStreamDoCheckpointMsg;
4541

4542
typedef struct {
4543
  int64_t status;
4544
} SMVSubscribeRsp;
4545

4546
typedef struct {
4547
  char    name[TSDB_TOPIC_FNAME_LEN];
4548
  int8_t  igNotExists;
4549
  int32_t sqlLen;
4550
  char*   sql;
4551
  int8_t  force;
4552
} SMDropTopicReq;
4553

4554
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4555
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4556
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4557

4558
typedef struct {
4559
  char    name[TSDB_TOPIC_FNAME_LEN];
4560
  int8_t  igNotExists;
4561
  int32_t sqlLen;
4562
  char*   sql;
4563
} SMReloadTopicReq;
4564

4565
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4566
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4567
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4568

4569
typedef struct {
4570
  char   topic[TSDB_TOPIC_FNAME_LEN];
4571
  char   cgroup[TSDB_CGROUP_LEN];
4572
  int8_t igNotExists;
4573
  int8_t force;
4574
} SMDropCgroupReq;
4575

4576
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4577
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4578

4579
typedef struct {
4580
  int8_t reserved;
4581
} SMDropCgroupRsp;
4582

4583
typedef struct {
4584
  char    name[TSDB_TABLE_FNAME_LEN];
4585
  int8_t  alterType;
4586
  SSchema schema;
4587
} SAlterTopicReq;
4588

4589
typedef struct {
4590
  SMsgHead head;
4591
  char     name[TSDB_TABLE_FNAME_LEN];
4592
  int64_t  tuid;
4593
  int32_t  sverson;
4594
  int32_t  execLen;
4595
  char*    executor;
4596
  int32_t  sqlLen;
4597
  char*    sql;
4598
} SDCreateTopicReq;
4599

4600
typedef struct {
4601
  SMsgHead head;
4602
  char     name[TSDB_TABLE_FNAME_LEN];
4603
  int64_t  tuid;
4604
} SDDropTopicReq;
4605

4606
typedef struct {
4607
  char*      name;
4608
  int64_t    uid;
4609
  int64_t    interval[2];
4610
  int8_t     intervalUnit;
4611
  int16_t    nFuncs;
4612
  col_id_t*  funcColIds;  // column ids specified by user
4613
  func_id_t* funcIds;     // function ids specified by user
4614
} SRSmaParam;
4615

4616
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4617
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4618

4619
// TDMT_VND_CREATE_STB ==============
4620
typedef struct SVCreateStbReq {
4621
  char*           name;
4622
  tb_uid_t        suid;
4623
  int8_t          rollup;
4624
  SSchemaWrapper  schemaRow;
4625
  SSchemaWrapper  schemaTag;
4626
  SRSmaParam      rsmaParam;
4627
  int32_t         alterOriDataLen;
4628
  void*           alterOriData;
4629
  int8_t          source;
4630
  int8_t          colCmpred;
4631
  SColCmprWrapper colCmpr;
4632
  int64_t         keep;
4633
  int64_t         ownerId;
4634
  SExtSchema*     pExtSchemas;
4635
  int8_t          virtualStb;
4636
} SVCreateStbReq;
4637

4638
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4639
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4640

4641
// TDMT_VND_DROP_STB ==============
4642
typedef struct SVDropStbReq {
4643
  char*    name;
4644
  tb_uid_t suid;
4645
} SVDropStbReq;
4646

4647
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4648
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4649

4650
// TDMT_VND_CREATE_TABLE ==============
4651
#define TD_CREATE_IF_NOT_EXISTS       0x1
4652
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4653
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4654
typedef struct SVCreateTbReq {
4655
  int32_t  flags;
4656
  char*    name;
4657
  tb_uid_t uid;
4658
  int64_t  btime;
4659
  int32_t  ttl;
4660
  int32_t  commentLen;
4661
  char*    comment;
4662
  int8_t   type;
4663
  union {
4664
    struct {
4665
      char*    stbName;  // super table name
4666
      uint8_t  tagNum;
4667
      tb_uid_t suid;
4668
      SArray*  tagName;
4669
      uint8_t* pTag;
4670
    } ctb;
4671
    struct {
4672
      SSchemaWrapper schemaRow;
4673
    } ntb;
4674
  };
4675
  int32_t         sqlLen;
4676
  char*           sql;
4677
  SColCmprWrapper colCmpr;
4678
  SExtSchema*     pExtSchemas;
4679
  SColRefWrapper  colRef;  // col reference for virtual table
4680
} SVCreateTbReq;
4681

4682
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4683
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4684
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4685
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4686

4687
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4688
  if (NULL == req) {
2,147,483,647✔
4689
    return;
2,137,254,285✔
4690
  }
4691

4692
  taosMemoryFreeClear(req->sql);
70,455,542✔
4693
  taosMemoryFreeClear(req->name);
70,454,536✔
4694
  taosMemoryFreeClear(req->comment);
70,457,675✔
4695
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
70,448,726✔
4696
    taosMemoryFreeClear(req->ctb.pTag);
55,751,115✔
4697
    taosMemoryFreeClear(req->ctb.stbName);
55,740,933✔
4698
    taosArrayDestroy(req->ctb.tagName);
55,731,018✔
4699
    req->ctb.tagName = NULL;
55,721,509✔
4700
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,709,751✔
4701
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,709,751✔
4702
  }
4703
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
70,441,635✔
4704
  taosMemoryFreeClear(req->pExtSchemas);
70,459,169✔
4705
  taosMemoryFreeClear(req->colRef.pColRef);
70,457,479✔
4706
}
4707

4708
typedef struct {
4709
  int32_t nReqs;
4710
  union {
4711
    SVCreateTbReq* pReqs;
4712
    SArray*        pArray;
4713
  };
4714
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4715
} SVCreateTbBatchReq;
4716

4717
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4718
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4719
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4720

4721
typedef struct {
4722
  int32_t        code;
4723
  STableMetaRsp* pMeta;
4724
} SVCreateTbRsp, SVUpdateTbRsp;
4725

4726
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4727
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4728
void tFreeSVCreateTbRsp(void* param);
4729

4730
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4731
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4732

4733
typedef struct {
4734
  int32_t nRsps;
4735
  union {
4736
    SVCreateTbRsp* pRsps;
4737
    SArray*        pArray;
4738
  };
4739
} SVCreateTbBatchRsp;
4740

4741
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4742
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4743

4744
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4745
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4746

4747
// TDMT_VND_DROP_TABLE =================
4748
typedef struct {
4749
  char*    name;
4750
  uint64_t suid;  // for tmq in wal format
4751
  int64_t  uid;
4752
  int8_t   igNotExists;
4753
  int8_t   isVirtual;
4754
} SVDropTbReq;
4755

4756
typedef struct {
4757
  int32_t code;
4758
} SVDropTbRsp;
4759

4760
typedef struct {
4761
  int32_t nReqs;
4762
  union {
4763
    SVDropTbReq* pReqs;
4764
    SArray*      pArray;
4765
  };
4766
} SVDropTbBatchReq;
4767

4768
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4769
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4770

4771
typedef struct {
4772
  int32_t nRsps;
4773
  union {
4774
    SVDropTbRsp* pRsps;
4775
    SArray*      pArray;
4776
  };
4777
} SVDropTbBatchRsp;
4778

4779
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4780
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4781

4782
// TDMT_VND_ALTER_TABLE =====================
4783
typedef struct SMultiTagUpateVal {
4784
  char*    tagName;
4785
  int32_t  colId;
4786
  int8_t   tagType;
4787
  int8_t   tagFree;
4788
  uint32_t nTagVal;
4789
  uint8_t* pTagVal;
4790
  int8_t   isNull;
4791
  SArray*  pTagArray;
4792
} SMultiTagUpateVal;
4793
typedef struct SVAlterTbReq {
4794
  char*   tbName;
4795
  int8_t  action;
4796
  char*   colName;
4797
  int32_t colId;
4798
  // TSDB_ALTER_TABLE_ADD_COLUMN
4799
  int8_t  type;
4800
  int8_t  flags;
4801
  int32_t bytes;
4802
  // TSDB_ALTER_TABLE_DROP_COLUMN
4803
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4804
  int8_t   colModType;
4805
  int32_t  colModBytes;
4806
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4807
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4808
  int8_t   isNull;
4809
  int8_t   tagType;
4810
  int8_t   tagFree;
4811
  uint32_t nTagVal;
4812
  uint8_t* pTagVal;
4813
  SArray*  pTagArray;
4814
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4815
  int8_t   updateTTL;
4816
  int32_t  newTTL;
4817
  int32_t  newCommentLen;
4818
  char*    newComment;
4819
  int64_t  ctimeMs;    // fill by vnode
4820
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4821
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4822
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4823
  // for Add column
4824
  STypeMod typeMod;
4825
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4826
  char* refDbName;
4827
  char* refTbName;
4828
  char* refColName;
4829
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4830
} SVAlterTbReq;
4831

4832
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4833
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4834
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4835
void    tfreeMultiTagUpateVal(void* pMultiTag);
4836

4837
typedef struct {
4838
  int32_t        code;
4839
  STableMetaRsp* pMeta;
4840
} SVAlterTbRsp;
4841

4842
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4843
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4844
// ======================
4845

4846
typedef struct {
4847
  SMsgHead head;
4848
  int64_t  uid;
4849
  int32_t  tid;
4850
  int16_t  tversion;
4851
  int16_t  colId;
4852
  int8_t   type;
4853
  int16_t  bytes;
4854
  int32_t  tagValLen;
4855
  int16_t  numOfTags;
4856
  int32_t  schemaLen;
4857
  char     data[];
4858
} SUpdateTagValReq;
4859

4860
typedef struct {
4861
  SMsgHead head;
4862
} SUpdateTagValRsp;
4863

4864
typedef struct {
4865
  SMsgHead head;
4866
} SVShowTablesReq;
4867

4868
typedef struct {
4869
  SMsgHead head;
4870
  int32_t  id;
4871
} SVShowTablesFetchReq;
4872

4873
typedef struct {
4874
  int64_t useconds;
4875
  int8_t  completed;  // all results are returned to client
4876
  int8_t  precision;
4877
  int8_t  compressed;
4878
  int32_t compLen;
4879
  int32_t numOfRows;
4880
  char    data[];
4881
} SVShowTablesFetchRsp;
4882

4883
typedef struct {
4884
  int64_t consumerId;
4885
  int32_t epoch;
4886
  char    cgroup[TSDB_CGROUP_LEN];
4887
} SMqAskEpReq;
4888

4889
typedef struct {
4890
  int32_t key;
4891
  int32_t valueLen;
4892
  void*   value;
4893
} SKv;
4894

4895
typedef struct {
4896
  int64_t tscRid;
4897
  int8_t  connType;
4898
} SClientHbKey;
4899

4900
typedef struct {
4901
  int64_t tid;
4902
  char    status[TSDB_JOB_STATUS_LEN];
4903
} SQuerySubDesc;
4904

4905
typedef struct {
4906
  char     sql[TSDB_SHOW_SQL_LEN];
4907
  uint64_t queryId;
4908
  int64_t  useconds;
4909
  int64_t  stime;  // timestamp precision ms
4910
  int64_t  reqRid;
4911
  bool     stableQuery;
4912
  bool     isSubQuery;
4913
  char     fqdn[TSDB_FQDN_LEN];
4914
  int32_t  subPlanNum;
4915
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4916
} SQueryDesc;
4917

4918
typedef struct {
4919
  uint32_t connId;
4920
  SArray*  queryDesc;  // SArray<SQueryDesc>
4921
} SQueryHbReqBasic;
4922

4923
typedef struct {
4924
  uint32_t connId;
4925
  uint64_t killRid;
4926
  int32_t  totalDnodes;
4927
  int32_t  onlineDnodes;
4928
  int8_t   killConnection;
4929
  int8_t   align[3];
4930
  SEpSet   epSet;
4931
  SArray*  pQnodeList;
4932
} SQueryHbRspBasic;
4933

4934
typedef struct SAppClusterSummary {
4935
  uint64_t numOfInsertsReq;
4936
  uint64_t numOfInsertRows;
4937
  uint64_t insertElapsedTime;
4938
  uint64_t insertBytes;  // submit to tsdb since launched.
4939

4940
  uint64_t fetchBytes;
4941
  uint64_t numOfQueryReq;
4942
  uint64_t queryElapsedTime;
4943
  uint64_t numOfSlowQueries;
4944
  uint64_t totalRequests;
4945
  uint64_t currentRequests;  // the number of SRequestObj
4946
} SAppClusterSummary;
4947

4948
typedef struct {
4949
  int64_t            appId;
4950
  int32_t            pid;
4951
  char               name[TSDB_APP_NAME_LEN];
4952
  int64_t            startTime;
4953
  SAppClusterSummary summary;
4954
} SAppHbReq;
4955

4956
typedef struct {
4957
  SClientHbKey      connKey;
4958
  int64_t           clusterId;
4959
  SAppHbReq         app;
4960
  SQueryHbReqBasic* query;
4961
  SHashObj*         info;  // hash<Skv.key, Skv>
4962
  char              user[TSDB_USER_LEN];
4963
  char              tokenName[TSDB_TOKEN_NAME_LEN];
4964
  char              userApp[TSDB_APP_NAME_LEN];
4965
  uint32_t          userIp;
4966
  SIpRange          userDualIp;
4967
  char              sVer[TSDB_VERSION_LEN];
4968
  char              cInfo[CONNECTOR_INFO_LEN];
4969
} SClientHbReq;
4970

4971
typedef struct {
4972
  int64_t reqId;
4973
  SArray* reqs;  // SArray<SClientHbReq>
4974
  int64_t ipWhiteListVer;
4975
} SClientHbBatchReq;
4976

4977
typedef struct {
4978
  SClientHbKey      connKey;
4979
  int32_t           status;
4980
  SQueryHbRspBasic* query;
4981
  SArray*           info;  // Array<Skv>
4982
} SClientHbRsp;
4983

4984
typedef struct {
4985
  int64_t       reqId;
4986
  int64_t       rspId;
4987
  int32_t       svrTimestamp;
4988
  SArray*       rsps;  // SArray<SClientHbRsp>
4989
  SMonitorParas monitorParas;
4990
  int8_t        enableAuditDelete;
4991
  int8_t        enableStrongPass;
4992
  int8_t        enableAuditSelect;
4993
  int8_t        enableAuditInsert;
4994
  int8_t        auditLevel;
4995
} SClientHbBatchRsp;
4996

4997
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
63,576,996✔
4998

4999
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5000
  void* pIter = taosHashIterate(info, NULL);
44,757,830✔
5001
  while (pIter != NULL) {
103,705,698✔
5002
    SKv* kv = (SKv*)pIter;
58,948,132✔
5003
    taosMemoryFreeClear(kv->value);
58,948,132✔
5004
    pIter = taosHashIterate(info, pIter);
58,948,132✔
5005
  }
5006
}
44,757,566✔
5007

5008
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
28,332,341✔
5009
  SQueryDesc* desc = (SQueryDesc*)pDesc;
28,332,341✔
5010
  if (desc->subDesc) {
28,332,341✔
5011
    taosArrayDestroy(desc->subDesc);
20,060,709✔
5012
    desc->subDesc = NULL;
20,060,229✔
5013
  }
5014
}
28,331,607✔
5015

5016
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
50,898,699✔
5017
  SClientHbReq* req = (SClientHbReq*)pReq;
53,241,525✔
5018
  if (req->query) {
53,241,525✔
5019
    if (req->query->queryDesc) {
50,898,643✔
5020
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
22,796,466✔
5021
    }
5022
    taosMemoryFreeClear(req->query);
50,898,727✔
5023
  }
5024

5025
  if (req->info) {
53,241,609✔
5026
    tFreeReqKvHash(req->info);
44,756,749✔
5027
    taosHashCleanup(req->info);
44,757,566✔
5028
    req->info = NULL;
44,756,144✔
5029
  }
5030
}
27,367,163✔
5031

5032
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5033
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5034

5035
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5036
  if (pReq == NULL) return;
21,828,077✔
5037
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
21,828,077✔
5038
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
21,828,077✔
5039
  taosMemoryFree(pReq);
21,828,077✔
5040
}
5041

5042
static FORCE_INLINE void tFreeClientKv(void* pKv) {
22,164,088✔
5043
  SKv* kv = (SKv*)pKv;
22,164,088✔
5044
  if (kv) {
22,164,088✔
5045
    taosMemoryFreeClear(kv->value);
22,164,088✔
5046
  }
5047
}
22,164,088✔
5048

5049
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
50,696,487✔
5050
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
50,696,487✔
5051
  if (rsp->query) {
50,696,487✔
5052
    taosArrayDestroy(rsp->query->pQnodeList);
50,686,959✔
5053
    taosMemoryFreeClear(rsp->query);
50,693,467✔
5054
  }
5055
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
50,705,834✔
5056
}
25,675,481✔
5057

5058
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5059
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
42,695,746✔
5060
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
42,695,746✔
5061
}
42,703,656✔
5062

5063
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5064
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5065
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5066

5067
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5068
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
169,131,471✔
5069
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
169,131,471✔
5070
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
169,131,864✔
5071
  return 0;
84,565,493✔
5072
}
5073

5074
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5075
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
82,924,035✔
5076
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
82,924,299✔
5077
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
41,462,311✔
5078
  if (pKv->value == NULL) {
41,461,705✔
UNCOV
5079
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5080
  }
5081
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
41,462,370✔
5082
  return 0;
41,461,705✔
5083
}
5084

5085
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5086
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
211,003,299✔
5087
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
210,998,867✔
5088
  return 0;
105,498,808✔
5089
}
5090

5091
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5092
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
105,081,205✔
5093
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
105,088,679✔
5094
  return 0;
52,546,101✔
5095
}
5096

5097
typedef struct {
5098
  int32_t vgId;
5099
  // TODO stas
5100
} SMqReportVgInfo;
5101

5102
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5103
  int32_t tlen = 0;
5104
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5105
  return tlen;
5106
}
5107

5108
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5109
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5110
  return buf;
5111
}
5112

5113
typedef struct {
5114
  int32_t epoch;
5115
  int64_t topicUid;
5116
  char    name[TSDB_TOPIC_FNAME_LEN];
5117
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5118
} SMqTopicInfo;
5119

5120
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5121
  int32_t tlen = 0;
5122
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5123
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5124
  tlen += taosEncodeString(buf, pTopicInfo->name);
5125
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5126
  tlen += taosEncodeFixedI32(buf, sz);
5127
  for (int32_t i = 0; i < sz; i++) {
5128
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5129
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5130
  }
5131
  return tlen;
5132
}
5133

5134
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5135
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5136
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5137
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5138
  int32_t sz;
5139
  buf = taosDecodeFixedI32(buf, &sz);
5140
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5141
    return NULL;
5142
  }
5143
  for (int32_t i = 0; i < sz; i++) {
5144
    SMqReportVgInfo vgInfo;
5145
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5146
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5147
      return NULL;
5148
    }
5149
  }
5150
  return buf;
5151
}
5152

5153
typedef struct {
5154
  int32_t status;  // ask hb endpoint
5155
  int32_t epoch;
5156
  int64_t consumerId;
5157
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5158
} SMqReportReq;
5159

5160
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5161
  int32_t tlen = 0;
5162
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5163
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5164
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5165
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5166
  tlen += taosEncodeFixedI32(buf, sz);
5167
  for (int32_t i = 0; i < sz; i++) {
5168
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5169
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5170
  }
5171
  return tlen;
5172
}
5173

5174
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5175
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5176
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5177
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5178
  int32_t sz;
5179
  buf = taosDecodeFixedI32(buf, &sz);
5180
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5181
    return NULL;
5182
  }
5183
  for (int32_t i = 0; i < sz; i++) {
5184
    SMqTopicInfo topicInfo;
5185
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5186
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5187
      return NULL;
5188
    }
5189
  }
5190
  return buf;
5191
}
5192

5193
typedef struct {
5194
  SMsgHead head;
5195
  int64_t  leftForVer;
5196
  int32_t  vgId;
5197
  int64_t  consumerId;
5198
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5199
} SMqVDeleteReq;
5200

5201
typedef struct {
5202
  int8_t reserved;
5203
} SMqVDeleteRsp;
5204

5205
typedef struct {
5206
  char**  name;
5207
  int32_t count;
5208
  int8_t igNotExists;
5209
} SMDropStreamReq;
5210

5211
typedef struct {
5212
  int8_t reserved;
5213
} SMDropStreamRsp;
5214

5215
typedef struct {
5216
  SMsgHead head;
5217
  int64_t  resetRelHalt;  // reset related stream task halt status
5218
  int64_t  streamId;
5219
  int32_t  taskId;
5220
} SVDropStreamTaskReq;
5221

5222
typedef struct {
5223
  int8_t reserved;
5224
} SVDropStreamTaskRsp;
5225

5226
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5227
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5228
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5229

5230
typedef struct {
5231
  char*  name;
5232
  int8_t igNotExists;
5233
} SMPauseStreamReq;
5234

5235
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5236
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5237
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5238

5239
typedef struct {
5240
  char*  name;
5241
  int8_t igNotExists;
5242
  int8_t igUntreated;
5243
} SMResumeStreamReq;
5244

5245
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5246
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5247
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5248

5249
typedef struct {
5250
  char*       name;
5251
  int8_t      calcAll;
5252
  STimeWindow timeRange;
5253
} SMRecalcStreamReq;
5254

5255
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5256
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5257
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5258

5259

5260
typedef struct SVndSetKeepVersionReq {
5261
  int64_t keepVersion;
5262
} SVndSetKeepVersionReq;
5263

5264
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5265
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5266

5267
typedef struct SVUpdateCheckpointInfoReq {
5268
  SMsgHead head;
5269
  int64_t  streamId;
5270
  int32_t  taskId;
5271
  int64_t  checkpointId;
5272
  int64_t  checkpointVer;
5273
  int64_t  checkpointTs;
5274
  int32_t  transId;
5275
  int64_t  hStreamId;  // add encode/decode
5276
  int64_t  hTaskId;
5277
  int8_t   dropRelHTask;
5278
} SVUpdateCheckpointInfoReq;
5279

5280
typedef struct {
5281
  int64_t leftForVer;
5282
  int32_t vgId;
5283
  int64_t oldConsumerId;
5284
  int64_t newConsumerId;
5285
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5286
  int8_t  subType;
5287
  int8_t  withMeta;
5288
  char*   qmsg;  // SubPlanToString
5289
  SSchemaWrapper schema;
5290
  int64_t suid;
5291
} SMqRebVgReq;
5292

5293
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5294
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5295

5296
// tqOffset
5297
enum {
5298
  TMQ_OFFSET__RESET_NONE = -3,
5299
  TMQ_OFFSET__RESET_EARLIEST = -2,
5300
  TMQ_OFFSET__RESET_LATEST = -1,
5301
  TMQ_OFFSET__LOG = 1,
5302
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5303
  TMQ_OFFSET__SNAPSHOT_META = 3,
5304
};
5305

5306
enum {
5307
  WITH_DATA = 0,
5308
  WITH_META = 1,
5309
  ONLY_META = 2,
5310
};
5311

5312
#define TQ_OFFSET_VERSION 1
5313

5314
typedef struct {
5315
  int8_t type;
5316
  union {
5317
    // snapshot
5318
    struct {
5319
      int64_t uid;
5320
      int64_t ts;
5321
      SValue  primaryKey;
5322
    };
5323
    // log
5324
    struct {
5325
      int64_t version;
5326
    };
5327
  };
5328
} STqOffsetVal;
5329

5330
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5331
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,244,000✔
5332
  pOffsetVal->uid = uid;
7,243,139✔
5333
  pOffsetVal->ts = ts;
7,242,526✔
5334
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,242,251✔
5335
    taosMemoryFree(pOffsetVal->primaryKey.pData);
286✔
5336
  }
5337
  pOffsetVal->primaryKey = primaryKey;
7,242,042✔
5338
}
7,241,967✔
5339

5340
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5341
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
39,269✔
5342
  pOffsetVal->uid = uid;
39,269✔
5343
}
39,269✔
5344

5345
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5346
  pOffsetVal->type = TMQ_OFFSET__LOG;
114,036,835✔
5347
  pOffsetVal->version = ver;
114,036,916✔
5348
}
114,035,764✔
5349

5350
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5351
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5352
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5353
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5354
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5355
void    tOffsetDestroy(void* pVal);
5356

5357
typedef struct {
5358
  STqOffsetVal val;
5359
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5360
} STqOffset;
5361

5362
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5363
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5364
void    tDeleteSTqOffset(void* val);
5365

5366
typedef struct SMqVgOffset {
5367
  int64_t   consumerId;
5368
  STqOffset offset;
5369
} SMqVgOffset;
5370

5371
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5372
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5373

5374
typedef struct {
5375
  char    name[TSDB_TABLE_FNAME_LEN];
5376
  char    stb[TSDB_TABLE_FNAME_LEN];
5377
  int8_t  igExists;
5378
  int8_t  intervalUnit;
5379
  int8_t  slidingUnit;
5380
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5381
  int32_t dstVgId;   // for stream
5382
  int64_t interval;
5383
  int64_t offset;
5384
  int64_t sliding;
5385
  int64_t maxDelay;
5386
  int64_t watermark;
5387
  int32_t exprLen;        // strlen + 1
5388
  int32_t tagsFilterLen;  // strlen + 1
5389
  int32_t sqlLen;         // strlen + 1
5390
  int32_t astLen;         // strlen + 1
5391
  char*   expr;
5392
  char*   tagsFilter;
5393
  char*   sql;
5394
  char*   ast;
5395
  int64_t deleteMark;
5396
  int64_t lastTs;
5397
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5398
  SArray* pVgroupVerList;
5399
  int8_t  recursiveTsma;
5400
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5401
  char*   createStreamReq;
5402
  int32_t streamReqLen;
5403
  char*   dropStreamReq;
5404
  int32_t dropStreamReqLen;
5405
  int64_t uid;
5406
} SMCreateSmaReq;
5407

5408
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5409
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5410
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5411

5412
typedef struct {
5413
  char    name[TSDB_TABLE_FNAME_LEN];
5414
  int8_t  igNotExists;
5415
  char*   dropStreamReq;
5416
  int32_t dropStreamReqLen;
5417
} SMDropSmaReq;
5418

5419
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5420
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5421
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5422

5423
typedef struct {
5424
  char name[TSDB_TABLE_NAME_LEN];
5425
  union {
5426
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5427
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5428
  };
5429
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5430
  union {
5431
    int8_t igExists;   // used by mnode
5432
    int8_t alterType;  // used by vnode
5433
  };
5434
  int8_t     intervalUnit;
5435
  int16_t    nFuncs;       // number of functions specified by user
5436
  col_id_t*  funcColIds;   // column ids specified by user
5437
  func_id_t* funcIds;      // function ids specified by user
5438
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5439
  int64_t    tbUid;
5440
  int64_t    uid;     // rsma uid
5441
  int32_t    sqlLen;  // strlen + 1
5442
  char*      sql;
5443
} SMCreateRsmaReq;
5444

5445
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5446
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5447
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5448

5449
typedef SMCreateRsmaReq SVCreateRsmaReq;
5450

5451
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5452
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5453
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5454

5455
typedef SMCreateRsmaReq SVAlterRsmaReq;
5456

5457
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5458
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5459
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5460

5461
typedef struct {
5462
  char       name[TSDB_TABLE_NAME_LEN];
5463
  int8_t     alterType;
5464
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5465
  int8_t     igNotExists;
5466
  int16_t    nFuncs;      // number of functions specified by user
5467
  col_id_t*  funcColIds;  // column ids specified by user
5468
  func_id_t* funcIds;     // function ids specified by user
5469
  int32_t    sqlLen;      // strlen + 1
5470
  char*      sql;
5471
} SMAlterRsmaReq;
5472

5473
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5474
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5475
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5476

5477
typedef struct {
5478
  int64_t    id;
5479
  char       name[TSDB_TABLE_NAME_LEN];
5480
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5481
  int64_t    ownerId;
5482
  int32_t    code;
5483
  int32_t    version;
5484
  int8_t     tbType;
5485
  int8_t     intervalUnit;
5486
  col_id_t   nFuncs;
5487
  col_id_t   nColNames;
5488
  int64_t    interval[2];
5489
  col_id_t*  funcColIds;
5490
  func_id_t* funcIds;
5491
  SArray*    colNames;
5492
} SRsmaInfoRsp;
5493

5494
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5495
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5496
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5497

5498
typedef struct {
5499
  char   name[TSDB_TABLE_FNAME_LEN];
5500
  int8_t igNotExists;
5501
} SMDropRsmaReq;
5502

5503
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5504
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5505

5506
typedef struct {
5507
  char    name[TSDB_TABLE_NAME_LEN];
5508
  char    tbName[TSDB_TABLE_NAME_LEN];
5509
  int64_t uid;
5510
  int64_t tbUid;
5511
  int8_t  tbType;
5512
} SVDropRsmaReq;
5513

5514
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5515
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5516

5517
typedef struct {
5518
  char   dbFName[TSDB_DB_FNAME_LEN];
5519
  char   stbName[TSDB_TABLE_NAME_LEN];
5520
  char   colName[TSDB_COL_NAME_LEN];
5521
  char   idxName[TSDB_INDEX_FNAME_LEN];
5522
  int8_t idxType;
5523
} SCreateTagIndexReq;
5524

5525
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5526
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5527

5528
typedef SMDropSmaReq SDropTagIndexReq;
5529

5530
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5531
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5532

5533
typedef struct {
5534
  int8_t         version;       // for compatibility(default 0)
5535
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5536
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5537
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5538
  int32_t        dstVgId;
5539
  char           indexName[TSDB_INDEX_NAME_LEN];
5540
  int32_t        exprLen;
5541
  int32_t        tagsFilterLen;
5542
  int64_t        indexUid;
5543
  tb_uid_t       tableUid;  // super/child/common table uid
5544
  tb_uid_t       dstTbUid;  // for dstVgroup
5545
  int64_t        interval;
5546
  int64_t        offset;  // use unit by precision of DB
5547
  int64_t        sliding;
5548
  char*          dstTbName;  // for dstVgroup
5549
  char*          expr;       // sma expression
5550
  char*          tagsFilter;
5551
  SSchemaWrapper schemaRow;  // for dstVgroup
5552
  SSchemaWrapper schemaTag;  // for dstVgroup
5553
} STSma;                     // Time-range-wise SMA
5554

5555
typedef STSma SVCreateTSmaReq;
5556

5557
typedef struct {
5558
  int8_t  type;  // 0 status report, 1 update data
5559
  int64_t indexUid;
5560
  int64_t skey;  // start TS key of interval/sliding window
5561
} STSmaMsg;
5562

5563
typedef struct {
5564
  int64_t indexUid;
5565
  char    indexName[TSDB_INDEX_NAME_LEN];
5566
} SVDropTSmaReq;
5567

5568
typedef struct {
5569
  int tmp;  // TODO: to avoid compile error
5570
} SVCreateTSmaRsp, SVDropTSmaRsp;
5571

5572
#if 0
5573
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5574
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5575
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5576
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5577
#endif
5578

5579
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5580
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5581
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5582
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5583

5584
typedef struct {
5585
  int32_t number;
5586
  STSma*  tSma;
5587
} STSmaWrapper;
5588

5589
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5590
  if (pSma) {
×
UNCOV
5591
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5592
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5593
    taosMemoryFreeClear(pSma->tagsFilter);
×
5594
  }
UNCOV
5595
}
×
5596

5597
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5598
  if (pSW) {
×
UNCOV
5599
    if (pSW->tSma) {
×
UNCOV
5600
      if (deepCopy) {
×
UNCOV
5601
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5602
          tDestroyTSma(pSW->tSma + i);
×
5603
        }
5604
      }
UNCOV
5605
      taosMemoryFreeClear(pSW->tSma);
×
5606
    }
5607
  }
UNCOV
5608
}
×
5609

5610
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5611
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5612
  taosMemoryFreeClear(pSW);
×
UNCOV
5613
  return NULL;
×
5614
}
5615

5616
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5617
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5618

5619
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5620
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5621

UNCOV
5622
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5623
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5624
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5625
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5626
  }
UNCOV
5627
  return 0;
×
5628
}
5629

UNCOV
5630
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5631
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5632
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5633
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5634
  }
UNCOV
5635
  return 0;
×
5636
}
5637

5638
typedef struct {
5639
  int idx;
5640
} SMCreateFullTextReq;
5641

5642
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5643
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5644
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5645

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

5651
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5652
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5653

5654
typedef struct {
5655
  char indexFName[TSDB_INDEX_FNAME_LEN];
5656
} SUserIndexReq;
5657

5658
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5659
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5660

5661
typedef struct {
5662
  char dbFName[TSDB_DB_FNAME_LEN];
5663
  char tblFName[TSDB_TABLE_FNAME_LEN];
5664
  char colName[TSDB_COL_NAME_LEN];
5665
  char owner[TSDB_USER_LEN];
5666
  char indexType[TSDB_INDEX_TYPE_LEN];
5667
  char indexExts[TSDB_INDEX_EXTS_LEN];
5668
} SUserIndexRsp;
5669

5670
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5671
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5672

5673
typedef struct {
5674
  char tbFName[TSDB_TABLE_FNAME_LEN];
5675
} STableIndexReq;
5676

5677
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5678
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5679

5680
typedef struct {
5681
  int8_t  intervalUnit;
5682
  int8_t  slidingUnit;
5683
  int64_t interval;
5684
  int64_t offset;
5685
  int64_t sliding;
5686
  int64_t dstTbUid;
5687
  int32_t dstVgId;
5688
  SEpSet  epSet;
5689
  char*   expr;
5690
} STableIndexInfo;
5691

5692
typedef struct {
5693
  char     tbName[TSDB_TABLE_NAME_LEN];
5694
  char     dbFName[TSDB_DB_FNAME_LEN];
5695
  uint64_t suid;
5696
  int32_t  version;
5697
  int32_t  indexSize;
5698
  SArray*  pIndex;  // STableIndexInfo
5699
} STableIndexRsp;
5700

5701
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5702
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5703
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5704

5705
void tFreeSTableIndexInfo(void* pInfo);
5706

5707
typedef struct {
5708
  int8_t  mqMsgType;
5709
  int32_t code;
5710
  int32_t epoch;
5711
  int64_t consumerId;
5712
  int64_t walsver;
5713
  int64_t walever;
5714
} SMqRspHead;
5715

5716
typedef struct {
5717
  SMsgHead     head;
5718
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5719
  int8_t       withTbName;
5720
  int8_t       useSnapshot;
5721
  int32_t      epoch;
5722
  uint64_t     reqId;
5723
  int64_t      consumerId;
5724
  int64_t      timeout;
5725
  STqOffsetVal reqOffset;
5726
  int8_t       enableReplay;
5727
  int8_t       sourceExcluded;
5728
  int8_t       rawData;
5729
  int32_t      minPollRows;
5730
  int8_t       enableBatchMeta;
5731
  SHashObj*    uidHash;  // to find if uid is duplicated
5732
} SMqPollReq;
5733

5734
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5735
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5736
void    tDestroySMqPollReq(SMqPollReq* pReq);
5737

5738
typedef struct {
5739
  int32_t vgId;
5740
  int64_t offset;
5741
  SEpSet  epSet;
5742
} SMqSubVgEp;
5743

5744
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5745
  int32_t tlen = 0;
2,361,824✔
5746
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,361,824✔
5747
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,361,824✔
5748
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,361,824✔
5749
  return tlen;
2,361,824✔
5750
}
5751

5752
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5753
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,170,122✔
5754
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,170,122✔
5755
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,170,122✔
5756
  return buf;
1,170,122✔
5757
}
5758

5759
typedef struct {
5760
  char           topic[TSDB_TOPIC_FNAME_LEN];
5761
  char           db[TSDB_DB_FNAME_LEN];
5762
  SArray*        vgs;  // SArray<SMqSubVgEp>
5763
} SMqSubTopicEp;
5764

5765
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5766
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5767
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5768

5769
typedef struct {
5770
  SMqRspHead   head;
5771
  STqOffsetVal rspOffset;
5772
  int16_t      resMsgType;
5773
  int32_t      metaRspLen;
5774
  void*        metaRsp;
5775
} SMqMetaRsp;
5776

5777
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5778
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5779
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5780

5781
#define MQ_DATA_RSP_VERSION 100
5782

5783
typedef struct {
5784
  SMqRspHead   head;
5785
  STqOffsetVal rspOffset;
5786
  STqOffsetVal reqOffset;
5787
  int32_t      blockNum;
5788
  int8_t       withTbName;
5789
  int8_t       withSchema;
5790
  SArray*      blockDataLen;
5791
  SArray*      blockData;
5792
  SArray*      blockTbName;
5793
  SArray*      blockSchema;
5794

5795
  union {
5796
    struct {
5797
      int64_t sleepTime;
5798
    };
5799
    struct {
5800
      int32_t createTableNum;
5801
      SArray* createTableLen;
5802
      SArray* createTableReq;
5803
    };
5804
    struct {
5805
      int32_t len;
5806
      void*   rawData;
5807
    };
5808
  };
5809
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5810
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5811
} SMqDataRsp;
5812

5813
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5814
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5815
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5816
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5817
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5818

5819
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5820
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5821
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5822

5823
typedef struct SMqBatchMetaRsp {
5824
  SMqRspHead   head;  // not serialize
5825
  STqOffsetVal rspOffset;
5826
  SArray*      batchMetaLen;
5827
  SArray*      batchMetaReq;
5828
  void*        pMetaBuff;    // not serialize
5829
  uint32_t     metaBuffLen;  // not serialize
5830
} SMqBatchMetaRsp;
5831

5832
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5833
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5834
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5835
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5836

5837
typedef struct {
5838
  int32_t    code;
5839
  SArray*    topics;  // SArray<SMqSubTopicEp>
5840
} SMqAskEpRsp;
5841

5842
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5843
  int32_t tlen = 0;
7,218,904✔
5844
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5845
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,218,904✔
5846
  tlen += taosEncodeFixedI32(buf, sz);
7,218,904✔
5847
  for (int32_t i = 0; i < sz; i++) {
8,972,635✔
5848
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,754,054✔
5849
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,754,054✔
5850
  }
5851
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,218,581✔
5852

5853
  return tlen;
7,218,904✔
5854
}
5855

5856
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5857
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5858
  int32_t sz;
3,242,304✔
5859
  buf = taosDecodeFixedI32(buf, &sz);
3,318,386✔
5860
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,318,386✔
5861
  if (pRsp->topics == NULL) {
3,318,386✔
UNCOV
5862
    return NULL;
×
5863
  }
5864
  for (int32_t i = 0; i < sz; i++) {
4,182,912✔
5865
    SMqSubTopicEp topicEp;
851,188✔
5866
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
864,526✔
5867
    if (buf == NULL) {
864,526✔
UNCOV
5868
      return NULL;
×
5869
    }
5870
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,729,052✔
UNCOV
5871
      return NULL;
×
5872
    }
5873
  }
5874
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,318,386✔
5875

5876
  return buf;
3,318,386✔
5877
}
5878

5879
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5880
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,306,215✔
5881
}
9,306,215✔
5882

5883
typedef struct {
5884
  int32_t      vgId;
5885
  STqOffsetVal offset;
5886
  int64_t      rows;
5887
  int64_t      ever;
5888
} OffsetRows;
5889

5890
typedef struct {
5891
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5892
  SArray* offsetRows;
5893
} TopicOffsetRows;
5894

5895
typedef struct {
5896
  int64_t consumerId;
5897
  int32_t epoch;
5898
  SArray* topics;
5899
  int8_t  pollFlag;
5900
} SMqHbReq;
5901

5902
typedef struct {
5903
  char   topic[TSDB_TOPIC_FNAME_LEN];
5904
  int8_t noPrivilege;
5905
} STopicPrivilege;
5906

5907
typedef struct {
5908
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5909
  int32_t debugFlag;
5910
} SMqHbRsp;
5911

5912
typedef struct {
5913
  SMsgHead head;
5914
  int64_t  consumerId;
5915
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5916
} SMqSeekReq;
5917

5918
#define TD_AUTO_CREATE_TABLE 0x1
5919
typedef struct {
5920
  int64_t       suid;
5921
  int64_t       uid;
5922
  int32_t       sver;
5923
  uint32_t      nData;
5924
  uint8_t*      pData;
5925
  SVCreateTbReq cTbReq;
5926
} SVSubmitBlk;
5927

5928
typedef struct {
5929
  SMsgHead header;
5930
  uint64_t sId;
5931
  uint64_t queryId;
5932
  uint64_t clientId;
5933
  uint64_t taskId;
5934
  uint32_t sqlLen;
5935
  uint32_t phyLen;
5936
  char*    sql;
5937
  char*    msg;
5938
  int8_t   source;
5939
} SVDeleteReq;
5940

5941
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5942
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5943

5944
typedef struct {
5945
  int64_t affectedRows;
5946
} SVDeleteRsp;
5947

5948
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5949
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5950

5951
typedef struct SDeleteRes {
5952
  uint64_t suid;
5953
  SArray*  uidList;
5954
  int64_t  skey;
5955
  int64_t  ekey;
5956
  int64_t  affectedRows;
5957
  char     tableFName[TSDB_TABLE_NAME_LEN];
5958
  char     tsColName[TSDB_COL_NAME_LEN];
5959
  int64_t  ctimeMs;  // fill by vnode
5960
  int8_t   source;
5961
} SDeleteRes;
5962

5963
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5964
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5965

5966
typedef struct {
5967
  // int64_t uid;
5968
  char    tbname[TSDB_TABLE_NAME_LEN];
5969
  int64_t startTs;
5970
  int64_t endTs;
5971
} SSingleDeleteReq;
5972

5973
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5974
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5975

5976
typedef struct {
5977
  int64_t suid;
5978
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5979
  int64_t ctimeMs;     // fill by vnode
5980
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5981
} SBatchDeleteReq;
5982

5983
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5984
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5985
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5986

5987
typedef struct {
5988
  int32_t msgIdx;
5989
  int32_t msgType;
5990
  int32_t msgLen;
5991
  void*   msg;
5992
} SBatchMsg;
5993

5994
typedef struct {
5995
  SMsgHead header;
5996
  SArray*  pMsgs;  // SArray<SBatchMsg>
5997
} SBatchReq;
5998

5999
typedef struct {
6000
  int32_t reqType;
6001
  int32_t msgIdx;
6002
  int32_t msgLen;
6003
  int32_t rspCode;
6004
  void*   msg;
6005
} SBatchRspMsg;
6006

6007
typedef struct {
6008
  SArray* pRsps;  // SArray<SBatchRspMsg>
6009
} SBatchRsp;
6010

6011
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6012
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6013
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
85,429,223✔
6014
  if (NULL == msg) {
85,429,223✔
UNCOV
6015
    return;
×
6016
  }
6017
  SBatchMsg* pMsg = (SBatchMsg*)msg;
85,429,223✔
6018
  taosMemoryFree(pMsg->msg);
85,429,223✔
6019
}
6020

6021
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6022
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6023

6024
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
114,460,494✔
6025
  if (NULL == p) {
114,460,494✔
UNCOV
6026
    return;
×
6027
  }
6028

6029
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
114,460,494✔
6030
  taosMemoryFree(pRsp->msg);
114,460,494✔
6031
}
6032

6033
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6034
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6035
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6036
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6037
void    tDestroySMqHbReq(SMqHbReq* pReq);
6038

6039
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6040
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6041
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6042

6043
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6044
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6045

6046
#define TD_REQ_FROM_APP               0x0
6047
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6048
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6049
#define SUBMIT_REQ_FROM_FILE          0x4
6050
#define TD_REQ_FROM_TAOX              0x8
6051
#define TD_REQ_FROM_SML               0x10
6052
#define SUBMIT_REQUEST_VERSION        (2)
6053
#define SUBMIT_REQ_WITH_BLOB          0x10
6054
#define SUBMIT_REQ_SCHEMA_RES         0x20
6055
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6056

6057
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6058

6059
typedef struct {
6060
  int32_t        flags;
6061
  SVCreateTbReq* pCreateTbReq;
6062
  int64_t        suid;
6063
  int64_t        uid;
6064
  int32_t        sver;
6065
  union {
6066
    SArray* aRowP;
6067
    SArray* aCol;
6068
  };
6069
  int64_t   ctimeMs;
6070
  SBlobSet* pBlobSet;
6071
} SSubmitTbData;
6072

6073
typedef struct {
6074
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6075
  SArray* aSubmitBlobData;
6076
  bool    raw;
6077
} SSubmitReq2;
6078

6079
typedef struct {
6080
  SMsgHead header;
6081
  int64_t  version;
6082
  char     data[];  // SSubmitReq2
6083
} SSubmitReq2Msg;
6084

6085
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6086
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6087
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6088
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6089
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6090

6091
typedef struct {
6092
  int32_t affectedRows;
6093
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6094
} SSubmitRsp2;
6095

6096
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6097
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6098
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6099

6100
#define TSDB_MSG_FLG_ENCODE 0x1
6101
#define TSDB_MSG_FLG_DECODE 0x2
6102
#define TSDB_MSG_FLG_CMPT   0x3
6103

6104
typedef struct {
6105
  union {
6106
    struct {
6107
      void*   msgStr;
6108
      int32_t msgLen;
6109
      int64_t ver;
6110
    };
6111
    void* pDataBlock;
6112
  };
6113
} SPackedData;
6114

6115
typedef struct {
6116
  char     fullname[TSDB_VIEW_FNAME_LEN];
6117
  char     name[TSDB_VIEW_NAME_LEN];
6118
  char     dbFName[TSDB_DB_FNAME_LEN];
6119
  char*    querySql;
6120
  char*    sql;
6121
  int8_t   orReplace;
6122
  int8_t   precision;
6123
  int32_t  numOfCols;
6124
  SSchema* pSchema;
6125
} SCMCreateViewReq;
6126

6127
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6128
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6129
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6130

6131
typedef struct {
6132
  char   fullname[TSDB_VIEW_FNAME_LEN];
6133
  char   name[TSDB_VIEW_NAME_LEN];
6134
  char   dbFName[TSDB_DB_FNAME_LEN];
6135
  char*  sql;
6136
  int8_t igNotExists;
6137
} SCMDropViewReq;
6138

6139
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6140
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6141
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6142

6143
typedef struct {
6144
  char fullname[TSDB_VIEW_FNAME_LEN];
6145
} SViewMetaReq;
6146
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6147
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6148

6149
typedef struct {
6150
  char     name[TSDB_VIEW_NAME_LEN];
6151
  char     dbFName[TSDB_DB_FNAME_LEN];
6152
  char*    createUser;
6153
  int64_t  ownerId;
6154
  uint64_t dbId;
6155
  uint64_t viewId;
6156
  char*    querySql;
6157
  int8_t   precision;
6158
  int8_t   type;
6159
  int32_t  version;
6160
  int32_t  numOfCols;
6161
  SSchema* pSchema;
6162
} SViewMetaRsp;
6163
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6164
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6165
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6166
typedef struct {
6167
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6168
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6169
} STableTSMAInfoReq;
6170

6171
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6172
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6173

6174
typedef struct {
6175
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6176
  union {
6177
    uint8_t flags;
6178
    struct {
6179
      uint8_t withColName : 1;
6180
      uint8_t reserved : 7;
6181
    };
6182
  };
6183

6184
} SRsmaInfoReq;
6185

6186
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6187
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6188

6189
typedef struct {
6190
  int32_t  funcId;
6191
  col_id_t colId;
6192
} STableTSMAFuncInfo;
6193

6194
typedef struct {
6195
  char     name[TSDB_TABLE_NAME_LEN];
6196
  uint64_t tsmaId;
6197
  char     targetTb[TSDB_TABLE_NAME_LEN];
6198
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6199
  char     tb[TSDB_TABLE_NAME_LEN];
6200
  char     dbFName[TSDB_DB_FNAME_LEN];
6201
  uint64_t suid;
6202
  uint64_t destTbUid;
6203
  uint64_t dbId;
6204
  int32_t  version;
6205
  int64_t  interval;
6206
  int8_t   unit;
6207
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6208
  SArray*  pTags;      // SArray<SSchema>
6209
  SArray*  pUsedCols;  // SArray<SSchema>
6210
  char*    ast;
6211

6212
  int64_t streamUid;
6213
  int64_t reqTs;
6214
  int64_t rspTs;
6215
  int64_t delayDuration;  // ms
6216
  bool    fillHistoryFinished;
6217

6218
  void* streamAddr;  // for stream task, the address of the stream task
6219
} STableTSMAInfo;
6220

6221
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6222
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6223
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6224
void    tFreeTableTSMAInfo(void* p);
6225
void    tFreeAndClearTableTSMAInfo(void* p);
6226
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6227

6228
#define STSMAHbRsp            STableTSMAInfoRsp
6229
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6230
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6231
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6232

6233
typedef struct SDropCtbWithTsmaSingleVgReq {
6234
  SVgroupInfo vgInfo;
6235
  SArray*     pTbs;  // SVDropTbReq
6236
} SMDropTbReqsOnSingleVg;
6237

6238
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6239
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6240
void    tFreeSMDropTbReqOnSingleVg(void* p);
6241

6242
typedef struct SDropTbsReq {
6243
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6244
} SMDropTbsReq;
6245

6246
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6247
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6248
void    tFreeSMDropTbsReq(void*);
6249

6250
typedef struct SVFetchTtlExpiredTbsRsp {
6251
  SArray* pExpiredTbs;  // SVDropTbReq
6252
  int32_t vgId;
6253
} SVFetchTtlExpiredTbsRsp;
6254

6255
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6256
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6257

6258
void tFreeFetchTtlExpiredTbsRsp(void* p);
6259

6260
void setDefaultOptionsForField(SFieldWithOptions* field);
6261
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6262

6263
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6264
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6265

6266

6267
typedef struct {
6268
  char    id[TSDB_INSTANCE_ID_LEN];
6269
  char    type[TSDB_INSTANCE_TYPE_LEN];
6270
  char    desc[TSDB_INSTANCE_DESC_LEN];
6271
  int32_t expire;
6272
} SInstanceRegisterReq;
6273

6274
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6275
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6276

6277
typedef struct {
6278
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6279
} SInstanceListReq;
6280

6281
typedef struct {
6282
  int32_t count;
6283
  char**  ids;  // Array of instance IDs
6284
} SInstanceListRsp;
6285

6286
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6287
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6288
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6289
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6290

6291
#ifdef USE_MOUNT
6292
typedef struct {
6293
  char     mountName[TSDB_MOUNT_NAME_LEN];
6294
  int8_t   ignoreExist;
6295
  int16_t  nMounts;
6296
  int32_t* dnodeIds;
6297
  char**   mountPaths;
6298
  int32_t  sqlLen;
6299
  char*    sql;
6300
} SCreateMountReq;
6301

6302
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6303
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6304
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6305

6306
typedef struct {
6307
  char    mountName[TSDB_MOUNT_NAME_LEN];
6308
  int8_t  ignoreNotExists;
6309
  int32_t sqlLen;
6310
  char*   sql;
6311
} SDropMountReq;
6312

6313
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6314
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6315
void    tFreeSDropMountReq(SDropMountReq* pReq);
6316

6317
typedef struct {
6318
  char     mountName[TSDB_MOUNT_NAME_LEN];
6319
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6320
  int64_t  mountUid;
6321
  int32_t  dnodeId;
6322
  uint32_t valLen;
6323
  int8_t   ignoreExist;
6324
  void*    pVal;
6325
} SRetrieveMountPathReq;
6326

6327
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6328
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6329

6330
typedef struct {
6331
  // path
6332
  int32_t diskPrimary;
6333
  // vgInfo
6334
  int32_t  vgId;
6335
  int32_t  cacheLastSize;
6336
  int32_t  szPage;
6337
  int32_t  szCache;
6338
  uint64_t szBuf;
6339
  int8_t   cacheLast;
6340
  int8_t   standby;
6341
  int8_t   hashMethod;
6342
  uint32_t hashBegin;
6343
  uint32_t hashEnd;
6344
  int16_t  hashPrefix;
6345
  int16_t  hashSuffix;
6346
  int16_t  sttTrigger;
6347
  // syncInfo
6348
  int32_t replications;
6349
  // tsdbInfo
6350
  int8_t  precision;
6351
  int8_t  compression;
6352
  int8_t  slLevel;
6353
  int32_t daysPerFile;
6354
  int32_t keep0;
6355
  int32_t keep1;
6356
  int32_t keep2;
6357
  int32_t keepTimeOffset;
6358
  int32_t minRows;
6359
  int32_t maxRows;
6360
  int32_t tsdbPageSize;
6361
  int32_t ssChunkSize;
6362
  int32_t ssKeepLocal;
6363
  int8_t  ssCompact;
6364
  // walInfo
6365
  int32_t walFsyncPeriod;      // millisecond
6366
  int32_t walRetentionPeriod;  // secs
6367
  int32_t walRollPeriod;       // secs
6368
  int64_t walRetentionSize;
6369
  int64_t walSegSize;
6370
  int32_t walLevel;
6371
  // encryptInfo
6372
  int32_t encryptAlgorithm;
6373
  // SVState
6374
  int64_t committed;
6375
  int64_t commitID;
6376
  int64_t commitTerm;
6377
  // stats
6378
  int64_t numOfSTables;
6379
  int64_t numOfCTables;
6380
  int64_t numOfNTables;
6381
  // dbInfo
6382
  uint64_t dbId;
6383
} SMountVgInfo;
6384

6385
typedef struct {
6386
  SMCreateStbReq req;
6387
  SArray*        pColExts;  // element: column id
6388
  SArray*        pTagExts;  // element: tag id
6389
} SMountStbInfo;
6390

6391
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6392
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6393

6394
typedef struct {
6395
  char     dbName[TSDB_DB_FNAME_LEN];
6396
  uint64_t dbId;
6397
  SArray*  pVgs;   // SMountVgInfo
6398
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6399
} SMountDbInfo;
6400

6401
typedef struct {
6402
  // common fields
6403
  char     mountName[TSDB_MOUNT_NAME_LEN];
6404
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6405
  int8_t   ignoreExist;
6406
  int64_t  mountUid;
6407
  int64_t  clusterId;
6408
  int32_t  dnodeId;
6409
  uint32_t valLen;
6410
  void*    pVal;
6411

6412
  // response fields
6413
  SArray* pDbs;  // SMountDbInfo
6414

6415
  // memory fields, no serialized
6416
  SArray*   pDisks[TFS_MAX_TIERS];
6417
  TdFilePtr pFile;
6418
} SMountInfo;
6419

6420
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6421
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6422
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6423

6424
typedef struct {
6425
  SCreateVnodeReq createReq;
6426
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6427
  char            mountName[TSDB_MOUNT_NAME_LEN];
6428
  int64_t         mountId;
6429
  int32_t         diskPrimary;
6430
  int32_t         mountVgId;
6431
  int64_t         committed;
6432
  int64_t         commitID;
6433
  int64_t         commitTerm;
6434
  int64_t         numOfSTables;
6435
  int64_t         numOfCTables;
6436
  int64_t         numOfNTables;
6437
} SMountVnodeReq;
6438

6439
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6440
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6441
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6442

6443
#endif  // USE_MOUNT
6444

6445
#pragma pack(pop)
6446

6447
typedef struct {
6448
  char        db[TSDB_DB_FNAME_LEN];
6449
  STimeWindow timeRange;
6450
  int32_t     sqlLen;
6451
  char*       sql;
6452
  SArray*     vgroupIds;
6453
} SScanDbReq;
6454

6455
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6456
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6457
void    tFreeSScanDbReq(SScanDbReq* pReq);
6458

6459
typedef struct {
6460
  int32_t scanId;
6461
  int8_t  bAccepted;
6462
} SScanDbRsp;
6463

6464
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6465
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6466

6467
typedef struct {
6468
  int32_t scanId;
6469
  int32_t sqlLen;
6470
  char*   sql;
6471
} SKillScanReq;
6472

6473
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6474
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6475
void    tFreeSKillScanReq(SKillScanReq* pReq);
6476

6477
typedef struct {
6478
  int32_t scanId;
6479
  int32_t vgId;
6480
  int32_t dnodeId;
6481
} SVKillScanReq;
6482

6483
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6484
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6485

6486
typedef struct {
6487
  int32_t scanId;
6488
  int32_t vgId;
6489
  int32_t dnodeId;
6490
  int32_t numberFileset;
6491
  int32_t finished;
6492
  int32_t progress;
6493
  int64_t remainingTime;
6494
} SQueryScanProgressRsp;
6495

6496
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6497
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6498

6499
typedef struct {
6500
  int32_t scanId;
6501
  int32_t vgId;
6502
  int32_t dnodeId;
6503
} SQueryScanProgressReq;
6504

6505
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6506
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6507

6508
typedef struct {
6509
  int64_t     dbUid;
6510
  char        db[TSDB_DB_FNAME_LEN];
6511
  int64_t     scanStartTime;
6512
  STimeWindow tw;
6513
  int32_t     scanId;
6514
} SScanVnodeReq;
6515

6516
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6517
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6518

6519
#ifdef __cplusplus
6520
}
6521
#endif
6522

6523
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6524
 
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