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

taosdata / TDengine / #4986

15 Mar 2026 08:32AM UTC coverage: 37.305% (-31.3%) from 68.601%
#4986

push

travis-ci

tomchon
test: keep docs and unit test

125478 of 336361 relevant lines covered (37.3%)

1134847.06 hits per line

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

55.46
/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) {
14,822✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
14,822✔
102
  int    segIdx = TMSG_SEG_CODE(type);
14,822✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
14,822✔
104
    return type < tMsgRangeDict[segIdx];
14,822✔
105
  }
106
  return false;
×
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
80✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
80✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
160✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

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

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

261

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

267

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

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

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

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

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

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

300
typedef enum ENodeType {
301
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
302
  // VALUE, OPERATOR, FUNCTION and so on.
303
  QUERY_NODE_COLUMN = 1,
304
  QUERY_NODE_VALUE,
305
  QUERY_NODE_OPERATOR,
306
  QUERY_NODE_LOGIC_CONDITION,
307
  QUERY_NODE_FUNCTION,
308
  QUERY_NODE_REAL_TABLE,
309
  QUERY_NODE_TEMP_TABLE,
310
  QUERY_NODE_JOIN_TABLE,
311
  QUERY_NODE_GROUPING_SET,
312
  QUERY_NODE_ORDER_BY_EXPR,
313
  QUERY_NODE_LIMIT,
314
  QUERY_NODE_STATE_WINDOW,
315
  QUERY_NODE_SESSION_WINDOW,
316
  QUERY_NODE_INTERVAL_WINDOW,
317
  QUERY_NODE_NODE_LIST,
318
  QUERY_NODE_FILL,
319
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
320
  QUERY_NODE_TARGET,
321
  QUERY_NODE_DATABLOCK_DESC,
322
  QUERY_NODE_SLOT_DESC,
323
  QUERY_NODE_COLUMN_DEF,
324
  QUERY_NODE_DOWNSTREAM_SOURCE,
325
  QUERY_NODE_DATABASE_OPTIONS,
326
  QUERY_NODE_TABLE_OPTIONS,
327
  QUERY_NODE_INDEX_OPTIONS,
328
  QUERY_NODE_EXPLAIN_OPTIONS,
329
  QUERY_NODE_LEFT_VALUE,
330
  QUERY_NODE_COLUMN_REF,
331
  QUERY_NODE_WHEN_THEN,
332
  QUERY_NODE_CASE_WHEN,
333
  QUERY_NODE_EVENT_WINDOW,
334
  QUERY_NODE_HINT,
335
  QUERY_NODE_VIEW,
336
  QUERY_NODE_WINDOW_OFFSET,
337
  QUERY_NODE_COUNT_WINDOW,
338
  QUERY_NODE_COLUMN_OPTIONS,
339
  QUERY_NODE_TSMA_OPTIONS,
340
  QUERY_NODE_ANOMALY_WINDOW,
341
  QUERY_NODE_RANGE_AROUND,
342
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
343
  QUERY_NODE_VIRTUAL_TABLE,
344
  QUERY_NODE_SLIDING_WINDOW,
345
  QUERY_NODE_PERIOD_WINDOW,
346
  QUERY_NODE_STREAM_TRIGGER,
347
  QUERY_NODE_STREAM,
348
  QUERY_NODE_STREAM_TAG_DEF,
349
  QUERY_NODE_EXTERNAL_WINDOW,
350
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
351
  QUERY_NODE_PLACE_HOLDER_TABLE,
352
  QUERY_NODE_TIME_RANGE,
353
  QUERY_NODE_STREAM_OUT_TABLE,
354
  QUERY_NODE_STREAM_CALC_RANGE,
355
  QUERY_NODE_COUNT_WINDOW_ARGS,
356
  QUERY_NODE_BNODE_OPTIONS,
357
  QUERY_NODE_DATE_TIME_RANGE,
358
  QUERY_NODE_IP_RANGE,
359
  QUERY_NODE_USER_OPTIONS,
360
  QUERY_NODE_REMOTE_VALUE,
361
  QUERY_NODE_TOKEN_OPTIONS,
362
  QUERY_NODE_TRUE_FOR,
363
  QUERY_NODE_REMOTE_VALUE_LIST,
364
  QUERY_NODE_SURROUND,
365
  QUERY_NODE_REMOTE_ROW,
366
  QUERY_NODE_REMOTE_ZERO_ROWS,
367
  
368
  // Statement nodes are used in parser and planner module.
369
  QUERY_NODE_SET_OPERATOR = 100,
370
  QUERY_NODE_SELECT_STMT,
371
  QUERY_NODE_VNODE_MODIFY_STMT,
372
  QUERY_NODE_CREATE_DATABASE_STMT,
373
  QUERY_NODE_DROP_DATABASE_STMT,
374
  QUERY_NODE_ALTER_DATABASE_STMT,
375
  QUERY_NODE_FLUSH_DATABASE_STMT,
376
  QUERY_NODE_TRIM_DATABASE_STMT,
377
  QUERY_NODE_CREATE_TABLE_STMT,
378
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
379
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
380
  QUERY_NODE_DROP_TABLE_CLAUSE,
381
  QUERY_NODE_DROP_TABLE_STMT,
382
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
383
  QUERY_NODE_ALTER_TABLE_STMT,
384
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
385
  QUERY_NODE_CREATE_USER_STMT,
386
  QUERY_NODE_ALTER_USER_STMT,
387
  QUERY_NODE_DROP_USER_STMT,
388
  QUERY_NODE_USE_DATABASE_STMT,
389
  QUERY_NODE_CREATE_DNODE_STMT,
390
  QUERY_NODE_DROP_DNODE_STMT,
391
  QUERY_NODE_ALTER_DNODE_STMT,
392
  QUERY_NODE_CREATE_INDEX_STMT,
393
  QUERY_NODE_DROP_INDEX_STMT,
394
  QUERY_NODE_CREATE_QNODE_STMT,
395
  QUERY_NODE_DROP_QNODE_STMT,
396
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
397
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
398
  QUERY_NODE_CREATE_SNODE_STMT,
399
  QUERY_NODE_DROP_SNODE_STMT,
400
  QUERY_NODE_CREATE_MNODE_STMT,
401
  QUERY_NODE_DROP_MNODE_STMT,
402
  QUERY_NODE_CREATE_TOPIC_STMT,
403
  QUERY_NODE_DROP_TOPIC_STMT,
404
  QUERY_NODE_DROP_CGROUP_STMT,
405
  QUERY_NODE_ALTER_LOCAL_STMT,
406
  QUERY_NODE_EXPLAIN_STMT,
407
  QUERY_NODE_DESCRIBE_STMT,
408
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
409
  QUERY_NODE_COMPACT_DATABASE_STMT,
410
  QUERY_NODE_COMPACT_VGROUPS_STMT,
411
  QUERY_NODE_CREATE_FUNCTION_STMT,
412
  QUERY_NODE_DROP_FUNCTION_STMT,
413
  QUERY_NODE_CREATE_STREAM_STMT,
414
  QUERY_NODE_DROP_STREAM_STMT,
415
  QUERY_NODE_BALANCE_VGROUP_STMT,
416
  QUERY_NODE_MERGE_VGROUP_STMT,
417
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
418
  QUERY_NODE_SPLIT_VGROUP_STMT,
419
  QUERY_NODE_SYNCDB_STMT,
420
  QUERY_NODE_GRANT_STMT,
421
  QUERY_NODE_REVOKE_STMT,
422
  QUERY_NODE_ALTER_CLUSTER_STMT,
423
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
424
  QUERY_NODE_CREATE_TSMA_STMT,
425
  QUERY_NODE_DROP_TSMA_STMT,
426
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
427
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
428
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
429
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
430
  QUERY_NODE_CREATE_MOUNT_STMT,
431
  QUERY_NODE_DROP_MOUNT_STMT,
432
  QUERY_NODE_SCAN_DATABASE_STMT,
433
  QUERY_NODE_SCAN_VGROUPS_STMT,
434
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
435
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
436
  QUERY_NODE_CREATE_TOKEN_STMT,
437
  QUERY_NODE_ALTER_TOKEN_STMT,
438
  QUERY_NODE_DROP_TOKEN_STMT,
439
  QUERY_NODE_ALTER_ENCRYPT_KEY_STMT,
440
  QUERY_NODE_CREATE_ROLE_STMT,
441
  QUERY_NODE_DROP_ROLE_STMT,
442
  QUERY_NODE_ALTER_ROLE_STMT,
443
  QUERY_NODE_CREATE_TOTP_SECRET_STMT,
444
  QUERY_NODE_DROP_TOTP_SECRET_STMT,
445
  QUERY_NODE_ALTER_KEY_EXPIRATION_STMT,
446

447

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

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

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

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

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

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

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

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

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

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

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

728
typedef struct {
729
  int32_t contLen;
730
  int32_t vgId;
731
} SMsgHead;
732

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

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

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

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

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

781
typedef struct {
782
  bool     hasRef;
783
  col_id_t id;
784
  char     refDbName[TSDB_DB_NAME_LEN];
785
  char     refTableName[TSDB_TABLE_NAME_LEN];
786
  char     refColName[TSDB_COL_NAME_LEN];
787
  char     colName[TSDB_COL_NAME_LEN];     // for tmq get json
788
} SColRef;
789

790
typedef struct {
791
  int32_t  nCols;
792
  int32_t  version;
793
  SColRef* pColRef;
794
} SColRefWrapper;
795

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

803
typedef struct {
804
  int16_t colId;
805
  char    refDbName[TSDB_DB_NAME_LEN];
806
  char    refTableName[TSDB_TABLE_NAME_LEN];
807
  char    refColName[TSDB_COL_NAME_LEN];
808
} SRefColInfo;
809

810
typedef struct SVCTableRefCols {
811
  uint64_t     uid;
812
  int32_t      numOfSrcTbls;
813
  int32_t      numOfColRefs;
814
  SRefColInfo* refCols;
815
} SVCTableRefCols;
816

817
typedef struct SVCTableMergeInfo {
818
  uint64_t uid;
819
  int32_t  numOfSrcTbls;
820
} SVCTableMergeInfo;
821

822
typedef struct {
823
  int32_t    nCols;
824
  SColRefEx* pColRefEx;
825
} SColRefExWrapper;
826

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

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

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

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

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

900
typedef struct {
901
  int32_t numOfRows;
902
  int32_t affectedRows;
903
  int32_t nBlocks;
904
  union {
905
    SArray*        pArray;
906
    SSubmitBlkRsp* pBlocks;
907
  };
908
} SSubmitRsp;
909

910
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
911
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
912
// void    tFreeSSubmitBlkRsp(void* param);
913
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
914

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

924
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
925
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
926

927
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
928
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
929
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
930

931
#define SSCHMEA_SET_IDX_ON(s) \
932
  do {                        \
933
    (s)->flags |= COL_IDX_ON; \
934
  } while (0)
935

936
#define SSCHMEA_SET_IDX_OFF(s)   \
937
  do {                           \
938
    (s)->flags &= (~COL_IDX_ON); \
939
  } while (0)
940

941
#define SSCHEMA_SET_TYPE_MOD(s)     \
942
  do {                              \
943
    (s)->flags |= COL_HAS_TYPE_MOD; \
944
  } while (0)
945

946
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
947

948
#define SSCHMEA_TYPE(s)  ((s)->type)
949
#define SSCHMEA_FLAGS(s) ((s)->flags)
950
#define SSCHMEA_COLID(s) ((s)->colId)
951
#define SSCHMEA_BYTES(s) ((s)->bytes)
952
#define SSCHMEA_NAME(s)  ((s)->name)
953

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

964
typedef struct {
965
  STypeMod typeMod;
966
} SExtSchema;
967

968
bool hasExtSchema(const SExtSchema* pExtSchema);
969

970
typedef struct {
971
  int32_t      nCols;
972
  int32_t      version;
973
  SSchema*     pSchema;
974
  SSchemaRsma* pRsma;
975
} SSchemaWrapper;
976

977
typedef struct {
978
  col_id_t id;
979
  uint32_t alg;
980
} SColCmpr;
981

982
typedef struct {
983
  int32_t   nCols;
984
  int32_t   version;
985
  SColCmpr* pColCmpr;
986
} SColCmprWrapper;
987

988
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
989
  if (pRef->pColRef) {
33✔
990
    return TSDB_CODE_INVALID_PARA;
×
991
  }
992
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
33✔
993
  if (pRef->pColRef == NULL) {
33✔
994
    return terrno;
×
995
  }
996
  pRef->nCols = nCols;
33✔
997
  for (int32_t i = 0; i < nCols; i++) {
156✔
998
    pRef->pColRef[i].hasRef = false;
123✔
999
    pRef->pColRef[i].id = (col_id_t)(i + 1);
123✔
1000
  }
1001
  return 0;
33✔
1002
}
1003

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

1010
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1011
  if (pDstWrapper == NULL) {
1012
    return NULL;
1013
  }
1014
  pDstWrapper->nCols = pSrcWrapper->nCols;
1015
  pDstWrapper->version = pSrcWrapper->version;
1016

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

1025
  return pDstWrapper;
1026
}
1027

1028
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1029
  if (!(!pCmpr->pColCmpr)) {
131✔
1030
    return TSDB_CODE_INVALID_PARA;
×
1031
  }
1032
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
131✔
1033
  if (pCmpr->pColCmpr == NULL) {
131✔
1034
    return terrno;
×
1035
  }
1036
  pCmpr->nCols = nCols;
131✔
1037
  return 0;
131✔
1038
}
1039

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

1058
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1059
  if (pWrapper == NULL) return;
1060

1061
  taosMemoryFreeClear(pWrapper->pColCmpr);
1062
  taosMemoryFreeClear(pWrapper);
1063
}
1064
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1065
  if (pSchemaWrapper->pSchema == NULL) return NULL;
10✔
1066

1067
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
10✔
1068
  if (pSW == NULL) {
10✔
1069
    return NULL;
×
1070
  }
1071
  pSW->nCols = pSchemaWrapper->nCols;
10✔
1072
  pSW->version = pSchemaWrapper->version;
10✔
1073
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
10✔
1074
  if (pSW->pSchema == NULL) {
10✔
1075
    taosMemoryFree(pSW);
×
1076
    return NULL;
×
1077
  }
1078

1079
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
10✔
1080
  return pSW;
10✔
1081
}
1082

1083
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
306✔
1084
  if (pSchemaWrapper) {
316✔
1085
    taosMemoryFree(pSchemaWrapper->pSchema);
316✔
1086
    if (pSchemaWrapper->pRsma) {
316✔
1087
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
×
1088
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
×
1089
    }
1090
    taosMemoryFree(pSchemaWrapper);
316✔
1091
  }
1092
}
316✔
1093

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

1104
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
×
1105
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
×
1106
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
×
1107
  }
1108
}
×
1109

1110
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1111
  int32_t tlen = 0;
×
1112
  tlen += taosEncodeFixedI8(buf, pSchema->type);
×
1113
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
×
1114
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
×
1115
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
×
1116
  tlen += taosEncodeString(buf, pSchema->name);
×
1117
  return tlen;
×
1118
}
1119

1120
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1121
  buf = taosDecodeFixedI8(buf, &pSchema->type);
×
1122
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
×
1123
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
×
1124
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
×
1125
  buf = taosDecodeStringTo(buf, pSchema->name);
×
1126
  return (void*)buf;
×
1127
}
1128

1129
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1130
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
5,789✔
1131
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
8,866✔
1132
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
8,866✔
1133
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
8,866✔
1134
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
8,866✔
1135
  return 0;
4,433✔
1136
}
1137

1138
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1139
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
8,610✔
1140
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
11,464✔
1141
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
11,464✔
1142
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
11,464✔
1143
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
5,732✔
1144
  return 0;
5,732✔
1145
}
1146

1147
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1148
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
1,596✔
1149
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
1,596✔
1150
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
1,596✔
1151
  return 0;
798✔
1152
}
1153

1154
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1155
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,196✔
1156
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,196✔
1157
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
3,196✔
1158
  return 0;
1,598✔
1159
}
1160

1161
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1162
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
×
1163
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
×
1164
  if (pColRef->hasRef) {
×
1165
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
×
1166
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
×
1167
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
×
1168
  }
1169
  return 0;
×
1170
}
1171

1172
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1173
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
246✔
1174
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
246✔
1175
  if (pColRef->hasRef) {
123✔
1176
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
48✔
1177
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
48✔
1178
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
48✔
1179
  }
1180

1181
  return 0;
123✔
1182
}
1183

1184
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1185
  int32_t tlen = 0;
×
1186
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
×
1187
  tlen += taosEncodeVariantI32(buf, pSW->version);
×
1188
  for (int32_t i = 0; i < pSW->nCols; i++) {
×
1189
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
×
1190
  }
1191
  return tlen;
×
1192
}
1193

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

1203
    for (int32_t i = 0; i < pSW->nCols; i++) {
×
1204
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
×
1205
    }
1206
  } else {
1207
    pSW->pSchema = NULL;
×
1208
  }
1209
  return (void*)buf;
×
1210
}
1211

1212
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1213
  if (pSW == NULL) {
1,052✔
1214
    return TSDB_CODE_INVALID_PARA;
×
1215
  }
1216
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
2,104✔
1217
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
2,104✔
1218
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,129✔
1219
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
6,154✔
1220
  }
1221
  return 0;
1,052✔
1222
}
1223

1224
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1225
  if (pSW == NULL) {
314✔
1226
    return TSDB_CODE_INVALID_PARA;
×
1227
  }
1228
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
628✔
1229
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
628✔
1230

1231
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
314✔
1232
  if (pSW->pSchema == NULL) {
314✔
1233
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1234
  }
1235
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,170✔
1236
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
3,712✔
1237
  }
1238

1239
  return 0;
314✔
1240
}
1241

1242
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1243
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
776✔
1244
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
776✔
1245

1246
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
388✔
1247
  if (pSW->pSchema == NULL) {
388✔
1248
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1249
  }
1250
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,386✔
1251
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,996✔
1252
  }
1253

1254
  return 0;
388✔
1255
}
1256

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

1290
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1291
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1292
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1293

1294
typedef struct {
1295
  STableMetaRsp* pMeta;
1296
} SMCreateStbRsp;
1297

1298
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1299
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1300
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1301

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

1312
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1313
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1314
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1315

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

1330
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1331
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1332
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1333

1334
typedef struct SEpSet {
1335
  int8_t inUse;
1336
  int8_t numOfEps;
1337
  SEp    eps[TSDB_MAX_REPLICA];
1338
} SEpSet;
1339

1340
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1341
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1342
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1343
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1344

1345
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1346
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1347

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

1363
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1364
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1365
void    tSignConnectReq(SConnectReq* pReq);
1366
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1367

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

1394
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1395
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1396

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

1408
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1409
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1410

1411
typedef struct {
1412
  char    user[TSDB_USER_LEN];
1413
  int8_t  ignoreNotExists;
1414
  int32_t sqlLen;
1415
  char*   sql;
1416
} SDropUserReq, SDropAcctReq;
1417

1418
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1419
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1420
void    tFreeSDropUserReq(SDropUserReq* pReq);
1421

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

1435
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1436
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1437
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1438

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

1452
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1453
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1454
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1455

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

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

1491
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1492
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1493
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1494

1495
typedef struct {
1496
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1497
  int32_t sqlLen;
1498
  char*   sql;
1499
} SDropEncryptAlgrReq;
1500

1501
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1502
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1503
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1504

1505
typedef struct SIpV4Range {
1506
  uint32_t ip;
1507
  uint32_t mask;
1508
} SIpV4Range;
1509

1510
typedef struct SIpv6Range {
1511
  uint64_t addr[2];
1512
  uint32_t mask;
1513
} SIpV6Range;
1514

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

1524
typedef struct {
1525
  int32_t    num;
1526
  SIpV4Range pIpRange[];
1527
} SIpWhiteList;
1528

1529
typedef struct {
1530
  int32_t  num;
1531
  SIpRange pIpRanges[];
1532
} SIpWhiteListDual;
1533

1534
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1535
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1536
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1537
int32_t           createDefaultIp6Range(SIpRange* pRange);
1538
int32_t           createDefaultIp4Range(SIpRange* pRange);
1539

1540
typedef struct {
1541
  int32_t sessPerUser;
1542
  int32_t sessConnTime;
1543
  int32_t sessConnIdleTime;
1544
  int32_t sessMaxConcurrency;
1545
  int32_t sessMaxCallVnodeNum;
1546
} SUserSessCfg;
1547

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

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

1564
bool isValidDateTimeRange(SDateTimeRange* pRange);
1565
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1566
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1567

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

1576
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1577
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1578

1579
typedef struct {
1580
  int32_t num;
1581
  SDateTimeWhiteListItem ranges[];
1582
} SDateTimeWhiteList;
1583

1584
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1585
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1586

1587

1588
typedef struct {
1589
  int8_t createType;
1590

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

1605
  int8_t superUser;  // denote if it is a super user or not
1606
  int8_t ignoreExists;
1607

1608
  char   user[TSDB_USER_LEN];
1609
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1610
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1611

1612
  int8_t sysInfo;
1613
  int8_t createDb;
1614
  int8_t isImport;
1615
  int8_t changepass;
1616
  int8_t enable;
1617

1618
  int8_t negIpRanges;
1619
  int8_t negTimeRanges;
1620

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

1635
  int32_t         numIpRanges;
1636
  SIpRange*       pIpDualRanges;
1637
  int32_t         numTimeRanges;
1638
  SDateTimeRange* pTimeRanges;
1639

1640
  int32_t sqlLen;
1641
  char*   sql;
1642
} SCreateUserReq;
1643

1644
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1645
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1646
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1647

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

1658
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1659
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1660
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1661

1662
typedef struct {
1663
  int32_t dnodeId;
1664
  int64_t analVer;
1665
} SRetrieveAnalyticsAlgoReq;
1666

1667
typedef struct {
1668
  int64_t   ver;
1669
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1670
} SRetrieveAnalyticAlgoRsp;
1671

1672
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1673
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1674
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1675
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1676
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1677

1678
typedef struct {
1679
  int8_t alterType;
1680

1681
  int8_t isView;
1682

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

1703
  int8_t enable;
1704
  int8_t sysinfo;
1705
  int8_t createdb;
1706
  int8_t changepass;
1707

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

1725
  int32_t         numIpRanges;
1726
  int32_t         numTimeRanges;
1727
  int32_t         numDropIpRanges;
1728
  int32_t         numDropTimeRanges;
1729
  SIpRange*       pIpRanges;
1730
  SDateTimeRange* pTimeRanges;
1731
  SIpRange*       pDropIpRanges;
1732
  SDateTimeRange* pDropTimeRanges;
1733
  SPrivSet        privileges;
1734

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

1743
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1744
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1745
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1746

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

1756
  int32_t sqlLen;
1757
  char*   sql;
1758
} SCreateTokenReq;
1759

1760
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1761
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1762
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1763

1764
typedef struct {
1765
  char name[TSDB_TOKEN_NAME_LEN];
1766
  char user[TSDB_USER_LEN];
1767
  char token[TSDB_TOKEN_LEN];
1768
} SCreateTokenRsp;
1769

1770
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1771
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1772
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1773

1774
typedef struct {
1775
  char    name[TSDB_TOKEN_NAME_LEN];
1776

1777
  int8_t hasEnable;
1778
  int8_t hasTtl;
1779
  int8_t hasProvider;
1780
  int8_t hasExtraInfo;
1781

1782
  int8_t  enable;
1783
  int32_t ttl;
1784
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1785
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1786

1787
  int32_t     sqlLen;
1788
  char*       sql;
1789
} SAlterTokenReq;
1790

1791
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1792
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1793
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1794

1795
typedef struct {
1796
  char    name[TSDB_TOKEN_NAME_LEN];
1797
  int8_t  ignoreNotExists;
1798
  int32_t sqlLen;
1799
  char*   sql;
1800
} SDropTokenReq;
1801

1802
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1803
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1804
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1805

1806
typedef struct {
1807
  char    user[TSDB_USER_LEN];
1808
  int32_t sqlLen;
1809
  char*   sql;
1810
} SCreateTotpSecretReq;
1811

1812
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1813
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1814
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1815

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

1821
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1822
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1823

1824
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1825
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1826
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1827
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1828

1829
typedef struct {
1830
  char user[TSDB_USER_LEN];
1831
} SGetUserAuthReq;
1832

1833
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1834
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1835

1836
typedef struct {
1837
  int8_t  enabled;
1838
  int32_t expireTime;
1839
} STokenStatus;
1840

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

1866
  SUserSessCfg sessCfg;
1867
  int64_t      timeWhiteListVer;
1868
  SHashObj*    tokens;
1869
} SGetUserAuthRsp;
1870

1871
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1872
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1873
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1874

1875
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1876
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1877
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1878
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1879

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

1892
typedef struct {
1893
  int64_t             ver;
1894
  int                 numOfUser;
1895
  SUpdateUserIpWhite* pUserIpWhite;
1896
} SUpdateIpWhite;
1897

1898
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1899
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1900
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1901
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1902

1903
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1904
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1905
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1906

1907

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

1914
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1915
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1916

1917

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

1924
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1925
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1926

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

1936
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1937
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1938
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1939
void    tIpRangeSetDefaultMask(SIpRange* range);
1940

1941
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1942
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1943
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1944

1945
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1946
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1947
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1948

1949
typedef struct {
1950
  int64_t ver;
1951
  char    user[TSDB_USER_LEN];
1952
  int32_t numWhiteLists;
1953
  SDateTimeWhiteListItem* pWhiteLists;
1954
} SUserDateTimeWhiteList;
1955

1956

1957
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1958
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1959
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1960
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1961

1962
typedef struct {
1963
  int64_t             ver;
1964
  int                 numOfUser;
1965
  SUserDateTimeWhiteList *pUsers;
1966
} SRetrieveDateTimeWhiteListRsp;
1967

1968
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1969
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1970
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1971
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1972

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

1983
  uint8_t precision;
1984
  uint8_t scale;
1985
  int32_t bytes;
1986
  int8_t  type;
1987
  uint8_t pk;
1988
  bool    noData;
1989
} SColumnInfo;
1990

1991
typedef struct STimeWindow {
1992
  TSKEY skey;
1993
  TSKEY ekey;
1994
} STimeWindow;
1995

1996
typedef struct SQueryHint {
1997
  bool batchScan;
1998
} SQueryHint;
1999

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

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

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

2026
typedef struct {
2027
  int32_t code;
2028
  int64_t affectedRows;
2029
  SArray* tbVerInfo;  // STbVerInfo
2030
} SQueryTableRsp;
2031

2032
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2033

2034
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2035

2036
typedef struct {
2037
  SMsgHead header;
2038
  char     dbFName[TSDB_DB_FNAME_LEN];
2039
  char     tbName[TSDB_TABLE_NAME_LEN];
2040
} STableCfgReq;
2041

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

2074
typedef STableCfg STableCfgRsp;
2075

2076
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2077
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2078

2079
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2080
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2081
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2082

2083
typedef struct {
2084
  SMsgHead header;
2085
  tb_uid_t suid;
2086
} SVSubTablesReq;
2087

2088
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2089
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2090

2091
typedef struct {
2092
  int32_t vgId;
2093
  SArray* pTables;  // SArray<SVCTableRefCols*>
2094
} SVSubTablesRsp;
2095

2096
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2097
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2098
void    tDestroySVSubTablesRsp(void* rsp);
2099

2100
typedef struct {
2101
  SMsgHead header;
2102
  tb_uid_t suid;
2103
} SVStbRefDbsReq;
2104

2105
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2106
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2107

2108
typedef struct {
2109
  int32_t vgId;
2110
  SArray* pDbs;  // SArray<char* (db name)>
2111
} SVStbRefDbsRsp;
2112

2113
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2114
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2115
void    tDestroySVStbRefDbsRsp(void* rsp);
2116

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

2169
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2170
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2171
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2172

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

2208
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2209
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2210
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2211

2212
typedef struct {
2213
  char    db[TSDB_DB_FNAME_LEN];
2214
  int8_t  ignoreNotExists;
2215
  int8_t  force;
2216
  int32_t sqlLen;
2217
  char*   sql;
2218
} SDropDbReq;
2219

2220
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2221
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2222
void    tFreeSDropDbReq(SDropDbReq* pReq);
2223

2224
typedef struct {
2225
  char    db[TSDB_DB_FNAME_LEN];
2226
  int64_t uid;
2227
} SDropDbRsp;
2228

2229
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2230
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2231

2232
typedef struct {
2233
  char    name[TSDB_MOUNT_NAME_LEN];
2234
  int64_t uid;
2235
} SDropMountRsp;
2236

2237
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2238
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2239

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

2248
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2249
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2250

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

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

2277
typedef struct {
2278
  char db[TSDB_DB_FNAME_LEN];
2279
} SDbCfgReq;
2280

2281
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2282
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2283

2284
typedef struct {
2285
  char db[TSDB_DB_FNAME_LEN];
2286
} SSsMigrateDbReq;
2287

2288
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2289
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2290

2291
typedef struct {
2292
  int32_t ssMigrateId;
2293
  bool    bAccepted;
2294
} SSsMigrateDbRsp;
2295

2296
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2297
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2298

2299
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2300
typedef struct {
2301
  int32_t ssMigrateId;
2302
} SListSsMigrateFileSetsReq;
2303

2304
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2305
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2306

2307
typedef struct {
2308
  int32_t ssMigrateId;
2309
  int32_t vgId;       // vgroup id
2310
  SArray* pFileSets;  // SArray<int32_t>
2311
} SListSsMigrateFileSetsRsp;
2312

2313
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2314
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2315
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2316

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

2325
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2326
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2327

2328
typedef struct {
2329
  int32_t ssMigrateId;
2330
  int32_t nodeId;  // node id of the leader vnode
2331
  int32_t vgId;
2332
  int32_t fid;
2333
} SSsMigrateFileSetRsp;
2334

2335
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2336
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2337

2338
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2339
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2340
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2341
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2342
#define SSMIGRATE_FILESET_STATE_FAILED      4
2343

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

2356
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2357
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2358

2359
// Request for TDMT_MND_KILL_SSMIGRATE
2360
typedef struct {
2361
  int32_t ssMigrateId;
2362
  int32_t sqlLen;
2363
  char*   sql;
2364
} SKillSsMigrateReq;
2365

2366
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2367
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2368
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2369

2370
// Request for TDMT_VND_KILL_SSMIGRATE
2371
typedef struct {
2372
  int32_t ssMigrateId;
2373
} SVnodeKillSsMigrateReq;
2374

2375
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2376
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2377

2378
typedef struct {
2379
  int32_t vgId;
2380
  int64_t keepVersion;
2381
} SMndSetVgroupKeepVersionReq;
2382

2383
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2384
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2385

2386
typedef struct {
2387
  int32_t timestampSec;
2388
  int32_t ttlDropMaxCount;
2389
  int32_t nUids;
2390
  SArray* pTbUids;
2391
} SVDropTtlTableReq;
2392

2393
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2394
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2395

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

2454
typedef SDbCfgRsp SDbCfgInfo;
2455

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

2462
typedef struct {
2463
  int32_t rowNum;
2464
} SQnodeListReq;
2465

2466
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2467
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2468

2469
typedef struct {
2470
  int32_t rowNum;
2471
} SDnodeListReq;
2472

2473
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2474

2475
typedef struct {
2476
  int32_t useless;  // useless
2477
} SServerVerReq;
2478

2479
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2480
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2481

2482
typedef struct {
2483
  char ver[TSDB_VERSION_LEN];
2484
} SServerVerRsp;
2485

2486
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2487
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2488

2489
typedef struct SQueryNodeAddr {
2490
  int32_t nodeId;  // vgId or qnodeId
2491
  SEpSet  epSet;
2492
} SQueryNodeAddr;
2493

2494
typedef struct {
2495
  SQueryNodeAddr addr;
2496
  uint64_t       load;
2497
} SQueryNodeLoad;
2498

2499
typedef struct {
2500
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2501
} SQnodeListRsp;
2502

2503
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2504
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2505
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2506

2507

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

2520

2521

2522
typedef struct SDNodeAddr {
2523
  int32_t nodeId;  // dnodeId
2524
  SEpSet  epSet;
2525
} SDNodeAddr;
2526

2527
typedef struct {
2528
  SArray* dnodeList;  // SArray<SDNodeAddr>
2529
} SDnodeListRsp;
2530

2531
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2532
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2533
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2534

2535
typedef struct {
2536
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2537
} STableTSMAInfoRsp;
2538

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

2548
typedef struct {
2549
  SArray* pArray;  // Array of SDbHbRsp
2550
} SDbHbBatchRsp;
2551

2552
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2553
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2554
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2555

2556
typedef struct {
2557
  SArray* pArray;  // Array of SGetUserAuthRsp
2558
} SUserAuthBatchRsp;
2559

2560
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2561
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2562
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2563

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

2575
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2576
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2577
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2578

2579
typedef struct {
2580
  union {
2581
    int32_t compactId;
2582
    int32_t id;
2583
  };
2584
  int8_t bAccepted;
2585
} SCompactDbRsp;
2586

2587
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2588
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2589

2590
typedef struct {
2591
  union {
2592
    int32_t compactId;
2593
    int32_t id;
2594
  };
2595
  int32_t sqlLen;
2596
  char*   sql;
2597
} SKillCompactReq;
2598

2599
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2600
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2601
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2602

2603
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2604
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2605

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

2621
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2622
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2623
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2624

2625
typedef struct {
2626
  char   name[TSDB_FUNC_NAME_LEN];
2627
  int8_t igNotExists;
2628
} SDropFuncReq;
2629

2630
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2631
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2632

2633
typedef struct {
2634
  int32_t numOfFuncs;
2635
  bool    ignoreCodeComment;
2636
  SArray* pFuncNames;
2637
} SRetrieveFuncReq;
2638

2639
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2640
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2641
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2642

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

2657
typedef struct {
2658
  int32_t funcVersion;
2659
  int64_t funcCreatedTime;
2660
} SFuncExtraInfo;
2661

2662
typedef struct {
2663
  int32_t numOfFuncs;
2664
  SArray* pFuncInfos;
2665
  SArray* pFuncExtraInfos;
2666
} SRetrieveFuncRsp;
2667

2668
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2669
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2670
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2671
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2672

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

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

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

2729
typedef struct {
2730
  int64_t total_requests;
2731
  int64_t total_rows;
2732
  int64_t total_bytes;
2733
  double  write_size;
2734
  double  cache_hit_ratio;
2735
  int64_t rpc_queue_wait;
2736
  int64_t preprocess_time;
2737

2738
  int64_t memory_table_size;
2739
  int64_t commit_count;
2740
  int64_t merge_count;
2741
  double  commit_time;
2742
  double  merge_time;
2743
  int64_t block_commit_time;
2744
  int64_t memtable_wait_time;
2745
} SVnodeMetrics;
2746

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

2763
typedef struct {
2764
  int32_t vgId;
2765
  int64_t nTimeSeries;
2766
} SVnodeLoadLite;
2767

2768
typedef struct {
2769
  int8_t  syncState;
2770
  int64_t syncTerm;
2771
  int8_t  syncRestore;
2772
  int64_t roleTimeMs;
2773
} SMnodeLoad;
2774

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

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

2820
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2821
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2822
void    tFreeSStatusReq(SStatusReq* pReq);
2823

2824
typedef struct {
2825
  int32_t forceReadConfig;
2826
  int32_t cver;
2827
  SArray* array;
2828
} SConfigReq;
2829

2830
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2831
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2832
void    tFreeSConfigReq(SConfigReq* pReq);
2833

2834
typedef struct {
2835
  int32_t dnodeId;
2836
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2837
} SDnodeInfoReq;
2838

2839
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2840
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2841

2842
typedef enum {
2843
  MONITOR_TYPE_COUNTER = 0,
2844
  MONITOR_TYPE_SLOW_LOG = 1,
2845
} MONITOR_TYPE;
2846

2847
typedef struct {
2848
  int32_t      contLen;
2849
  char*        pCont;
2850
  MONITOR_TYPE type;
2851
} SStatisReq;
2852

2853
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2854
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2855
void    tFreeSStatisReq(SStatisReq* pReq);
2856

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

2870
typedef struct {
2871
  SArray* auditArr;
2872
} SBatchAuditReq;
2873
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2874
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2875
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2876

2877
typedef struct {
2878
  int32_t dnodeId;
2879
  int64_t clusterId;
2880
  SArray* pVloads;
2881
} SNotifyReq;
2882

2883
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2884
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2885
void    tFreeSNotifyReq(SNotifyReq* pReq);
2886

2887
typedef struct {
2888
  int32_t dnodeId;
2889
  int64_t clusterId;
2890
} SDnodeCfg;
2891

2892
typedef struct {
2893
  int32_t id;
2894
  int8_t  isMnode;
2895
  SEp     ep;
2896
} SDnodeEp;
2897

2898
typedef struct {
2899
  int32_t id;
2900
  int8_t  isMnode;
2901
  int8_t  offlineReason;
2902
  SEp     ep;
2903
  char    active[TSDB_ACTIVE_KEY_LEN];
2904
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2905
} SDnodeInfo;
2906

2907
typedef struct {
2908
  int64_t   dnodeVer;
2909
  SDnodeCfg dnodeCfg;
2910
  SArray*   pDnodeEps;  // Array of SDnodeEp
2911
  int32_t   statusSeq;
2912
  int64_t   ipWhiteVer;
2913
  int64_t   analVer;
2914
  int64_t   timeWhiteVer;
2915
  char      auditDB[TSDB_DB_FNAME_LEN];
2916
  char      auditToken[TSDB_TOKEN_LEN];
2917
  SEpSet    auditEpSet;
2918
  int32_t   auditVgId;
2919
} SStatusRsp;
2920

2921
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2922
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2923
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2924

2925
typedef struct {
2926
  int32_t forceReadConfig;
2927
  int32_t isConifgVerified;
2928
  int32_t isVersionVerified;
2929
  int32_t cver;
2930
  SArray* array;
2931
} SConfigRsp;
2932

2933
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2934
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2935
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2936

2937
typedef struct {
2938
  int32_t dnodeId;
2939
  int32_t keyVersion;  // Local key version
2940
} SKeySyncReq;
2941

2942
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2943
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2944

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

2962
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2963
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2964

2965
typedef struct {
2966
  int32_t reserved;
2967
} SMTimerReq;
2968

2969
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2970
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2971

2972
typedef struct SOrphanTask {
2973
  int64_t streamId;
2974
  int32_t taskId;
2975
  int32_t nodeId;
2976
} SOrphanTask;
2977

2978
typedef struct SMStreamDropOrphanMsg {
2979
  SArray* pList;  // SArray<SOrphanTask>
2980
} SMStreamDropOrphanMsg;
2981

2982
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2983
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2984
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2985

2986
typedef struct {
2987
  int32_t  id;
2988
  uint16_t port;                 // node sync Port
2989
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2990
} SReplica;
2991

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

3053
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3054
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3055
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3056

3057
typedef struct {
3058
  union {
3059
    int32_t compactId;
3060
    int32_t id;
3061
  };
3062
  int32_t vgId;
3063
  int32_t dnodeId;
3064
} SQueryCompactProgressReq;
3065

3066
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3067
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3068

3069
typedef struct {
3070
  union {
3071
    int32_t compactId;
3072
    int32_t id;
3073
  };
3074
  int32_t vgId;
3075
  int32_t dnodeId;
3076
  int32_t numberFileset;
3077
  int32_t finished;
3078
  int32_t progress;
3079
  int64_t remainingTime;
3080
} SQueryCompactProgressRsp;
3081

3082
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3083
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3084

3085
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3086
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3087

3088
typedef struct {
3089
  int32_t vgId;
3090
  int32_t dnodeId;
3091
  int64_t dbUid;
3092
  char    db[TSDB_DB_FNAME_LEN];
3093
  int64_t reserved[8];
3094
} SDropVnodeReq;
3095

3096
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3097
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3098

3099
typedef struct {
3100
  char    colName[TSDB_COL_NAME_LEN];
3101
  char    stb[TSDB_TABLE_FNAME_LEN];
3102
  int64_t stbUid;
3103
  int64_t dbUid;
3104
  int64_t reserved[8];
3105
} SDropIndexReq;
3106

3107
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3108
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3109

3110
typedef struct {
3111
  int64_t dbUid;
3112
  char    db[TSDB_DB_FNAME_LEN];
3113
  union {
3114
    int64_t compactStartTime;
3115
    int64_t startTime;
3116
  };
3117

3118
  STimeWindow tw;
3119
  union {
3120
    int32_t compactId;
3121
    int32_t id;
3122
  };
3123
  int8_t metaOnly;
3124
  union {
3125
    uint16_t flags;
3126
    struct {
3127
      uint16_t optrType : 3;     // ETsdbOpType
3128
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3129
      uint16_t reserved : 12;
3130
    };
3131
  };
3132
  int8_t force;  // force compact
3133
} SCompactVnodeReq;
3134

3135
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3136
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3137

3138
typedef struct {
3139
  union {
3140
    int32_t compactId;
3141
    int32_t taskId;
3142
  };
3143
  int32_t vgId;
3144
  int32_t dnodeId;
3145
} SVKillCompactReq;
3146

3147
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3148
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3149

3150
typedef SVKillCompactReq SVKillRetentionReq;
3151

3152
typedef struct {
3153
  char        db[TSDB_DB_FNAME_LEN];
3154
  int32_t     maxSpeed;
3155
  int32_t     sqlLen;
3156
  char*       sql;
3157
  SArray*     vgroupIds;
3158
  STimeWindow tw;  // unit is second
3159
  union {
3160
    uint32_t flags;
3161
    struct {
3162
      uint32_t optrType : 3;     // ETsdbOpType
3163
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3164
      uint32_t reserved : 28;
3165
    };
3166
  };
3167
} STrimDbReq;
3168

3169
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3170
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3171
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3172

3173
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3174

3175
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3176
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3177

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

3205
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3206
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3207

3208
typedef struct {
3209
  int32_t  vgId;
3210
  int8_t   strict;
3211
  int8_t   selfIndex;
3212
  int8_t   replica;
3213
  SReplica replicas[TSDB_MAX_REPLICA];
3214
  int64_t  reserved[8];
3215
  int8_t   learnerSelfIndex;
3216
  int8_t   learnerReplica;
3217
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3218
  int32_t  changeVersion;
3219
  int32_t  electBaseLine;
3220
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3221

3222
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3223
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3224

3225
typedef struct {
3226
  int32_t vgId;
3227
  int8_t  disable;
3228
} SDisableVnodeWriteReq;
3229

3230
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3231
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3232

3233
typedef struct {
3234
  int32_t  srcVgId;
3235
  int32_t  dstVgId;
3236
  uint32_t hashBegin;
3237
  uint32_t hashEnd;
3238
  int32_t  changeVersion;
3239
  int32_t  reserved;
3240
} SAlterVnodeHashRangeReq;
3241

3242
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3243
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3244

3245
#define REQ_OPT_TBNAME 0x0
3246
#define REQ_OPT_TBUID  0x01
3247
typedef struct {
3248
  SMsgHead header;
3249
  char     dbFName[TSDB_DB_FNAME_LEN];
3250
  char     tbName[TSDB_TABLE_NAME_LEN];
3251
  uint8_t  option;
3252
  uint8_t  autoCreateCtb;
3253
} STableInfoReq;
3254

3255
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3256
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3257

3258
typedef struct {
3259
  int8_t  metaClone;  // create local clone of the cached table meta
3260
  int32_t numOfVgroups;
3261
  int32_t numOfTables;
3262
  int32_t numOfUdfs;
3263
  char    tableNames[];
3264
} SMultiTableInfoReq;
3265

3266
// todo refactor
3267
typedef struct SVgroupInfo {
3268
  int32_t  vgId;
3269
  uint32_t hashBegin;
3270
  uint32_t hashEnd;
3271
  SEpSet   epSet;
3272
  union {
3273
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3274
    int32_t taskId;      // used in stream
3275
  };
3276
} SVgroupInfo;
3277

3278
typedef struct {
3279
  int32_t     numOfVgroups;
3280
  SVgroupInfo vgroups[];
3281
} SVgroupsInfo;
3282

3283
typedef struct {
3284
  STableMetaRsp* pMeta;
3285
} SMAlterStbRsp;
3286

3287
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3288
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3289
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3290

3291
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3292
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3293
void    tFreeSTableMetaRsp(void* pRsp);
3294
void    tFreeSTableIndexRsp(void* info);
3295

3296
typedef struct {
3297
  SArray* pMetaRsp;   // Array of STableMetaRsp
3298
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3299
} SSTbHbRsp;
3300

3301
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3302
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3303
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3304

3305
typedef struct {
3306
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3307
} SViewHbRsp;
3308

3309
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3310
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3311
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3312

3313
typedef struct {
3314
  int32_t numOfTables;
3315
  int32_t numOfVgroup;
3316
  int32_t numOfUdf;
3317
  int32_t contLen;
3318
  int8_t  compressed;  // denote if compressed or not
3319
  int32_t rawLen;      // size before compress
3320
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3321
  char    meta[];
3322
} SMultiTableMeta;
3323

3324
typedef struct {
3325
  int32_t dataLen;
3326
  char    name[TSDB_TABLE_FNAME_LEN];
3327
  char*   data;
3328
} STagData;
3329

3330
typedef struct {
3331
  int32_t  opType;
3332
  uint32_t valLen;
3333
  char*    val;
3334
} SShowVariablesReq;
3335

3336
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3337
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3338
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3339

3340
typedef struct {
3341
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3342
  char value[TSDB_CONFIG_PATH_LEN + 1];
3343
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3344
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3345
  char info[TSDB_CONFIG_INFO_LEN + 1];
3346
} SVariablesInfo;
3347

3348
typedef struct {
3349
  SArray* variables;  // SArray<SVariablesInfo>
3350
} SShowVariablesRsp;
3351

3352
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3353
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3354

3355
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3356

3357
/*
3358
 * sql: show tables like '%a_%'
3359
 * payload is the query condition, e.g., '%a_%'
3360
 * payloadLen is the length of payload
3361
 */
3362
typedef struct {
3363
  int32_t type;
3364
  char    db[TSDB_DB_FNAME_LEN];
3365
  int32_t payloadLen;
3366
  char*   payload;
3367
} SShowReq;
3368

3369
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3370
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3371
void tFreeSShowReq(SShowReq* pReq);
3372

3373
typedef struct {
3374
  int64_t       showId;
3375
  STableMetaRsp tableMeta;
3376
} SShowRsp, SVShowTablesRsp;
3377

3378
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3379
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3380
// void    tFreeSShowRsp(SShowRsp* pRsp);
3381

3382
typedef struct {
3383
  char    db[TSDB_DB_FNAME_LEN];
3384
  char    tb[TSDB_TABLE_NAME_LEN];
3385
  char    user[TSDB_USER_LEN];
3386
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3387
  int64_t showId;
3388
  int64_t compactId;  // for compact
3389
  bool    withFull;   // for show users full
3390
} SRetrieveTableReq;
3391

3392
typedef struct SSysTableSchema {
3393
  int8_t   type;
3394
  col_id_t colId;
3395
  int32_t  bytes;
3396
} SSysTableSchema;
3397

3398
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3399
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3400

3401
#define RETRIEVE_TABLE_RSP_VERSION         0
3402
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3403
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3404

3405
typedef struct {
3406
  int64_t useconds;
3407
  int8_t  completed;  // all results are returned to client
3408
  int8_t  precision;
3409
  int8_t  compressed;
3410
  int8_t  streamBlockType;
3411
  int32_t payloadLen;
3412
  int32_t compLen;
3413
  int32_t numOfBlocks;
3414
  int64_t numOfRows;  // from int32_t change to int64_t
3415
  int64_t numOfCols;
3416
  int64_t skey;
3417
  int64_t ekey;
3418
  int64_t version;                         // for stream
3419
  TSKEY   watermark;                       // for stream
3420
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3421
  char    data[];
3422
} SRetrieveTableRsp;
3423

3424
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3425

3426
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3427
  do {                                          \
3428
    ((int32_t*)(_p))[0] = (_compLen);           \
3429
    ((int32_t*)(_p))[1] = (_fullLen);           \
3430
  } while (0);
3431

3432
typedef struct {
3433
  int64_t version;
3434
  int64_t numOfRows;
3435
  int8_t  compressed;
3436
  int8_t  precision;
3437
  char    data[];
3438
} SRetrieveTableRspForTmq;
3439

3440
typedef struct {
3441
  int64_t handle;
3442
  int64_t useconds;
3443
  int8_t  completed;  // all results are returned to client
3444
  int8_t  precision;
3445
  int8_t  compressed;
3446
  int32_t compLen;
3447
  int32_t numOfRows;
3448
  int32_t fullLen;
3449
  char    data[];
3450
} SRetrieveMetaTableRsp;
3451

3452
typedef struct SExplainExecInfo {
3453
  double   startupCost;
3454
  double   totalCost;
3455
  uint64_t numOfRows;
3456
  uint32_t verboseLen;
3457
  void*    verboseInfo;
3458
} SExplainExecInfo;
3459

3460
typedef struct {
3461
  int32_t           numOfPlans;
3462
  SExplainExecInfo* subplanInfo;
3463
} SExplainRsp;
3464

3465
typedef struct {
3466
  SExplainRsp rsp;
3467
  uint64_t    qId;
3468
  uint64_t    cId;
3469
  uint64_t    tId;
3470
  int64_t     rId;
3471
  int32_t     eId;
3472
} SExplainLocalRsp;
3473

3474
typedef struct STableScanAnalyzeInfo {
3475
  uint64_t totalRows;
3476
  uint64_t totalCheckedRows;
3477
  uint32_t totalBlocks;
3478
  uint32_t loadBlocks;
3479
  uint32_t loadBlockStatis;
3480
  uint32_t skipBlocks;
3481
  uint32_t filterOutBlocks;
3482
  double   elapsedTime;
3483
  double   filterTime;
3484
} STableScanAnalyzeInfo;
3485

3486
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3487
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3488
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3489

3490
typedef struct {
3491
  char    config[TSDB_DNODE_CONFIG_LEN];
3492
  char    value[TSDB_CLUSTER_VALUE_LEN];
3493
  int32_t sqlLen;
3494
  char*   sql;
3495
} SMCfgClusterReq;
3496

3497
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3498
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3499
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3500

3501
typedef struct {
3502
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3503
  int32_t port;
3504
  int32_t sqlLen;
3505
  char*   sql;
3506
} SCreateDnodeReq;
3507

3508
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3509
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3510
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3511

3512
typedef struct {
3513
  int32_t dnodeId;
3514
  char    fqdn[TSDB_FQDN_LEN];
3515
  int32_t port;
3516
  int8_t  force;
3517
  int8_t  unsafe;
3518
  int32_t sqlLen;
3519
  char*   sql;
3520
} SDropDnodeReq;
3521

3522
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3523
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3524
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3525

3526
enum {
3527
  RESTORE_TYPE__ALL = 1,
3528
  RESTORE_TYPE__MNODE,
3529
  RESTORE_TYPE__VNODE,
3530
  RESTORE_TYPE__QNODE,
3531
};
3532

3533
typedef struct {
3534
  int32_t dnodeId;
3535
  int8_t  restoreType;
3536
  int32_t sqlLen;
3537
  char*   sql;
3538
} SRestoreDnodeReq;
3539

3540
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3541
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3542
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3543

3544
typedef struct {
3545
  int32_t dnodeId;
3546
  char    config[TSDB_DNODE_CONFIG_LEN];
3547
  char    value[TSDB_DNODE_VALUE_LEN];
3548
  int32_t sqlLen;
3549
  char*   sql;
3550
} SMCfgDnodeReq;
3551

3552
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3553
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3554
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3555

3556
typedef struct {
3557
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3558
  char    newKey[ENCRYPT_KEY_LEN + 1];
3559
  int32_t sqlLen;
3560
  char*   sql;
3561
} SMAlterEncryptKeyReq;
3562

3563
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3564
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3565
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3566

3567
typedef struct {
3568
  int32_t days;
3569
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3570
  int32_t sqlLen;
3571
  char*   sql;
3572
} SMAlterKeyExpirationReq;
3573

3574
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3575
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3576
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3577

3578
typedef struct {
3579
  char    config[TSDB_DNODE_CONFIG_LEN];
3580
  char    value[TSDB_DNODE_VALUE_LEN];
3581
  int32_t version;
3582
} SDCfgDnodeReq;
3583

3584
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3585
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3586

3587
typedef struct {
3588
  int32_t dnodeId;
3589
  int32_t sqlLen;
3590
  char*   sql;
3591
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3592
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3593

3594
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3595
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3596

3597
typedef struct {
3598
  int32_t nodeId;
3599
  SEpSet  epSet;
3600
} SNodeEpSet;
3601

3602
typedef struct {
3603
  int32_t    snodeId;
3604
  SNodeEpSet leaders[2];
3605
  SNodeEpSet replica;
3606
  int32_t    sqlLen;
3607
  char*      sql;
3608
} SDCreateSnodeReq;
3609

3610
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3611
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3612
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3613

3614
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3615
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3616
typedef struct {
3617
  int8_t   replica;
3618
  SReplica replicas[TSDB_MAX_REPLICA];
3619
  int8_t   learnerReplica;
3620
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3621
  int64_t  lastIndex;
3622
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3623
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3624

3625
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3626
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3627

3628
typedef struct {
3629
  int32_t urlLen;
3630
  int32_t sqlLen;
3631
  char*   url;
3632
  char*   sql;
3633
} SMCreateAnodeReq;
3634

3635
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3636
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3637
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3638

3639
typedef struct {
3640
  int32_t anodeId;
3641
  int32_t sqlLen;
3642
  char*   sql;
3643
} SMDropAnodeReq, SMUpdateAnodeReq;
3644

3645
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3646
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3647
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3648
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3649
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3650
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3651

3652
typedef struct {
3653
  int32_t dnodeId;
3654
  int32_t bnodeProto;
3655
  int32_t sqlLen;
3656
  char*   sql;
3657
} SMCreateBnodeReq, SDCreateBnodeReq;
3658

3659
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3660
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3661
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3662

3663
typedef struct {
3664
  int32_t dnodeId;
3665
  int32_t sqlLen;
3666
  char*   sql;
3667
} SMDropBnodeReq, SDDropBnodeReq;
3668

3669
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3670
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3671
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3672

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

3733
typedef struct {
3734
  int32_t sqlLen;
3735
  int32_t urlLen;
3736
  int32_t userLen;
3737
  int32_t passLen;
3738
  int32_t passIsMd5;
3739
  char*   sql;
3740
  char*   url;
3741
  char*   user;
3742
  char*   pass;
3743
  CowStr  token;
3744
} SMCreateXnodeReq, SDCreateXnodeReq;
3745

3746
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3747
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3748
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3749

3750
typedef struct {
3751
  int32_t xnodeId;
3752
  int32_t force;
3753
  int32_t urlLen;
3754
  int32_t sqlLen;
3755
  char*   url;
3756
  char*   sql;
3757
} SMDropXnodeReq, SDDropXnodeReq;
3758

3759
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3760
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3761
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3762

3763
typedef struct {
3764
  int32_t id;
3765
  CowStr  token;
3766
  CowStr  user;
3767
  CowStr  pass;
3768
  int32_t urlLen;
3769
  int32_t sqlLen;
3770
  char*   url;
3771
  char*   sql;
3772
} SMUpdateXnodeReq;
3773
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3774
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3775
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3776

3777
typedef struct {
3778
  int32_t xnodeId;
3779
  int32_t sqlLen;
3780
  char*   sql;
3781
} SMDrainXnodeReq;
3782
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3783
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3784
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3785
typedef enum {
3786
  XNODE_TASK_SOURCE_DSN = 1,
3787
  XNODE_TASK_SOURCE_DATABASE,
3788
  XNODE_TASK_SOURCE_TOPIC,
3789
} ENodeXTaskSourceType;
3790

3791
typedef enum {
3792
  XNODE_TASK_SINK_DSN = 1,
3793
  XNODE_TASK_SINK_DATABASE,
3794
} ENodeXTaskSinkType;
3795

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

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

3848
typedef struct {
3849
  int32_t via;
3850
  CowStr  parser;
3851
  // CowStr  reason;
3852
  CowStr  trigger;
3853
  CowStr  health;
3854
  int32_t optionsNum;
3855
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3856
} xTaskOptions;
3857
/**
3858
 * @brief Deallocate a xTaskOptions object.
3859
 *
3860
 * @param options ptr
3861
 */
3862
void    xFreeTaskOptions(xTaskOptions* options);
3863
void    printXnodeTaskOptions(xTaskOptions* options);
3864
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3865
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3866

3867
typedef struct {
3868
  int32_t sqlLen;
3869
  char*   sql;
3870
  int32_t      xnodeId;
3871
  CowStr       name;
3872
  xTaskSource  source;
3873
  xTaskSink    sink;
3874
  xTaskOptions options;
3875
} SMCreateXnodeTaskReq;
3876
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3877
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3878
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3879

3880
typedef struct {
3881
  int32_t     tid;
3882
  CowStr      name;
3883
  int32_t     via;
3884
  int32_t     xnodeId;
3885
  CowStr      status;
3886
  xTaskSource source;
3887
  xTaskSink   sink;
3888
  CowStr      parser;
3889
  CowStr      reason;
3890
  CowStr      updateName;
3891
  CowStr      labels;
3892
  int32_t     sqlLen;
3893
  char*       sql;
3894
} SMUpdateXnodeTaskReq;
3895
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3896
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3897
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3898

3899
typedef struct {
3900
  int32_t id;
3901
  bool    force;
3902
  CowStr  name;
3903
  int32_t sqlLen;
3904
  char*   sql;
3905
} SMDropXnodeTaskReq;
3906
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3907
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3908
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3909

3910
typedef struct {
3911
  int32_t tid;
3912
  CowStr  name;
3913
  int32_t sqlLen;
3914
  char*   sql;
3915
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3916
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3917
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3918
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3919

3920
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3921
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3922
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3923

3924
typedef struct {
3925
  int32_t tid;
3926
  int32_t via;
3927
  int32_t xnodeId;
3928
  CowStr  status;
3929
  CowStr  config;
3930
  CowStr  reason;
3931
  int32_t sqlLen;
3932
  char*   sql;
3933
} SMCreateXnodeJobReq;
3934
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3935
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3936
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3937

3938
typedef struct {
3939
  int32_t jid;
3940
  int32_t via;
3941
  int32_t xnodeId;
3942
  CowStr  status;
3943
  int32_t configLen;
3944
  int32_t reasonLen;
3945
  int32_t sqlLen;
3946
  char*   config;
3947
  char*   reason;
3948
  char*   sql;
3949
} SMUpdateXnodeJobReq;
3950
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3951
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3952
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3953

3954
typedef struct {
3955
  int32_t jid;
3956
  int32_t xnodeId;
3957
  int32_t sqlLen;
3958
  char*   sql;
3959
} SMRebalanceXnodeJobReq;
3960
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3961
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3962
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3963

3964
typedef struct {
3965
  CowStr  ast;
3966
  int32_t sqlLen;
3967
  char*   sql;
3968
} SMRebalanceXnodeJobsWhereReq;
3969
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3970
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3971
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3972

3973
typedef struct {
3974
  int32_t jid;
3975
  CowStr  ast;
3976
  int32_t sqlLen;
3977
  char*   sql;
3978
} SMDropXnodeJobReq;
3979
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3980
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3981
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3982

3983
typedef struct {
3984
  int32_t      sqlLen;
3985
  char*        sql;
3986
  CowStr       name;
3987
  CowStr       status;
3988
  xTaskOptions options;
3989
} SMCreateXnodeAgentReq;
3990
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3991
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3992
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3993

3994
typedef struct {
3995
  int32_t      sqlLen;
3996
  char*        sql;
3997
  int32_t      id;
3998
  CowStr       name;
3999
  xTaskOptions options;
4000
} SMUpdateXnodeAgentReq;
4001
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4002
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4003
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4004

4005
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4006
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4007
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4008
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4009

4010
typedef struct {
4011
  int32_t vgId;
4012
  int32_t hbSeq;
4013
} SVArbHbReqMember;
4014

4015
typedef struct {
4016
  int32_t dnodeId;
4017
  char*   arbToken;
4018
  int64_t arbTerm;
4019
  SArray* hbMembers;  // SVArbHbReqMember
4020
} SVArbHeartBeatReq;
4021

4022
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4023
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4024
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4025

4026
typedef struct {
4027
  int32_t vgId;
4028
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4029
  int32_t hbSeq;
4030
} SVArbHbRspMember;
4031

4032
typedef struct {
4033
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4034
  int32_t dnodeId;
4035
  SArray* hbMembers;  // SVArbHbRspMember
4036
} SVArbHeartBeatRsp;
4037

4038
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4039
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4040
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4041

4042
typedef struct {
4043
  char*   arbToken;
4044
  int64_t arbTerm;
4045
  char*   member0Token;
4046
  char*   member1Token;
4047
} SVArbCheckSyncReq;
4048

4049
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4050
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4051
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4052

4053
typedef struct {
4054
  char*   arbToken;
4055
  char*   member0Token;
4056
  char*   member1Token;
4057
  int32_t vgId;
4058
  int32_t errCode;
4059
} SVArbCheckSyncRsp;
4060

4061
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4062
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4063
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4064

4065
typedef struct {
4066
  char*   arbToken;
4067
  int64_t arbTerm;
4068
  char*   memberToken;
4069
  int8_t  force;
4070
} SVArbSetAssignedLeaderReq;
4071

4072
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4073
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4074
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4075

4076
typedef struct {
4077
  char* data;
4078
} SVAuditRecordReq;
4079
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4080
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4081
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4082

4083
typedef struct {
4084
  char*   arbToken;
4085
  char*   memberToken;
4086
  int32_t vgId;
4087
} SVArbSetAssignedLeaderRsp;
4088

4089
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4090
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4091
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4092

4093
typedef struct {
4094
  int32_t dnodeId;
4095
  char*   token;
4096
} SMArbUpdateGroupMember;
4097

4098
typedef struct {
4099
  int32_t dnodeId;
4100
  char*   token;
4101
  int8_t  acked;
4102
} SMArbUpdateGroupAssigned;
4103

4104
typedef struct {
4105
  int32_t                  vgId;
4106
  int64_t                  dbUid;
4107
  SMArbUpdateGroupMember   members[2];
4108
  int8_t                   isSync;
4109
  int8_t                   assignedAcked;
4110
  SMArbUpdateGroupAssigned assignedLeader;
4111
  int64_t                  version;
4112
  int32_t                  code;
4113
  int64_t                  updateTimeMs;
4114
} SMArbUpdateGroup;
4115

4116
typedef struct {
4117
  SArray* updateArray;  // SMArbUpdateGroup
4118
} SMArbUpdateGroupBatchReq;
4119

4120
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4121
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4122
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4123

4124
typedef struct {
4125
  char queryStrId[TSDB_QUERY_ID_LEN];
4126
} SKillQueryReq;
4127

4128
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4129
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4130

4131
typedef struct {
4132
  uint32_t connId;
4133
} SKillConnReq;
4134

4135
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4136
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4137

4138
typedef struct {
4139
  int32_t transId;
4140
} SKillTransReq;
4141

4142
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4143
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4144

4145
typedef struct {
4146
  int32_t useless;  // useless
4147
  int32_t sqlLen;
4148
  char*   sql;
4149
} SBalanceVgroupReq;
4150

4151
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4152
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4153
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4154

4155
typedef struct {
4156
  int32_t useless;  // useless
4157
  int32_t sqlLen;
4158
  char*   sql;
4159
} SAssignLeaderReq;
4160

4161
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4162
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4163
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4164
typedef struct {
4165
  int32_t vgId1;
4166
  int32_t vgId2;
4167
} SMergeVgroupReq;
4168

4169
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4170
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4171

4172
typedef struct {
4173
  int32_t vgId;
4174
  int32_t dnodeId1;
4175
  int32_t dnodeId2;
4176
  int32_t dnodeId3;
4177
  int32_t sqlLen;
4178
  char*   sql;
4179
} SRedistributeVgroupReq;
4180

4181
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4182
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4183
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4184

4185
typedef struct {
4186
  int32_t reserved;
4187
  int32_t vgId;
4188
  int32_t sqlLen;
4189
  char*   sql;
4190
  char    db[TSDB_DB_FNAME_LEN];
4191
} SBalanceVgroupLeaderReq;
4192

4193
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4194
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4195
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4196

4197
typedef struct {
4198
  int32_t vgId;
4199
} SForceBecomeFollowerReq;
4200

4201
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4202
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4203

4204
typedef struct {
4205
  int32_t vgId;
4206
  bool    force;
4207
} SSplitVgroupReq;
4208

4209
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4210
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4211

4212
typedef struct {
4213
  char user[TSDB_USER_LEN];
4214
  char spi;
4215
  char encrypt;
4216
  char secret[TSDB_PASSWORD_LEN];
4217
  char ckey[TSDB_PASSWORD_LEN];
4218
} SAuthReq, SAuthRsp;
4219

4220
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4221
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4222

4223
typedef struct {
4224
  int32_t statusCode;
4225
  char    details[1024];
4226
} SServerStatusRsp;
4227

4228
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4229
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4230

4231
/**
4232
 * The layout of the query message payload is as following:
4233
 * +--------------------+---------------------------------+
4234
 * |Sql statement       | Physical plan                   |
4235
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4236
 * +--------------------+---------------------------------+
4237
 */
4238
typedef struct SSubQueryMsg {
4239
  SMsgHead header;
4240
  uint64_t sId;
4241
  uint64_t queryId;
4242
  uint64_t clientId;
4243
  uint64_t taskId;
4244
  int64_t  refId;
4245
  int32_t  execId;
4246
  int32_t  msgMask;
4247
  int32_t  subQType;
4248
  int8_t   taskType;
4249
  int8_t   explain;
4250
  int8_t   needFetch;
4251
  int8_t   compress;
4252
  uint32_t sqlLen;
4253
  char*    sql;
4254
  uint32_t msgLen;
4255
  char*    msg;
4256
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4257
} SSubQueryMsg;
4258

4259
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4260
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4261
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4262

4263
typedef struct {
4264
  SMsgHead header;
4265
  uint64_t sId;
4266
  uint64_t queryId;
4267
  uint64_t taskId;
4268
} SSinkDataReq;
4269

4270
typedef struct {
4271
  SMsgHead header;
4272
  uint64_t sId;
4273
  uint64_t queryId;
4274
  uint64_t clientId;
4275
  uint64_t taskId;
4276
  int32_t  execId;
4277
} SQueryContinueReq;
4278

4279
typedef struct {
4280
  SMsgHead header;
4281
  uint64_t sId;
4282
  uint64_t queryId;
4283
  uint64_t taskId;
4284
} SResReadyReq;
4285

4286
typedef struct {
4287
  int32_t code;
4288
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4289
  int32_t sversion;
4290
  int32_t tversion;
4291
} SResReadyRsp;
4292

4293
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4294

4295
typedef struct SOperatorParam {
4296
  int32_t opType;
4297
  int32_t downstreamIdx;
4298
  void*   value;
4299
  SArray* pChildren;  // SArray<SOperatorParam*>
4300
  bool    reUse;
4301
} SOperatorParam;
4302

4303
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4304

4305
// virtual table's colId to origin table's colname
4306
typedef struct SColIdNameKV {
4307
  col_id_t colId;
4308
  char     colName[TSDB_COL_NAME_LEN];
4309
} SColIdNameKV;
4310

4311
#define COL_MASK_ON   ((int8_t)0x1)
4312
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4313
#define COL_SET_MASK_ON(c)     \
4314
  do {                         \
4315
    (c)->flags |= COL_MASK_ON; \
4316
  } while (0)
4317

4318
typedef struct SColNameFlag {
4319
  col_id_t colId;
4320
  char     colName[TSDB_COL_NAME_LEN];
4321
  int8_t   flags;  // 0x01: COL_MASK_ON
4322
} SColNameFlag;
4323

4324
typedef struct SColIdPair {
4325
  col_id_t  vtbColId;
4326
  col_id_t  orgColId;
4327
  SDataType type;
4328
} SColIdPair;
4329

4330
typedef struct SColIdSlotIdPair {
4331
  int32_t  vtbSlotId;
4332
  col_id_t orgColId;
4333
} SColIdSlotIdPair;
4334

4335
typedef struct SOrgTbInfo {
4336
  int32_t vgId;
4337
  char    tbName[TSDB_TABLE_FNAME_LEN];
4338
  SArray* colMap;  // SArray<SColIdNameKV>
4339
} SOrgTbInfo;
4340

4341
void destroySOrgTbInfo(void *info);
4342

4343
typedef enum {
4344
  DYN_TYPE_STB_JOIN = 1,
4345
  DYN_TYPE_VSTB_SINGLE_SCAN,
4346
  DYN_TYPE_VSTB_BATCH_SCAN,
4347
  DYN_TYPE_VSTB_WIN_SCAN,
4348
} ETableScanDynType;
4349

4350
typedef enum {
4351
  DYN_TYPE_SCAN_PARAM = 1,
4352
  NOTIFY_TYPE_SCAN_PARAM,
4353
} ETableScanGetParamType;
4354

4355
typedef struct STableScanOperatorParam {
4356
  ETableScanGetParamType paramType;
4357
  /* for building scan data source */
4358
  bool                   tableSeq;
4359
  bool                   isNewParam;
4360
  uint64_t               groupid;
4361
  SArray*                pUidList;
4362
  SOrgTbInfo*            pOrgTbInfo;
4363
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4364
  SArray*                pTagList;
4365
  STimeWindow            window;
4366
  ETableScanDynType      dynType;
4367
  /* for notifying source step done */
4368
  bool                   notifyToProcess;  // received notify STEP DONE message
4369
  TSKEY                  notifyTs;         // notify timestamp
4370
} STableScanOperatorParam;
4371

4372
typedef struct STagScanOperatorParam {
4373
  tb_uid_t vcUid;
4374
} STagScanOperatorParam;
4375

4376
typedef struct SRefColIdGroup {
4377
  SArray* pSlotIdList;  // SArray<int32_t>
4378
} SRefColIdGroup;
4379

4380
typedef struct SVTableScanOperatorParam {
4381
  uint64_t        uid;
4382
  STimeWindow     window;
4383
  SOperatorParam* pTagScanOp;
4384
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4385
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4386
} SVTableScanOperatorParam;
4387

4388
typedef struct SMergeOperatorParam {
4389
  int32_t         winNum;
4390
} SMergeOperatorParam;
4391

4392
typedef struct SAggOperatorParam {
4393
  bool            needCleanRes;
4394
} SAggOperatorParam;
4395

4396
typedef struct SExternalWindowOperatorParam {
4397
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4398
} SExternalWindowOperatorParam;
4399

4400
typedef struct SDynQueryCtrlOperatorParam {
4401
  STimeWindow    window;
4402
} SDynQueryCtrlOperatorParam;
4403

4404
struct SStreamRuntimeFuncInfo;
4405
typedef struct {
4406
  SMsgHead        header;
4407
  uint64_t        sId;
4408
  uint64_t        queryId;
4409
  uint64_t        clientId;
4410
  uint64_t        taskId;
4411
  uint64_t        srcTaskId;  // used for subQ
4412
  uint64_t        blockIdx;   // used for subQ
4413
  int32_t         execId;
4414
  SOperatorParam* pOpParam;
4415

4416
  // used for new-stream
4417
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4418
  bool                           reset;
4419
  bool                           dynTbname;
4420
  // used for new-stream
4421
} SResFetchReq;
4422

4423
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4424
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4425
void    tDestroySResFetchReq(SResFetchReq* pReq);
4426
typedef struct {
4427
  SMsgHead header;
4428
  uint64_t clientId;
4429
} SSchTasksStatusReq;
4430

4431
typedef struct {
4432
  uint64_t queryId;
4433
  uint64_t clientId;
4434
  uint64_t taskId;
4435
  int64_t  refId;
4436
  int32_t  subJobId;
4437
  int32_t  execId;
4438
  int8_t   status;
4439
} STaskStatus;
4440

4441
typedef struct {
4442
  int64_t refId;
4443
  SArray* taskStatus;  // SArray<STaskStatus>
4444
} SSchedulerStatusRsp;
4445

4446
typedef struct {
4447
  uint64_t queryId;
4448
  uint64_t taskId;
4449
  int8_t   action;
4450
} STaskAction;
4451

4452
typedef struct SQueryNodeEpId {
4453
  int32_t nodeId;  // vgId or qnodeId
4454
  SEp     ep;
4455
} SQueryNodeEpId;
4456

4457
typedef struct {
4458
  SMsgHead       header;
4459
  uint64_t       clientId;
4460
  SQueryNodeEpId epId;
4461
  SArray*        taskAction;  // SArray<STaskAction>
4462
} SSchedulerHbReq;
4463

4464
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4465
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4466
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4467

4468
typedef struct {
4469
  SQueryNodeEpId epId;
4470
  SArray*        taskStatus;  // SArray<STaskStatus>
4471
} SSchedulerHbRsp;
4472

4473
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4474
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4475
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4476

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

4487
typedef struct {
4488
  int32_t code;
4489
} STaskCancelRsp;
4490

4491
typedef struct {
4492
  SMsgHead header;
4493
  uint64_t sId;
4494
  uint64_t queryId;
4495
  uint64_t clientId;
4496
  uint64_t taskId;
4497
  int64_t  refId;
4498
  int32_t  execId;
4499
} STaskDropReq;
4500

4501
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4502
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4503

4504
typedef enum {
4505
  TASK_NOTIFY_FINISHED = 1,
4506
} ETaskNotifyType;
4507

4508
typedef struct {
4509
  SMsgHead        header;
4510
  uint64_t        sId;
4511
  uint64_t        queryId;
4512
  uint64_t        clientId;
4513
  uint64_t        taskId;
4514
  int64_t         refId;
4515
  int32_t         execId;
4516
  ETaskNotifyType type;
4517
} STaskNotifyReq;
4518

4519
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4520
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4521

4522
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4523
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4524

4525
typedef struct {
4526
  int32_t code;
4527
} STaskDropRsp;
4528

4529
#define STREAM_TRIGGER_AT_ONCE                 1
4530
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4531
#define STREAM_TRIGGER_MAX_DELAY               3
4532
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4533
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4534

4535
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4536
#define STREAM_FILL_HISTORY_ON        1
4537
#define STREAM_FILL_HISTORY_OFF       0
4538
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4539
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4540
#define STREAM_CREATE_STABLE_TRUE     1
4541
#define STREAM_CREATE_STABLE_FALSE    0
4542

4543
typedef struct SVgroupVer {
4544
  int32_t vgId;
4545
  int64_t ver;
4546
} SVgroupVer;
4547

4548
enum {
4549
  TOPIC_SUB_TYPE__DB = 1,
4550
  TOPIC_SUB_TYPE__TABLE,
4551
  TOPIC_SUB_TYPE__COLUMN,
4552
};
4553

4554
#define DEFAULT_MAX_POLL_INTERVAL  300000
4555
#define DEFAULT_SESSION_TIMEOUT    12000
4556
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4557
#define DEFAULT_MIN_POLL_ROWS      4096
4558

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

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

4575
typedef struct {
4576
  int64_t consumerId;
4577
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4578

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

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

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

4604
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
22✔
4605
  tlen += taosEncodeFixedI32(buf, topicNum);
22✔
4606

4607
  for (int32_t i = 0; i < topicNum; i++) {
36✔
4608
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
28✔
4609
  }
4610

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

4622
  return tlen;
22✔
4623
}
4624

4625
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4626
  void* start = buf;
×
4627
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
×
4628
  buf = taosDecodeStringTo(buf, pReq->cgroup);
×
4629
  buf = taosDecodeStringTo(buf, pReq->clientId);
×
4630

4631
  int32_t topicNum = 0;
×
4632
  buf = taosDecodeFixedI32(buf, &topicNum);
×
4633

4634
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
×
4635
  if (pReq->topicNames == NULL) {
×
4636
    return terrno;
×
4637
  }
4638
  for (int32_t i = 0; i < topicNum; i++) {
×
4639
    char* name = NULL;
×
4640
    buf = taosDecodeString(buf, &name);
×
4641
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
×
4642
      return terrno;
×
4643
    }
4644
  }
4645

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

4662
  return 0;
×
4663
}
4664

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

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

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

4699
typedef struct {
4700
  int64_t status;
4701
} SMVSubscribeRsp;
4702

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

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

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

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

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

4733
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4734
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4735

4736
typedef struct {
4737
  int8_t reserved;
4738
} SMDropCgroupRsp;
4739

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

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

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

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

4773
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4774
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4775

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

4795
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4796
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4797

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

4804
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4805
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4806

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

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

4845
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4846
  if (NULL == req) {
6,782✔
4847
    return;
4,385✔
4848
  }
4849

4850
  taosMemoryFreeClear(req->sql);
2,397✔
4851
  taosMemoryFreeClear(req->name);
2,397✔
4852
  taosMemoryFreeClear(req->comment);
2,397✔
4853
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,397✔
4854
    taosMemoryFreeClear(req->ctb.pTag);
2,263✔
4855
    taosMemoryFreeClear(req->ctb.stbName);
2,263✔
4856
    taosArrayDestroy(req->ctb.tagName);
2,263✔
4857
    req->ctb.tagName = NULL;
2,263✔
4858
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
134✔
4859
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
134✔
4860
  }
4861
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
2,397✔
4862
  taosMemoryFreeClear(req->pExtSchemas);
2,397✔
4863
  taosMemoryFreeClear(req->colRef.pColRef);
2,397✔
4864
}
4865

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

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

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

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

4888
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4889
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4890

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

4899
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4900
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4901

4902
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4903
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4904

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

4914
typedef struct {
4915
  int32_t code;
4916
} SVDropTbRsp;
4917

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

4926
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4927
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4928

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

4937
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4938
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4939

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

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

4995
typedef struct {
4996
  int32_t        code;
4997
  STableMetaRsp* pMeta;
4998
} SVAlterTbRsp;
4999

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

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

5018
typedef struct {
5019
  SMsgHead head;
5020
} SUpdateTagValRsp;
5021

5022
typedef struct {
5023
  SMsgHead head;
5024
} SVShowTablesReq;
5025

5026
typedef struct {
5027
  SMsgHead head;
5028
  int32_t  id;
5029
} SVShowTablesFetchReq;
5030

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

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

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

5053
typedef struct {
5054
  int64_t tscRid;
5055
  int8_t  connType;
5056
} SClientHbKey;
5057

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

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

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

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

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

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

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

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

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

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

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

5155
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
2,946✔
5156

5157
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5158
  void* pIter = taosHashIterate(info, NULL);
529✔
5159
  while (pIter != NULL) {
1,292✔
5160
    SKv* kv = (SKv*)pIter;
763✔
5161
    taosMemoryFreeClear(kv->value);
763✔
5162
    pIter = taosHashIterate(info, pIter);
763✔
5163
  }
5164
}
529✔
5165

5166
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
205✔
5167
  SQueryDesc* desc = (SQueryDesc*)pDesc;
205✔
5168
  if (desc->subDesc) {
205✔
5169
    taosArrayDestroy(desc->subDesc);
204✔
5170
    desc->subDesc = NULL;
204✔
5171
  }
5172
}
205✔
5173

5174
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
1,151✔
5175
  SClientHbReq* req = (SClientHbReq*)pReq;
1,430✔
5176
  if (req->query) {
1,430✔
5177
    if (req->query->queryDesc) {
1,149✔
5178
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
343✔
5179
    }
5180
    taosMemoryFreeClear(req->query);
1,149✔
5181
  }
5182

5183
  if (req->info) {
1,430✔
5184
    tFreeReqKvHash(req->info);
529✔
5185
    taosHashCleanup(req->info);
529✔
5186
    req->info = NULL;
529✔
5187
  }
5188
}
281✔
5189

5190
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5191
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5192

5193
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5194
  if (pReq == NULL) return;
698✔
5195
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
698✔
5196
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
698✔
5197
  taosMemoryFree(pReq);
698✔
5198
}
5199

5200
static FORCE_INLINE void tFreeClientKv(void* pKv) {
761✔
5201
  SKv* kv = (SKv*)pKv;
761✔
5202
  if (kv) {
761✔
5203
    taosMemoryFreeClear(kv->value);
761✔
5204
  }
5205
}
761✔
5206

5207
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
1,151✔
5208
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
1,151✔
5209
  if (rsp->query) {
1,151✔
5210
    taosArrayDestroy(rsp->query->pQnodeList);
1,149✔
5211
    taosMemoryFreeClear(rsp->query);
1,149✔
5212
  }
5213
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
1,151✔
5214
}
1,149✔
5215

5216
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5217
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
700✔
5218
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
700✔
5219
}
700✔
5220

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

5225
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5226
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
6,824✔
5227
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
6,824✔
5228
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
6,824✔
5229
  return 0;
3,412✔
5230
}
5231

5232
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5233
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
1,706✔
5234
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
1,706✔
5235
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
853✔
5236
  if (pKv->value == NULL) {
853✔
5237
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5238
  }
5239
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
853✔
5240
  return 0;
853✔
5241
}
5242

5243
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5244
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
10,180✔
5245
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
10,180✔
5246
  return 0;
5,090✔
5247
}
5248

5249
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5250
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
2,548✔
5251
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
2,548✔
5252
  return 0;
1,274✔
5253
}
5254

5255
typedef struct {
5256
  int32_t vgId;
5257
  // TODO stas
5258
} SMqReportVgInfo;
5259

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

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

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

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

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

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

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

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

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

5359
typedef struct {
5360
  int8_t reserved;
5361
} SMqVDeleteRsp;
5362

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

5369
typedef struct {
5370
  int8_t reserved;
5371
} SMDropStreamRsp;
5372

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

5380
typedef struct {
5381
  int8_t reserved;
5382
} SVDropStreamTaskRsp;
5383

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

5388
typedef struct {
5389
  char*  name;
5390
  int8_t igNotExists;
5391
} SMPauseStreamReq;
5392

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

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

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

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

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

5417

5418
typedef struct SVndSetKeepVersionReq {
5419
  int64_t keepVersion;
5420
} SVndSetKeepVersionReq;
5421

5422
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5423
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5424

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

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

5451
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5452
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5453

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

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

5470
#define TQ_OFFSET_VERSION 1
5471

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

5488
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5489
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
×
5490
  pOffsetVal->uid = uid;
×
5491
  pOffsetVal->ts = ts;
×
5492
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
×
5493
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
5494
  }
5495
  pOffsetVal->primaryKey = primaryKey;
×
5496
}
×
5497

5498
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5499
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
×
5500
  pOffsetVal->uid = uid;
×
5501
}
×
5502

5503
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5504
  pOffsetVal->type = TMQ_OFFSET__LOG;
×
5505
  pOffsetVal->version = ver;
×
5506
}
×
5507

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

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

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

5524
typedef struct SMqVgOffset {
5525
  int64_t   consumerId;
5526
  STqOffset offset;
5527
} SMqVgOffset;
5528

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

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

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

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

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

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

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

5607
typedef SMCreateRsmaReq SVCreateRsmaReq;
5608

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

5613
typedef SMCreateRsmaReq SVAlterRsmaReq;
5614

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

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

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

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

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

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

5661
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5662
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5663

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

5672
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5673
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5674

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

5683
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5684
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5685

5686
typedef SMDropSmaReq SDropTagIndexReq;
5687

5688
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5689
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5690

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

5713
typedef STSma SVCreateTSmaReq;
5714

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

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

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

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

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

5742
typedef struct {
5743
  int32_t number;
5744
  STSma*  tSma;
5745
} STSmaWrapper;
5746

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

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

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

5774
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5775
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5776

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

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

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

5796
typedef struct {
5797
  int idx;
5798
} SMCreateFullTextReq;
5799

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

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

5809
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5810
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5811

5812
typedef struct {
5813
  char indexFName[TSDB_INDEX_FNAME_LEN];
5814
} SUserIndexReq;
5815

5816
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5817
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5818

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

5828
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5829
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5830

5831
typedef struct {
5832
  char tbFName[TSDB_TABLE_FNAME_LEN];
5833
} STableIndexReq;
5834

5835
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5836
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5837

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

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

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

5863
void tFreeSTableIndexInfo(void* pInfo);
5864

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

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

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

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

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

5910
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5911
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4✔
5912
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4✔
5913
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4✔
5914
  return buf;
4✔
5915
}
5916

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

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

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

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

5939
#define MQ_DATA_RSP_VERSION 100
5940

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

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

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

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

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

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

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

6001
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6002
  int32_t tlen = 0;
×
6003
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6004
  int32_t sz = taosArrayGetSize(pRsp->topics);
×
6005
  tlen += taosEncodeFixedI32(buf, sz);
×
6006
  for (int32_t i = 0; i < sz; i++) {
×
6007
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
×
6008
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
×
6009
  }
6010
  tlen += taosEncodeFixedI32(buf, pRsp->code);
×
6011

6012
  return tlen;
×
6013
}
6014

6015
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6016
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6017
  int32_t sz;
6018
  buf = taosDecodeFixedI32(buf, &sz);
310✔
6019
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
310✔
6020
  if (pRsp->topics == NULL) {
310✔
6021
    return NULL;
×
6022
  }
6023
  for (int32_t i = 0; i < sz; i++) {
312✔
6024
    SMqSubTopicEp topicEp;
6025
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
2✔
6026
    if (buf == NULL) {
2✔
6027
      return NULL;
×
6028
    }
6029
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
4✔
6030
      return NULL;
×
6031
    }
6032
  }
6033
  buf = taosDecodeFixedI32(buf, &pRsp->code);
310✔
6034

6035
  return buf;
310✔
6036
}
6037

6038
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6039
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
610✔
6040
}
610✔
6041

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

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

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

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

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

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

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

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

6100
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6101
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6102

6103
typedef struct {
6104
  int64_t affectedRows;
6105
} SVDeleteRsp;
6106

6107
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6108
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6109

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

6122
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6123
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6124

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

6132
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6133
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6134

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

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

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

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

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

6166
typedef struct {
6167
  SArray* pRsps;  // SArray<SBatchRspMsg>
6168
} SBatchRsp;
6169

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

6180
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6181
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6182

6183
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
864✔
6184
  if (NULL == p) {
864✔
6185
    return;
×
6186
  }
6187

6188
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
864✔
6189
  taosMemoryFree(pRsp->msg);
864✔
6190
}
6191

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

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

6202
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6203
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6204

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

6216
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6217

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

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

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

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

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

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

6259
#define TSDB_MSG_FLG_ENCODE 0x1
6260
#define TSDB_MSG_FLG_DECODE 0x2
6261
#define TSDB_MSG_FLG_CMPT   0x3
6262

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

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

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

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

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

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

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

6330
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6331
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6332

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

6343
} SRsmaInfoReq;
6344

6345
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6346
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6347

6348
typedef struct {
6349
  int32_t  funcId;
6350
  col_id_t colId;
6351
} STableTSMAFuncInfo;
6352

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

6371
  int64_t streamUid;
6372
  int64_t reqTs;
6373
  int64_t rspTs;
6374
  int64_t delayDuration;  // ms
6375
  bool    fillHistoryFinished;
6376

6377
  void* streamAddr;  // for stream task, the address of the stream task
6378
} STableTSMAInfo;
6379

6380
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6381
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6382
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6383
void    tFreeTableTSMAInfo(void* p);
6384
void    tFreeAndClearTableTSMAInfo(void* p);
6385
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6386

6387
#define STSMAHbRsp            STableTSMAInfoRsp
6388
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6389
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6390
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6391

6392
typedef struct SDropCtbWithTsmaSingleVgReq {
6393
  SVgroupInfo vgInfo;
6394
  SArray*     pTbs;  // SVDropTbReq
6395
} SMDropTbReqsOnSingleVg;
6396

6397
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6398
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6399
void    tFreeSMDropTbReqOnSingleVg(void* p);
6400

6401
typedef struct SDropTbsReq {
6402
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6403
} SMDropTbsReq;
6404

6405
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6406
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6407
void    tFreeSMDropTbsReq(void*);
6408

6409
typedef struct SVFetchTtlExpiredTbsRsp {
6410
  SArray* pExpiredTbs;  // SVDropTbReq
6411
  int32_t vgId;
6412
} SVFetchTtlExpiredTbsRsp;
6413

6414
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6415
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6416

6417
void tFreeFetchTtlExpiredTbsRsp(void* p);
6418

6419
void setDefaultOptionsForField(SFieldWithOptions* field);
6420
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6421

6422
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6423
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6424

6425

6426
typedef struct {
6427
  char    id[TSDB_INSTANCE_ID_LEN];
6428
  char    type[TSDB_INSTANCE_TYPE_LEN];
6429
  char    desc[TSDB_INSTANCE_DESC_LEN];
6430
  int32_t expire;
6431
} SInstanceRegisterReq;
6432

6433
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6434
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6435

6436
typedef struct {
6437
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6438
} SInstanceListReq;
6439

6440
typedef struct {
6441
  int32_t count;
6442
  char**  ids;  // Array of instance IDs
6443
} SInstanceListRsp;
6444

6445
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6446
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6447
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6448
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6449

6450
#ifdef USE_MOUNT
6451
typedef struct {
6452
  char     mountName[TSDB_MOUNT_NAME_LEN];
6453
  int8_t   ignoreExist;
6454
  int16_t  nMounts;
6455
  int32_t* dnodeIds;
6456
  char**   mountPaths;
6457
  int32_t  sqlLen;
6458
  char*    sql;
6459
} SCreateMountReq;
6460

6461
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6462
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6463
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6464

6465
typedef struct {
6466
  char    mountName[TSDB_MOUNT_NAME_LEN];
6467
  int8_t  ignoreNotExists;
6468
  int32_t sqlLen;
6469
  char*   sql;
6470
} SDropMountReq;
6471

6472
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6473
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6474
void    tFreeSDropMountReq(SDropMountReq* pReq);
6475

6476
typedef struct {
6477
  char     mountName[TSDB_MOUNT_NAME_LEN];
6478
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6479
  int64_t  mountUid;
6480
  int32_t  dnodeId;
6481
  uint32_t valLen;
6482
  int8_t   ignoreExist;
6483
  void*    pVal;
6484
} SRetrieveMountPathReq;
6485

6486
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6487
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6488

6489
typedef struct {
6490
  // path
6491
  int32_t diskPrimary;
6492
  // vgInfo
6493
  int32_t  vgId;
6494
  int32_t  cacheLastSize;
6495
  int32_t  szPage;
6496
  int32_t  szCache;
6497
  uint64_t szBuf;
6498
  int8_t   cacheLast;
6499
  int8_t   standby;
6500
  int8_t   hashMethod;
6501
  uint32_t hashBegin;
6502
  uint32_t hashEnd;
6503
  int16_t  hashPrefix;
6504
  int16_t  hashSuffix;
6505
  int16_t  sttTrigger;
6506
  // syncInfo
6507
  int32_t replications;
6508
  // tsdbInfo
6509
  int8_t  precision;
6510
  int8_t  compression;
6511
  int8_t  slLevel;
6512
  int32_t daysPerFile;
6513
  int32_t keep0;
6514
  int32_t keep1;
6515
  int32_t keep2;
6516
  int32_t keepTimeOffset;
6517
  int32_t minRows;
6518
  int32_t maxRows;
6519
  int32_t tsdbPageSize;
6520
  int32_t ssChunkSize;
6521
  int32_t ssKeepLocal;
6522
  int8_t  ssCompact;
6523
  union {
6524
    uint8_t flags;
6525
    struct {
6526
      uint8_t isAudit : 1;
6527
      uint8_t allowDrop : 1;
6528
      uint8_t reserved : 6;
6529
    };
6530
  };
6531
  // walInfo
6532
  int32_t walFsyncPeriod;      // millisecond
6533
  int32_t walRetentionPeriod;  // secs
6534
  int32_t walRollPeriod;       // secs
6535
  int64_t walRetentionSize;
6536
  int64_t walSegSize;
6537
  int32_t walLevel;
6538
  // encryptInfo
6539
  int32_t encryptAlgorithm;
6540
  // SVState
6541
  int64_t committed;
6542
  int64_t commitID;
6543
  int64_t commitTerm;
6544
  // stats
6545
  int64_t numOfSTables;
6546
  int64_t numOfCTables;
6547
  int64_t numOfNTables;
6548
  // dbInfo
6549
  uint64_t dbId;
6550
} SMountVgInfo;
6551

6552
typedef struct {
6553
  SMCreateStbReq req;
6554
  SArray*        pColExts;  // element: column id
6555
  SArray*        pTagExts;  // element: tag id
6556
} SMountStbInfo;
6557

6558
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6559
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6560

6561
typedef struct {
6562
  char     dbName[TSDB_DB_FNAME_LEN];
6563
  uint64_t dbId;
6564
  SArray*  pVgs;   // SMountVgInfo
6565
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6566
} SMountDbInfo;
6567

6568
typedef struct {
6569
  // common fields
6570
  char     mountName[TSDB_MOUNT_NAME_LEN];
6571
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6572
  int8_t   ignoreExist;
6573
  int64_t  mountUid;
6574
  int64_t  clusterId;
6575
  int32_t  dnodeId;
6576
  uint32_t valLen;
6577
  void*    pVal;
6578

6579
  // response fields
6580
  SArray* pDbs;  // SMountDbInfo
6581

6582
  // memory fields, no serialized
6583
  SArray*   pDisks[TFS_MAX_TIERS];
6584
  TdFilePtr pFile;
6585
} SMountInfo;
6586

6587
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6588
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6589
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6590

6591
typedef struct {
6592
  SCreateVnodeReq createReq;
6593
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6594
  char            mountName[TSDB_MOUNT_NAME_LEN];
6595
  int64_t         mountId;
6596
  int32_t         diskPrimary;
6597
  int32_t         mountVgId;
6598
  int64_t         committed;
6599
  int64_t         commitID;
6600
  int64_t         commitTerm;
6601
  int64_t         numOfSTables;
6602
  int64_t         numOfCTables;
6603
  int64_t         numOfNTables;
6604
} SMountVnodeReq;
6605

6606
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6607
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6608
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6609

6610
#endif  // USE_MOUNT
6611

6612
#pragma pack(pop)
6613

6614
typedef struct {
6615
  char        db[TSDB_DB_FNAME_LEN];
6616
  STimeWindow timeRange;
6617
  int32_t     sqlLen;
6618
  char*       sql;
6619
  SArray*     vgroupIds;
6620
} SScanDbReq;
6621

6622
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6623
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6624
void    tFreeSScanDbReq(SScanDbReq* pReq);
6625

6626
typedef struct {
6627
  int32_t scanId;
6628
  int8_t  bAccepted;
6629
} SScanDbRsp;
6630

6631
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6632
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6633

6634
typedef struct {
6635
  int32_t scanId;
6636
  int32_t sqlLen;
6637
  char*   sql;
6638
} SKillScanReq;
6639

6640
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6641
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6642
void    tFreeSKillScanReq(SKillScanReq* pReq);
6643

6644
typedef struct {
6645
  int32_t scanId;
6646
  int32_t vgId;
6647
  int32_t dnodeId;
6648
} SVKillScanReq;
6649

6650
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6651
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6652

6653
typedef struct {
6654
  int32_t scanId;
6655
  int32_t vgId;
6656
  int32_t dnodeId;
6657
  int32_t numberFileset;
6658
  int32_t finished;
6659
  int32_t progress;
6660
  int64_t remainingTime;
6661
} SQueryScanProgressRsp;
6662

6663
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6664
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6665

6666
typedef struct {
6667
  int32_t scanId;
6668
  int32_t vgId;
6669
  int32_t dnodeId;
6670
} SQueryScanProgressReq;
6671

6672
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6673
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6674

6675
typedef struct {
6676
  int64_t     dbUid;
6677
  char        db[TSDB_DB_FNAME_LEN];
6678
  int64_t     scanStartTime;
6679
  STimeWindow tw;
6680
  int32_t     scanId;
6681
} SScanVnodeReq;
6682

6683
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6684
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6685

6686
#ifdef __cplusplus
6687
}
6688
#endif
6689

6690
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6691
 
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