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

taosdata / TDengine / #4994

18 Mar 2026 06:36AM UTC coverage: 72.244%. Remained the same
#4994

push

travis-ci

web-flow
Merge cab2af0c8 into b1e934936

143 of 168 new or added lines in 10 files covered. (85.12%)

1172 existing lines in 10 files now uncovered.

245100 of 339268 relevant lines covered (72.24%)

354029556.59 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

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

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

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

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

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

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

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

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

232
#define TSDB_ALTER_TABLE_ADD_TAG                         1
233
#define TSDB_ALTER_TABLE_DROP_TAG                        2
234
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
235
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4 // deprecated, kept for wire compatibility
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 // deprecated, kept for wire compatibility
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
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL      19 // alter multiple tag values of multi tables
251
#define TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL      20 // alter multiple tag values of the child tables of a stable
252

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

263

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

269

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

275
#define TSDB_ALTER_RSMA_FUNCTION        0x1
276

277
#define TSDB_KILL_MSG_LEN 30
278

279
#define TSDB_TABLE_NUM_UNIT 100000
280

281
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
282
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
283
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
284

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

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

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

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

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

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

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

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

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

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

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

699
typedef struct SField {
700
  char    name[TSDB_COL_NAME_LEN];
701
  uint8_t type;
702
  int8_t  flags;
703
  int32_t bytes;
704
} SField;
705

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

715
typedef struct SRetention {
716
  int64_t freq;
717
  int64_t keep;
718
  int8_t  freqUnit;
719
  int8_t  keepUnit;
720
} SRetention;
721

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

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

731
typedef struct {
732
  int32_t contLen;
733
  int32_t vgId;
734
} SMsgHead;
735

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

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

756
typedef struct {
757
  int32_t totalLen;
758
  int32_t len;
759
  STSRow* row;
760
} SSubmitBlkIter;
761

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

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

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

793
typedef struct {
794
  int32_t  nCols;
795
  int32_t  version;
796
  SColRef* pColRef;
797
} SColRefWrapper;
798

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

806
typedef struct {
807
  int16_t colId;
808
  char    refDbName[TSDB_DB_NAME_LEN];
809
  char    refTableName[TSDB_TABLE_NAME_LEN];
810
  char    refColName[TSDB_COL_NAME_LEN];
811
} SRefColInfo;
812

813
typedef struct SVCTableRefCols {
814
  uint64_t     uid;
815
  int32_t      numOfSrcTbls;
816
  int32_t      numOfColRefs;
817
  SRefColInfo* refCols;
818
} SVCTableRefCols;
819

820
typedef struct SVCTableMergeInfo {
821
  uint64_t uid;
822
  int32_t  numOfSrcTbls;
823
} SVCTableMergeInfo;
824

825
typedef struct {
826
  int32_t    nCols;
827
  SColRefEx* pColRefEx;
828
} SColRefExWrapper;
829

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

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

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

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

894
typedef struct {
895
  int32_t        code;
896
  int64_t        uid;
897
  char*          tblFName;
898
  int32_t        numOfRows;
899
  int32_t        affectedRows;
900
  int64_t        sver;
901
  STableMetaRsp* pMeta;
902
} SSubmitBlkRsp;
903

904
typedef struct {
905
  int32_t numOfRows;
906
  int32_t affectedRows;
907
  int32_t nBlocks;
908
  union {
909
    SArray*        pArray;
910
    SSubmitBlkRsp* pBlocks;
911
  };
912
} SSubmitRsp;
913

914
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
915
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
916
// void    tFreeSSubmitBlkRsp(void* param);
917
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
918

919
#define COL_SMA_ON       ((int8_t)0x1)
920
#define COL_IDX_ON       ((int8_t)0x2)
921
#define COL_IS_KEY       ((int8_t)0x4)
922
#define COL_SET_NULL     ((int8_t)0x10)
923
#define COL_SET_VAL      ((int8_t)0x20)
924
#define COL_IS_SYSINFO   ((int8_t)0x40)
925
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
926
#define COL_REF_BY_STM   ((int8_t)0x08)
927

928
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
929
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
930

931
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
932
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
933
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
934

935
#define SSCHMEA_SET_IDX_ON(s) \
936
  do {                        \
937
    (s)->flags |= COL_IDX_ON; \
938
  } while (0)
939

940
#define SSCHMEA_SET_IDX_OFF(s)   \
941
  do {                           \
942
    (s)->flags &= (~COL_IDX_ON); \
943
  } while (0)
944

945
#define SSCHEMA_SET_TYPE_MOD(s)     \
946
  do {                              \
947
    (s)->flags |= COL_HAS_TYPE_MOD; \
948
  } while (0)
949

950
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
951

952
#define SSCHMEA_TYPE(s)  ((s)->type)
953
#define SSCHMEA_FLAGS(s) ((s)->flags)
954
#define SSCHMEA_COLID(s) ((s)->colId)
955
#define SSCHMEA_BYTES(s) ((s)->bytes)
956
#define SSCHMEA_NAME(s)  ((s)->name)
957

958
typedef struct {
959
  bool    tsEnableMonitor;
960
  int32_t tsMonitorInterval;
961
  int32_t tsSlowLogThreshold;
962
  int32_t tsSlowLogMaxLen;
963
  int32_t tsSlowLogScope;
964
  int32_t tsSlowLogThresholdTest;  // Obsolete
965
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
966
} SMonitorParas;
967

968
typedef struct {
969
  STypeMod typeMod;
970
} SExtSchema;
971

972
bool hasExtSchema(const SExtSchema* pExtSchema);
973

974
typedef struct {
975
  int32_t      nCols;
976
  int32_t      version;
977
  SSchema*     pSchema;
978
  SSchemaRsma* pRsma;
979
} SSchemaWrapper;
980

981
typedef struct {
982
  col_id_t id;
983
  uint32_t alg;
984
} SColCmpr;
985

986
typedef struct {
987
  int32_t   nCols;
988
  int32_t   version;
989
  SColCmpr* pColCmpr;
990
} SColCmprWrapper;
9,380,803✔
UNCOV
991

×
992
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
993
  if (pRef->pColRef) {
9,380,803✔
994
    return TSDB_CODE_INVALID_PARA;
9,380,803✔
UNCOV
995
  }
×
996
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
997
  if (pRef->pColRef == NULL) {
9,380,803✔
998
    return terrno;
2,147,483,647✔
999
  }
2,147,483,647✔
1000
  pRef->nCols = nCols;
2,147,483,647✔
1001
  for (int32_t i = 0; i < nCols; i++) {
1002
    pRef->pColRef[i].hasRef = false;
9,380,803✔
1003
    pRef->pColRef[i].id = (col_id_t)(i + 1);
1004
  }
1005
  return 0;
1006
}
1007

1008
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1009
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1010
    terrno = TSDB_CODE_INVALID_PARA;
1011
    return NULL;
1012
  }
1013

1014
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1015
  if (pDstWrapper == NULL) {
1016
    return NULL;
1017
  }
1018
  pDstWrapper->nCols = pSrcWrapper->nCols;
1019
  pDstWrapper->version = pSrcWrapper->version;
1020

1021
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1022
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1023
  if (pDstWrapper->pColCmpr == NULL) {
1024
    taosMemoryFree(pDstWrapper);
1025
    return NULL;
1026
  }
1027
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1028

1029
  return pDstWrapper;
1030
}
162,322,454✔
UNCOV
1031

×
1032
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1033
  if (!(!pCmpr->pColCmpr)) {
162,322,454✔
1034
    return TSDB_CODE_INVALID_PARA;
162,322,454✔
UNCOV
1035
  }
×
1036
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
1037
  if (pCmpr->pColCmpr == NULL) {
162,322,454✔
1038
    return terrno;
162,322,454✔
1039
  }
1040
  pCmpr->nCols = nCols;
1041
  return 0;
1042
}
1043

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

1062
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1063
  if (pWrapper == NULL) return;
1064

1065
  taosMemoryFreeClear(pWrapper->pColCmpr);
1066
  taosMemoryFreeClear(pWrapper);
2,147,483,647✔
1067
}
1068
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
2,147,483,647✔
1069
  if (pSchemaWrapper->pSchema == NULL) return NULL;
2,147,483,647✔
UNCOV
1070

×
1071
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
1072
  if (pSW == NULL) {
2,147,483,647✔
1073
    return NULL;
2,147,483,647✔
1074
  }
2,147,483,647✔
1075
  pSW->nCols = pSchemaWrapper->nCols;
2,147,483,647✔
1076
  pSW->version = pSchemaWrapper->version;
×
UNCOV
1077
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
×
1078
  if (pSW->pSchema == NULL) {
1079
    taosMemoryFree(pSW);
1080
    return NULL;
2,147,483,647✔
1081
  }
2,147,483,647✔
1082

1083
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
1084
  return pSW;
2,147,483,647✔
1085
}
2,147,483,647✔
1086

2,147,483,647✔
1087
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
2,147,483,647✔
1088
  if (pSchemaWrapper) {
637,399✔
1089
    taosMemoryFree(pSchemaWrapper->pSchema);
637,399✔
1090
    if (pSchemaWrapper->pRsma) {
1091
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
2,147,483,647✔
1092
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1093
    }
2,147,483,647✔
1094
    taosMemoryFree(pSchemaWrapper);
1095
  }
1096
}
1097

1098
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1099
  if (pSchemaWrapper) {
1100
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1101
    if (pSchemaWrapper->pRsma) {
1102
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1103
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1104
    }
1105
  }
204,233,008✔
1106
}
204,233,008✔
1107

204,233,307✔
1108
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1109
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
204,178,038✔
1110
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
1111
  }
1112
}
63,711,932✔
1113

63,764,648✔
1114
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
63,711,932✔
1115
  int32_t tlen = 0;
63,711,932✔
1116
  tlen += taosEncodeFixedI8(buf, pSchema->type);
63,711,932✔
1117
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
63,711,932✔
1118
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
63,711,932✔
1119
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
1120
  tlen += taosEncodeString(buf, pSchema->name);
1121
  return tlen;
1122
}
28,827,855✔
1123

28,816,539✔
1124
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
28,816,539✔
1125
  buf = taosDecodeFixedI8(buf, &pSchema->type);
28,816,539✔
1126
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
28,816,539✔
1127
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
28,816,539✔
1128
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1129
  buf = taosDecodeStringTo(buf, pSchema->name);
1130
  return (void*)buf;
1131
}
2,147,483,647✔
1132

2,147,483,647✔
1133
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
2,147,483,647✔
1134
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1135
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1136
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1137
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
1138
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
1139
  return 0;
1140
}
2,147,483,647✔
1141

2,147,483,647✔
1142
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
2,147,483,647✔
1143
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1144
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1145
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1146
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1147
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
1148
  return 0;
1149
}
2,147,483,647✔
1150

2,147,483,647✔
1151
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
2,147,483,647✔
1152
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1153
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
1154
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
1155
  return 0;
1156
}
2,147,483,647✔
1157

2,147,483,647✔
1158
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
2,147,483,647✔
1159
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1160
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
1161
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
1162
  return 0;
1163
}
2,147,483,647✔
1164

2,147,483,647✔
1165
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
2,147,483,647✔
1166
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
2,147,483,647✔
1167
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
2,147,483,647✔
1168
  if (pColRef->hasRef) {
2,147,483,647✔
1169
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
1170
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
2,147,483,647✔
1171
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
1172
  }
1173
  return 0;
1174
}
2,147,483,647✔
1175

2,147,483,647✔
1176
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
2,147,483,647✔
1177
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
2,147,483,647✔
1178
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
2,147,483,647✔
1179
  if (pColRef->hasRef) {
2,147,483,647✔
1180
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
1181
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
1182
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
2,147,483,647✔
1183
  }
1184

1185
  return 0;
1186
}
10,617,122✔
1187

10,617,122✔
1188
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
10,617,122✔
1189
  int32_t tlen = 0;
74,329,054✔
1190
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
127,423,864✔
1191
  tlen += taosEncodeVariantI32(buf, pSW->version);
1192
  for (int32_t i = 0; i < pSW->nCols; i++) {
10,617,122✔
1193
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
1194
  }
1195
  return tlen;
1196
}
4,619,757✔
1197

4,619,757✔
1198
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
4,619,757✔
1199
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
4,619,757✔
1200
  buf = taosDecodeVariantI32(buf, &pSW->version);
4,619,757✔
UNCOV
1201
  if (pSW->nCols > 0) {
×
1202
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1203
    if (pSW->pSchema == NULL) {
1204
      return NULL;
33,436,296✔
1205
    }
57,633,078✔
1206

1207
    for (int32_t i = 0; i < pSW->nCols; i++) {
UNCOV
1208
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
×
1209
    }
1210
  } else {
4,619,757✔
1211
    pSW->pSchema = NULL;
1212
  }
1213
  return (void*)buf;
1214
}
2,147,483,647✔
UNCOV
1215

×
1216
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1217
  if (pSW == NULL) {
2,147,483,647✔
1218
    return TSDB_CODE_INVALID_PARA;
2,147,483,647✔
1219
  }
2,147,483,647✔
1220
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
2,147,483,647✔
1221
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1222
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1223
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
1224
  }
1225
  return 0;
1226
}
2,147,483,647✔
UNCOV
1227

×
1228
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1229
  if (pSW == NULL) {
2,147,483,647✔
1230
    return TSDB_CODE_INVALID_PARA;
2,147,483,647✔
1231
  }
1232
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1233
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
UNCOV
1234

×
1235
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1236
  if (pSW->pSchema == NULL) {
2,147,483,647✔
1237
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
2,147,483,647✔
1238
  }
1239
  for (int32_t i = 0; i < pSW->nCols; i++) {
1240
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1241
  }
1242

1243
  return 0;
1244
}
2,147,483,647✔
1245

2,147,483,647✔
1246
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1247
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1248
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
UNCOV
1249

×
1250
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
1251
  if (pSW->pSchema == NULL) {
2,147,483,647✔
1252
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
2,147,483,647✔
1253
  }
1254
  for (int32_t i = 0; i < pSW->nCols; i++) {
1255
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1256
  }
1257

1258
  return 0;
1259
}
1260

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

1295
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1296
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1297
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1298

1299
typedef struct {
1300
  STableMetaRsp* pMeta;
1301
} SMCreateStbRsp;
1302

1303
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1304
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1305
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1306

1307
typedef struct {
1308
  char     name[TSDB_TABLE_FNAME_LEN];
1309
  int8_t   igNotExists;
1310
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1311
  int8_t   reserved[6];
1312
  tb_uid_t suid;
1313
  int32_t  sqlLen;
1314
  char*    sql;
1315
} SMDropStbReq;
1316

1317
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1318
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1319
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1320

1321
typedef struct {
1322
  char    name[TSDB_TABLE_FNAME_LEN];
1323
  int8_t  alterType;
1324
  int32_t numOfFields;
1325
  SArray* pFields;
1326
  int32_t ttl;
1327
  int32_t commentLen;
1328
  char*   comment;
1329
  int32_t sqlLen;
1330
  char*   sql;
1331
  int64_t keep;
1332
  SArray* pTypeMods;
1333
  int8_t  secureDelete;
1334
} SMAlterStbReq;
1335

1336
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1337
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1338
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1339

1340
typedef struct SEpSet {
1341
  int8_t inUse;
1342
  int8_t numOfEps;
1343
  SEp    eps[TSDB_MAX_REPLICA];
1344
} SEpSet;
1345

1346
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1347
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1348
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1349
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1350

1351
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1352
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1353

1354
typedef struct {
1355
  int8_t  connType;
1356
  int32_t pid;
1357
  int32_t totpCode;
1358
  char    app[TSDB_APP_NAME_LEN];
1359
  char    db[TSDB_DB_NAME_LEN];
1360
  char    user[TSDB_USER_LEN];
1361
  char    passwd[TSDB_PASSWORD_LEN];
1362
  char    token[TSDB_TOKEN_LEN];
1363
  int64_t startTime;
1364
  int64_t connectTime;
1365
  char    sVer[TSDB_VERSION_LEN];
1366
  char    signature[20]; // SHA1 produces a 20-byte signature
1367
} SConnectReq;
1368

1369
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1370
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1371
void    tSignConnectReq(SConnectReq* pReq);
1372
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1373

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

1400
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1401
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1402

1403
typedef struct {
1404
  char    user[TSDB_USER_LEN];
1405
  char    pass[TSDB_PASSWORD_LEN];
1406
  int32_t maxUsers;
1407
  int32_t maxDbs;
1408
  int32_t maxTimeSeries;
1409
  int32_t maxStreams;
1410
  int32_t accessState;  // Configured only by command
1411
  int64_t maxStorage;
1412
} SCreateAcctReq, SAlterAcctReq;
1413

1414
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1415
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1416

1417
typedef struct {
1418
  char    user[TSDB_USER_LEN];
1419
  int8_t  ignoreNotExists;
1420
  int32_t sqlLen;
1421
  char*   sql;
1422
} SDropUserReq, SDropAcctReq;
1423

1424
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1425
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1426
void    tFreeSDropUserReq(SDropUserReq* pReq);
1427

1428
typedef struct {
1429
  char name[TSDB_ROLE_LEN];
1430
  union {
1431
    uint8_t flag;
1432
    struct {
1433
      uint8_t ignoreExists : 1;
1434
      uint8_t reserve : 7;
1435
    };
1436
  };
1437
  int32_t sqlLen;
1438
  char*   sql;
1439
} SCreateRoleReq;
1440

1441
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1442
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1443
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1444

1445
typedef struct {
1446
  char name[TSDB_ROLE_LEN];
1447
  union {
1448
    uint8_t flag;
1449
    struct {
1450
      uint8_t ignoreNotExists : 1;
1451
      uint8_t reserve : 7;
1452
    };
1453
  };
1454
  int32_t sqlLen;
1455
  char*   sql;
1456
} SDropRoleReq;
1457

1458
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1459
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1460
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1461

1462
typedef struct {
1463
  SPrivSet privSet;
1464
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1465
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1466
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1467
  // delete can only specify conditions by cond and cannot specify columns
1468
  char*    cond;     // for table privileges
1469
  int32_t  condLen;  // for table privileges
1470
} SPrivSetReqArgs;
1471

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

1497
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1498
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1499
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1500

1501
typedef struct {
1502
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1503
  int32_t sqlLen;
1504
  char*   sql;
1505
} SDropEncryptAlgrReq;
1506

1507
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1508
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1509
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1510

1511
typedef struct SIpV4Range {
1512
  uint32_t ip;
1513
  uint32_t mask;
1514
} SIpV4Range;
1515

1516
typedef struct SIpv6Range {
1517
  uint64_t addr[2];
1518
  uint32_t mask;
1519
} SIpV6Range;
1520

1521
typedef struct {
1522
  int8_t type;   // 0: IPv4, 1: IPv6
1523
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1524
  union {
1525
    SIpV4Range ipV4;
1526
    SIpV6Range ipV6;
1527
  };
1528
} SIpRange;
1529

1530
typedef struct {
1531
  int32_t    num;
1532
  SIpV4Range pIpRange[];
1533
} SIpWhiteList;
1534

1535
typedef struct {
1536
  int32_t  num;
1537
  SIpRange pIpRanges[];
1538
} SIpWhiteListDual;
1539

1540
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1541
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1542
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1543
int32_t           createDefaultIp6Range(SIpRange* pRange);
1544
int32_t           createDefaultIp4Range(SIpRange* pRange);
1545

1546
typedef struct {
1547
  int32_t sessPerUser;
1548
  int32_t sessConnTime;
1549
  int32_t sessConnIdleTime;
1550
  int32_t sessMaxConcurrency;
1551
  int32_t sessMaxCallVnodeNum;
1552
} SUserSessCfg;
1553

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

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

1570
bool isValidDateTimeRange(SDateTimeRange* pRange);
1571
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1572
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1573

1574
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1575
typedef struct {
1576
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1577
  bool neg;         // this is a negative entry
1578
  int32_t duration; // duration in seconds
1579
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1580
} SDateTimeWhiteListItem;
1581

1582
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1583
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1584

1585
typedef struct {
1586
  int32_t num;
1587
  SDateTimeWhiteListItem ranges[];
1588
} SDateTimeWhiteList;
1589

1590
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1591
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1592

1593

1594
typedef struct {
1595
  int8_t createType;
1596

1597
  int8_t hasSessionPerUser;
1598
  int8_t hasConnectTime;
1599
  int8_t hasConnectIdleTime;
1600
  int8_t hasCallPerSession;
1601
  int8_t hasVnodePerCall;
1602
  int8_t hasFailedLoginAttempts;
1603
  int8_t hasPasswordLifeTime;
1604
  int8_t hasPasswordReuseTime;
1605
  int8_t hasPasswordReuseMax;
1606
  int8_t hasPasswordLockTime;
1607
  int8_t hasPasswordGraceTime;
1608
  int8_t hasInactiveAccountTime;
1609
  int8_t hasAllowTokenNum;
1610

1611
  int8_t superUser;  // denote if it is a super user or not
1612
  int8_t ignoreExists;
1613

1614
  char   user[TSDB_USER_LEN];
1615
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1616
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1617

1618
  int8_t sysInfo;
1619
  int8_t createDb;
1620
  int8_t isImport;
1621
  int8_t changepass;
1622
  int8_t enable;
1623

1624
  int8_t negIpRanges;
1625
  int8_t negTimeRanges;
1626

1627
  int32_t sessionPerUser;
1628
  int32_t connectTime;
1629
  int32_t connectIdleTime;
1630
  int32_t callPerSession;
1631
  int32_t vnodePerCall;
1632
  int32_t failedLoginAttempts;
1633
  int32_t passwordLifeTime;
1634
  int32_t passwordReuseTime;
1635
  int32_t passwordReuseMax;
1636
  int32_t passwordLockTime;
1637
  int32_t passwordGraceTime;
1638
  int32_t inactiveAccountTime;
1639
  int32_t allowTokenNum;
1640

1641
  int32_t         numIpRanges;
1642
  SIpRange*       pIpDualRanges;
1643
  int32_t         numTimeRanges;
1644
  SDateTimeRange* pTimeRanges;
1645

1646
  int32_t sqlLen;
1647
  char*   sql;
1648
} SCreateUserReq;
1649

1650
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1651
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1652
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1653

1654
typedef struct {
1655
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1656
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1657
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1658
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1659
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1660
  int32_t sqlLen;
1661
  char*   sql;
1662
} SCreateEncryptAlgrReq;
1663

1664
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1665
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1666
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1667

1668
typedef struct {
1669
  int32_t dnodeId;
1670
  int64_t analVer;
1671
} SRetrieveAnalyticsAlgoReq;
1672

1673
typedef struct {
1674
  int64_t   ver;
1675
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1676
} SRetrieveAnalyticAlgoRsp;
1677

1678
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1679
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1680
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1681
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1682
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1683

1684
typedef struct {
1685
  int8_t alterType;
1686

1687
  int8_t isView;
1688

1689
  int8_t hasPassword;
1690
  int8_t hasTotpseed;
1691
  int8_t hasEnable;
1692
  int8_t hasSysinfo;
1693
  int8_t hasCreatedb;
1694
  int8_t hasChangepass;
1695
  int8_t hasSessionPerUser;
1696
  int8_t hasConnectTime;
1697
  int8_t hasConnectIdleTime;
1698
  int8_t hasCallPerSession;
1699
  int8_t hasVnodePerCall;
1700
  int8_t hasFailedLoginAttempts;
1701
  int8_t hasPasswordLifeTime;
1702
  int8_t hasPasswordReuseTime;
1703
  int8_t hasPasswordReuseMax;
1704
  int8_t hasPasswordLockTime;
1705
  int8_t hasPasswordGraceTime;
1706
  int8_t hasInactiveAccountTime;
1707
  int8_t hasAllowTokenNum;
1708

1709
  int8_t enable;
1710
  int8_t sysinfo;
1711
  int8_t createdb;
1712
  int8_t changepass;
1713

1714
  char   user[TSDB_USER_LEN];
1715
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1716
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1717
  int32_t sessionPerUser;
1718
  int32_t connectTime;
1719
  int32_t connectIdleTime;
1720
  int32_t callPerSession;
1721
  int32_t vnodePerCall;
1722
  int32_t failedLoginAttempts;
1723
  int32_t passwordLifeTime;
1724
  int32_t passwordReuseTime;
1725
  int32_t passwordReuseMax;
1726
  int32_t passwordLockTime;
1727
  int32_t passwordGraceTime;
1728
  int32_t inactiveAccountTime;
1729
  int32_t allowTokenNum;
1730

1731
  int32_t         numIpRanges;
1732
  int32_t         numTimeRanges;
1733
  int32_t         numDropIpRanges;
1734
  int32_t         numDropTimeRanges;
1735
  SIpRange*       pIpRanges;
1736
  SDateTimeRange* pTimeRanges;
1737
  SIpRange*       pDropIpRanges;
1738
  SDateTimeRange* pDropTimeRanges;
1739
  SPrivSet        privileges;
1740

1741
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1742
  char        tabName[TSDB_TABLE_NAME_LEN];
1743
  char*       tagCond;
1744
  int32_t     tagCondLen;
1745
  int32_t     sqlLen;
1746
  char*       sql;
1747
} SAlterUserReq;
1748

1749
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1750
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1751
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1752

1753
typedef struct {
1754
  char    name[TSDB_TOKEN_NAME_LEN];
1755
  char    user[TSDB_USER_LEN];
1756
  int8_t  enable;
1757
  int8_t  ignoreExists;
1758
  int32_t ttl;
1759
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1760
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1761

1762
  int32_t sqlLen;
1763
  char*   sql;
1764
} SCreateTokenReq;
1765

1766
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1767
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1768
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1769

1770
typedef struct {
1771
  char name[TSDB_TOKEN_NAME_LEN];
1772
  char user[TSDB_USER_LEN];
1773
  char token[TSDB_TOKEN_LEN];
1774
} SCreateTokenRsp;
1775

1776
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1777
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1778
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1779

1780
typedef struct {
1781
  char    name[TSDB_TOKEN_NAME_LEN];
1782

1783
  int8_t hasEnable;
1784
  int8_t hasTtl;
1785
  int8_t hasProvider;
1786
  int8_t hasExtraInfo;
1787

1788
  int8_t  enable;
1789
  int32_t ttl;
1790
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1791
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1792

1793
  int32_t     sqlLen;
1794
  char*       sql;
1795
} SAlterTokenReq;
1796

1797
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1798
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1799
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1800

1801
typedef struct {
1802
  char    name[TSDB_TOKEN_NAME_LEN];
1803
  int8_t  ignoreNotExists;
1804
  int32_t sqlLen;
1805
  char*   sql;
1806
} SDropTokenReq;
1807

1808
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1809
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1810
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1811

1812
typedef struct {
1813
  char    user[TSDB_USER_LEN];
1814
  int32_t sqlLen;
1815
  char*   sql;
1816
} SCreateTotpSecretReq;
1817

1818
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1819
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1820
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1821

1822
typedef struct {
1823
  char user[TSDB_USER_LEN];
1824
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1825
} SCreateTotpSecretRsp;
1826

1827
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1828
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1829

1830
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1831
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1832
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1833
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1834

1835
typedef struct {
1836
  char user[TSDB_USER_LEN];
1837
} SGetUserAuthReq;
1838

1839
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1840
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1841

1842
typedef struct {
1843
  int8_t  enabled;
1844
  int32_t expireTime;
1845
} STokenStatus;
1846

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

1872
  SUserSessCfg sessCfg;
1873
  int64_t      timeWhiteListVer;
1874
  SHashObj*    tokens;
1875
} SGetUserAuthRsp;
1876

1877
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1878
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1879
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1880

1881
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1882
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1883
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1884
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1885

1886
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1887
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1888
typedef struct {
1889
  int64_t ver;
1890
  char    user[TSDB_USER_LEN];
1891
  int32_t numOfRange;
1892
  union {
1893
    SIpV4Range* pIpRanges;
1894
    SIpRange*   pIpDualRanges;
1895
  };
1896
} SUpdateUserIpWhite;
1897

1898
typedef struct {
1899
  int64_t             ver;
1900
  int                 numOfUser;
1901
  SUpdateUserIpWhite* pUserIpWhite;
1902
} SUpdateIpWhite;
1903

1904
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1905
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1906
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1907
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1908

1909
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1910
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1911
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1912

1913

1914
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1915
// corresponding response struct is different.
1916
typedef struct {
1917
  int64_t ver;
1918
} SRetrieveWhiteListReq;
1919

1920
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1921
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1922

1923

1924
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1925
// corresponding response struct is different.
1926
typedef struct {
1927
  char user[TSDB_USER_LEN];
1928
} SGetUserWhiteListReq;
1929

1930
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1931
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1932

1933
typedef struct {
1934
  char    user[TSDB_USER_LEN];
1935
  int32_t numWhiteLists;
1936
  union {
1937
    SIpV4Range* pWhiteLists;
1938
    SIpRange*   pWhiteListsDual;
1939
  };
1940
} SGetUserIpWhiteListRsp;
1941

1942
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1943
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1944
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1945
void    tIpRangeSetDefaultMask(SIpRange* range);
1946

1947
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1948
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1949
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1950

1951
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1952
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1953
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1954

1955
typedef struct {
1956
  int64_t ver;
1957
  char    user[TSDB_USER_LEN];
1958
  int32_t numWhiteLists;
1959
  SDateTimeWhiteListItem* pWhiteLists;
1960
} SUserDateTimeWhiteList;
1961

1962

1963
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1964
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1965
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1966
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1967

1968
typedef struct {
1969
  int64_t             ver;
1970
  int                 numOfUser;
1971
  SUserDateTimeWhiteList *pUsers;
1972
} SRetrieveDateTimeWhiteListRsp;
1973

1974
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1975
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1976
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1977
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1978

1979
/*
1980
 * for client side struct, only column id, type, bytes are necessary
1981
 * But for data in vnode side, we need all the following information.
1982
 */
1983
typedef struct {
1984
  union {
1985
    col_id_t colId;
1986
    int16_t  slotId;
1987
  };
1988

1989
  uint8_t precision;
1990
  uint8_t scale;
1991
  int32_t bytes;
1992
  int8_t  type;
1993
  uint8_t pk;
1994
  bool    noData;
1995
} SColumnInfo;
1996

1997
typedef struct STimeWindow {
1998
  TSKEY skey;
1999
  TSKEY ekey;
2000
} STimeWindow;
2001

2002
typedef struct SQueryHint {
2003
  bool batchScan;
2004
} SQueryHint;
2005

2006
typedef struct {
2007
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2008
  int32_t tsLen;          // total length of ts comp block
2009
  int32_t tsNumOfBlocks;  // ts comp block numbers
2010
  int32_t tsOrder;        // ts comp block order
2011
} STsBufInfo;
2012

2013
typedef struct {
2014
  void*       timezone;
2015
  char        intervalUnit;
2016
  char        slidingUnit;
2017
  char        offsetUnit;
2018
  int8_t      precision;
2019
  int64_t     interval;
2020
  int64_t     sliding;
2021
  int64_t     offset;
2022
  STimeWindow timeRange;
2023
} SInterval;
2024

2025
typedef struct STbVerInfo {
2026
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2027
  int32_t sversion;
2028
  int32_t tversion;
2029
  int32_t rversion;  // virtual table's column ref's version
2030
} STbVerInfo;
2031

2032
typedef struct {
2033
  int32_t code;
2034
  int64_t affectedRows;
2035
  SArray* tbVerInfo;  // STbVerInfo
2036
} SQueryTableRsp;
2037

2038
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2039

2040
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2041

2042
typedef struct {
2043
  SMsgHead header;
2044
  char     dbFName[TSDB_DB_FNAME_LEN];
2045
  char     tbName[TSDB_TABLE_NAME_LEN];
2046
} STableCfgReq;
2047

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

2081
typedef STableCfg STableCfgRsp;
2082

2083
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2084
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2085

2086
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2087
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2088
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2089

2090
typedef struct {
2091
  SMsgHead header;
2092
  tb_uid_t suid;
2093
} SVSubTablesReq;
2094

2095
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2096
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2097

2098
typedef struct {
2099
  int32_t vgId;
2100
  SArray* pTables;  // SArray<SVCTableRefCols*>
2101
} SVSubTablesRsp;
2102

2103
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2104
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2105
void    tDestroySVSubTablesRsp(void* rsp);
2106

2107
typedef struct {
2108
  SMsgHead header;
2109
  tb_uid_t suid;
2110
} SVStbRefDbsReq;
2111

2112
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2113
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2114

2115
typedef struct {
2116
  int32_t vgId;
2117
  SArray* pDbs;  // SArray<char* (db name)>
2118
} SVStbRefDbsRsp;
2119

2120
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2121
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2122
void    tDestroySVStbRefDbsRsp(void* rsp);
2123

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

2177
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2178
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2179
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2180

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

2217
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2218
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2219
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2220

2221
typedef struct {
2222
  char    db[TSDB_DB_FNAME_LEN];
2223
  int8_t  ignoreNotExists;
2224
  int8_t  force;
2225
  int32_t sqlLen;
2226
  char*   sql;
2227
} SDropDbReq;
2228

2229
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2230
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2231
void    tFreeSDropDbReq(SDropDbReq* pReq);
2232

2233
typedef struct {
2234
  char    db[TSDB_DB_FNAME_LEN];
2235
  int64_t uid;
2236
} SDropDbRsp;
2237

2238
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2239
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2240

2241
typedef struct {
2242
  char    name[TSDB_MOUNT_NAME_LEN];
2243
  int64_t uid;
2244
} SDropMountRsp;
2245

2246
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2247
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2248

2249
typedef struct {
2250
  char    db[TSDB_DB_FNAME_LEN];
2251
  int64_t dbId;
2252
  int32_t vgVersion;
2253
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2254
  int64_t stateTs;     // ms
2255
} SUseDbReq;
2256

2257
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2258
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2259

2260
typedef struct {
2261
  char    db[TSDB_DB_FNAME_LEN];
2262
  int64_t uid;
2263
  int32_t vgVersion;
2264
  int32_t vgNum;
2265
  int16_t hashPrefix;
2266
  int16_t hashSuffix;
2267
  int8_t  hashMethod;
2268
  union {
2269
    uint8_t flags;
2270
    struct {
2271
      uint8_t isMount : 1;  // TS-5868
2272
      uint8_t padding : 7;
2273
    };
2274
  };
2275
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2276
  int32_t errCode;
2277
  int64_t stateTs;  // ms
2278
} SUseDbRsp;
2279

2280
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2281
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2282
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2283
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2284
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2285

2286
typedef struct {
2287
  char db[TSDB_DB_FNAME_LEN];
2288
} SDbCfgReq;
2289

2290
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2291
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2292

2293
typedef struct {
2294
  char db[TSDB_DB_FNAME_LEN];
2295
} SSsMigrateDbReq;
2296

2297
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2298
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2299

2300
typedef struct {
2301
  int32_t ssMigrateId;
2302
  bool    bAccepted;
2303
} SSsMigrateDbRsp;
2304

2305
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2306
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2307

2308
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2309
typedef struct {
2310
  int32_t ssMigrateId;
2311
} SListSsMigrateFileSetsReq;
2312

2313
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2314
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2315

2316
typedef struct {
2317
  int32_t ssMigrateId;
2318
  int32_t vgId;       // vgroup id
2319
  SArray* pFileSets;  // SArray<int32_t>
2320
} SListSsMigrateFileSetsRsp;
2321

2322
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2323
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2324
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2325

2326
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2327
typedef struct {
2328
  int32_t ssMigrateId;
2329
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2330
  int32_t fid;
2331
  int64_t startTimeSec;
2332
} SSsMigrateFileSetReq;
2333

2334
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2335
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2336

2337
typedef struct {
2338
  int32_t ssMigrateId;
2339
  int32_t nodeId;  // node id of the leader vnode
2340
  int32_t vgId;
2341
  int32_t fid;
2342
} SSsMigrateFileSetRsp;
2343

2344
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2345
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2346

2347
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2348
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2349
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2350
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2351
#define SSMIGRATE_FILESET_STATE_FAILED      4
2352

2353
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2354
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2355
// while as a request, the 'state' field is not used.
2356
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2357
typedef struct {
2358
  int32_t ssMigrateId;  // ss migrate id
2359
  int32_t nodeId;       // node id of the leader vnode
2360
  int32_t vgId;         // vgroup id
2361
  int32_t fid;          // file set id
2362
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2363
} SSsMigrateProgress;
2364

2365
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2366
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2367

2368
// Request for TDMT_MND_KILL_SSMIGRATE
2369
typedef struct {
2370
  int32_t ssMigrateId;
2371
  int32_t sqlLen;
2372
  char*   sql;
2373
} SKillSsMigrateReq;
2374

2375
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2376
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2377
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2378

2379
// Request for TDMT_VND_KILL_SSMIGRATE
2380
typedef struct {
2381
  int32_t ssMigrateId;
2382
} SVnodeKillSsMigrateReq;
2383

2384
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2385
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2386

2387
typedef struct {
2388
  int32_t vgId;
2389
  int64_t keepVersion;
2390
} SMndSetVgroupKeepVersionReq;
2391

2392
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2393
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2394

2395
typedef struct {
2396
  int32_t timestampSec;
2397
  int32_t ttlDropMaxCount;
2398
  int32_t nUids;
2399
  SArray* pTbUids;
2400
} SVDropTtlTableReq;
2401

2402
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2403
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2404

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

2464
typedef SDbCfgRsp SDbCfgInfo;
2465

2466
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2467
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2468
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2469
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2470
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2471

2472
typedef struct {
2473
  int32_t rowNum;
2474
} SQnodeListReq;
2475

2476
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2477
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2478

2479
typedef struct {
2480
  int32_t rowNum;
2481
} SDnodeListReq;
2482

2483
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2484

2485
typedef struct {
2486
  int32_t useless;  // useless
2487
} SServerVerReq;
2488

2489
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2490
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2491

2492
typedef struct {
2493
  char ver[TSDB_VERSION_LEN];
2494
} SServerVerRsp;
2495

2496
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2497
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2498

2499
typedef struct SQueryNodeAddr {
2500
  int32_t nodeId;  // vgId or qnodeId
2501
  SEpSet  epSet;
2502
} SQueryNodeAddr;
2503

2504
typedef struct {
2505
  SQueryNodeAddr addr;
2506
  uint64_t       load;
2507
} SQueryNodeLoad;
2508

2509
typedef struct {
2510
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2511
} SQnodeListRsp;
2512

2513
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2514
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2515
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2516

2517

2518
typedef struct SDownstreamSourceNode {
2519
  ENodeType      type;
2520
  SQueryNodeAddr addr;
2521
  uint64_t       clientId;
2522
  uint64_t       taskId;
2523
  uint64_t       sId;
2524
  uint64_t       srcTaskId;
2525
  int32_t        execId;
2526
  int32_t        fetchMsgType;
2527
  bool           localExec;
2528
} SDownstreamSourceNode;
2529

2530

2531

2532
typedef struct SDNodeAddr {
2533
  int32_t nodeId;  // dnodeId
2534
  SEpSet  epSet;
2535
} SDNodeAddr;
2536

2537
typedef struct {
2538
  SArray* dnodeList;  // SArray<SDNodeAddr>
2539
} SDnodeListRsp;
2540

2541
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2542
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2543
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2544

2545
typedef struct {
2546
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2547
} STableTSMAInfoRsp;
2548

2549
typedef struct {
2550
  SUseDbRsp*         useDbRsp;
2551
  SDbCfgRsp*         cfgRsp;
2552
  STableTSMAInfoRsp* pTsmaRsp;
2553
  int32_t            dbTsmaVersion;
2554
  char               db[TSDB_DB_FNAME_LEN];
2555
  int64_t            dbId;
2556
} SDbHbRsp;
2557

2558
typedef struct {
2559
  SArray* pArray;  // Array of SDbHbRsp
2560
} SDbHbBatchRsp;
2561

2562
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2563
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2564
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2565

2566
typedef struct {
2567
  SArray* pArray;  // Array of SGetUserAuthRsp
2568
} SUserAuthBatchRsp;
2569

2570
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2571
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2572
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2573

2574
typedef struct {
2575
  char        db[TSDB_DB_FNAME_LEN];
2576
  STimeWindow timeRange;
2577
  int32_t     sqlLen;
2578
  char*       sql;
2579
  SArray*     vgroupIds;
2580
  int32_t     compactId;
2581
  int8_t      metaOnly;
2582
  int8_t      force;
2583
} SCompactDbReq;
2584

2585
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2586
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2587
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2588

2589
typedef struct {
2590
  union {
2591
    int32_t compactId;
2592
    int32_t id;
2593
  };
2594
  int8_t bAccepted;
2595
} SCompactDbRsp;
2596

2597
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2598
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2599

2600
typedef struct {
2601
  union {
2602
    int32_t compactId;
2603
    int32_t id;
2604
  };
2605
  int32_t sqlLen;
2606
  char*   sql;
2607
} SKillCompactReq;
2608

2609
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2610
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2611
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2612

2613
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2614
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2615

2616
typedef struct {
2617
  char    name[TSDB_FUNC_NAME_LEN];
2618
  int8_t  igExists;
2619
  int8_t  funcType;
2620
  int8_t  scriptType;
2621
  int8_t  outputType;
2622
  int32_t outputLen;
2623
  int32_t bufSize;
2624
  int32_t codeLen;
2625
  int64_t signature;
2626
  char*   pComment;
2627
  char*   pCode;
2628
  int8_t  orReplace;
2629
} SCreateFuncReq;
2630

2631
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2632
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2633
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2634

2635
typedef struct {
2636
  char   name[TSDB_FUNC_NAME_LEN];
2637
  int8_t igNotExists;
2638
} SDropFuncReq;
2639

2640
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2641
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2642

2643
typedef struct {
2644
  int32_t numOfFuncs;
2645
  bool    ignoreCodeComment;
2646
  SArray* pFuncNames;
2647
} SRetrieveFuncReq;
2648

2649
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2650
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2651
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2652

2653
typedef struct {
2654
  char    name[TSDB_FUNC_NAME_LEN];
2655
  int8_t  funcType;
2656
  int8_t  scriptType;
2657
  int8_t  outputType;
2658
  int32_t outputLen;
2659
  int32_t bufSize;
2660
  int64_t signature;
2661
  int32_t commentSize;
2662
  int32_t codeSize;
2663
  char*   pComment;
2664
  char*   pCode;
2665
} SFuncInfo;
2666

2667
typedef struct {
2668
  int32_t funcVersion;
2669
  int64_t funcCreatedTime;
2670
} SFuncExtraInfo;
2671

2672
typedef struct {
2673
  int32_t numOfFuncs;
2674
  SArray* pFuncInfos;
2675
  SArray* pFuncExtraInfos;
2676
} SRetrieveFuncRsp;
2677

2678
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2679
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2680
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2681
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2682

2683
typedef struct {
2684
  int32_t       statusInterval;
2685
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2686
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2687
  char          locale[TD_LOCALE_LEN];      // tsLocale
2688
  char          charset[TD_LOCALE_LEN];     // tsCharset
2689
  int8_t        ttlChangeOnWrite;
2690
  int8_t        enableWhiteList;
2691
  int8_t        encryptionKeyStat;
2692
  uint32_t      encryptionKeyChksum;
2693
  SMonitorParas monitorParas;
2694
  int32_t       statusIntervalMs;
2695
} SClusterCfg;
2696

2697
typedef struct {
2698
  int32_t openVnodes;
2699
  int32_t dropVnodes;
2700
  int32_t totalVnodes;
2701
  int32_t masterNum;
2702
  int64_t numOfSelectReqs;
2703
  int64_t numOfInsertReqs;
2704
  int64_t numOfInsertSuccessReqs;
2705
  int64_t numOfBatchInsertReqs;
2706
  int64_t numOfBatchInsertSuccessReqs;
2707
  int64_t errors;
2708
} SVnodesStat;
2709

2710
typedef struct {
2711
  int32_t vgId;
2712
  int8_t  syncState;
2713
  int8_t  syncRestore;
2714
  int64_t syncTerm;
2715
  int64_t roleTimeMs;
2716
  int64_t startTimeMs;
2717
  int8_t  syncCanRead;
2718
  int64_t cacheUsage;
2719
  int64_t numOfTables;
2720
  int64_t numOfTimeSeries;
2721
  int64_t totalStorage;
2722
  int64_t compStorage;
2723
  int64_t pointsWritten;
2724
  int64_t numOfSelectReqs;
2725
  int64_t numOfInsertReqs;
2726
  int64_t numOfInsertSuccessReqs;
2727
  int64_t numOfBatchInsertReqs;
2728
  int64_t numOfBatchInsertSuccessReqs;
2729
  int32_t numOfCachedTables;
2730
  int32_t learnerProgress;  // use one reservered
2731
  int64_t syncAppliedIndex;
2732
  int64_t syncCommitIndex;
2733
  int64_t bufferSegmentUsed;
2734
  int64_t bufferSegmentSize;
2735
  int32_t snapSeq;
2736
  int64_t syncTotalIndex;
2737
} SVnodeLoad;
2738

2739
typedef struct {
2740
  int64_t total_requests;
2741
  int64_t total_rows;
2742
  int64_t total_bytes;
2743
  double  write_size;
2744
  double  cache_hit_ratio;
2745
  int64_t rpc_queue_wait;
2746
  int64_t preprocess_time;
2747

2748
  int64_t memory_table_size;
2749
  int64_t commit_count;
2750
  int64_t merge_count;
2751
  double  commit_time;
2752
  double  merge_time;
2753
  int64_t block_commit_time;
2754
  int64_t memtable_wait_time;
2755
} SVnodeMetrics;
2756

2757
typedef struct {
2758
  int32_t     vgId;
2759
  int64_t     numOfTables;
2760
  int64_t     memSize;
2761
  int64_t     l1Size;
2762
  int64_t     l2Size;
2763
  int64_t     l3Size;
2764
  int64_t     cacheSize;
2765
  int64_t     walSize;
2766
  int64_t     metaSize;
2767
  int64_t     rawDataSize;
2768
  int64_t     ssSize;
2769
  const char* dbname;
2770
  int8_t      estimateRawData;
2771
} SDbSizeStatisInfo;
2772

2773
typedef struct {
2774
  int32_t vgId;
2775
  int64_t nTimeSeries;
2776
} SVnodeLoadLite;
2777

2778
typedef struct {
2779
  int8_t  syncState;
2780
  int64_t syncTerm;
2781
  int8_t  syncRestore;
2782
  int64_t roleTimeMs;
2783
} SMnodeLoad;
2784

2785
typedef struct {
2786
  int32_t dnodeId;
2787
  int64_t numOfProcessedQuery;
2788
  int64_t numOfProcessedCQuery;
2789
  int64_t numOfProcessedFetch;
2790
  int64_t numOfProcessedDrop;
2791
  int64_t numOfProcessedNotify;
2792
  int64_t numOfProcessedHb;
2793
  int64_t numOfProcessedDelete;
2794
  int64_t cacheDataSize;
2795
  int64_t numOfQueryInQueue;
2796
  int64_t numOfFetchInQueue;
2797
  int64_t timeInQueryQueue;
2798
  int64_t timeInFetchQueue;
2799
} SQnodeLoad;
2800

2801
typedef struct {
2802
  int32_t     sver;      // software version
2803
  int64_t     dnodeVer;  // dnode table version in sdb
2804
  int32_t     dnodeId;
2805
  int64_t     clusterId;
2806
  int64_t     rebootTime;
2807
  int64_t     updateTime;
2808
  float       numOfCores;
2809
  int32_t     numOfSupportVnodes;
2810
  int32_t     numOfDiskCfg;
2811
  int64_t     memTotal;
2812
  int64_t     memAvail;
2813
  char        dnodeEp[TSDB_EP_LEN];
2814
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2815
  SMnodeLoad  mload;
2816
  SQnodeLoad  qload;
2817
  SClusterCfg clusterCfg;
2818
  SArray*     pVloads;  // array of SVnodeLoad
2819
  int32_t     statusSeq;
2820
  int64_t     ipWhiteVer;
2821
  int64_t     timeWhiteVer;
2822
  int64_t     analVer;
2823
  int64_t     timestamp;
2824
  char        auditDB[TSDB_DB_FNAME_LEN];
2825
  char        auditToken[TSDB_TOKEN_LEN];
2826
  SEpSet      auditEpSet;
2827
  int32_t     auditVgId;
2828
} SStatusReq;
2829

2830
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2831
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2832
void    tFreeSStatusReq(SStatusReq* pReq);
2833

2834
typedef struct {
2835
  int32_t forceReadConfig;
2836
  int32_t cver;
2837
  SArray* array;
2838
} SConfigReq;
2839

2840
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2841
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2842
void    tFreeSConfigReq(SConfigReq* pReq);
2843

2844
typedef struct {
2845
  int32_t dnodeId;
2846
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2847
} SDnodeInfoReq;
2848

2849
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2850
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2851

2852
typedef enum {
2853
  MONITOR_TYPE_COUNTER = 0,
2854
  MONITOR_TYPE_SLOW_LOG = 1,
2855
} MONITOR_TYPE;
2856

2857
typedef struct {
2858
  int32_t      contLen;
2859
  char*        pCont;
2860
  MONITOR_TYPE type;
2861
} SStatisReq;
2862

2863
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2864
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2865
void    tFreeSStatisReq(SStatisReq* pReq);
2866

2867
typedef struct {
2868
  char    db[TSDB_DB_FNAME_LEN];
2869
  char    table[TSDB_TABLE_NAME_LEN];
2870
  char    operation[AUDIT_OPERATION_LEN];
2871
  int32_t sqlLen;
2872
  char*   pSql;
2873
  double  duration;
2874
  int64_t affectedRows;
2875
} SAuditReq;
2876
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2877
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2878
void    tFreeSAuditReq(SAuditReq* pReq);
2879

2880
typedef struct {
2881
  SArray* auditArr;
2882
} SBatchAuditReq;
2883
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2884
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2885
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2886

2887
typedef struct {
2888
  int32_t dnodeId;
2889
  int64_t clusterId;
2890
  SArray* pVloads;
2891
} SNotifyReq;
2892

2893
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2894
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2895
void    tFreeSNotifyReq(SNotifyReq* pReq);
2896

2897
typedef struct {
2898
  int32_t dnodeId;
2899
  int64_t clusterId;
2900
} SDnodeCfg;
2901

2902
typedef struct {
2903
  int32_t id;
2904
  int8_t  isMnode;
2905
  SEp     ep;
2906
} SDnodeEp;
2907

2908
typedef struct {
2909
  int32_t id;
2910
  int8_t  isMnode;
2911
  int8_t  offlineReason;
2912
  SEp     ep;
2913
  char    active[TSDB_ACTIVE_KEY_LEN];
2914
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2915
} SDnodeInfo;
2916

2917
typedef struct {
2918
  int64_t   dnodeVer;
2919
  SDnodeCfg dnodeCfg;
2920
  SArray*   pDnodeEps;  // Array of SDnodeEp
2921
  int32_t   statusSeq;
2922
  int64_t   ipWhiteVer;
2923
  int64_t   analVer;
2924
  int64_t   timeWhiteVer;
2925
  char      auditDB[TSDB_DB_FNAME_LEN];
2926
  char      auditToken[TSDB_TOKEN_LEN];
2927
  SEpSet    auditEpSet;
2928
  int32_t   auditVgId;
2929
} SStatusRsp;
2930

2931
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2932
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2933
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2934

2935
typedef struct {
2936
  int32_t forceReadConfig;
2937
  int32_t isConifgVerified;
2938
  int32_t isVersionVerified;
2939
  int32_t cver;
2940
  SArray* array;
2941
} SConfigRsp;
2942

2943
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2944
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2945
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2946

2947
typedef struct {
2948
  int32_t dnodeId;
2949
  int32_t keyVersion;  // Local key version
2950
} SKeySyncReq;
2951

2952
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2953
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2954

2955
typedef struct {
2956
  int32_t keyVersion;        // mnode's key version
2957
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2958
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2959
  char    svrKey[129];       // Server key (if needUpdate)
2960
  char    dbKey[129];        // Database key (if needUpdate)
2961
  char    cfgKey[129];       // Config key (if needUpdate)
2962
  char    metaKey[129];      // Metadata key (if needUpdate)
2963
  char    dataKey[129];      // Data key (if needUpdate)
2964
  int32_t algorithm;         // Encryption algorithm for master keys
2965
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2966
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2967
  int64_t createTime;        // Key creation time
2968
  int64_t svrKeyUpdateTime;  // Server key update time
2969
  int64_t dbKeyUpdateTime;   // Database key update time
2970
} SKeySyncRsp;
2971

2972
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2973
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2974

2975
typedef struct {
2976
  int32_t reserved;
2977
} SMTimerReq;
2978

2979
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2980
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2981

2982
typedef struct SOrphanTask {
2983
  int64_t streamId;
2984
  int32_t taskId;
2985
  int32_t nodeId;
2986
} SOrphanTask;
2987

2988
typedef struct SMStreamDropOrphanMsg {
2989
  SArray* pList;  // SArray<SOrphanTask>
2990
} SMStreamDropOrphanMsg;
2991

2992
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2993
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2994
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2995

2996
typedef struct {
2997
  int32_t  id;
2998
  uint16_t port;                 // node sync Port
2999
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3000
} SReplica;
3001

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

3064
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3065
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3066
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3067

3068
typedef struct {
3069
  union {
3070
    int32_t compactId;
3071
    int32_t id;
3072
  };
3073
  int32_t vgId;
3074
  int32_t dnodeId;
3075
} SQueryCompactProgressReq;
3076

3077
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3078
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3079

3080
typedef struct {
3081
  union {
3082
    int32_t compactId;
3083
    int32_t id;
3084
  };
3085
  int32_t vgId;
3086
  int32_t dnodeId;
3087
  int32_t numberFileset;
3088
  int32_t finished;
3089
  int32_t progress;
3090
  int64_t remainingTime;
3091
} SQueryCompactProgressRsp;
3092

3093
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3094
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3095

3096
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3097
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3098

3099
typedef struct {
3100
  int32_t vgId;
3101
  int32_t dnodeId;
3102
  int64_t dbUid;
3103
  char    db[TSDB_DB_FNAME_LEN];
3104
  int64_t reserved[8];
3105
} SDropVnodeReq;
3106

3107
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3108
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3109

3110
typedef struct {
3111
  char    colName[TSDB_COL_NAME_LEN];
3112
  char    stb[TSDB_TABLE_FNAME_LEN];
3113
  int64_t stbUid;
3114
  int64_t dbUid;
3115
  int64_t reserved[8];
3116
} SDropIndexReq;
3117

3118
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3119
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3120

3121
typedef struct {
3122
  int64_t dbUid;
3123
  char    db[TSDB_DB_FNAME_LEN];
3124
  union {
3125
    int64_t compactStartTime;
3126
    int64_t startTime;
3127
  };
3128

3129
  STimeWindow tw;
3130
  union {
3131
    int32_t compactId;
3132
    int32_t id;
3133
  };
3134
  int8_t metaOnly;
3135
  union {
3136
    uint16_t flags;
3137
    struct {
3138
      uint16_t optrType : 3;     // ETsdbOpType
3139
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3140
      uint16_t reserved : 12;
3141
    };
3142
  };
3143
  int8_t force;  // force compact
3144
} SCompactVnodeReq;
3145

3146
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3147
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3148

3149
typedef struct {
3150
  union {
3151
    int32_t compactId;
3152
    int32_t taskId;
3153
  };
3154
  int32_t vgId;
3155
  int32_t dnodeId;
3156
} SVKillCompactReq;
3157

3158
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3159
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3160

3161
typedef SVKillCompactReq SVKillRetentionReq;
3162

3163
typedef struct {
3164
  char        db[TSDB_DB_FNAME_LEN];
3165
  int32_t     maxSpeed;
3166
  int32_t     sqlLen;
3167
  char*       sql;
3168
  SArray*     vgroupIds;
3169
  STimeWindow tw;  // unit is second
3170
  union {
3171
    uint32_t flags;
3172
    struct {
3173
      uint32_t optrType : 3;     // ETsdbOpType
3174
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3175
      uint32_t reserved : 28;
3176
    };
3177
  };
3178
} STrimDbReq;
3179

3180
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3181
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3182
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3183

3184
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3185

3186
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3187
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3188

3189
typedef struct {
3190
  int32_t vgVersion;
3191
  int32_t buffer;
3192
  int32_t pageSize;
3193
  int32_t pages;
3194
  int32_t cacheLastSize;
3195
  int32_t daysPerFile;
3196
  int32_t daysToKeep0;
3197
  int32_t daysToKeep1;
3198
  int32_t daysToKeep2;
3199
  int32_t keepTimeOffset;
3200
  int32_t walFsyncPeriod;
3201
  int8_t  walLevel;
3202
  int8_t  strict;
3203
  int8_t  cacheLast;
3204
  int64_t reserved[7];
3205
  // 1st modification
3206
  int16_t sttTrigger;
3207
  int32_t minRows;
3208
  // 2nd modification
3209
  int32_t walRetentionPeriod;
3210
  int32_t walRetentionSize;
3211
  int32_t ssKeepLocal;
3212
  int8_t  ssCompact;
3213
  int8_t  allowDrop;
3214
  int8_t  secureDelete;
3215
} SAlterVnodeConfigReq;
3216

3217
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3218
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3219

3220
typedef struct {
3221
  int32_t  vgId;
3222
  int8_t   strict;
3223
  int8_t   selfIndex;
3224
  int8_t   replica;
3225
  SReplica replicas[TSDB_MAX_REPLICA];
3226
  int64_t  reserved[8];
3227
  int8_t   learnerSelfIndex;
3228
  int8_t   learnerReplica;
3229
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3230
  int32_t  changeVersion;
3231
  int32_t  electBaseLine;
3232
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3233

3234
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3235
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3236

3237
typedef struct {
3238
  int32_t vgId;
3239
  int8_t  disable;
3240
} SDisableVnodeWriteReq;
3241

3242
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3243
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3244

3245
typedef struct {
3246
  int32_t  srcVgId;
3247
  int32_t  dstVgId;
3248
  uint32_t hashBegin;
3249
  uint32_t hashEnd;
3250
  int32_t  changeVersion;
3251
  int32_t  reserved;
3252
} SAlterVnodeHashRangeReq;
3253

3254
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3255
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3256

3257
#define REQ_OPT_TBNAME 0x0
3258
#define REQ_OPT_TBUID  0x01
3259
typedef struct {
3260
  SMsgHead header;
3261
  char     dbFName[TSDB_DB_FNAME_LEN];
3262
  char     tbName[TSDB_TABLE_NAME_LEN];
3263
  uint8_t  option;
3264
  uint8_t  autoCreateCtb;
3265
} STableInfoReq;
3266

3267
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3268
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3269

3270
typedef struct {
3271
  int8_t  metaClone;  // create local clone of the cached table meta
3272
  int32_t numOfVgroups;
3273
  int32_t numOfTables;
3274
  int32_t numOfUdfs;
3275
  char    tableNames[];
3276
} SMultiTableInfoReq;
3277

3278
// todo refactor
3279
typedef struct SVgroupInfo {
3280
  int32_t  vgId;
3281
  uint32_t hashBegin;
3282
  uint32_t hashEnd;
3283
  SEpSet   epSet;
3284
  union {
3285
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3286
    int32_t taskId;      // used in stream
3287
  };
3288
} SVgroupInfo;
3289

3290
typedef struct {
3291
  int32_t     numOfVgroups;
3292
  SVgroupInfo vgroups[];
3293
} SVgroupsInfo;
3294

3295
typedef struct {
3296
  STableMetaRsp* pMeta;
3297
} SMAlterStbRsp;
3298

3299
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3300
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3301
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3302

3303
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3304
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3305
void    tFreeSTableMetaRsp(void* pRsp);
3306
void    tFreeSTableIndexRsp(void* info);
3307

3308
typedef struct {
3309
  SArray* pMetaRsp;   // Array of STableMetaRsp
3310
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3311
} SSTbHbRsp;
3312

3313
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3314
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3315
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3316

3317
typedef struct {
3318
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3319
} SViewHbRsp;
3320

3321
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3322
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3323
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3324

3325
typedef struct {
3326
  int32_t numOfTables;
3327
  int32_t numOfVgroup;
3328
  int32_t numOfUdf;
3329
  int32_t contLen;
3330
  int8_t  compressed;  // denote if compressed or not
3331
  int32_t rawLen;      // size before compress
3332
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3333
  char    meta[];
3334
} SMultiTableMeta;
3335

3336
typedef struct {
3337
  int32_t dataLen;
3338
  char    name[TSDB_TABLE_FNAME_LEN];
3339
  char*   data;
3340
} STagData;
3341

3342
typedef struct {
3343
  int32_t  opType;
3344
  uint32_t valLen;
3345
  char*    val;
3346
} SShowVariablesReq;
3347

3348
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3349
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3350
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3351

3352
typedef struct {
3353
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3354
  char value[TSDB_CONFIG_PATH_LEN + 1];
3355
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3356
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3357
  char info[TSDB_CONFIG_INFO_LEN + 1];
3358
} SVariablesInfo;
3359

3360
typedef struct {
3361
  SArray* variables;  // SArray<SVariablesInfo>
3362
} SShowVariablesRsp;
3363

3364
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3365
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3366

3367
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3368

3369
/*
3370
 * sql: show tables like '%a_%'
3371
 * payload is the query condition, e.g., '%a_%'
3372
 * payloadLen is the length of payload
3373
 */
3374
typedef struct {
3375
  int32_t type;
3376
  char    db[TSDB_DB_FNAME_LEN];
3377
  int32_t payloadLen;
3378
  char*   payload;
3379
} SShowReq;
3380

3381
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3382
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3383
void tFreeSShowReq(SShowReq* pReq);
3384

3385
typedef struct {
3386
  int64_t       showId;
3387
  STableMetaRsp tableMeta;
3388
} SShowRsp, SVShowTablesRsp;
3389

3390
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3391
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3392
// void    tFreeSShowRsp(SShowRsp* pRsp);
3393

3394
typedef struct {
3395
  char    db[TSDB_DB_FNAME_LEN];
3396
  char    tb[TSDB_TABLE_NAME_LEN];
3397
  char    user[TSDB_USER_LEN];
3398
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3399
  int64_t showId;
3400
  int64_t compactId;  // for compact
3401
  bool    withFull;   // for show users full
3402
} SRetrieveTableReq;
3403

3404
typedef struct SSysTableSchema {
3405
  int8_t   type;
3406
  col_id_t colId;
3407
  int32_t  bytes;
3408
} SSysTableSchema;
3409

3410
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3411
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3412

3413
#define RETRIEVE_TABLE_RSP_VERSION         0
3414
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3415
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3416

3417
typedef struct {
3418
  int64_t useconds;
3419
  int8_t  completed;  // all results are returned to client
3420
  int8_t  precision;
3421
  int8_t  compressed;
3422
  int8_t  streamBlockType;
3423
  int32_t payloadLen;
3424
  int32_t compLen;
3425
  int32_t numOfBlocks;
3426
  int64_t numOfRows;  // from int32_t change to int64_t
3427
  int64_t numOfCols;
3428
  int64_t skey;
3429
  int64_t ekey;
3430
  int64_t version;                         // for stream
3431
  TSKEY   watermark;                       // for stream
3432
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3433
  char    data[];
3434
} SRetrieveTableRsp;
3435

3436
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3437

3438
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3439
  do {                                          \
3440
    ((int32_t*)(_p))[0] = (_compLen);           \
3441
    ((int32_t*)(_p))[1] = (_fullLen);           \
3442
  } while (0);
3443

3444
typedef struct {
3445
  int64_t version;
3446
  int64_t numOfRows;
3447
  int8_t  compressed;
3448
  int8_t  precision;
3449
  char    data[];
3450
} SRetrieveTableRspForTmq;
3451

3452
typedef struct {
3453
  int64_t handle;
3454
  int64_t useconds;
3455
  int8_t  completed;  // all results are returned to client
3456
  int8_t  precision;
3457
  int8_t  compressed;
3458
  int32_t compLen;
3459
  int32_t numOfRows;
3460
  int32_t fullLen;
3461
  char    data[];
3462
} SRetrieveMetaTableRsp;
3463

3464
typedef struct SExplainExecInfo {
3465
  double   startupCost;
3466
  double   totalCost;
3467
  uint64_t numOfRows;
3468
  uint32_t verboseLen;
3469
  void*    verboseInfo;
3470
} SExplainExecInfo;
3471

3472
typedef struct {
3473
  int32_t           numOfPlans;
3474
  SExplainExecInfo* subplanInfo;
3475
} SExplainRsp;
3476

3477
typedef struct {
3478
  SExplainRsp rsp;
3479
  uint64_t    qId;
3480
  uint64_t    cId;
3481
  uint64_t    tId;
3482
  int64_t     rId;
3483
  int32_t     eId;
3484
} SExplainLocalRsp;
3485

3486
typedef struct STableScanAnalyzeInfo {
3487
  uint64_t totalRows;
3488
  uint64_t totalCheckedRows;
3489
  uint32_t totalBlocks;
3490
  uint32_t loadBlocks;
3491
  uint32_t loadBlockStatis;
3492
  uint32_t skipBlocks;
3493
  uint32_t filterOutBlocks;
3494
  double   elapsedTime;
3495
  double   filterTime;
3496
} STableScanAnalyzeInfo;
3497

3498
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3499
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3500
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3501

3502
typedef struct {
3503
  char    config[TSDB_DNODE_CONFIG_LEN];
3504
  char    value[TSDB_CLUSTER_VALUE_LEN];
3505
  int32_t sqlLen;
3506
  char*   sql;
3507
} SMCfgClusterReq;
3508

3509
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3510
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3511
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3512

3513
typedef struct {
3514
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3515
  int32_t port;
3516
  int32_t sqlLen;
3517
  char*   sql;
3518
} SCreateDnodeReq;
3519

3520
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3521
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3522
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3523

3524
typedef struct {
3525
  int32_t dnodeId;
3526
  char    fqdn[TSDB_FQDN_LEN];
3527
  int32_t port;
3528
  int8_t  force;
3529
  int8_t  unsafe;
3530
  int32_t sqlLen;
3531
  char*   sql;
3532
} SDropDnodeReq;
3533

3534
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3535
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3536
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3537

3538
enum {
3539
  RESTORE_TYPE__ALL = 1,
3540
  RESTORE_TYPE__MNODE,
3541
  RESTORE_TYPE__VNODE,
3542
  RESTORE_TYPE__QNODE,
3543
};
3544

3545
typedef struct {
3546
  int32_t dnodeId;
3547
  int8_t  restoreType;
3548
  int32_t sqlLen;
3549
  char*   sql;
3550
} SRestoreDnodeReq;
3551

3552
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3553
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3554
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3555

3556
typedef struct {
3557
  int32_t dnodeId;
3558
  char    config[TSDB_DNODE_CONFIG_LEN];
3559
  char    value[TSDB_DNODE_VALUE_LEN];
3560
  int32_t sqlLen;
3561
  char*   sql;
3562
} SMCfgDnodeReq;
3563

3564
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3565
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3566
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3567

3568
typedef struct {
3569
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3570
  char    newKey[ENCRYPT_KEY_LEN + 1];
3571
  int32_t sqlLen;
3572
  char*   sql;
3573
} SMAlterEncryptKeyReq;
3574

3575
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3576
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3577
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3578

3579
typedef struct {
3580
  int32_t days;
3581
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3582
  int32_t sqlLen;
3583
  char*   sql;
3584
} SMAlterKeyExpirationReq;
3585

3586
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3587
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3588
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3589

3590
typedef struct {
3591
  char    config[TSDB_DNODE_CONFIG_LEN];
3592
  char    value[TSDB_DNODE_VALUE_LEN];
3593
  int32_t version;
3594
} SDCfgDnodeReq;
3595

3596
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3597
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3598

3599
typedef struct {
3600
  int32_t dnodeId;
3601
  int32_t sqlLen;
3602
  char*   sql;
3603
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3604
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3605

3606
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3607
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3608

3609
typedef struct {
3610
  int32_t nodeId;
3611
  SEpSet  epSet;
3612
} SNodeEpSet;
3613

3614
typedef struct {
3615
  int32_t    snodeId;
3616
  SNodeEpSet leaders[2];
3617
  SNodeEpSet replica;
3618
  int32_t    sqlLen;
3619
  char*      sql;
3620
} SDCreateSnodeReq;
3621

3622
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3623
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3624
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3625

3626
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3627
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3628
typedef struct {
3629
  int8_t   replica;
3630
  SReplica replicas[TSDB_MAX_REPLICA];
3631
  int8_t   learnerReplica;
3632
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3633
  int64_t  lastIndex;
3634
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3635
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3636

3637
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3638
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3639

3640
typedef struct {
3641
  int32_t urlLen;
3642
  int32_t sqlLen;
3643
  char*   url;
3644
  char*   sql;
3645
} SMCreateAnodeReq;
3646

3647
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3648
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3649
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3650

3651
typedef struct {
3652
  int32_t anodeId;
3653
  int32_t sqlLen;
3654
  char*   sql;
3655
} SMDropAnodeReq, SMUpdateAnodeReq;
3656

3657
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3658
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3659
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3660
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3661
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3662
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3663

3664
typedef struct {
3665
  int32_t dnodeId;
3666
  int32_t bnodeProto;
3667
  int32_t sqlLen;
3668
  char*   sql;
3669
} SMCreateBnodeReq, SDCreateBnodeReq;
3670

3671
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3672
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3673
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3674

3675
typedef struct {
3676
  int32_t dnodeId;
3677
  int32_t sqlLen;
3678
  char*   sql;
3679
} SMDropBnodeReq, SDDropBnodeReq;
3680

3681
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3682
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3683
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3684

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

3745
typedef struct {
3746
  int32_t sqlLen;
3747
  int32_t urlLen;
3748
  int32_t userLen;
3749
  int32_t passLen;
3750
  int32_t passIsMd5;
3751
  char*   sql;
3752
  char*   url;
3753
  char*   user;
3754
  char*   pass;
3755
  CowStr  token;
3756
} SMCreateXnodeReq, SDCreateXnodeReq;
3757

3758
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3759
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3760
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3761

3762
typedef struct {
3763
  int32_t xnodeId;
3764
  int32_t force;
3765
  int32_t urlLen;
3766
  int32_t sqlLen;
3767
  char*   url;
3768
  char*   sql;
3769
} SMDropXnodeReq, SDDropXnodeReq;
3770

3771
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3772
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3773
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3774

3775
typedef struct {
3776
  int32_t id;
3777
  CowStr  token;
3778
  CowStr  user;
3779
  CowStr  pass;
3780
  int32_t urlLen;
3781
  int32_t sqlLen;
3782
  char*   url;
3783
  char*   sql;
3784
} SMUpdateXnodeReq;
3785
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3786
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3787
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3788

3789
typedef struct {
3790
  int32_t xnodeId;
3791
  int32_t sqlLen;
3792
  char*   sql;
3793
} SMDrainXnodeReq;
3794
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3795
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3796
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3797
typedef enum {
3798
  XNODE_TASK_SOURCE_DSN = 1,
3799
  XNODE_TASK_SOURCE_DATABASE,
3800
  XNODE_TASK_SOURCE_TOPIC,
3801
} ENodeXTaskSourceType;
3802

3803
typedef enum {
3804
  XNODE_TASK_SINK_DSN = 1,
3805
  XNODE_TASK_SINK_DATABASE,
3806
} ENodeXTaskSinkType;
3807

3808
typedef struct {
3809
  ENodeXTaskSourceType type;
3810
  CowStr               cstr;
3811
} xTaskSource;
3812
/**
3813
 * @brief Deallocate a xTaskSource object.
3814
 *
3815
 * @param source ptr
3816
 */
3817
void xFreeTaskSource(xTaskSource* source);
3818
/**
3819
 * @brief Create a xTaskSource object with cloned source string.
3820
 *
3821
 * @param sourceType: source type.
3822
 * @param len: length of source string.
3823
 * @param source: source string ptr.
3824
 * @return xTaskSource object
3825
 */
3826
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3827
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3828
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3829
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3830
const char* xGetTaskSourceStr(xTaskSource* source);
3831
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3832
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3833

3834
typedef struct {
3835
  ENodeXTaskSinkType type;
3836
  CowStr             cstr;
3837
} xTaskSink;
3838
/**
3839
 * @brief Deallocate a xTaskSink object.
3840
 *
3841
 * @param sink ptr
3842
 */
3843
void xFreeTaskSink(xTaskSink* sink);
3844
/**
3845
 * @brief Create a xTaskSink object with cloned name string.
3846
 *
3847
 * @param sinkType: sink type.
3848
 * @param len: length of sink string.
3849
 * @param ptr: sink string ptr.
3850
 * @return xTaskSink object
3851
 */
3852
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3853
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3854
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3855
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3856
const char* xGetTaskSinkStr(xTaskSink* sink);
3857
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3858
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3859

3860
typedef struct {
3861
  int32_t via;
3862
  CowStr  parser;
3863
  // CowStr  reason;
3864
  CowStr  trigger;
3865
  CowStr  health;
3866
  int32_t optionsNum;
3867
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3868
} xTaskOptions;
3869
/**
3870
 * @brief Deallocate a xTaskOptions object.
3871
 *
3872
 * @param options ptr
3873
 */
3874
void    xFreeTaskOptions(xTaskOptions* options);
3875
void    printXnodeTaskOptions(xTaskOptions* options);
3876
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3877
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3878

3879
typedef struct {
3880
  int32_t sqlLen;
3881
  char*   sql;
3882
  int32_t      xnodeId;
3883
  CowStr       name;
3884
  xTaskSource  source;
3885
  xTaskSink    sink;
3886
  xTaskOptions options;
3887
} SMCreateXnodeTaskReq;
3888
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3889
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3890
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3891

3892
typedef struct {
3893
  int32_t     tid;
3894
  CowStr      name;
3895
  int32_t     via;
3896
  int32_t     xnodeId;
3897
  CowStr      status;
3898
  xTaskSource source;
3899
  xTaskSink   sink;
3900
  CowStr      parser;
3901
  CowStr      reason;
3902
  CowStr      updateName;
3903
  CowStr      labels;
3904
  int32_t     sqlLen;
3905
  char*       sql;
3906
} SMUpdateXnodeTaskReq;
3907
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3908
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3909
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3910

3911
typedef struct {
3912
  int32_t id;
3913
  bool    force;
3914
  CowStr  name;
3915
  int32_t sqlLen;
3916
  char*   sql;
3917
} SMDropXnodeTaskReq;
3918
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3919
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3920
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3921

3922
typedef struct {
3923
  int32_t tid;
3924
  CowStr  name;
3925
  int32_t sqlLen;
3926
  char*   sql;
3927
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3928
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3929
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3930
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3931

3932
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3933
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3934
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3935

3936
typedef struct {
3937
  int32_t tid;
3938
  int32_t via;
3939
  int32_t xnodeId;
3940
  CowStr  status;
3941
  CowStr  config;
3942
  CowStr  reason;
3943
  int32_t sqlLen;
3944
  char*   sql;
3945
} SMCreateXnodeJobReq;
3946
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3947
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3948
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3949

3950
typedef struct {
3951
  int32_t jid;
3952
  int32_t via;
3953
  int32_t xnodeId;
3954
  CowStr  status;
3955
  int32_t configLen;
3956
  int32_t reasonLen;
3957
  int32_t sqlLen;
3958
  char*   config;
3959
  char*   reason;
3960
  char*   sql;
3961
} SMUpdateXnodeJobReq;
3962
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3963
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3964
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3965

3966
typedef struct {
3967
  int32_t jid;
3968
  int32_t xnodeId;
3969
  int32_t sqlLen;
3970
  char*   sql;
3971
} SMRebalanceXnodeJobReq;
3972
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3973
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3974
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3975

3976
typedef struct {
3977
  CowStr  ast;
3978
  int32_t sqlLen;
3979
  char*   sql;
3980
} SMRebalanceXnodeJobsWhereReq;
3981
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3982
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3983
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3984

3985
typedef struct {
3986
  int32_t jid;
3987
  CowStr  ast;
3988
  int32_t sqlLen;
3989
  char*   sql;
3990
} SMDropXnodeJobReq;
3991
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3992
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3993
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3994

3995
typedef struct {
3996
  int32_t      sqlLen;
3997
  char*        sql;
3998
  CowStr       name;
3999
  CowStr       status;
4000
  xTaskOptions options;
4001
} SMCreateXnodeAgentReq;
4002
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4003
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4004
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4005

4006
typedef struct {
4007
  int32_t      sqlLen;
4008
  char*        sql;
4009
  int32_t      id;
4010
  CowStr       name;
4011
  xTaskOptions options;
4012
} SMUpdateXnodeAgentReq;
4013
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4014
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4015
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4016

4017
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4018
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4019
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4020
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4021

4022
typedef struct {
4023
  int32_t vgId;
4024
  int32_t hbSeq;
4025
} SVArbHbReqMember;
4026

4027
typedef struct {
4028
  int32_t dnodeId;
4029
  char*   arbToken;
4030
  int64_t arbTerm;
4031
  SArray* hbMembers;  // SVArbHbReqMember
4032
} SVArbHeartBeatReq;
4033

4034
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4035
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4036
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4037

4038
typedef struct {
4039
  int32_t vgId;
4040
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4041
  int32_t hbSeq;
4042
} SVArbHbRspMember;
4043

4044
typedef struct {
4045
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4046
  int32_t dnodeId;
4047
  SArray* hbMembers;  // SVArbHbRspMember
4048
} SVArbHeartBeatRsp;
4049

4050
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4051
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4052
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4053

4054
typedef struct {
4055
  char*   arbToken;
4056
  int64_t arbTerm;
4057
  char*   member0Token;
4058
  char*   member1Token;
4059
} SVArbCheckSyncReq;
4060

4061
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4062
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4063
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4064

4065
typedef struct {
4066
  char*   arbToken;
4067
  char*   member0Token;
4068
  char*   member1Token;
4069
  int32_t vgId;
4070
  int32_t errCode;
4071
} SVArbCheckSyncRsp;
4072

4073
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4074
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4075
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4076

4077
typedef struct {
4078
  char*   arbToken;
4079
  int64_t arbTerm;
4080
  char*   memberToken;
4081
  int8_t  force;
4082
} SVArbSetAssignedLeaderReq;
4083

4084
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4085
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4086
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4087

4088
typedef struct {
4089
  char* data;
4090
} SVAuditRecordReq;
4091
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4092
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4093
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4094

4095
typedef struct {
4096
  char*   arbToken;
4097
  char*   memberToken;
4098
  int32_t vgId;
4099
} SVArbSetAssignedLeaderRsp;
4100

4101
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4102
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4103
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4104

4105
typedef struct {
4106
  int32_t dnodeId;
4107
  char*   token;
4108
} SMArbUpdateGroupMember;
4109

4110
typedef struct {
4111
  int32_t dnodeId;
4112
  char*   token;
4113
  int8_t  acked;
4114
} SMArbUpdateGroupAssigned;
4115

4116
typedef struct {
4117
  int32_t                  vgId;
4118
  int64_t                  dbUid;
4119
  SMArbUpdateGroupMember   members[2];
4120
  int8_t                   isSync;
4121
  int8_t                   assignedAcked;
4122
  SMArbUpdateGroupAssigned assignedLeader;
4123
  int64_t                  version;
4124
  int32_t                  code;
4125
  int64_t                  updateTimeMs;
4126
} SMArbUpdateGroup;
4127

4128
typedef struct {
4129
  SArray* updateArray;  // SMArbUpdateGroup
4130
} SMArbUpdateGroupBatchReq;
4131

4132
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4133
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4134
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4135

4136
typedef struct {
4137
  char queryStrId[TSDB_QUERY_ID_LEN];
4138
} SKillQueryReq;
4139

4140
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4141
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4142

4143
typedef struct {
4144
  uint32_t connId;
4145
} SKillConnReq;
4146

4147
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4148
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4149

4150
typedef struct {
4151
  int32_t transId;
4152
} SKillTransReq;
4153

4154
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4155
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4156

4157
typedef struct {
4158
  int32_t useless;  // useless
4159
  int32_t sqlLen;
4160
  char*   sql;
4161
} SBalanceVgroupReq;
4162

4163
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4164
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4165
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4166

4167
typedef struct {
4168
  int32_t useless;  // useless
4169
  int32_t sqlLen;
4170
  char*   sql;
4171
} SAssignLeaderReq;
4172

4173
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4174
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4175
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4176
typedef struct {
4177
  int32_t vgId1;
4178
  int32_t vgId2;
4179
} SMergeVgroupReq;
4180

4181
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4182
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4183

4184
typedef struct {
4185
  int32_t vgId;
4186
  int32_t dnodeId1;
4187
  int32_t dnodeId2;
4188
  int32_t dnodeId3;
4189
  int32_t sqlLen;
4190
  char*   sql;
4191
} SRedistributeVgroupReq;
4192

4193
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4194
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4195
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4196

4197
typedef struct {
4198
  int32_t reserved;
4199
  int32_t vgId;
4200
  int32_t sqlLen;
4201
  char*   sql;
4202
  char    db[TSDB_DB_FNAME_LEN];
4203
} SBalanceVgroupLeaderReq;
4204

4205
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4206
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4207
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4208

4209
typedef struct {
4210
  int32_t vgId;
4211
} SForceBecomeFollowerReq;
4212

4213
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4214
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4215

4216
typedef struct {
4217
  int32_t vgId;
4218
  bool    force;
4219
} SSplitVgroupReq;
4220

4221
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4222
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4223

4224
typedef struct {
4225
  char user[TSDB_USER_LEN];
4226
  char spi;
4227
  char encrypt;
4228
  char secret[TSDB_PASSWORD_LEN];
4229
  char ckey[TSDB_PASSWORD_LEN];
4230
} SAuthReq, SAuthRsp;
4231

4232
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4233
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4234

4235
typedef struct {
4236
  int32_t statusCode;
4237
  char    details[1024];
4238
} SServerStatusRsp;
4239

4240
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4241
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4242

4243
/**
4244
 * The layout of the query message payload is as following:
4245
 * +--------------------+---------------------------------+
4246
 * |Sql statement       | Physical plan                   |
4247
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4248
 * +--------------------+---------------------------------+
4249
 */
4250
typedef struct SSubQueryMsg {
4251
  SMsgHead header;
4252
  uint64_t sId;
4253
  uint64_t queryId;
4254
  uint64_t clientId;
4255
  uint64_t taskId;
4256
  int64_t  refId;
4257
  int32_t  execId;
4258
  int32_t  msgMask;
4259
  int32_t  subQType;
4260
  int8_t   taskType;
4261
  int8_t   explain;
4262
  int8_t   needFetch;
4263
  int8_t   compress;
4264
  uint32_t sqlLen;
4265
  char*    sql;
4266
  uint32_t msgLen;
4267
  char*    msg;
4268
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4269
} SSubQueryMsg;
4270

4271
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4272
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4273
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4274

4275
typedef struct {
4276
  SMsgHead header;
4277
  uint64_t sId;
4278
  uint64_t queryId;
4279
  uint64_t taskId;
4280
} SSinkDataReq;
4281

4282
typedef struct {
4283
  SMsgHead header;
4284
  uint64_t sId;
4285
  uint64_t queryId;
4286
  uint64_t clientId;
4287
  uint64_t taskId;
4288
  int32_t  execId;
4289
} SQueryContinueReq;
4290

4291
typedef struct {
4292
  SMsgHead header;
4293
  uint64_t sId;
4294
  uint64_t queryId;
4295
  uint64_t taskId;
4296
} SResReadyReq;
4297

4298
typedef struct {
4299
  int32_t code;
4300
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4301
  int32_t sversion;
4302
  int32_t tversion;
4303
} SResReadyRsp;
4304

4305
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4306

4307
typedef struct SOperatorParam {
4308
  int32_t opType;
4309
  int32_t downstreamIdx;
4310
  void*   value;
4311
  SArray* pChildren;  // SArray<SOperatorParam*>
4312
  bool    reUse;
4313
} SOperatorParam;
4314

4315
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4316

4317
// virtual table's colId to origin table's colname
4318
typedef struct SColIdNameKV {
4319
  col_id_t colId;
4320
  char     colName[TSDB_COL_NAME_LEN];
4321
} SColIdNameKV;
4322

4323
#define COL_MASK_ON   ((int8_t)0x1)
4324
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4325
#define COL_SET_MASK_ON(c)     \
4326
  do {                         \
4327
    (c)->flags |= COL_MASK_ON; \
4328
  } while (0)
4329

4330
typedef struct SColNameFlag {
4331
  col_id_t colId;
4332
  char     colName[TSDB_COL_NAME_LEN];
4333
  int8_t   flags;  // 0x01: COL_MASK_ON
4334
} SColNameFlag;
4335

4336
typedef struct SColIdPair {
4337
  col_id_t  vtbColId;
4338
  col_id_t  orgColId;
4339
  SDataType type;
4340
} SColIdPair;
4341

4342
typedef struct SColIdSlotIdPair {
4343
  int32_t  vtbSlotId;
4344
  col_id_t orgColId;
4345
} SColIdSlotIdPair;
4346

4347
typedef struct SOrgTbInfo {
4348
  int32_t vgId;
4349
  char    tbName[TSDB_TABLE_FNAME_LEN];
4350
  SArray* colMap;  // SArray<SColIdNameKV>
4351
} SOrgTbInfo;
4352

4353
void destroySOrgTbInfo(void *info);
4354

4355
typedef enum {
4356
  DYN_TYPE_STB_JOIN = 1,
4357
  DYN_TYPE_VSTB_SINGLE_SCAN,
4358
  DYN_TYPE_VSTB_BATCH_SCAN,
4359
  DYN_TYPE_VSTB_WIN_SCAN,
4360
} ETableScanDynType;
4361

4362
typedef enum {
4363
  DYN_TYPE_SCAN_PARAM = 1,
4364
  NOTIFY_TYPE_SCAN_PARAM,
4365
} ETableScanGetParamType;
4366

4367
typedef struct STableScanOperatorParam {
4368
  ETableScanGetParamType paramType;
4369
  /* for building scan data source */
4370
  bool                   tableSeq;
4371
  bool                   isNewParam;
4372
  uint64_t               groupid;
4373
  SArray*                pUidList;
4374
  SOrgTbInfo*            pOrgTbInfo;
4375
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4376
  SArray*                pTagList;
4377
  STimeWindow            window;
4378
  ETableScanDynType      dynType;
4379
  /* for notifying source step done */
4380
  bool                   notifyToProcess;  // received notify STEP DONE message
4381
  TSKEY                  notifyTs;         // notify timestamp
4382
} STableScanOperatorParam;
4383

4384
typedef struct STagScanOperatorParam {
4385
  tb_uid_t vcUid;
4386
} STagScanOperatorParam;
4387

4388
typedef struct SRefColIdGroup {
4389
  SArray* pSlotIdList;  // SArray<int32_t>
4390
} SRefColIdGroup;
4391

4392
typedef struct SVTableScanOperatorParam {
4393
  uint64_t        uid;
4394
  STimeWindow     window;
4395
  SOperatorParam* pTagScanOp;
4396
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4397
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4398
} SVTableScanOperatorParam;
4399

4400
typedef struct SMergeOperatorParam {
4401
  int32_t         winNum;
4402
} SMergeOperatorParam;
4403

4404
typedef struct SAggOperatorParam {
4405
  bool            needCleanRes;
4406
} SAggOperatorParam;
4407

4408
typedef struct SExternalWindowOperatorParam {
4409
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4410
} SExternalWindowOperatorParam;
4411

4412
typedef struct SDynQueryCtrlOperatorParam {
4413
  STimeWindow    window;
4414
} SDynQueryCtrlOperatorParam;
4415

4416
struct SStreamRuntimeFuncInfo;
4417
typedef struct {
4418
  SMsgHead        header;
4419
  uint64_t        sId;
4420
  uint64_t        queryId;
4421
  uint64_t        clientId;
4422
  uint64_t        taskId;
4423
  uint64_t        srcTaskId;  // used for subQ
4424
  uint64_t        blockIdx;   // used for subQ
4425
  int32_t         execId;
4426
  SOperatorParam* pOpParam;
4427

4428
  // used for new-stream
4429
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4430
  bool                           reset;
4431
  bool                           dynTbname;
4432
  // used for new-stream
4433
} SResFetchReq;
4434

4435
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4436
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4437
void    tDestroySResFetchReq(SResFetchReq* pReq);
4438
typedef struct {
4439
  SMsgHead header;
4440
  uint64_t clientId;
4441
} SSchTasksStatusReq;
4442

4443
typedef struct {
4444
  uint64_t queryId;
4445
  uint64_t clientId;
4446
  uint64_t taskId;
4447
  int64_t  refId;
4448
  int32_t  subJobId;
4449
  int32_t  execId;
4450
  int8_t   status;
4451
} STaskStatus;
4452

4453
typedef struct {
4454
  int64_t refId;
4455
  SArray* taskStatus;  // SArray<STaskStatus>
4456
} SSchedulerStatusRsp;
4457

4458
typedef struct {
4459
  uint64_t queryId;
4460
  uint64_t taskId;
4461
  int8_t   action;
4462
} STaskAction;
4463

4464
typedef struct SQueryNodeEpId {
4465
  int32_t nodeId;  // vgId or qnodeId
4466
  SEp     ep;
4467
} SQueryNodeEpId;
4468

4469
typedef struct {
4470
  SMsgHead       header;
4471
  uint64_t       clientId;
4472
  SQueryNodeEpId epId;
4473
  SArray*        taskAction;  // SArray<STaskAction>
4474
} SSchedulerHbReq;
4475

4476
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4477
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4478
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4479

4480
typedef struct {
4481
  SQueryNodeEpId epId;
4482
  SArray*        taskStatus;  // SArray<STaskStatus>
4483
} SSchedulerHbRsp;
4484

4485
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4486
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4487
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4488

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

4499
typedef struct {
4500
  int32_t code;
4501
} STaskCancelRsp;
4502

4503
typedef struct {
4504
  SMsgHead header;
4505
  uint64_t sId;
4506
  uint64_t queryId;
4507
  uint64_t clientId;
4508
  uint64_t taskId;
4509
  int64_t  refId;
4510
  int32_t  execId;
4511
} STaskDropReq;
4512

4513
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4514
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4515

4516
typedef enum {
4517
  TASK_NOTIFY_FINISHED = 1,
4518
} ETaskNotifyType;
4519

4520
typedef struct {
4521
  SMsgHead        header;
4522
  uint64_t        sId;
4523
  uint64_t        queryId;
4524
  uint64_t        clientId;
4525
  uint64_t        taskId;
4526
  int64_t         refId;
4527
  int32_t         execId;
4528
  ETaskNotifyType type;
4529
} STaskNotifyReq;
4530

4531
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4532
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4533

4534
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4535
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4536

4537
typedef struct {
4538
  int32_t code;
4539
} STaskDropRsp;
4540

4541
#define STREAM_TRIGGER_AT_ONCE                 1
4542
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4543
#define STREAM_TRIGGER_MAX_DELAY               3
4544
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4545
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4546

4547
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4548
#define STREAM_FILL_HISTORY_ON        1
4549
#define STREAM_FILL_HISTORY_OFF       0
4550
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4551
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4552
#define STREAM_CREATE_STABLE_TRUE     1
4553
#define STREAM_CREATE_STABLE_FALSE    0
4554

4555
typedef struct SVgroupVer {
4556
  int32_t vgId;
4557
  int64_t ver;
4558
} SVgroupVer;
4559

4560
enum {
4561
  TOPIC_SUB_TYPE__DB = 1,
4562
  TOPIC_SUB_TYPE__TABLE,
4563
  TOPIC_SUB_TYPE__COLUMN,
4564
};
4565

4566
#define DEFAULT_MAX_POLL_INTERVAL  300000
4567
#define DEFAULT_SESSION_TIMEOUT    12000
4568
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4569
#define DEFAULT_MIN_POLL_ROWS      4096
4570

4571
typedef struct {
4572
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4573
  int8_t igExists;
4574
  int8_t subType;
4575
  int8_t withMeta;
4576
  char*  sql;
4577
  char   subDbName[TSDB_DB_FNAME_LEN];
4578
  char*  ast;
4579
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4580
  int8_t reload;
4581
} SCMCreateTopicReq;
4582

4583
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4584
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4585
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4586

4587
typedef struct {
4588
  int64_t consumerId;
4589
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4590

4591
typedef struct {
4592
  int64_t consumerId;
4593
  char    cgroup[TSDB_CGROUP_LEN];
4594
  char    clientId[TSDB_CLIENT_ID_LEN];
4595
  char    user[TSDB_USER_LEN];
4596
  char    fqdn[TSDB_FQDN_LEN];
4597
  SArray* topicNames;  // SArray<char**>
4598

4599
  int8_t  withTbName;
4600
  int8_t  autoCommit;
4601
  int32_t autoCommitInterval;
4602
  int8_t  resetOffsetCfg;
4603
  int8_t  enableReplay;
4604
  int8_t  enableBatchMeta;
4605
  int32_t sessionTimeoutMs;
4606
  int32_t maxPollIntervalMs;
4607
  int64_t ownerId;
4608
} SCMSubscribeReq;
16,763,228✔
4609

16,763,228✔
4610
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
16,763,228✔
4611
  int32_t tlen = 0;
16,755,385✔
4612
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
4613
  tlen += taosEncodeString(buf, pReq->cgroup);
16,763,228✔
4614
  tlen += taosEncodeString(buf, pReq->clientId);
16,763,228✔
4615

4616
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
23,500,480✔
4617
  tlen += taosEncodeFixedI32(buf, topicNum);
13,466,661✔
4618

4619
  for (int32_t i = 0; i < topicNum; i++) {
4620
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
16,771,071✔
4621
  }
16,755,385✔
4622

16,755,385✔
4623
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
16,755,385✔
4624
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
16,763,228✔
4625
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
16,763,228✔
4626
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
16,755,385✔
4627
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
16,763,228✔
4628
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
16,755,385✔
4629
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
16,763,228✔
4630
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
4631
  tlen += taosEncodeString(buf, pReq->user);
16,755,385✔
4632
  tlen += taosEncodeString(buf, pReq->fqdn);
4633

4634
  return tlen;
4635
}
8,557,334✔
4636

8,557,334✔
4637
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
8,557,334✔
4638
  void* start = buf;
8,557,334✔
4639
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
4640
  buf = taosDecodeStringTo(buf, pReq->cgroup);
8,557,334✔
4641
  buf = taosDecodeStringTo(buf, pReq->clientId);
8,557,334✔
4642

4643
  int32_t topicNum = 0;
8,557,334✔
4644
  buf = taosDecodeFixedI32(buf, &topicNum);
8,557,334✔
UNCOV
4645

×
4646
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
4647
  if (pReq->topicNames == NULL) {
12,483,687✔
4648
    return terrno;
3,926,353✔
4649
  }
3,926,353✔
4650
  for (int32_t i = 0; i < topicNum; i++) {
7,852,706✔
UNCOV
4651
    char* name = NULL;
×
4652
    buf = taosDecodeString(buf, &name);
4653
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
4654
      return terrno;
4655
    }
8,557,334✔
4656
  }
8,557,334✔
4657

8,557,334✔
4658
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
8,557,334✔
4659
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
8,557,334✔
4660
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
8,557,334✔
4661
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
8,557,334✔
4662
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
8,557,334✔
4663
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
8,557,334✔
4664
  if ((char*)buf - (char*)start < len) {
8,557,334✔
4665
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
17,114,668✔
4666
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
4667
    buf = taosDecodeStringTo(buf, pReq->user);
×
UNCOV
4668
    buf = taosDecodeStringTo(buf, pReq->fqdn);
×
4669
  } else {
4670
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
4671
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
8,557,334✔
4672
  }
4673

4674
  return 0;
4675
}
4676

4677
typedef struct {
4678
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4679
  SArray* removedConsumers;  // SArray<int64_t>
4680
  SArray* newConsumers;      // SArray<int64_t>
4681
} SMqRebInfo;
7,943,901✔
4682

7,943,901✔
UNCOV
4683
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
×
4684
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
4685
  if (pRebInfo == NULL) {
7,943,901✔
4686
    return NULL;
7,943,901✔
4687
  }
7,943,901✔
UNCOV
4688
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
×
4689
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
4690
  if (pRebInfo->removedConsumers == NULL) {
7,943,901✔
4691
    goto _err;
7,943,901✔
UNCOV
4692
  }
×
4693
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
4694
  if (pRebInfo->newConsumers == NULL) {
7,943,901✔
4695
    goto _err;
×
4696
  }
×
4697
  return pRebInfo;
×
4698
_err:
×
UNCOV
4699
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4700
  taosArrayDestroy(pRebInfo->newConsumers);
4701
  taosMemoryFreeClear(pRebInfo);
4702
  return NULL;
4703
}
4704

4705
typedef struct {
4706
  int64_t streamId;
4707
  int64_t checkpointId;
4708
  char    streamName[TSDB_STREAM_FNAME_LEN];
4709
} SMStreamDoCheckpointMsg;
4710

4711
typedef struct {
4712
  int64_t status;
4713
} SMVSubscribeRsp;
4714

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

4723
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4724
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4725
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4726

4727
typedef struct {
4728
  char    name[TSDB_TOPIC_FNAME_LEN];
4729
  int8_t  igNotExists;
4730
  int32_t sqlLen;
4731
  char*   sql;
4732
} SMReloadTopicReq;
4733

4734
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4735
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4736
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4737

4738
typedef struct {
4739
  char   topic[TSDB_TOPIC_FNAME_LEN];
4740
  char   cgroup[TSDB_CGROUP_LEN];
4741
  int8_t igNotExists;
4742
  int8_t force;
4743
} SMDropCgroupReq;
4744

4745
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4746
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4747

4748
typedef struct {
4749
  int8_t reserved;
4750
} SMDropCgroupRsp;
4751

4752
typedef struct {
4753
  char    name[TSDB_TABLE_FNAME_LEN];
4754
  int8_t  alterType;
4755
  SSchema schema;
4756
} SAlterTopicReq;
4757

4758
typedef struct {
4759
  SMsgHead head;
4760
  char     name[TSDB_TABLE_FNAME_LEN];
4761
  int64_t  tuid;
4762
  int32_t  sverson;
4763
  int32_t  execLen;
4764
  char*    executor;
4765
  int32_t  sqlLen;
4766
  char*    sql;
4767
} SDCreateTopicReq;
4768

4769
typedef struct {
4770
  SMsgHead head;
4771
  char     name[TSDB_TABLE_FNAME_LEN];
4772
  int64_t  tuid;
4773
} SDDropTopicReq;
4774

4775
typedef struct {
4776
  char*      name;
4777
  int64_t    uid;
4778
  int64_t    interval[2];
4779
  int8_t     intervalUnit;
4780
  int16_t    nFuncs;
4781
  col_id_t*  funcColIds;  // column ids specified by user
4782
  func_id_t* funcIds;     // function ids specified by user
4783
} SRSmaParam;
4784

4785
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4786
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4787

4788
// TDMT_VND_CREATE_STB ==============
4789
typedef struct SVCreateStbReq {
4790
  char*           name;
4791
  tb_uid_t        suid;
4792
  int8_t          rollup;
4793
  SSchemaWrapper  schemaRow;
4794
  SSchemaWrapper  schemaTag;
4795
  SRSmaParam      rsmaParam;
4796
  int32_t         alterOriDataLen;
4797
  void*           alterOriData;
4798
  int8_t          source;
4799
  int8_t          colCmpred;
4800
  SColCmprWrapper colCmpr;
4801
  int64_t         keep;
4802
  int64_t         ownerId;
4803
  SExtSchema*     pExtSchemas;
4804
  int8_t          virtualStb;
4805
  int8_t          secureDelete;
4806
} SVCreateStbReq;
4807

4808
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4809
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4810

4811
// TDMT_VND_DROP_STB ==============
4812
typedef struct SVDropStbReq {
4813
  char*    name;
4814
  tb_uid_t suid;
4815
} SVDropStbReq;
4816

4817
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4818
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4819

4820
// TDMT_VND_CREATE_TABLE ==============
4821
#define TD_CREATE_IF_NOT_EXISTS       0x1
4822
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4823
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4824
typedef struct SVCreateTbReq {
4825
  int32_t  flags;
4826
  char*    name;
4827
  tb_uid_t uid;
4828
  int64_t  btime;
4829
  int32_t  ttl;
4830
  int32_t  commentLen;
4831
  char*    comment;
4832
  int8_t   type;
4833
  union {
4834
    struct {
4835
      char*    stbName;  // super table name
4836
      uint8_t  tagNum;
4837
      tb_uid_t suid;
4838
      SArray*  tagName;
4839
      uint8_t* pTag;
4840
    } ctb;
4841
    struct {
4842
      SSchemaWrapper schemaRow;
4843
      int64_t        userId;
4844
    } ntb;
4845
  };
4846
  int32_t         sqlLen;
4847
  char*           sql;
4848
  SColCmprWrapper colCmpr;
4849
  SExtSchema*     pExtSchemas;
4850
  SColRefWrapper  colRef;  // col reference for virtual table
4851
} SVCreateTbReq;
4852

4853
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4854
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4855
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4856
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
2,147,483,647✔
4857

2,147,483,647✔
4858
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4859
  if (NULL == req) {
4860
    return;
1,806,025,320✔
4861
  }
1,805,939,921✔
4862

1,805,356,756✔
4863
  taosMemoryFreeClear(req->sql);
1,805,774,436✔
4864
  taosMemoryFreeClear(req->name);
1,636,621,212✔
4865
  taosMemoryFreeClear(req->comment);
1,636,225,773✔
4866
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,636,901,996✔
4867
    taosMemoryFreeClear(req->ctb.pTag);
1,635,822,928✔
4868
    taosMemoryFreeClear(req->ctb.stbName);
168,890,380✔
4869
    taosArrayDestroy(req->ctb.tagName);
168,890,380✔
4870
    req->ctb.tagName = NULL;
4871
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
1,805,037,355✔
4872
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
1,805,483,417✔
4873
  }
1,805,517,089✔
4874
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
4875
  taosMemoryFreeClear(req->pExtSchemas);
4876
  taosMemoryFreeClear(req->colRef.pColRef);
4877
}
4878

4879
typedef struct {
4880
  int32_t nReqs;
4881
  union {
4882
    SVCreateTbReq* pReqs;
4883
    SArray*        pArray;
4884
  };
4885
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4886
} SVCreateTbBatchReq;
4887

4888
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4889
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4890
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4891

4892
typedef struct {
4893
  int32_t        code;
4894
  STableMetaRsp* pMeta;
4895
} SVCreateTbRsp, SVUpdateTbRsp;
4896

4897
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4898
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4899
void tFreeSVCreateTbRsp(void* param);
4900

4901
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4902
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4903

4904
typedef struct {
4905
  int32_t nRsps;
4906
  union {
4907
    SVCreateTbRsp* pRsps;
4908
    SArray*        pArray;
4909
  };
4910
} SVCreateTbBatchRsp;
4911

4912
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4913
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4914

4915
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4916
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4917

4918
// TDMT_VND_DROP_TABLE =================
4919
typedef struct {
4920
  char*    name;
4921
  uint64_t suid;  // for tmq in wal format
4922
  int64_t  uid;
4923
  int8_t   igNotExists;
4924
  int8_t   isVirtual;
4925
} SVDropTbReq;
4926

4927
typedef struct {
4928
  int32_t code;
4929
} SVDropTbRsp;
4930

4931
typedef struct {
4932
  int32_t nReqs;
4933
  union {
4934
    SVDropTbReq* pReqs;
4935
    SArray*      pArray;
4936
  };
4937
} SVDropTbBatchReq;
4938

4939
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4940
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4941

4942
typedef struct {
4943
  int32_t nRsps;
4944
  union {
4945
    SVDropTbRsp* pRsps;
4946
    SArray*      pArray;
4947
  };
4948
} SVDropTbBatchRsp;
4949

4950
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4951
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4952

4953
// TDMT_VND_ALTER_TABLE =====================
4954
typedef struct SUpdatedTagVal {
4955
  char*    tagName;
4956
  int32_t  colId;
4957
  int8_t   tagType;
4958
  int8_t   tagFree;
4959
  uint32_t nTagVal;
4960
  uint8_t* pTagVal;
4961
  int8_t   isNull;
4962
  SArray*  pTagArray;
4963
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
4964
  // they should be replaced by a more generic solution in the future for full expression
4965
  // support
4966
  char*    regexp;
4967
  char*    replacement;
4968
} SUpdatedTagVal;
4969

4970
typedef struct SUpdateTableTagVal {
4971
  char *tbName;
4972
  SArray* tags; // Array of SUpdatedTagVal
4973
} SUpdateTableTagVal;
4974

4975
typedef struct SVAlterTbReq {
4976
  char*   tbName;
4977
  int8_t  action;
4978
  char*   colName;
4979
  int32_t colId;
4980
  // TSDB_ALTER_TABLE_ADD_COLUMN
4981
  int8_t  type;
4982
  int8_t  flags;
4983
  int32_t bytes;
4984
  // TSDB_ALTER_TABLE_DROP_COLUMN
4985
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4986
  int8_t   colModType;
4987
  int32_t  colModBytes;
4988
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4989
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4990
  int8_t   isNull;
4991
  int8_t   tagType;
4992
  int8_t   tagFree;
4993
  uint32_t nTagVal;
4994
  uint8_t* pTagVal;
4995
  SArray*  pTagArray;
4996
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4997
  int8_t   updateTTL;
4998
  int32_t  newTTL;
4999
  int32_t  newCommentLen;
5000
  char*    newComment;
5001
  int64_t  ctimeMs;    // fill by vnode
5002
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5003
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5004
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5005
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5006
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5007
  uint8_t* where;      // [where] is the encode where condition.
5008
  // for Add column
5009
  STypeMod typeMod;
5010
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5011
  char* refDbName;
5012
  char* refTbName;
5013
  char* refColName;
5014
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5015
} SVAlterTbReq;
5016

5017
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5018
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5019
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5020
void    tfreeMultiTagUpateVal(void* pMultiTag);
5021
void    tfreeUpdateTableTagVal(void* pMultiTable);
5022

5023
typedef struct {
5024
  int32_t        code;
5025
  STableMetaRsp* pMeta;
5026
} SVAlterTbRsp;
5027

5028
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5029
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5030
// ======================
5031

5032
typedef struct {
5033
  SMsgHead head;
5034
  int64_t  uid;
5035
  int32_t  tid;
5036
  int16_t  tversion;
5037
  int16_t  colId;
5038
  int8_t   type;
5039
  int16_t  bytes;
5040
  int32_t  tagValLen;
5041
  int16_t  numOfTags;
5042
  int32_t  schemaLen;
5043
  char     data[];
5044
} SUpdateTagValReq;
5045

5046
typedef struct {
5047
  SMsgHead head;
5048
} SUpdateTagValRsp;
5049

5050
typedef struct {
5051
  SMsgHead head;
5052
} SVShowTablesReq;
5053

5054
typedef struct {
5055
  SMsgHead head;
5056
  int32_t  id;
5057
} SVShowTablesFetchReq;
5058

5059
typedef struct {
5060
  int64_t useconds;
5061
  int8_t  completed;  // all results are returned to client
5062
  int8_t  precision;
5063
  int8_t  compressed;
5064
  int32_t compLen;
5065
  int32_t numOfRows;
5066
  char    data[];
5067
} SVShowTablesFetchRsp;
5068

5069
typedef struct {
5070
  int64_t consumerId;
5071
  int32_t epoch;
5072
  char    cgroup[TSDB_CGROUP_LEN];
5073
} SMqAskEpReq;
5074

5075
typedef struct {
5076
  int32_t key;
5077
  int32_t valueLen;
5078
  void*   value;
5079
} SKv;
5080

5081
typedef struct {
5082
  int64_t tscRid;
5083
  int8_t  connType;
5084
} SClientHbKey;
5085

5086
typedef struct {
5087
  int64_t tid;
5088
  char    status[TSDB_JOB_STATUS_LEN];
5089
  int64_t startTs;  // sub-task first execution start time, us
5090
} SQuerySubDesc;
5091

5092
typedef enum EQueryExecPhase {
5093
  /* Main phases: 0-9 */
5094
  QUERY_PHASE_NONE     = 0,
5095
  QUERY_PHASE_PARSE    = 1,
5096
  QUERY_PHASE_CATALOG  = 2,
5097
  QUERY_PHASE_PLAN     = 3,
5098
  QUERY_PHASE_SCHEDULE = 4,
5099
  QUERY_PHASE_EXECUTE  = 5,
5100
  QUERY_PHASE_FETCH    = 6,
5101
  QUERY_PHASE_DONE     = 7,
5102

5103
  /* SCHEDULE sub-phases: 4x */
5104
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5105
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5106
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5107

5108
  /* EXECUTE sub-phases: 5x */
5109
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5110
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5111
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5112

5113
  /* FETCH sub-phases: 6x */
5114
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5115
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5116
} EQueryExecPhase;
5117

5118
const char* queryPhaseStr(int32_t phase);
5119

5120
typedef struct {
5121
  char     sql[TSDB_SHOW_SQL_LEN];
5122
  uint64_t queryId;
5123
  int64_t  useconds;
5124
  int64_t  stime;  // timestamp precision ms
5125
  int64_t  reqRid;
5126
  bool     stableQuery;
5127
  bool     isSubQuery;
5128
  char     fqdn[TSDB_FQDN_LEN];
5129
  int32_t  subPlanNum;
5130
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5131
  int32_t  execPhase;       // EQueryExecPhase
5132
  int64_t  phaseStartTime;  // when current phase started, ms
5133
} SQueryDesc;
5134

5135
typedef struct {
5136
  uint32_t connId;
5137
  SArray*  queryDesc;  // SArray<SQueryDesc>
5138
} SQueryHbReqBasic;
5139

5140
typedef struct {
5141
  uint32_t connId;
5142
  uint64_t killRid;
5143
  int32_t  totalDnodes;
5144
  int32_t  onlineDnodes;
5145
  int8_t   killConnection;
5146
  int8_t   align[3];
5147
  SEpSet   epSet;
5148
  SArray*  pQnodeList;
5149
} SQueryHbRspBasic;
5150

5151
typedef struct SAppClusterSummary {
5152
  uint64_t numOfInsertsReq;
5153
  uint64_t numOfInsertRows;
5154
  uint64_t insertElapsedTime;
5155
  uint64_t insertBytes;  // submit to tsdb since launched.
5156

5157
  uint64_t fetchBytes;
5158
  uint64_t numOfQueryReq;
5159
  uint64_t queryElapsedTime;
5160
  uint64_t numOfSlowQueries;
5161
  uint64_t totalRequests;
5162
  uint64_t currentRequests;  // the number of SRequestObj
5163
} SAppClusterSummary;
5164

5165
typedef struct {
2,147,483,647✔
5166
  int64_t            appId;
5167
  int32_t            pid;
5168
  char               name[TSDB_APP_NAME_LEN];
1,071,791,099✔
5169
  int64_t            startTime;
2,147,483,647✔
5170
  SAppClusterSummary summary;
1,456,502,393✔
5171
} SAppHbReq;
1,456,502,393✔
5172

1,456,527,302✔
5173
typedef struct {
5174
  SClientHbKey      connKey;
1,071,872,726✔
5175
  int64_t           clusterId;
5176
  SAppHbReq         app;
711,250,298✔
5177
  SQueryHbReqBasic* query;
711,250,298✔
5178
  SHashObj*         info;  // hash<Skv.key, Skv>
711,250,298✔
5179
  char              user[TSDB_USER_LEN];
479,824,321✔
5180
  char              tokenName[TSDB_TOKEN_NAME_LEN];
479,800,401✔
5181
  char              userApp[TSDB_APP_NAME_LEN];
5182
  uint32_t          userIp;
711,202,458✔
5183
  SIpRange          userDualIp;
5184
  char              sVer[TSDB_VERSION_LEN];
1,229,771,521✔
5185
  char              cInfo[CONNECTOR_INFO_LEN];
2,147,483,647✔
5186
} SClientHbReq;
2,147,483,647✔
5187

1,229,741,023✔
5188
typedef struct {
565,041,391✔
5189
  int64_t reqId;
5190
  SArray* reqs;  // SArray<SClientHbReq>
1,229,755,559✔
5191
  int64_t ipWhiteListVer;
5192
} SClientHbBatchReq;
5193

2,147,483,647✔
5194
typedef struct {
1,071,824,472✔
5195
  SClientHbKey      connKey;
1,071,872,726✔
5196
  int32_t           status;
1,071,836,754✔
5197
  SQueryHbRspBasic* query;
5198
  SArray*           info;  // Array<Skv>
2,147,483,647✔
5199
} SClientHbRsp;
5200

5201
typedef struct {
5202
  int64_t       reqId;
5203
  int64_t       rspId;
5204
  int32_t       svrTimestamp;
518,464,183✔
5205
  SArray*       rsps;  // SArray<SClientHbRsp>
518,464,183✔
5206
  SMonitorParas monitorParas;
518,464,183✔
5207
  int8_t        enableAuditDelete;
518,464,183✔
5208
  int8_t        enableStrongPass;
5209
  int8_t        enableAuditSelect;
5210
  int8_t        enableAuditInsert;
1,451,555,944✔
5211
  int8_t        auditLevel;
1,451,555,944✔
5212
} SClientHbBatchRsp;
1,451,555,944✔
5213

1,451,553,391✔
5214
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
5215

1,451,610,040✔
5216
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5217
  void* pIter = taosHashIterate(info, NULL);
1,224,203,543✔
5218
  while (pIter != NULL) {
1,224,203,543✔
5219
    SKv* kv = (SKv*)pIter;
1,224,203,543✔
5220
    taosMemoryFreeClear(kv->value);
1,224,084,403✔
5221
    pIter = taosHashIterate(info, pIter);
1,223,842,949✔
5222
  }
5223
}
1,224,063,841✔
5224

629,054,209✔
5225
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
5226
  SQueryDesc* desc = (SQueryDesc*)pDesc;
5227
  if (desc->subDesc) {
1,009,257,618✔
5228
    taosArrayDestroy(desc->subDesc);
1,009,257,618✔
5229
    desc->subDesc = NULL;
1,009,322,294✔
5230
  }
5231
}
5232

5233
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
5234
  SClientHbReq* req = (SClientHbReq*)pReq;
5235
  if (req->query) {
5236
    if (req->query->queryDesc) {
2,147,483,647✔
5237
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
2,147,483,647✔
5238
    }
2,147,483,647✔
5239
    taosMemoryFreeClear(req->query);
2,147,483,647✔
5240
  }
5241

5242
  if (req->info) {
5243
    tFreeReqKvHash(req->info);
2,147,483,647✔
5244
    taosHashCleanup(req->info);
2,147,483,647✔
5245
    req->info = NULL;
1,423,274,385✔
5246
  }
1,423,260,792✔
UNCOV
5247
}
×
5248

5249
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
1,423,251,385✔
5250
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
1,423,248,763✔
5251

5252
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5253
  if (pReq == NULL) return;
5254
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
2,147,483,647✔
5255
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
2,147,483,647✔
5256
  taosMemoryFree(pReq);
2,147,483,647✔
5257
}
5258

5259
static FORCE_INLINE void tFreeClientKv(void* pKv) {
5260
  SKv* kv = (SKv*)pKv;
2,147,483,647✔
5261
  if (kv) {
2,147,483,647✔
5262
    taosMemoryFreeClear(kv->value);
1,195,894,499✔
5263
  }
5264
}
5265

5266
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
5267
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
5268
  if (rsp->query) {
5269
    taosArrayDestroy(rsp->query->pQnodeList);
5270
    taosMemoryFreeClear(rsp->query);
5271
  }
5272
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
5273
}
5274

5275
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5276
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
5277
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
5278
}
5279

5280
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5281
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5282
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5283

5284
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5285
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
5286
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
5287
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
5288
  return 0;
5289
}
5290

5291
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5292
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
5293
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
5294

5295
  if (pKv->valueLen < 0) {
5296
    return TSDB_CODE_INVALID_MSG;
5297
  }
5298

5299
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
5300
  if (pKv->value == NULL) {
5301
    return TSDB_CODE_OUT_OF_MEMORY;
5302
  }
5303
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
5304
  return 0;
5305
}
5306

5307
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5308
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
5309
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
5310
  return 0;
5311
}
5312

5313
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5314
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
5315
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
5316
  return 0;
5317
}
5318

5319
typedef struct {
5320
  int32_t vgId;
5321
  // TODO stas
5322
} SMqReportVgInfo;
5323

5324
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5325
  int32_t tlen = 0;
5326
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5327
  return tlen;
5328
}
5329

5330
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5331
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5332
  return buf;
5333
}
5334

5335
typedef struct {
5336
  int32_t epoch;
5337
  int64_t topicUid;
5338
  char    name[TSDB_TOPIC_FNAME_LEN];
5339
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5340
} SMqTopicInfo;
5341

5342
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5343
  int32_t tlen = 0;
5344
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5345
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5346
  tlen += taosEncodeString(buf, pTopicInfo->name);
5347
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5348
  tlen += taosEncodeFixedI32(buf, sz);
5349
  for (int32_t i = 0; i < sz; i++) {
5350
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5351
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5352
  }
5353
  return tlen;
5354
}
5355

5356
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5357
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5358
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5359
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5360
  int32_t sz;
5361
  buf = taosDecodeFixedI32(buf, &sz);
5362
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5363
    return NULL;
5364
  }
5365
  for (int32_t i = 0; i < sz; i++) {
5366
    SMqReportVgInfo vgInfo;
5367
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5368
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5369
      return NULL;
5370
    }
5371
  }
5372
  return buf;
5373
}
5374

5375
typedef struct {
5376
  int32_t status;  // ask hb endpoint
5377
  int32_t epoch;
5378
  int64_t consumerId;
5379
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5380
} SMqReportReq;
5381

5382
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5383
  int32_t tlen = 0;
5384
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5385
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5386
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5387
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5388
  tlen += taosEncodeFixedI32(buf, sz);
5389
  for (int32_t i = 0; i < sz; i++) {
5390
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5391
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5392
  }
5393
  return tlen;
5394
}
5395

5396
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5397
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5398
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5399
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5400
  int32_t sz;
5401
  buf = taosDecodeFixedI32(buf, &sz);
5402
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5403
    return NULL;
5404
  }
5405
  for (int32_t i = 0; i < sz; i++) {
5406
    SMqTopicInfo topicInfo;
5407
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5408
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5409
      return NULL;
5410
    }
5411
  }
5412
  return buf;
5413
}
5414

5415
typedef struct {
5416
  SMsgHead head;
5417
  int64_t  leftForVer;
5418
  int32_t  vgId;
5419
  int64_t  consumerId;
5420
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5421
} SMqVDeleteReq;
5422

5423
typedef struct {
5424
  int8_t reserved;
5425
} SMqVDeleteRsp;
5426

5427
typedef struct {
5428
  char**  name;
5429
  int32_t count;
5430
  int8_t  igNotExists;
5431
} SMDropStreamReq;
5432

5433
typedef struct {
5434
  int8_t reserved;
5435
} SMDropStreamRsp;
5436

5437
typedef struct {
5438
  SMsgHead head;
5439
  int64_t  resetRelHalt;  // reset related stream task halt status
5440
  int64_t  streamId;
5441
  int32_t  taskId;
5442
} SVDropStreamTaskReq;
5443

5444
typedef struct {
5445
  int8_t reserved;
5446
} SVDropStreamTaskRsp;
5447

5448
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5449
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5450
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5451

5452
typedef struct {
5453
  char*  name;
5454
  int8_t igNotExists;
5455
} SMPauseStreamReq;
5456

5457
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5458
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5459
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5460

5461
typedef struct {
5462
  char*  name;
5463
  int8_t igNotExists;
5464
  int8_t igUntreated;
5465
} SMResumeStreamReq;
5466

5467
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5468
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5469
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5470

5471
typedef struct {
5472
  char*       name;
5473
  int8_t      calcAll;
5474
  STimeWindow timeRange;
5475
} SMRecalcStreamReq;
5476

5477
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5478
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5479
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5480

5481
typedef struct SVndSetKeepVersionReq {
5482
  int64_t keepVersion;
5483
} SVndSetKeepVersionReq;
5484

5485
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5486
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5487

5488
typedef struct SVUpdateCheckpointInfoReq {
5489
  SMsgHead head;
5490
  int64_t  streamId;
5491
  int32_t  taskId;
5492
  int64_t  checkpointId;
5493
  int64_t  checkpointVer;
5494
  int64_t  checkpointTs;
5495
  int32_t  transId;
5496
  int64_t  hStreamId;  // add encode/decode
5497
  int64_t  hTaskId;
5498
  int8_t   dropRelHTask;
5499
} SVUpdateCheckpointInfoReq;
189,473,563✔
5500

189,422,710✔
5501
typedef struct {
189,458,360✔
5502
  int64_t        leftForVer;
189,422,595✔
5503
  int32_t        vgId;
7,222✔
5504
  int64_t        oldConsumerId;
5505
  int64_t        newConsumerId;
189,398,859✔
5506
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
189,428,736✔
5507
  int8_t         subType;
5508
  int8_t         withMeta;
5509
  char*          qmsg;  // SubPlanToString
1,145,193✔
5510
  SSchemaWrapper schema;
1,145,193✔
5511
  int64_t        suid;
1,138,684✔
5512
} SMqRebVgReq;
5513

5514
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
700,501,777✔
5515
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
700,487,402✔
5516

700,493,129✔
5517
// tqOffset
5518
enum {
5519
  TMQ_OFFSET__RESET_NONE = -3,
5520
  TMQ_OFFSET__RESET_EARLIEST = -2,
5521
  TMQ_OFFSET__RESET_LATEST = -1,
5522
  TMQ_OFFSET__LOG = 1,
5523
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5524
  TMQ_OFFSET__SNAPSHOT_META = 3,
5525
};
5526

5527
enum {
5528
  WITH_DATA = 0,
5529
  WITH_META = 1,
5530
  ONLY_META = 2,
5531
};
5532

5533
#define TQ_OFFSET_VERSION 1
5534

5535
typedef struct {
5536
  int8_t type;
5537
  union {
5538
    // snapshot
5539
    struct {
5540
      int64_t uid;
5541
      int64_t ts;
5542
      SValue  primaryKey;
5543
    };
5544
    // log
5545
    struct {
5546
      int64_t version;
5547
    };
5548
  };
5549
} STqOffsetVal;
5550

5551
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5552
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
5553
  pOffsetVal->uid = uid;
5554
  pOffsetVal->ts = ts;
5555
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
5556
    taosMemoryFree(pOffsetVal->primaryKey.pData);
5557
  }
5558
  pOffsetVal->primaryKey = primaryKey;
5559
}
5560

5561
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5562
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
5563
  pOffsetVal->uid = uid;
5564
}
5565

5566
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5567
  pOffsetVal->type = TMQ_OFFSET__LOG;
5568
  pOffsetVal->version = ver;
5569
}
5570

5571
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5572
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5573
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5574
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5575
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5576
void    tOffsetDestroy(void* pVal);
5577

5578
typedef struct {
5579
  STqOffsetVal val;
5580
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5581
} STqOffset;
5582

5583
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5584
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5585
void    tDeleteSTqOffset(void* val);
5586

5587
typedef struct SMqVgOffset {
5588
  int64_t   consumerId;
5589
  STqOffset offset;
5590
} SMqVgOffset;
5591

5592
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5593
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5594

5595
typedef struct {
5596
  char    name[TSDB_TABLE_FNAME_LEN];
5597
  char    stb[TSDB_TABLE_FNAME_LEN];
5598
  int8_t  igExists;
5599
  int8_t  intervalUnit;
5600
  int8_t  slidingUnit;
5601
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5602
  int32_t dstVgId;   // for stream
5603
  int64_t interval;
5604
  int64_t offset;
5605
  int64_t sliding;
5606
  int64_t maxDelay;
5607
  int64_t watermark;
5608
  int32_t exprLen;        // strlen + 1
5609
  int32_t tagsFilterLen;  // strlen + 1
5610
  int32_t sqlLen;         // strlen + 1
5611
  int32_t astLen;         // strlen + 1
5612
  char*   expr;
5613
  char*   tagsFilter;
5614
  char*   sql;
5615
  char*   ast;
5616
  int64_t deleteMark;
5617
  int64_t lastTs;
5618
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5619
  SArray* pVgroupVerList;
5620
  int8_t  recursiveTsma;
5621
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5622
  char*   createStreamReq;
5623
  int32_t streamReqLen;
5624
  char*   dropStreamReq;
5625
  int32_t dropStreamReqLen;
5626
  int64_t uid;
5627
} SMCreateSmaReq;
5628

5629
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5630
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5631
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5632

5633
typedef struct {
5634
  char    name[TSDB_TABLE_FNAME_LEN];
5635
  int8_t  igNotExists;
5636
  char*   dropStreamReq;
5637
  int32_t dropStreamReqLen;
5638
} SMDropSmaReq;
5639

5640
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5641
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5642
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5643

5644
typedef struct {
5645
  char name[TSDB_TABLE_NAME_LEN];
5646
  union {
5647
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5648
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5649
  };
5650
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5651
  union {
5652
    int8_t igExists;   // used by mnode
5653
    int8_t alterType;  // used by vnode
5654
  };
5655
  int8_t     intervalUnit;
5656
  int16_t    nFuncs;       // number of functions specified by user
5657
  col_id_t*  funcColIds;   // column ids specified by user
5658
  func_id_t* funcIds;      // function ids specified by user
5659
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5660
  int64_t    tbUid;
5661
  int64_t    uid;     // rsma uid
5662
  int32_t    sqlLen;  // strlen + 1
5663
  char*      sql;
5664
} SMCreateRsmaReq;
5665

5666
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5667
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5668
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5669

5670
typedef SMCreateRsmaReq SVCreateRsmaReq;
5671

5672
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5673
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5674
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5675

5676
typedef SMCreateRsmaReq SVAlterRsmaReq;
5677

5678
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5679
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5680
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5681

5682
typedef struct {
5683
  char       name[TSDB_TABLE_NAME_LEN];
5684
  int8_t     alterType;
5685
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5686
  int8_t     igNotExists;
5687
  int16_t    nFuncs;      // number of functions specified by user
5688
  col_id_t*  funcColIds;  // column ids specified by user
5689
  func_id_t* funcIds;     // function ids specified by user
5690
  int32_t    sqlLen;      // strlen + 1
5691
  char*      sql;
5692
} SMAlterRsmaReq;
5693

5694
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5695
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5696
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5697

5698
typedef struct {
5699
  int64_t    id;
5700
  char       name[TSDB_TABLE_NAME_LEN];
5701
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5702
  int64_t    ownerId;
5703
  int32_t    code;
5704
  int32_t    version;
5705
  int8_t     tbType;
5706
  int8_t     intervalUnit;
5707
  col_id_t   nFuncs;
5708
  col_id_t   nColNames;
5709
  int64_t    interval[2];
5710
  col_id_t*  funcColIds;
5711
  func_id_t* funcIds;
5712
  SArray*    colNames;
5713
} SRsmaInfoRsp;
5714

5715
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5716
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5717
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5718

5719
typedef struct {
5720
  char   name[TSDB_TABLE_FNAME_LEN];
5721
  int8_t igNotExists;
5722
} SMDropRsmaReq;
5723

5724
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5725
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5726

5727
typedef struct {
5728
  char    name[TSDB_TABLE_NAME_LEN];
5729
  char    tbName[TSDB_TABLE_NAME_LEN];
5730
  int64_t uid;
5731
  int64_t tbUid;
5732
  int8_t  tbType;
5733
} SVDropRsmaReq;
5734

5735
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5736
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5737

5738
typedef struct {
5739
  char   dbFName[TSDB_DB_FNAME_LEN];
5740
  char   stbName[TSDB_TABLE_NAME_LEN];
5741
  char   colName[TSDB_COL_NAME_LEN];
5742
  char   idxName[TSDB_INDEX_FNAME_LEN];
5743
  int8_t idxType;
5744
} SCreateTagIndexReq;
5745

5746
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5747
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5748

5749
typedef SMDropSmaReq SDropTagIndexReq;
5750

5751
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5752
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5753

5754
typedef struct {
5755
  int8_t         version;       // for compatibility(default 0)
5756
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5757
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
UNCOV
5758
  int8_t         timezoneInt;   // sma data expired if timezone changes.
×
UNCOV
5759
  int32_t        dstVgId;
×
UNCOV
5760
  char           indexName[TSDB_INDEX_NAME_LEN];
×
UNCOV
5761
  int32_t        exprLen;
×
5762
  int32_t        tagsFilterLen;
UNCOV
5763
  int64_t        indexUid;
×
5764
  tb_uid_t       tableUid;  // super/child/common table uid
5765
  tb_uid_t       dstTbUid;  // for dstVgroup
UNCOV
5766
  int64_t        interval;
×
UNCOV
5767
  int64_t        offset;  // use unit by precision of DB
×
UNCOV
5768
  int64_t        sliding;
×
UNCOV
5769
  char*          dstTbName;  // for dstVgroup
×
UNCOV
5770
  char*          expr;       // sma expression
×
5771
  char*          tagsFilter;
5772
  SSchemaWrapper schemaRow;  // for dstVgroup
UNCOV
5773
  SSchemaWrapper schemaTag;  // for dstVgroup
×
5774
} STSma;                     // Time-range-wise SMA
5775

UNCOV
5776
typedef STSma SVCreateTSmaReq;
×
5777

5778
typedef struct {
UNCOV
5779
  int8_t  type;  // 0 status report, 1 update data
×
UNCOV
5780
  int64_t indexUid;
×
UNCOV
5781
  int64_t skey;  // start TS key of interval/sliding window
×
5782
} STSmaMsg;
5783

5784
typedef struct {
5785
  int64_t indexUid;
5786
  char    indexName[TSDB_INDEX_NAME_LEN];
5787
} SVDropTSmaReq;
5788

5789
typedef struct {
UNCOV
5790
  int tmp;  // TODO: to avoid compile error
×
UNCOV
5791
} SVCreateTSmaRsp, SVDropTSmaRsp;
×
5792

×
5793
#if 0
×
5794
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5795
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
×
5796
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5797
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
UNCOV
5798
#endif
×
UNCOV
5799

×
5800
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
×
5801
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
×
5802
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5803
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
×
5804

5805
typedef struct {
5806
  int32_t number;
5807
  STSma*  tSma;
5808
} STSmaWrapper;
5809

5810
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5811
  if (pSma) {
5812
    taosMemoryFreeClear(pSma->dstTbName);
5813
    taosMemoryFreeClear(pSma->expr);
5814
    taosMemoryFreeClear(pSma->tagsFilter);
5815
  }
5816
}
5817

5818
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5819
  if (pSW) {
5820
    if (pSW->tSma) {
5821
      if (deepCopy) {
5822
        for (uint32_t i = 0; i < pSW->number; ++i) {
5823
          tDestroyTSma(pSW->tSma + i);
5824
        }
5825
      }
5826
      taosMemoryFreeClear(pSW->tSma);
5827
    }
5828
  }
5829
}
5830

5831
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5832
  tDestroyTSmaWrapper(pSW, deepCopy);
5833
  taosMemoryFreeClear(pSW);
5834
  return NULL;
5835
}
5836

5837
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5838
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5839

5840
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5841
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5842

5843
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
5844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
5845
  for (int32_t i = 0; i < pReq->number; ++i) {
5846
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
5847
  }
5848
  return 0;
5849
}
5850

5851
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
5852
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
5853
  for (int32_t i = 0; i < pReq->number; ++i) {
5854
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
5855
  }
5856
  return 0;
5857
}
5858

5859
typedef struct {
5860
  int idx;
5861
} SMCreateFullTextReq;
5862

5863
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5864
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5865
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5866

5867
typedef struct {
5868
  char   name[TSDB_TABLE_FNAME_LEN];
5869
  int8_t igNotExists;
5870
} SMDropFullTextReq;
5871

5872
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5873
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5874

5875
typedef struct {
5876
  char indexFName[TSDB_INDEX_FNAME_LEN];
5877
} SUserIndexReq;
5878

5879
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5880
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5881

5882
typedef struct {
5883
  char dbFName[TSDB_DB_FNAME_LEN];
5884
  char tblFName[TSDB_TABLE_FNAME_LEN];
5885
  char colName[TSDB_COL_NAME_LEN];
5886
  char owner[TSDB_USER_LEN];
5887
  char indexType[TSDB_INDEX_TYPE_LEN];
5888
  char indexExts[TSDB_INDEX_EXTS_LEN];
5889
} SUserIndexRsp;
5890

5891
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5892
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5893

5894
typedef struct {
5895
  char tbFName[TSDB_TABLE_FNAME_LEN];
5896
} STableIndexReq;
5897

5898
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5899
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5900

5901
typedef struct {
5902
  int8_t  intervalUnit;
5903
  int8_t  slidingUnit;
5904
  int64_t interval;
5905
  int64_t offset;
5906
  int64_t sliding;
5907
  int64_t dstTbUid;
5908
  int32_t dstVgId;
5909
  SEpSet  epSet;
5910
  char*   expr;
5911
} STableIndexInfo;
5912

5913
typedef struct {
56,743,944✔
5914
  char     tbName[TSDB_TABLE_NAME_LEN];
56,743,944✔
5915
  char     dbFName[TSDB_DB_FNAME_LEN];
56,743,944✔
5916
  uint64_t suid;
56,743,944✔
5917
  int32_t  version;
56,743,944✔
5918
  int32_t  indexSize;
5919
  SArray*  pIndex;  // STableIndexInfo
5920
} STableIndexRsp;
5921

28,075,111✔
5922
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
28,075,111✔
5923
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
28,075,111✔
5924
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
28,075,111✔
5925

5926
void tFreeSTableIndexInfo(void* pInfo);
5927

5928
typedef struct {
5929
  int8_t  mqMsgType;
5930
  int32_t code;
5931
  int32_t epoch;
5932
  int64_t consumerId;
5933
  int64_t walsver;
5934
  int64_t walever;
5935
} SMqRspHead;
5936

5937
typedef struct {
5938
  SMsgHead     head;
5939
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5940
  int8_t       withTbName;
5941
  int8_t       useSnapshot;
5942
  int32_t      epoch;
5943
  uint64_t     reqId;
5944
  int64_t      consumerId;
5945
  int64_t      timeout;
5946
  STqOffsetVal reqOffset;
5947
  int8_t       enableReplay;
5948
  int8_t       sourceExcluded;
5949
  int8_t       rawData;
5950
  int32_t      minPollRows;
5951
  int8_t       enableBatchMeta;
5952
  SHashObj*    uidHash;  // to find if uid is duplicated
5953
} SMqPollReq;
5954

5955
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5956
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5957
void    tDestroySMqPollReq(SMqPollReq* pReq);
5958

5959
typedef struct {
5960
  int32_t vgId;
5961
  int64_t offset;
5962
  SEpSet  epSet;
5963
} SMqSubVgEp;
5964

5965
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5966
  int32_t tlen = 0;
5967
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
5968
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
5969
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
5970
  return tlen;
5971
}
5972

5973
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5974
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
5975
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
5976
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
5977
  return buf;
5978
}
5979

5980
typedef struct {
5981
  char    topic[TSDB_TOPIC_FNAME_LEN];
5982
  char    db[TSDB_DB_FNAME_LEN];
5983
  SArray* vgs;  // SArray<SMqSubVgEp>
5984
} SMqSubTopicEp;
5985

5986
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5987
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5988
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5989

5990
typedef struct {
5991
  SMqRspHead   head;
5992
  STqOffsetVal rspOffset;
5993
  int16_t      resMsgType;
5994
  int32_t      metaRspLen;
5995
  void*        metaRsp;
5996
} SMqMetaRsp;
5997

5998
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5999
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6000
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6001

6002
#define MQ_DATA_RSP_VERSION 100
6003

6004
typedef struct {
6005
  SMqRspHead   head;
6006
  STqOffsetVal rspOffset;
6007
  STqOffsetVal reqOffset;
6008
  int32_t      blockNum;
6009
  int8_t       withTbName;
6010
  int8_t       withSchema;
6011
  SArray*      blockDataLen;
6012
  SArray*      blockData;
176,745,179✔
6013
  SArray*      blockTbName;
6014
  SArray*      blockSchema;
176,745,179✔
6015

176,752,999✔
6016
  union {
221,098,747✔
6017
    struct {
44,386,504✔
6018
      int64_t sleepTime;
44,386,504✔
6019
    };
6020
    struct {
176,712,243✔
6021
      int32_t createTableNum;
6022
      SArray* createTableLen;
176,728,320✔
6023
      SArray* createTableReq;
6024
    };
6025
    struct {
6026
      int32_t len;
6027
      void*   rawData;
80,865,723✔
6028
    };
82,686,081✔
6029
  };
82,686,081✔
6030
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
82,694,568✔
UNCOV
6031
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
×
6032
  bool  timeout;
6033
} SMqDataRsp;
104,808,930✔
6034

21,782,610✔
6035
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
22,114,362✔
6036
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
22,114,362✔
UNCOV
6037
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
×
6038
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6039
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
44,228,724✔
UNCOV
6040

×
6041
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6042
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6043
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
82,694,568✔
6044

6045
typedef struct SMqBatchMetaRsp {
82,694,568✔
6046
  SMqRspHead   head;  // not serialize
6047
  STqOffsetVal rspOffset;
6048
  SArray*      batchMetaLen;
6049
  SArray*      batchMetaReq;
229,525,740✔
6050
  void*        pMetaBuff;    // not serialize
229,476,359✔
6051
  uint32_t     metaBuffLen;  // not serialize
6052
} SMqBatchMetaRsp;
6053

6054
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6055
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6056
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6057
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6058

6059
typedef struct {
6060
  int32_t code;
6061
  SArray* topics;  // SArray<SMqSubTopicEp>
6062
} SMqAskEpRsp;
6063

6064
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6065
  int32_t tlen = 0;
6066
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6067
  int32_t sz = taosArrayGetSize(pRsp->topics);
6068
  tlen += taosEncodeFixedI32(buf, sz);
6069
  for (int32_t i = 0; i < sz; i++) {
6070
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6071
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6072
  }
6073
  tlen += taosEncodeFixedI32(buf, pRsp->code);
6074

6075
  return tlen;
6076
}
6077

6078
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6079
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6080
  int32_t sz;
6081
  buf = taosDecodeFixedI32(buf, &sz);
6082
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
6083
  if (pRsp->topics == NULL) {
6084
    return NULL;
6085
  }
6086
  for (int32_t i = 0; i < sz; i++) {
6087
    SMqSubTopicEp topicEp;
6088
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
6089
    if (buf == NULL) {
6090
      return NULL;
6091
    }
6092
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6093
      return NULL;
6094
    }
6095
  }
6096
  buf = taosDecodeFixedI32(buf, &pRsp->code);
6097

6098
  return buf;
6099
}
6100

6101
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6102
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
6103
}
6104

6105
typedef struct {
6106
  int32_t      vgId;
6107
  STqOffsetVal offset;
6108
  int64_t      rows;
6109
  int64_t      ever;
6110
} OffsetRows;
6111

6112
typedef struct {
6113
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6114
  SArray* offsetRows;
6115
} TopicOffsetRows;
6116

6117
typedef struct {
6118
  int64_t consumerId;
6119
  int32_t epoch;
6120
  SArray* topics;
6121
  int8_t  pollFlag;
6122
} SMqHbReq;
6123

6124
typedef struct {
6125
  char   topic[TSDB_TOPIC_FNAME_LEN];
6126
  int8_t noPrivilege;
6127
} STopicPrivilege;
6128

6129
typedef struct {
6130
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6131
  int32_t debugFlag;
6132
} SMqHbRsp;
6133

6134
typedef struct {
6135
  SMsgHead head;
6136
  int64_t  consumerId;
6137
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6138
} SMqSeekReq;
6139

6140
#define TD_AUTO_CREATE_TABLE 0x1
6141
typedef struct {
6142
  int64_t       suid;
6143
  int64_t       uid;
6144
  int32_t       sver;
6145
  uint32_t      nData;
6146
  uint8_t*      pData;
6147
  SVCreateTbReq cTbReq;
6148
} SVSubmitBlk;
6149

6150
typedef struct {
6151
  SMsgHead header;
6152
  uint64_t sId;
6153
  uint64_t queryId;
6154
  uint64_t clientId;
6155
  uint64_t taskId;
6156
  uint32_t sqlLen;
6157
  uint32_t phyLen;
6158
  char*    sql;
6159
  char*    msg;
6160
  int8_t   source;
6161
  int8_t   secureDelete;
6162
} SVDeleteReq;
6163

6164
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6165
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6166

6167
typedef struct {
6168
  int64_t affectedRows;
6169
} SVDeleteRsp;
6170

6171
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6172
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6173

6174
typedef struct SDeleteRes {
6175
  uint64_t suid;
6176
  SArray*  uidList;
6177
  int64_t  skey;
6178
  int64_t  ekey;
6179
  int64_t  affectedRows;
6180
  char     tableFName[TSDB_TABLE_NAME_LEN];
6181
  char     tsColName[TSDB_COL_NAME_LEN];
6182
  int64_t  ctimeMs;  // fill by vnode
6183
  int8_t   source;
6184
  int8_t   secureDelete;  // force physical overwrite
2,147,483,647✔
6185
} SDeleteRes;
2,147,483,647✔
UNCOV
6186

×
6187
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6188
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
2,147,483,647✔
6189

2,147,483,647✔
6190
typedef struct {
6191
  // int64_t uid;
6192
  char    tbname[TSDB_TABLE_NAME_LEN];
6193
  int64_t startTs;
6194
  int64_t endTs;
6195
} SSingleDeleteReq;
2,147,483,647✔
6196

2,147,483,647✔
UNCOV
6197
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
×
6198
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6199

6200
typedef struct {
2,147,483,647✔
6201
  int64_t suid;
2,147,483,647✔
6202
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6203
  int64_t ctimeMs;     // fill by vnode
6204
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6205
} SBatchDeleteReq;
6206

6207
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6208
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6209
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6210

6211
typedef struct {
6212
  int32_t msgIdx;
6213
  int32_t msgType;
6214
  int32_t msgLen;
6215
  void*   msg;
6216
} SBatchMsg;
6217

6218
typedef struct {
6219
  SMsgHead header;
6220
  SArray*  pMsgs;  // SArray<SBatchMsg>
6221
} SBatchReq;
6222

6223
typedef struct {
6224
  int32_t reqType;
6225
  int32_t msgIdx;
6226
  int32_t msgLen;
6227
  int32_t rspCode;
6228
  void*   msg;
6229
} SBatchRspMsg;
6230

6231
typedef struct {
6232
  SArray* pRsps;  // SArray<SBatchRspMsg>
6233
} SBatchRsp;
6234

6235
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6236
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6237
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6238
  if (NULL == msg) {
6239
    return;
6240
  }
6241
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6242
  taosMemoryFree(pMsg->msg);
6243
}
6244

6245
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6246
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6247

6248
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
6249
  if (NULL == p) {
6250
    return;
6251
  }
6252

6253
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
6254
  taosMemoryFree(pRsp->msg);
6255
}
6256

6257
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6258
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6259
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6260
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6261
void    tDestroySMqHbReq(SMqHbReq* pReq);
6262

6263
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6264
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6265
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6266

6267
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6268
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6269

6270
#define TD_REQ_FROM_APP               0x0
6271
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6272
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6273
#define SUBMIT_REQ_FROM_FILE          0x4
6274
#define TD_REQ_FROM_TAOX              0x8
6275
#define TD_REQ_FROM_SML               0x10
6276
#define SUBMIT_REQUEST_VERSION        (2)
6277
#define SUBMIT_REQ_WITH_BLOB          0x10
6278
#define SUBMIT_REQ_SCHEMA_RES         0x20
6279
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6280

6281
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6282

6283
typedef struct {
6284
  int32_t        flags;
6285
  SVCreateTbReq* pCreateTbReq;
6286
  int64_t        suid;
6287
  int64_t        uid;
6288
  int32_t        sver;
6289
  union {
6290
    SArray* aRowP;
6291
    SArray* aCol;
6292
  };
6293
  int64_t   ctimeMs;
6294
  SBlobSet* pBlobSet;
6295
} SSubmitTbData;
6296

6297
typedef struct {
6298
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6299
  SArray* aSubmitBlobData;
6300
  bool    raw;
6301
} SSubmitReq2;
6302

6303
typedef struct {
6304
  SMsgHead header;
6305
  int64_t  version;
6306
  char     data[];  // SSubmitReq2
6307
} SSubmitReq2Msg;
6308

6309
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6310
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6311
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6312
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6313
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6314

6315
typedef struct {
6316
  int32_t affectedRows;
6317
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6318
} SSubmitRsp2;
6319

6320
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6321
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6322
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6323

6324
#define TSDB_MSG_FLG_ENCODE 0x1
6325
#define TSDB_MSG_FLG_DECODE 0x2
6326
#define TSDB_MSG_FLG_CMPT   0x3
6327

6328
typedef struct {
6329
  union {
6330
    struct {
6331
      void*   msgStr;
6332
      int32_t msgLen;
6333
      int64_t ver;
6334
    };
6335
    void* pDataBlock;
6336
  };
6337
} SPackedData;
6338

6339
typedef struct {
6340
  char     fullname[TSDB_VIEW_FNAME_LEN];
6341
  char     name[TSDB_VIEW_NAME_LEN];
6342
  char     dbFName[TSDB_DB_FNAME_LEN];
6343
  char*    querySql;
6344
  char*    sql;
6345
  int8_t   orReplace;
6346
  int8_t   precision;
6347
  int32_t  numOfCols;
6348
  SSchema* pSchema;
6349
} SCMCreateViewReq;
6350

6351
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6352
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6353
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6354

6355
typedef struct {
6356
  char   fullname[TSDB_VIEW_FNAME_LEN];
6357
  char   name[TSDB_VIEW_NAME_LEN];
6358
  char   dbFName[TSDB_DB_FNAME_LEN];
6359
  char*  sql;
6360
  int8_t igNotExists;
6361
} SCMDropViewReq;
6362

6363
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6364
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6365
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6366

6367
typedef struct {
6368
  char fullname[TSDB_VIEW_FNAME_LEN];
6369
} SViewMetaReq;
6370
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6371
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6372

6373
typedef struct {
6374
  char     name[TSDB_VIEW_NAME_LEN];
6375
  char     dbFName[TSDB_DB_FNAME_LEN];
6376
  char*    createUser;
6377
  int64_t  ownerId;
6378
  uint64_t dbId;
6379
  uint64_t viewId;
6380
  char*    querySql;
6381
  int8_t   precision;
6382
  int8_t   type;
6383
  int32_t  version;
6384
  int32_t  numOfCols;
6385
  SSchema* pSchema;
6386
} SViewMetaRsp;
6387
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6388
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6389
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6390
typedef struct {
6391
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6392
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6393
} STableTSMAInfoReq;
6394

6395
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6396
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6397

6398
typedef struct {
6399
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6400
  union {
6401
    uint8_t flags;
6402
    struct {
6403
      uint8_t withColName : 1;
6404
      uint8_t reserved : 7;
6405
    };
6406
  };
6407

6408
} SRsmaInfoReq;
6409

6410
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6411
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6412

6413
typedef struct {
6414
  int32_t  funcId;
6415
  col_id_t colId;
6416
} STableTSMAFuncInfo;
6417

6418
typedef struct {
6419
  char     name[TSDB_TABLE_NAME_LEN];
6420
  uint64_t tsmaId;
6421
  char     targetTb[TSDB_TABLE_NAME_LEN];
6422
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6423
  char     tb[TSDB_TABLE_NAME_LEN];
6424
  char     dbFName[TSDB_DB_FNAME_LEN];
6425
  uint64_t suid;
6426
  uint64_t destTbUid;
6427
  uint64_t dbId;
6428
  int32_t  version;
6429
  int64_t  interval;
6430
  int8_t   unit;
6431
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6432
  SArray*  pTags;      // SArray<SSchema>
6433
  SArray*  pUsedCols;  // SArray<SSchema>
6434
  char*    ast;
6435

6436
  int64_t streamUid;
6437
  int64_t reqTs;
6438
  int64_t rspTs;
6439
  int64_t delayDuration;  // ms
6440
  bool    fillHistoryFinished;
6441

6442
  void* streamAddr;  // for stream task, the address of the stream task
6443
} STableTSMAInfo;
6444

6445
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6446
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6447
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6448
void    tFreeTableTSMAInfo(void* p);
6449
void    tFreeAndClearTableTSMAInfo(void* p);
6450
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6451

6452
#define STSMAHbRsp            STableTSMAInfoRsp
6453
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6454
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6455
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6456

6457
typedef struct SDropCtbWithTsmaSingleVgReq {
6458
  SVgroupInfo vgInfo;
6459
  SArray*     pTbs;  // SVDropTbReq
6460
} SMDropTbReqsOnSingleVg;
6461

6462
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6463
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6464
void    tFreeSMDropTbReqOnSingleVg(void* p);
6465

6466
typedef struct SDropTbsReq {
6467
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6468
} SMDropTbsReq;
6469

6470
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6471
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6472
void    tFreeSMDropTbsReq(void*);
6473

6474
typedef struct SVFetchTtlExpiredTbsRsp {
6475
  SArray* pExpiredTbs;  // SVDropTbReq
6476
  int32_t vgId;
6477
} SVFetchTtlExpiredTbsRsp;
6478

6479
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6480
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6481

6482
void tFreeFetchTtlExpiredTbsRsp(void* p);
6483

6484
void setDefaultOptionsForField(SFieldWithOptions* field);
6485
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6486

6487
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6488
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6489

6490
typedef struct {
6491
  char    id[TSDB_INSTANCE_ID_LEN];
6492
  char    type[TSDB_INSTANCE_TYPE_LEN];
6493
  char    desc[TSDB_INSTANCE_DESC_LEN];
6494
  int32_t expire;
6495
} SInstanceRegisterReq;
6496

6497
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6498
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6499

6500
typedef struct {
6501
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6502
} SInstanceListReq;
6503

6504
typedef struct {
6505
  int32_t count;
6506
  char**  ids;  // Array of instance IDs
6507
} SInstanceListRsp;
6508

6509
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6510
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6511
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6512
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6513

6514
#ifdef USE_MOUNT
6515
typedef struct {
6516
  char     mountName[TSDB_MOUNT_NAME_LEN];
6517
  int8_t   ignoreExist;
6518
  int16_t  nMounts;
6519
  int32_t* dnodeIds;
6520
  char**   mountPaths;
6521
  int32_t  sqlLen;
6522
  char*    sql;
6523
} SCreateMountReq;
6524

6525
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6526
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6527
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6528

6529
typedef struct {
6530
  char    mountName[TSDB_MOUNT_NAME_LEN];
6531
  int8_t  ignoreNotExists;
6532
  int32_t sqlLen;
6533
  char*   sql;
6534
} SDropMountReq;
6535

6536
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6537
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6538
void    tFreeSDropMountReq(SDropMountReq* pReq);
6539

6540
typedef struct {
6541
  char     mountName[TSDB_MOUNT_NAME_LEN];
6542
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6543
  int64_t  mountUid;
6544
  int32_t  dnodeId;
6545
  uint32_t valLen;
6546
  int8_t   ignoreExist;
6547
  void*    pVal;
6548
} SRetrieveMountPathReq;
6549

6550
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6551
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6552

6553
typedef struct {
6554
  // path
6555
  int32_t diskPrimary;
6556
  // vgInfo
6557
  int32_t  vgId;
6558
  int32_t  cacheLastSize;
6559
  int32_t  szPage;
6560
  int32_t  szCache;
6561
  uint64_t szBuf;
6562
  int8_t   cacheLast;
6563
  int8_t   standby;
6564
  int8_t   hashMethod;
6565
  uint32_t hashBegin;
6566
  uint32_t hashEnd;
6567
  int16_t  hashPrefix;
6568
  int16_t  hashSuffix;
6569
  int16_t  sttTrigger;
6570
  // syncInfo
6571
  int32_t replications;
6572
  // tsdbInfo
6573
  int8_t  precision;
6574
  int8_t  compression;
6575
  int8_t  slLevel;
6576
  int32_t daysPerFile;
6577
  int32_t keep0;
6578
  int32_t keep1;
6579
  int32_t keep2;
6580
  int32_t keepTimeOffset;
6581
  int32_t minRows;
6582
  int32_t maxRows;
6583
  int32_t tsdbPageSize;
6584
  int32_t ssChunkSize;
6585
  int32_t ssKeepLocal;
6586
  int8_t  ssCompact;
6587
  union {
6588
    uint8_t flags;
6589
    struct {
6590
      uint8_t isAudit : 1;
6591
      uint8_t allowDrop : 1;
6592
      uint8_t reserved : 6;
6593
    };
6594
  };
6595
  int8_t secureDelete;
6596
  // walInfo
6597
  int32_t walFsyncPeriod;      // millisecond
6598
  int32_t walRetentionPeriod;  // secs
6599
  int32_t walRollPeriod;       // secs
6600
  int64_t walRetentionSize;
6601
  int64_t walSegSize;
6602
  int32_t walLevel;
6603
  // encryptInfo
6604
  int32_t encryptAlgorithm;
6605
  // SVState
6606
  int64_t committed;
6607
  int64_t commitID;
6608
  int64_t commitTerm;
6609
  // stats
6610
  int64_t numOfSTables;
6611
  int64_t numOfCTables;
6612
  int64_t numOfNTables;
6613
  // dbInfo
6614
  uint64_t dbId;
6615
} SMountVgInfo;
6616

6617
typedef struct {
6618
  SMCreateStbReq req;
6619
  SArray*        pColExts;  // element: column id
6620
  SArray*        pTagExts;  // element: tag id
6621
} SMountStbInfo;
6622

6623
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6624
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6625

6626
typedef struct {
6627
  char     dbName[TSDB_DB_FNAME_LEN];
6628
  uint64_t dbId;
6629
  SArray*  pVgs;   // SMountVgInfo
6630
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6631
} SMountDbInfo;
6632

6633
typedef struct {
6634
  // common fields
6635
  char     mountName[TSDB_MOUNT_NAME_LEN];
6636
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6637
  int8_t   ignoreExist;
6638
  int64_t  mountUid;
6639
  int64_t  clusterId;
6640
  int32_t  dnodeId;
6641
  uint32_t valLen;
6642
  void*    pVal;
6643

6644
  // response fields
6645
  SArray* pDbs;  // SMountDbInfo
6646

6647
  // memory fields, no serialized
6648
  SArray*   pDisks[TFS_MAX_TIERS];
6649
  TdFilePtr pFile;
6650
} SMountInfo;
6651

6652
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6653
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6654
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6655

6656
typedef struct {
6657
  SCreateVnodeReq createReq;
6658
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6659
  char            mountName[TSDB_MOUNT_NAME_LEN];
6660
  int64_t         mountId;
6661
  int32_t         diskPrimary;
6662
  int32_t         mountVgId;
6663
  int64_t         committed;
6664
  int64_t         commitID;
6665
  int64_t         commitTerm;
6666
  int64_t         numOfSTables;
6667
  int64_t         numOfCTables;
6668
  int64_t         numOfNTables;
6669
} SMountVnodeReq;
6670

6671
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6672
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6673
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6674

6675
#endif  // USE_MOUNT
6676

6677
#pragma pack(pop)
6678

6679
typedef struct {
6680
  char        db[TSDB_DB_FNAME_LEN];
6681
  STimeWindow timeRange;
6682
  int32_t     sqlLen;
6683
  char*       sql;
6684
  SArray*     vgroupIds;
6685
} SScanDbReq;
6686

6687
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6688
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6689
void    tFreeSScanDbReq(SScanDbReq* pReq);
6690

6691
typedef struct {
6692
  int32_t scanId;
6693
  int8_t  bAccepted;
6694
} SScanDbRsp;
6695

6696
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6697
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6698

6699
typedef struct {
6700
  int32_t scanId;
6701
  int32_t sqlLen;
6702
  char*   sql;
6703
} SKillScanReq;
6704

6705
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6706
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6707
void    tFreeSKillScanReq(SKillScanReq* pReq);
6708

6709
typedef struct {
6710
  int32_t scanId;
6711
  int32_t vgId;
6712
  int32_t dnodeId;
6713
} SVKillScanReq;
6714

6715
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6716
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6717

6718
typedef struct {
6719
  int32_t scanId;
6720
  int32_t vgId;
6721
  int32_t dnodeId;
6722
  int32_t numberFileset;
6723
  int32_t finished;
6724
  int32_t progress;
6725
  int64_t remainingTime;
6726
} SQueryScanProgressRsp;
6727

6728
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6729
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6730

6731
typedef struct {
6732
  int32_t scanId;
6733
  int32_t vgId;
6734
  int32_t dnodeId;
6735
} SQueryScanProgressReq;
6736

6737
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6738
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6739

6740
typedef struct {
6741
  int64_t     dbUid;
6742
  char        db[TSDB_DB_FNAME_LEN];
6743
  int64_t     scanStartTime;
6744
  STimeWindow tw;
6745
  int32_t     scanId;
6746
} SScanVnodeReq;
6747

6748
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6749
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6750

6751
#ifdef __cplusplus
6752
}
6753
#endif
6754

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