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

taosdata / TDengine / #5014

03 Apr 2026 03:59PM UTC coverage: 72.256% (-0.06%) from 72.317%
#5014

push

travis-ci

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

4054 of 5985 new or added lines in 68 files covered. (67.74%)

13285 existing lines in 168 files now uncovered.

257272 of 356056 relevant lines covered (72.26%)

133154720.42 hits per line

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

81.99
/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;
347✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
966,771,281✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
915,087,375✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,881,858,656✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,098,624,429✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,098,624,429✔
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_VIRTUAL_TABLES_REFERENCING,
219
  TSDB_MGMT_TABLE_MAX,
220
} EShowType;
221

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

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

233
#define TSDB_ALTER_TABLE_ADD_TAG                         1
234
#define TSDB_ALTER_TABLE_DROP_TAG                        2
235
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
236
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4 // deprecated, kept for wire compatibility
237
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
238
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
239
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
240
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
241
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
242
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
243
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
244
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
245
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
246
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
247
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15 // deprecated, kept for wire compatibility
248
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
249
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
250
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
251
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL      19 // alter multiple tag values of multi tables
252
#define TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL      20 // alter multiple tag values of the child tables of a stable
253

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

264

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

270

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

276
#define TSDB_ALTER_RSMA_FUNCTION        0x1
277

278
#define TSDB_KILL_MSG_LEN 30
279

280
#define TSDB_TABLE_NUM_UNIT 100000
281

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

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

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

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

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

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

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

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

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

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

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

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

702
typedef struct SField {
703
  char    name[TSDB_COL_NAME_LEN];
704
  uint8_t type;
705
  int8_t  flags;
706
  int32_t bytes;
707
} SField;
708

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

718
typedef struct SRetention {
719
  int64_t freq;
720
  int64_t keep;
721
  int8_t  freqUnit;
722
  int8_t  keepUnit;
723
} SRetention;
724

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

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

734
typedef struct {
735
  int32_t contLen;
736
  int32_t vgId;
737
} SMsgHead;
738

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

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

759
typedef struct {
760
  int32_t totalLen;
761
  int32_t len;
762
  STSRow* row;
763
} SSubmitBlkIter;
764

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

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

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

796
typedef struct {
797
  int32_t  nCols;
798
  int32_t  version;
799
  SColRef* pColRef;
800
  int32_t  nTagRefs;
801
  SColRef* pTagRef;
802
} SColRefWrapper;
803

804
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
805
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
806
typedef struct {
807
  int32_t vgId;
808
  SColRef colRef;
809
} SColRefEx;
810

811
typedef struct {
812
  int16_t colId;
813
  char    refDbName[TSDB_DB_NAME_LEN];
814
  char    refTableName[TSDB_TABLE_NAME_LEN];
815
  char    refColName[TSDB_COL_NAME_LEN];
816
} SRefColInfo;
817

818
typedef struct SVCTableRefCols {
819
  uint64_t     uid;
820
  int32_t      numOfSrcTbls;
821
  int32_t      numOfColRefs;
822
  SRefColInfo* refCols;
823
} SVCTableRefCols;
824

825
typedef struct SVCTableMergeInfo {
826
  uint64_t uid;
827
  int32_t  numOfSrcTbls;
828
} SVCTableMergeInfo;
829

830
typedef struct {
831
  int32_t    nCols;
832
  SColRefEx* pColRefEx;
833
} SColRefExWrapper;
834

835
struct SSchema {
836
  int8_t   type;
837
  int8_t   flags;
838
  col_id_t colId;
839
  int32_t  bytes;
840
  char     name[TSDB_COL_NAME_LEN];
841
};
842
struct SSchemaExt {
843
  col_id_t colId;
844
  uint32_t compress;
845
  STypeMod typeMod;
846
};
847

848
struct SSchemaRsma {
849
  int64_t    interval[2];
850
  int32_t    nFuncs;
851
  int8_t     tbType;
852
  tb_uid_t   tbUid;
853
  func_id_t* funcIds;
854
  char       tbName[TSDB_TABLE_NAME_LEN];
855
};
856

857
struct SSchema2 {
858
  int8_t   type;
859
  int8_t   flags;
860
  col_id_t colId;
861
  int32_t  bytes;
862
  char     name[TSDB_COL_NAME_LEN];
863
  uint32_t compress;
864
};
865

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

901
typedef struct {
902
  int32_t        code;
903
  int64_t        uid;
904
  char*          tblFName;
905
  int32_t        numOfRows;
906
  int32_t        affectedRows;
907
  int64_t        sver;
908
  STableMetaRsp* pMeta;
909
} SSubmitBlkRsp;
910

911
typedef struct {
912
  int32_t numOfRows;
913
  int32_t affectedRows;
914
  int32_t nBlocks;
915
  union {
916
    SArray*        pArray;
917
    SSubmitBlkRsp* pBlocks;
918
  };
919
} SSubmitRsp;
920

921
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
922
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
923
// void    tFreeSSubmitBlkRsp(void* param);
924
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
925

926
#define COL_SMA_ON       ((int8_t)0x1)
927
#define COL_IDX_ON       ((int8_t)0x2)
928
#define COL_IS_KEY       ((int8_t)0x4)
929
#define COL_SET_NULL     ((int8_t)0x10)
930
#define COL_SET_VAL      ((int8_t)0x20)
931
#define COL_IS_SYSINFO   ((int8_t)0x40)
932
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
933
#define COL_REF_BY_STM   ((int8_t)0x08)
934

935
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
936
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
937

938
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
939
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
940
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
941

942
#define SSCHMEA_SET_IDX_ON(s) \
943
  do {                        \
944
    (s)->flags |= COL_IDX_ON; \
945
  } while (0)
946

947
#define SSCHMEA_SET_IDX_OFF(s)   \
948
  do {                           \
949
    (s)->flags &= (~COL_IDX_ON); \
950
  } while (0)
951

952
#define SSCHEMA_SET_TYPE_MOD(s)     \
953
  do {                              \
954
    (s)->flags |= COL_HAS_TYPE_MOD; \
955
  } while (0)
956

957
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
958

959
#define SSCHMEA_TYPE(s)  ((s)->type)
960
#define SSCHMEA_FLAGS(s) ((s)->flags)
961
#define SSCHMEA_COLID(s) ((s)->colId)
962
#define SSCHMEA_BYTES(s) ((s)->bytes)
963
#define SSCHMEA_NAME(s)  ((s)->name)
964

965
typedef struct {
966
  bool    tsEnableMonitor;
967
  int32_t tsMonitorInterval;
968
  int32_t tsSlowLogThreshold;
969
  int32_t tsSlowLogMaxLen;
970
  int32_t tsSlowLogScope;
971
  int32_t tsSlowLogThresholdTest;  // Obsolete
972
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
973
} SMonitorParas;
974

975
typedef struct {
976
  STypeMod typeMod;
977
} SExtSchema;
978

979
bool hasExtSchema(const SExtSchema* pExtSchema);
980

981
typedef struct {
982
  int32_t      nCols;
983
  int32_t      version;
984
  SSchema*     pSchema;
985
  SSchemaRsma* pRsma;
986
} SSchemaWrapper;
987

988
typedef struct {
989
  col_id_t id;
990
  uint32_t alg;
991
} SColCmpr;
992

993
typedef struct {
994
  int32_t   nCols;
995
  int32_t   version;
996
  SColCmpr* pColCmpr;
997
} SColCmprWrapper;
998

999
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
1000
  if (pRef->pColRef) {
578,497✔
UNCOV
1001
    return TSDB_CODE_INVALID_PARA;
×
1002
  }
1003
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
578,497✔
1004
  if (pRef->pColRef == NULL) {
578,497✔
UNCOV
1005
    return terrno;
×
1006
  }
1007
  pRef->nCols = nCols;
578,497✔
1008
  for (int32_t i = 0; i < nCols; i++) {
158,901,001✔
1009
    pRef->pColRef[i].hasRef = false;
158,322,504✔
1010
    pRef->pColRef[i].id = (col_id_t)(i + 1);
158,322,504✔
1011
  }
1012
  return 0;
578,497✔
1013
}
1014

1015
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByTags(SColRefWrapper* pRef, int32_t nTags, col_id_t startColId) {
UNCOV
1016
  if (pRef->pTagRef) {
×
1017
    return TSDB_CODE_INVALID_PARA;
×
1018
  }
UNCOV
1019
  pRef->pTagRef = (SColRef*)taosMemoryCalloc(nTags, sizeof(SColRef));
×
1020
  if (pRef->pTagRef == NULL) {
×
1021
    return terrno;
×
1022
  }
UNCOV
1023
  pRef->nTagRefs = nTags;
×
1024
  for (int32_t i = 0; i < nTags; i++) {
×
1025
    pRef->pTagRef[i].hasRef = false;
×
1026
    pRef->pTagRef[i].id = (col_id_t)(startColId + i);
×
1027
  }
UNCOV
1028
  return 0;
×
1029
}
1030

1031
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1032
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1033
    terrno = TSDB_CODE_INVALID_PARA;
1034
    return NULL;
1035
  }
1036

1037
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1038
  if (pDstWrapper == NULL) {
1039
    return NULL;
1040
  }
1041
  pDstWrapper->nCols = pSrcWrapper->nCols;
1042
  pDstWrapper->version = pSrcWrapper->version;
1043

1044
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1045
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1046
  if (pDstWrapper->pColCmpr == NULL) {
1047
    taosMemoryFree(pDstWrapper);
1048
    return NULL;
1049
  }
1050
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1051

1052
  return pDstWrapper;
1053
}
1054

1055
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1056
  if (!(!pCmpr->pColCmpr)) {
7,417,377✔
UNCOV
1057
    return TSDB_CODE_INVALID_PARA;
×
1058
  }
1059
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
7,417,377✔
1060
  if (pCmpr->pColCmpr == NULL) {
7,417,377✔
UNCOV
1061
    return terrno;
×
1062
  }
1063
  pCmpr->nCols = nCols;
7,417,377✔
1064
  return 0;
7,417,377✔
1065
}
1066

1067
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1068
  pCmpr->nCols = pSchema->nCols;
1069
  if (!(!pCmpr->pColCmpr)) {
1070
    return TSDB_CODE_INVALID_PARA;
1071
  }
1072
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1073
  if (pCmpr->pColCmpr == NULL) {
1074
    return terrno;
1075
  }
1076
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1077
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1078
    SSchema*  pColSchema = &pSchema->pSchema[i];
1079
    pColCmpr->id = pColSchema->colId;
1080
    pColCmpr->alg = 0;
1081
  }
1082
  return 0;
1083
}
1084

1085
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1086
  if (pWrapper == NULL) return;
1087

1088
  taosMemoryFreeClear(pWrapper->pColCmpr);
1089
  taosMemoryFreeClear(pWrapper);
1090
}
1091
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1092
  if (pSchemaWrapper->pSchema == NULL) return NULL;
689,528,771✔
1093

1094
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
689,429,774✔
1095
  if (pSW == NULL) {
689,403,435✔
UNCOV
1096
    return NULL;
×
1097
  }
1098
  pSW->nCols = pSchemaWrapper->nCols;
689,403,435✔
1099
  pSW->version = pSchemaWrapper->version;
689,428,316✔
1100
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
689,248,899✔
1101
  if (pSW->pSchema == NULL) {
689,214,242✔
UNCOV
1102
    taosMemoryFree(pSW);
×
1103
    return NULL;
×
1104
  }
1105

1106
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
689,183,322✔
1107
  return pSW;
689,599,984✔
1108
}
1109

1110
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
147,287,269✔
1111
  if (pSchemaWrapper) {
1,530,249,132✔
1112
    taosMemoryFree(pSchemaWrapper->pSchema);
1,058,428,579✔
1113
    if (pSchemaWrapper->pRsma) {
1,058,434,974✔
1114
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
28,453✔
1115
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
28,453✔
1116
    }
1117
    taosMemoryFree(pSchemaWrapper);
1,058,264,121✔
1118
  }
1119
}
1,490,770,650✔
1120

1121
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1122
  if (pSchemaWrapper) {
1123
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1124
    if (pSchemaWrapper->pRsma) {
1125
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1126
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1127
    }
1128
  }
1129
}
1130

1131
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
8,425,907✔
1132
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
8,425,907✔
1133
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
8,426,517✔
1134
  }
1135
}
8,425,907✔
1136

1137
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1138
  int32_t tlen = 0;
2,772,622✔
1139
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,774,914✔
1140
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,772,622✔
1141
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,772,622✔
1142
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,772,622✔
1143
  tlen += taosEncodeString(buf, pSchema->name);
2,772,622✔
1144
  return tlen;
2,772,622✔
1145
}
1146

1147
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1148
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,265,351✔
1149
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,264,859✔
1150
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,264,859✔
1151
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,264,859✔
1152
  buf = taosDecodeStringTo(buf, pSchema->name);
1,264,859✔
1153
  return (void*)buf;
1,264,859✔
1154
}
1155

1156
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1157
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1158
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1159
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1160
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1161
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1162
  return 0;
2,147,483,647✔
1163
}
1164

1165
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1166
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1167
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1168
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1169
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1170
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1171
  return 0;
2,147,483,647✔
1172
}
1173

1174
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1175
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1176
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1177
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1178
  return 0;
2,147,483,647✔
1179
}
1180

1181
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1182
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1183
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1184
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1185
  return 0;
2,147,483,647✔
1186
}
1187

1188
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1189
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
953,823,244✔
1190
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
953,823,244✔
1191
  if (pColRef->hasRef) {
476,911,622✔
1192
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
632,907,180✔
1193
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
632,907,180✔
1194
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
632,907,180✔
1195
  }
1196
  return 0;
476,911,622✔
1197
}
1198

1199
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1200
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
477,452,770✔
1201
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
477,452,770✔
1202
  if (pColRef->hasRef) {
238,726,385✔
1203
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
158,449,765✔
1204
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
158,449,765✔
1205
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
158,449,765✔
1206
  }
1207

1208
  return 0;
238,726,385✔
1209
}
1210

1211
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1212
  int32_t tlen = 0;
458,372✔
1213
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
458,372✔
1214
  tlen += taosEncodeVariantI32(buf, pSW->version);
458,372✔
1215
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,230,994✔
1216
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,545,244✔
1217
  }
1218
  return tlen;
458,372✔
1219
}
1220

1221
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1222
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
204,066✔
1223
  buf = taosDecodeVariantI32(buf, &pSW->version);
204,066✔
1224
  if (pSW->nCols > 0) {
204,066✔
1225
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
204,066✔
1226
    if (pSW->pSchema == NULL) {
204,066✔
UNCOV
1227
      return NULL;
×
1228
    }
1229

1230
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,468,925✔
1231
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,529,718✔
1232
    }
1233
  } else {
UNCOV
1234
    pSW->pSchema = NULL;
×
1235
  }
1236
  return (void*)buf;
204,066✔
1237
}
1238

1239
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1240
  if (pSW == NULL) {
290,561,253✔
UNCOV
1241
    return TSDB_CODE_INVALID_PARA;
×
1242
  }
1243
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
581,152,737✔
1244
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
581,034,991✔
1245
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1246
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1247
  }
1248
  return 0;
290,772,887✔
1249
}
1250

1251
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1252
  if (pSW == NULL) {
125,440,136✔
UNCOV
1253
    return TSDB_CODE_INVALID_PARA;
×
1254
  }
1255
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
250,822,109✔
1256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
250,767,810✔
1257

1258
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
125,385,837✔
1259
  if (pSW->pSchema == NULL) {
125,349,597✔
UNCOV
1260
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1261
  }
1262
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,374,696,823✔
1263
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1264
  }
1265

1266
  return 0;
125,508,582✔
1267
}
1268

1269
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1270
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1271
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1272

1273
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1274
  if (pSW->pSchema == NULL) {
2,147,483,647✔
UNCOV
1275
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1276
  }
1277
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1278
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1279
  }
1280

1281
  return 0;
2,147,483,647✔
1282
}
1283

1284
typedef struct {
1285
  char     name[TSDB_TABLE_FNAME_LEN];
1286
  int8_t   igExists;
1287
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1288
  int8_t   reserved[6];
1289
  tb_uid_t suid;
1290
  int64_t  delay1;
1291
  int64_t  delay2;
1292
  int64_t  watermark1;
1293
  int64_t  watermark2;
1294
  int32_t  ttl;
1295
  int32_t  colVer;
1296
  int32_t  tagVer;
1297
  int32_t  numOfColumns;
1298
  int32_t  numOfTags;
1299
  int32_t  numOfFuncs;
1300
  int32_t  commentLen;
1301
  int32_t  ast1Len;
1302
  int32_t  ast2Len;
1303
  SArray*  pColumns;  // array of SFieldWithOptions
1304
  SArray*  pTags;     // array of SField
1305
  SArray*  pFuncs;
1306
  char*    pComment;
1307
  char*    pAst1;
1308
  char*    pAst2;
1309
  int64_t  deleteMark1;
1310
  int64_t  deleteMark2;
1311
  int32_t  sqlLen;
1312
  char*    sql;
1313
  int64_t  keep;
1314
  int8_t   virtualStb;
1315
  int8_t   secureDelete;
1316
} SMCreateStbReq;
1317

1318
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1319
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1320
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1321

1322
typedef struct {
1323
  STableMetaRsp* pMeta;
1324
} SMCreateStbRsp;
1325

1326
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1327
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1328
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1329

1330
typedef struct {
1331
  char     name[TSDB_TABLE_FNAME_LEN];
1332
  int8_t   igNotExists;
1333
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1334
  int8_t   reserved[6];
1335
  tb_uid_t suid;
1336
  int32_t  sqlLen;
1337
  char*    sql;
1338
} SMDropStbReq;
1339

1340
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1341
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1342
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1343

1344
typedef struct {
1345
  char    name[TSDB_TABLE_FNAME_LEN];
1346
  int8_t  alterType;
1347
  int32_t numOfFields;
1348
  SArray* pFields;
1349
  int32_t ttl;
1350
  int32_t commentLen;
1351
  char*   comment;
1352
  int32_t sqlLen;
1353
  char*   sql;
1354
  int64_t keep;
1355
  SArray* pTypeMods;
1356
  int8_t  secureDelete;
1357
} SMAlterStbReq;
1358

1359
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1360
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1361
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1362

1363
typedef struct SEpSet {
1364
  int8_t inUse;
1365
  int8_t numOfEps;
1366
  SEp    eps[TSDB_MAX_REPLICA];
1367
} SEpSet;
1368

1369
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1370
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1371
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1372
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1373

1374
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1375
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1376

1377
typedef struct {
1378
  int8_t  connType;
1379
  int32_t pid;
1380
  int32_t totpCode;
1381
  char    app[TSDB_APP_NAME_LEN];
1382
  char    db[TSDB_DB_NAME_LEN];
1383
  char    user[TSDB_USER_LEN];
1384
  char    passwd[TSDB_PASSWORD_LEN];
1385
  char    token[TSDB_TOKEN_LEN];
1386
  int64_t startTime;
1387
  int64_t connectTime;
1388
  char    sVer[TSDB_VERSION_LEN];
1389
  char    signature[20]; // SHA1 produces a 20-byte signature
1390
} SConnectReq;
1391

1392
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1393
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1394
void    tSignConnectReq(SConnectReq* pReq);
1395
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1396

1397
typedef struct {
1398
  int64_t       clusterId;
1399
  int32_t       acctId;
1400
  uint32_t      connId;
1401
  int32_t       dnodeNum;
1402
  int8_t        superUser;
1403
  int8_t        sysInfo;
1404
  int8_t        connType;
1405
  int8_t        enableAuditDelete;
1406
  SEpSet        epSet;
1407
  int32_t       svrTimestamp;
1408
  int32_t       passVer;
1409
  int32_t       authVer;
1410
  char          sVer[TSDB_VERSION_LEN];
1411
  char          sDetailVer[128];
1412
  int64_t       whiteListVer;
1413
  int64_t       timeWhiteListVer;
1414
  int64_t       userId;
1415
  SMonitorParas monitorParas;
1416
  char          user[TSDB_USER_LEN];
1417
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1418
  int8_t        enableAuditSelect;
1419
  int8_t        enableAuditInsert;
1420
  int8_t        auditLevel;
1421
} SConnectRsp;
1422

1423
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1424
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1425

1426
typedef struct {
1427
  char    user[TSDB_USER_LEN];
1428
  char    pass[TSDB_PASSWORD_LEN];
1429
  int32_t maxUsers;
1430
  int32_t maxDbs;
1431
  int32_t maxTimeSeries;
1432
  int32_t maxStreams;
1433
  int32_t accessState;  // Configured only by command
1434
  int64_t maxStorage;
1435
} SCreateAcctReq, SAlterAcctReq;
1436

1437
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1438
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1439

1440
typedef struct {
1441
  char    user[TSDB_USER_LEN];
1442
  int8_t  ignoreNotExists;
1443
  int32_t sqlLen;
1444
  char*   sql;
1445
} SDropUserReq, SDropAcctReq;
1446

1447
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1448
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1449
void    tFreeSDropUserReq(SDropUserReq* pReq);
1450

1451
typedef struct {
1452
  char name[TSDB_ROLE_LEN];
1453
  union {
1454
    uint8_t flag;
1455
    struct {
1456
      uint8_t ignoreExists : 1;
1457
      uint8_t reserve : 7;
1458
    };
1459
  };
1460
  int32_t sqlLen;
1461
  char*   sql;
1462
} SCreateRoleReq;
1463

1464
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1465
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1466
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1467

1468
typedef struct {
1469
  char name[TSDB_ROLE_LEN];
1470
  union {
1471
    uint8_t flag;
1472
    struct {
1473
      uint8_t ignoreNotExists : 1;
1474
      uint8_t reserve : 7;
1475
    };
1476
  };
1477
  int32_t sqlLen;
1478
  char*   sql;
1479
} SDropRoleReq;
1480

1481
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1482
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1483
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1484

1485
typedef struct {
1486
  SPrivSet privSet;
1487
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1488
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1489
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1490
  // delete can only specify conditions by cond and cannot specify columns
1491
  char*    cond;     // for table privileges
1492
  int32_t  condLen;  // for table privileges
1493
} SPrivSetReqArgs;
1494

1495
typedef struct {
1496
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1497
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1498
  union {
1499
    uint32_t flag;
1500
    struct {
1501
      uint32_t lock : 1;     // lock or unlock role
1502
      uint32_t add : 1;      // add or remove
1503
      uint32_t sysPriv : 1;  // system or object privileges
1504
      uint32_t objLevel : 2;
1505
      uint32_t ignoreNotExists : 1;
1506
      uint32_t reserve : 26;
1507
    };
1508
  };
1509
  union {
1510
    SPrivSetReqArgs privileges;
1511
    char            roleName[TSDB_ROLE_LEN];
1512
  };
1513
  char    principal[TSDB_ROLE_LEN];      // role or user name
1514
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1515
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1516
  int32_t sqlLen;
1517
  char*   sql;
1518
} SAlterRoleReq;
1519

1520
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1521
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1522
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1523

1524
typedef struct {
1525
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1526
  int32_t sqlLen;
1527
  char*   sql;
1528
} SDropEncryptAlgrReq;
1529

1530
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1531
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1532
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1533

1534
typedef struct SIpV4Range {
1535
  uint32_t ip;
1536
  uint32_t mask;
1537
} SIpV4Range;
1538

1539
typedef struct SIpv6Range {
1540
  uint64_t addr[2];
1541
  uint32_t mask;
1542
} SIpV6Range;
1543

1544
typedef struct {
1545
  int8_t type;   // 0: IPv4, 1: IPv6
1546
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1547
  union {
1548
    SIpV4Range ipV4;
1549
    SIpV6Range ipV6;
1550
  };
1551
} SIpRange;
1552

1553
typedef struct {
1554
  int32_t    num;
1555
  SIpV4Range pIpRange[];
1556
} SIpWhiteList;
1557

1558
typedef struct {
1559
  int32_t  num;
1560
  SIpRange pIpRanges[];
1561
} SIpWhiteListDual;
1562

1563
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1564
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1565
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1566
int32_t           createDefaultIp6Range(SIpRange* pRange);
1567
int32_t           createDefaultIp4Range(SIpRange* pRange);
1568

1569
typedef struct {
1570
  int32_t sessPerUser;
1571
  int32_t sessConnTime;
1572
  int32_t sessConnIdleTime;
1573
  int32_t sessMaxConcurrency;
1574
  int32_t sessMaxCallVnodeNum;
1575
} SUserSessCfg;
1576

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

1581
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1582
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1583
typedef struct {
1584
  int16_t year;
1585
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1586
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1587
  int8_t hour;
1588
  int8_t minute;
1589
  int8_t neg;   // this is a negative entry
1590
  int32_t duration; // duration in minute
1591
} SDateTimeRange;
1592

1593
bool isValidDateTimeRange(SDateTimeRange* pRange);
1594
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1595
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1596

1597
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1598
typedef struct {
1599
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1600
  bool neg;         // this is a negative entry
1601
  int32_t duration; // duration in seconds
1602
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1603
} SDateTimeWhiteListItem;
1604

1605
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1606
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1607

1608
typedef struct {
1609
  int32_t num;
1610
  SDateTimeWhiteListItem ranges[];
1611
} SDateTimeWhiteList;
1612

1613
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1614
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1615

1616

1617
typedef struct {
1618
  int8_t createType;
1619

1620
  int8_t hasSessionPerUser;
1621
  int8_t hasConnectTime;
1622
  int8_t hasConnectIdleTime;
1623
  int8_t hasCallPerSession;
1624
  int8_t hasVnodePerCall;
1625
  int8_t hasFailedLoginAttempts;
1626
  int8_t hasPasswordLifeTime;
1627
  int8_t hasPasswordReuseTime;
1628
  int8_t hasPasswordReuseMax;
1629
  int8_t hasPasswordLockTime;
1630
  int8_t hasPasswordGraceTime;
1631
  int8_t hasInactiveAccountTime;
1632
  int8_t hasAllowTokenNum;
1633

1634
  int8_t superUser;  // denote if it is a super user or not
1635
  int8_t ignoreExists;
1636

1637
  char   user[TSDB_USER_LEN];
1638
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1639
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1640

1641
  int8_t sysInfo;
1642
  int8_t createDb;
1643
  int8_t isImport;
1644
  int8_t changepass;
1645
  int8_t enable;
1646

1647
  int8_t negIpRanges;
1648
  int8_t negTimeRanges;
1649

1650
  int32_t sessionPerUser;
1651
  int32_t connectTime;
1652
  int32_t connectIdleTime;
1653
  int32_t callPerSession;
1654
  int32_t vnodePerCall;
1655
  int32_t failedLoginAttempts;
1656
  int32_t passwordLifeTime;
1657
  int32_t passwordReuseTime;
1658
  int32_t passwordReuseMax;
1659
  int32_t passwordLockTime;
1660
  int32_t passwordGraceTime;
1661
  int32_t inactiveAccountTime;
1662
  int32_t allowTokenNum;
1663

1664
  int32_t         numIpRanges;
1665
  SIpRange*       pIpDualRanges;
1666
  int32_t         numTimeRanges;
1667
  SDateTimeRange* pTimeRanges;
1668

1669
  int32_t sqlLen;
1670
  char*   sql;
1671
} SCreateUserReq;
1672

1673
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1674
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1675
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1676

1677
typedef struct {
1678
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1679
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1680
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1681
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1682
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1683
  int32_t sqlLen;
1684
  char*   sql;
1685
} SCreateEncryptAlgrReq;
1686

1687
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1688
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1689
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1690

1691
typedef struct {
1692
  int32_t dnodeId;
1693
  int64_t analVer;
1694
} SRetrieveAnalyticsAlgoReq;
1695

1696
typedef struct {
1697
  int64_t   ver;
1698
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1699
} SRetrieveAnalyticAlgoRsp;
1700

1701
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1702
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1703
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1704
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1705
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1706

1707
typedef struct {
1708
  int8_t alterType;
1709

1710
  int8_t isView;
1711

1712
  int8_t hasPassword;
1713
  int8_t hasTotpseed;
1714
  int8_t hasEnable;
1715
  int8_t hasSysinfo;
1716
  int8_t hasCreatedb;
1717
  int8_t hasChangepass;
1718
  int8_t hasSessionPerUser;
1719
  int8_t hasConnectTime;
1720
  int8_t hasConnectIdleTime;
1721
  int8_t hasCallPerSession;
1722
  int8_t hasVnodePerCall;
1723
  int8_t hasFailedLoginAttempts;
1724
  int8_t hasPasswordLifeTime;
1725
  int8_t hasPasswordReuseTime;
1726
  int8_t hasPasswordReuseMax;
1727
  int8_t hasPasswordLockTime;
1728
  int8_t hasPasswordGraceTime;
1729
  int8_t hasInactiveAccountTime;
1730
  int8_t hasAllowTokenNum;
1731

1732
  int8_t enable;
1733
  int8_t sysinfo;
1734
  int8_t createdb;
1735
  int8_t changepass;
1736

1737
  char   user[TSDB_USER_LEN];
1738
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1739
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1740
  int32_t sessionPerUser;
1741
  int32_t connectTime;
1742
  int32_t connectIdleTime;
1743
  int32_t callPerSession;
1744
  int32_t vnodePerCall;
1745
  int32_t failedLoginAttempts;
1746
  int32_t passwordLifeTime;
1747
  int32_t passwordReuseTime;
1748
  int32_t passwordReuseMax;
1749
  int32_t passwordLockTime;
1750
  int32_t passwordGraceTime;
1751
  int32_t inactiveAccountTime;
1752
  int32_t allowTokenNum;
1753

1754
  int32_t         numIpRanges;
1755
  int32_t         numTimeRanges;
1756
  int32_t         numDropIpRanges;
1757
  int32_t         numDropTimeRanges;
1758
  SIpRange*       pIpRanges;
1759
  SDateTimeRange* pTimeRanges;
1760
  SIpRange*       pDropIpRanges;
1761
  SDateTimeRange* pDropTimeRanges;
1762
  SPrivSet        privileges;
1763

1764
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1765
  char        tabName[TSDB_TABLE_NAME_LEN];
1766
  char*       tagCond;
1767
  int32_t     tagCondLen;
1768
  int32_t     sqlLen;
1769
  char*       sql;
1770
} SAlterUserReq;
1771

1772
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1773
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1774
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1775

1776
typedef struct {
1777
  char    name[TSDB_TOKEN_NAME_LEN];
1778
  char    user[TSDB_USER_LEN];
1779
  int8_t  enable;
1780
  int8_t  ignoreExists;
1781
  int32_t ttl;
1782
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1783
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1784

1785
  int32_t sqlLen;
1786
  char*   sql;
1787
} SCreateTokenReq;
1788

1789
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1790
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1791
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1792

1793
typedef struct {
1794
  char name[TSDB_TOKEN_NAME_LEN];
1795
  char user[TSDB_USER_LEN];
1796
  char token[TSDB_TOKEN_LEN];
1797
} SCreateTokenRsp;
1798

1799
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1800
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1801
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1802

1803
typedef struct {
1804
  char    name[TSDB_TOKEN_NAME_LEN];
1805

1806
  int8_t hasEnable;
1807
  int8_t hasTtl;
1808
  int8_t hasProvider;
1809
  int8_t hasExtraInfo;
1810

1811
  int8_t  enable;
1812
  int32_t ttl;
1813
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1814
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1815

1816
  int32_t     sqlLen;
1817
  char*       sql;
1818
} SAlterTokenReq;
1819

1820
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1821
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1822
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1823

1824
typedef struct {
1825
  char    name[TSDB_TOKEN_NAME_LEN];
1826
  int8_t  ignoreNotExists;
1827
  int32_t sqlLen;
1828
  char*   sql;
1829
} SDropTokenReq;
1830

1831
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1832
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1833
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1834

1835
typedef struct {
1836
  char    user[TSDB_USER_LEN];
1837
  int32_t sqlLen;
1838
  char*   sql;
1839
} SCreateTotpSecretReq;
1840

1841
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1842
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1843
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1844

1845
typedef struct {
1846
  char user[TSDB_USER_LEN];
1847
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1848
} SCreateTotpSecretRsp;
1849

1850
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1851
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1852

1853
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1854
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1855
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1856
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1857

1858
typedef struct {
1859
  char user[TSDB_USER_LEN];
1860
} SGetUserAuthReq;
1861

1862
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1863
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1864

1865
typedef struct {
1866
  int8_t  enabled;
1867
  int32_t expireTime;
1868
} STokenStatus;
1869

1870
typedef struct {
1871
  char    user[TSDB_USER_LEN];
1872
  int64_t userId;
1873
  int32_t version;
1874
  int32_t passVer;
1875
  int8_t  superAuth;
1876
  int8_t  sysInfo;
1877
  int8_t  enable;
1878
  int8_t  dropped;
1879
  union {
1880
    uint8_t flags;
1881
    struct {
1882
      uint8_t privLevel : 3;
1883
      uint8_t withInsertCond : 1;
1884
      uint8_t reserve : 4;
1885
    };
1886
  };
1887
  SPrivSet  sysPrivs;
1888
  SHashObj* objPrivs;
1889
  SHashObj* selectTbs;
1890
  SHashObj* insertTbs;
1891
  SHashObj* deleteTbs;
1892
  SHashObj* ownedDbs;
1893
  int64_t   whiteListVer;
1894

1895
  SUserSessCfg sessCfg;
1896
  int64_t      timeWhiteListVer;
1897
  SHashObj*    tokens;
1898
} SGetUserAuthRsp;
1899

1900
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1901
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1902
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1903

1904
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1905
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1906
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1907
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1908

1909
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1910
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1911
typedef struct {
1912
  int64_t ver;
1913
  char    user[TSDB_USER_LEN];
1914
  int32_t numOfRange;
1915
  union {
1916
    SIpV4Range* pIpRanges;
1917
    SIpRange*   pIpDualRanges;
1918
  };
1919
} SUpdateUserIpWhite;
1920

1921
typedef struct {
1922
  int64_t             ver;
1923
  int                 numOfUser;
1924
  SUpdateUserIpWhite* pUserIpWhite;
1925
} SUpdateIpWhite;
1926

1927
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1928
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1929
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1930
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1931

1932
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1933
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1934
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1935

1936

1937
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1938
// corresponding response struct is different.
1939
typedef struct {
1940
  int64_t ver;
1941
} SRetrieveWhiteListReq;
1942

1943
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1944
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1945

1946

1947
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1948
// corresponding response struct is different.
1949
typedef struct {
1950
  char user[TSDB_USER_LEN];
1951
} SGetUserWhiteListReq;
1952

1953
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1954
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1955

1956
typedef struct {
1957
  char    user[TSDB_USER_LEN];
1958
  int32_t numWhiteLists;
1959
  union {
1960
    SIpV4Range* pWhiteLists;
1961
    SIpRange*   pWhiteListsDual;
1962
  };
1963
} SGetUserIpWhiteListRsp;
1964

1965
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1966
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1967
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1968
void    tIpRangeSetDefaultMask(SIpRange* range);
1969

1970
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1971
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1972
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1973

1974
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1975
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1976
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1977

1978
typedef struct {
1979
  int64_t ver;
1980
  char    user[TSDB_USER_LEN];
1981
  int32_t numWhiteLists;
1982
  SDateTimeWhiteListItem* pWhiteLists;
1983
} SUserDateTimeWhiteList;
1984

1985

1986
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1987
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1988
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1989
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1990

1991
typedef struct {
1992
  int64_t             ver;
1993
  int                 numOfUser;
1994
  SUserDateTimeWhiteList *pUsers;
1995
} SRetrieveDateTimeWhiteListRsp;
1996

1997
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1998
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1999
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
2000
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
2001

2002
/*
2003
 * for client side struct, only column id, type, bytes are necessary
2004
 * But for data in vnode side, we need all the following information.
2005
 */
2006
typedef struct {
2007
  union {
2008
    col_id_t colId;
2009
    int16_t  slotId;
2010
  };
2011

2012
  uint8_t precision;
2013
  uint8_t scale;
2014
  int32_t bytes;
2015
  int8_t  type;
2016
  uint8_t pk;
2017
  bool    noData;
2018
} SColumnInfo;
2019

2020
typedef struct STimeWindow {
2021
  TSKEY skey;
2022
  TSKEY ekey;
2023
} STimeWindow;
2024

2025
typedef struct SQueryHint {
2026
  bool batchScan;
2027
} SQueryHint;
2028

2029
typedef struct {
2030
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2031
  int32_t tsLen;          // total length of ts comp block
2032
  int32_t tsNumOfBlocks;  // ts comp block numbers
2033
  int32_t tsOrder;        // ts comp block order
2034
} STsBufInfo;
2035

2036
typedef struct {
2037
  void*       timezone;
2038
  char        intervalUnit;
2039
  char        slidingUnit;
2040
  char        offsetUnit;
2041
  int8_t      precision;
2042
  int64_t     interval;
2043
  int64_t     sliding;
2044
  int64_t     offset;
2045
  STimeWindow timeRange;
2046
} SInterval;
2047

2048
typedef struct STbVerInfo {
2049
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2050
  int32_t sversion;
2051
  int32_t tversion;
2052
  int32_t rversion;  // virtual table's column ref's version
2053
} STbVerInfo;
2054

2055
typedef struct {
2056
  int32_t code;
2057
  int64_t affectedRows;
2058
  SArray* tbVerInfo;  // STbVerInfo
2059
} SQueryTableRsp;
2060

2061
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2062

2063
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2064

2065
typedef struct {
2066
  SMsgHead header;
2067
  char     dbFName[TSDB_DB_FNAME_LEN];
2068
  char     tbName[TSDB_TABLE_NAME_LEN];
2069
} STableCfgReq;
2070

2071
typedef struct {
2072
  char        tbName[TSDB_TABLE_NAME_LEN];
2073
  char        stbName[TSDB_TABLE_NAME_LEN];
2074
  char        dbFName[TSDB_DB_FNAME_LEN];
2075
  int32_t     numOfTags;
2076
  int32_t     numOfColumns;
2077
  int8_t      tableType;
2078
  int64_t     delay1;
2079
  int64_t     delay2;
2080
  int64_t     watermark1;
2081
  int64_t     watermark2;
2082
  int32_t     ttl;
2083
  int32_t     keep;
2084
  int64_t     ownerId;
2085
  SArray*     pFuncs;
2086
  int32_t     commentLen;
2087
  char*       pComment;
2088
  SSchema*    pSchemas;
2089
  int32_t     tagsLen;
2090
  char*       pTags;
2091
  SSchemaExt* pSchemaExt;
2092
  union {
2093
    uint8_t flag;
2094
    struct {
2095
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2096
      uint8_t isAudit : 1;
2097
      uint8_t reserve : 6;
2098
    };
2099
  };
2100
  SColRef* pColRefs;
2101
  int32_t  numOfTagRefs;
2102
  SColRef* pTagRefs;
2103
  int8_t   secureDelete;
2104
} STableCfg;
2105

2106
typedef STableCfg STableCfgRsp;
2107

2108
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2109
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2110

2111
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2112
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2113
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2114

2115
typedef struct {
2116
  SMsgHead header;
2117
  tb_uid_t suid;
2118
} SVSubTablesReq;
2119

2120
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2121
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2122

2123
typedef struct {
2124
  int32_t vgId;
2125
  SArray* pTables;  // SArray<SVCTableRefCols*>
2126
} SVSubTablesRsp;
2127

2128
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2129
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2130
void    tDestroySVSubTablesRsp(void* rsp);
2131

2132
typedef struct {
2133
  SMsgHead header;
2134
  tb_uid_t suid;
2135
} SVStbRefDbsReq;
2136

2137
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2138
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2139

2140
typedef struct {
2141
  int32_t vgId;
2142
  SArray* pDbs;  // SArray<char* (db name)>
2143
} SVStbRefDbsRsp;
2144

2145
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2146
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2147
void    tDestroySVStbRefDbsRsp(void* rsp);
2148

2149
typedef struct {
2150
  char    db[TSDB_DB_FNAME_LEN];
2151
  int32_t numOfVgroups;
2152
  int32_t numOfStables;  // single_stable
2153
  int32_t buffer;        // MB
2154
  int32_t pageSize;
2155
  int32_t pages;
2156
  int32_t cacheLastSize;
2157
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2158
  int32_t daysPerFile;
2159
  int32_t daysToKeep0;
2160
  int32_t daysToKeep1;
2161
  int32_t daysToKeep2;
2162
  int32_t keepTimeOffset;
2163
  int32_t minRows;
2164
  int32_t maxRows;
2165
  int32_t walFsyncPeriod;
2166
  int8_t  walLevel;
2167
  int8_t  precision;  // time resolution
2168
  int8_t  compression;
2169
  int8_t  replications;
2170
  int8_t  strict;
2171
  int8_t  cacheLast;
2172
  int8_t  schemaless;
2173
  int8_t  ignoreExist;
2174
  int32_t numOfRetensions;
2175
  SArray* pRetensions;  // SRetention
2176
  int32_t walRetentionPeriod;
2177
  int64_t walRetentionSize;
2178
  int32_t walRollPeriod;
2179
  int64_t walSegmentSize;
2180
  int32_t sstTrigger;
2181
  int16_t hashPrefix;
2182
  int16_t hashSuffix;
2183
  int32_t ssChunkSize;
2184
  int32_t ssKeepLocal;
2185
  int8_t  ssCompact;
2186
  int32_t tsdbPageSize;
2187
  int32_t sqlLen;
2188
  char*   sql;
2189
  int8_t  withArbitrator;
2190
  int8_t  encryptAlgorithm;
2191
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2192
  // 1. add auto-compact parameters
2193
  int32_t compactInterval;    // minutes
2194
  int32_t compactStartTime;   // minutes
2195
  int32_t compactEndTime;     // minutes
2196
  int8_t  compactTimeOffset;  // hour
2197
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2198
  int8_t  isAudit;
2199
  int8_t  allowDrop;
2200
  int8_t  secureDelete;
2201
} SCreateDbReq;
2202

2203
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2204
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2205
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2206

2207
typedef struct {
2208
  char    db[TSDB_DB_FNAME_LEN];
2209
  int32_t buffer;
2210
  int32_t pageSize;
2211
  int32_t pages;
2212
  int32_t cacheLastSize;
2213
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2214
  int32_t daysPerFile;
2215
  int32_t daysToKeep0;
2216
  int32_t daysToKeep1;
2217
  int32_t daysToKeep2;
2218
  int32_t keepTimeOffset;
2219
  int32_t walFsyncPeriod;
2220
  int8_t  walLevel;
2221
  int8_t  strict;
2222
  int8_t  cacheLast;
2223
  int8_t  replications;
2224
  int32_t sstTrigger;
2225
  int32_t minRows;
2226
  int32_t walRetentionPeriod;
2227
  int32_t walRetentionSize;
2228
  int32_t ssKeepLocal;
2229
  int8_t  ssCompact;
2230
  int32_t sqlLen;
2231
  char*   sql;
2232
  int8_t  withArbitrator;
2233
  // 1. add auto-compact parameters
2234
  int32_t compactInterval;
2235
  int32_t compactStartTime;
2236
  int32_t compactEndTime;
2237
  int8_t  compactTimeOffset;
2238
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2239
  int8_t  isAudit;
2240
  int8_t  allowDrop;
2241
  int8_t  secureDelete;
2242
} SAlterDbReq;
2243

2244
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2245
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2246
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2247

2248
typedef struct {
2249
  char    db[TSDB_DB_FNAME_LEN];
2250
  int8_t  ignoreNotExists;
2251
  int8_t  force;
2252
  int32_t sqlLen;
2253
  char*   sql;
2254
} SDropDbReq;
2255

2256
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2257
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2258
void    tFreeSDropDbReq(SDropDbReq* pReq);
2259

2260
typedef struct {
2261
  char    db[TSDB_DB_FNAME_LEN];
2262
  int64_t uid;
2263
} SDropDbRsp;
2264

2265
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2266
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2267

2268
typedef struct {
2269
  char    name[TSDB_MOUNT_NAME_LEN];
2270
  int64_t uid;
2271
} SDropMountRsp;
2272

2273
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2274
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2275

2276
typedef struct {
2277
  char    db[TSDB_DB_FNAME_LEN];
2278
  int64_t dbId;
2279
  int32_t vgVersion;
2280
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2281
  int64_t stateTs;     // ms
2282
} SUseDbReq;
2283

2284
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2285
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2286

2287
typedef struct {
2288
  char    db[TSDB_DB_FNAME_LEN];
2289
  int64_t uid;
2290
  int32_t vgVersion;
2291
  int32_t vgNum;
2292
  int16_t hashPrefix;
2293
  int16_t hashSuffix;
2294
  int8_t  hashMethod;
2295
  union {
2296
    uint8_t flags;
2297
    struct {
2298
      uint8_t isMount : 1;  // TS-5868
2299
      uint8_t padding : 7;
2300
    };
2301
  };
2302
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2303
  int32_t errCode;
2304
  int64_t stateTs;  // ms
2305
} SUseDbRsp;
2306

2307
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2308
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2309
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2310
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2311
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2312

2313
typedef struct {
2314
  char db[TSDB_DB_FNAME_LEN];
2315
} SDbCfgReq;
2316

2317
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2318
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2319

2320
typedef struct {
2321
  char db[TSDB_DB_FNAME_LEN];
2322
} SSsMigrateDbReq;
2323

2324
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2325
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2326

2327
typedef struct {
2328
  int32_t ssMigrateId;
2329
  bool    bAccepted;
2330
} SSsMigrateDbRsp;
2331

2332
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2333
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2334

2335
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2336
typedef struct {
2337
  int32_t ssMigrateId;
2338
} SListSsMigrateFileSetsReq;
2339

2340
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2341
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2342

2343
typedef struct {
2344
  int32_t ssMigrateId;
2345
  int32_t vgId;       // vgroup id
2346
  SArray* pFileSets;  // SArray<int32_t>
2347
} SListSsMigrateFileSetsRsp;
2348

2349
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2350
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2351
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2352

2353
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2354
typedef struct {
2355
  int32_t ssMigrateId;
2356
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2357
  int32_t fid;
2358
  int64_t startTimeSec;
2359
} SSsMigrateFileSetReq;
2360

2361
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2362
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2363

2364
typedef struct {
2365
  int32_t ssMigrateId;
2366
  int32_t nodeId;  // node id of the leader vnode
2367
  int32_t vgId;
2368
  int32_t fid;
2369
} SSsMigrateFileSetRsp;
2370

2371
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2372
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2373

2374
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2375
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2376
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2377
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2378
#define SSMIGRATE_FILESET_STATE_FAILED      4
2379

2380
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2381
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2382
// while as a request, the 'state' field is not used.
2383
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2384
typedef struct {
2385
  int32_t ssMigrateId;  // ss migrate id
2386
  int32_t nodeId;       // node id of the leader vnode
2387
  int32_t vgId;         // vgroup id
2388
  int32_t fid;          // file set id
2389
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2390
} SSsMigrateProgress;
2391

2392
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2393
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2394

2395
// Request for TDMT_MND_KILL_SSMIGRATE
2396
typedef struct {
2397
  int32_t ssMigrateId;
2398
  int32_t sqlLen;
2399
  char*   sql;
2400
} SKillSsMigrateReq;
2401

2402
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2403
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2404
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2405

2406
// Request for TDMT_VND_KILL_SSMIGRATE
2407
typedef struct {
2408
  int32_t ssMigrateId;
2409
} SVnodeKillSsMigrateReq;
2410

2411
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2412
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2413

2414
typedef struct {
2415
  int32_t vgId;
2416
  int64_t keepVersion;
2417
} SMndSetVgroupKeepVersionReq;
2418

2419
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2420
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2421

2422
typedef struct {
2423
  int32_t timestampSec;
2424
  int32_t ttlDropMaxCount;
2425
  int32_t nUids;
2426
  SArray* pTbUids;
2427
} SVDropTtlTableReq;
2428

2429
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2430
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2431

2432
typedef struct {
2433
  char    db[TSDB_DB_FNAME_LEN];
2434
  int64_t dbId;
2435
  int64_t ownerId;
2436
  int32_t cfgVersion;
2437
  int32_t numOfVgroups;
2438
  int32_t numOfStables;
2439
  int32_t buffer;
2440
  int32_t cacheSize;
2441
  int32_t cacheShardBits;
2442
  int32_t pageSize;
2443
  int32_t pages;
2444
  int32_t daysPerFile;
2445
  int32_t daysToKeep0;
2446
  int32_t daysToKeep1;
2447
  int32_t daysToKeep2;
2448
  int32_t keepTimeOffset;
2449
  int32_t minRows;
2450
  int32_t maxRows;
2451
  int32_t walFsyncPeriod;
2452
  int16_t hashPrefix;
2453
  int16_t hashSuffix;
2454
  int8_t  hashMethod;
2455
  int8_t  walLevel;
2456
  int8_t  precision;
2457
  int8_t  compression;
2458
  int8_t  replications;
2459
  int8_t  strict;
2460
  int8_t  cacheLast;
2461
  int8_t  encryptAlgr;
2462
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2463
  int32_t ssChunkSize;
2464
  int32_t ssKeepLocal;
2465
  int8_t  ssCompact;
2466
  union {
2467
    uint8_t flags;
2468
    struct {
2469
      uint8_t isMount : 1;    // TS-5868
2470
      uint8_t allowDrop : 1;  // TS-7232
2471
      uint8_t padding : 6;
2472
    };
2473
  };
2474
  int8_t  compactTimeOffset;
2475
  int32_t compactInterval;
2476
  int32_t compactStartTime;
2477
  int32_t compactEndTime;
2478
  int32_t tsdbPageSize;
2479
  int32_t walRetentionPeriod;
2480
  int32_t walRollPeriod;
2481
  int64_t walRetentionSize;
2482
  int64_t walSegmentSize;
2483
  int32_t numOfRetensions;
2484
  SArray* pRetensions;
2485
  int8_t  schemaless;
2486
  int16_t sstTrigger;
2487
  int8_t  withArbitrator;
2488
  int8_t  isAudit;
2489
  int8_t  secureDelete;
2490
} SDbCfgRsp;
2491

2492
typedef SDbCfgRsp SDbCfgInfo;
2493

2494
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2495
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2496
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2497
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2498
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2499

2500
typedef struct {
2501
  int32_t rowNum;
2502
} SQnodeListReq;
2503

2504
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2505
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2506

2507
typedef struct {
2508
  int32_t rowNum;
2509
} SDnodeListReq;
2510

2511
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2512

2513
typedef struct {
2514
  int32_t useless;  // useless
2515
} SServerVerReq;
2516

2517
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2518
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2519

2520
typedef struct {
2521
  char ver[TSDB_VERSION_LEN];
2522
} SServerVerRsp;
2523

2524
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2525
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2526

2527
typedef struct SQueryNodeAddr {
2528
  int32_t nodeId;  // vgId or qnodeId
2529
  SEpSet  epSet;
2530
} SQueryNodeAddr;
2531

2532
typedef struct {
2533
  SQueryNodeAddr addr;
2534
  uint64_t       load;
2535
} SQueryNodeLoad;
2536

2537
typedef struct {
2538
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2539
} SQnodeListRsp;
2540

2541
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2542
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2543
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2544

2545

2546
typedef struct SDownstreamSourceNode {
2547
  ENodeType      type;
2548
  SQueryNodeAddr addr;
2549
  uint64_t       clientId;
2550
  uint64_t       taskId;
2551
  uint64_t       sId;
2552
  uint64_t       srcTaskId;
2553
  int32_t        execId;
2554
  int32_t        fetchMsgType;
2555
  bool           localExec;
2556
} SDownstreamSourceNode;
2557

2558

2559

2560
typedef struct SDNodeAddr {
2561
  int32_t nodeId;  // dnodeId
2562
  SEpSet  epSet;
2563
} SDNodeAddr;
2564

2565
typedef struct {
2566
  SArray* dnodeList;  // SArray<SDNodeAddr>
2567
} SDnodeListRsp;
2568

2569
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2570
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2571
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2572

2573
typedef struct {
2574
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2575
} STableTSMAInfoRsp;
2576

2577
typedef struct {
2578
  SUseDbRsp*         useDbRsp;
2579
  SDbCfgRsp*         cfgRsp;
2580
  STableTSMAInfoRsp* pTsmaRsp;
2581
  int32_t            dbTsmaVersion;
2582
  char               db[TSDB_DB_FNAME_LEN];
2583
  int64_t            dbId;
2584
} SDbHbRsp;
2585

2586
typedef struct {
2587
  SArray* pArray;  // Array of SDbHbRsp
2588
} SDbHbBatchRsp;
2589

2590
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2591
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2592
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2593

2594
typedef struct {
2595
  SArray* pArray;  // Array of SGetUserAuthRsp
2596
} SUserAuthBatchRsp;
2597

2598
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2599
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2600
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2601

2602
typedef struct {
2603
  char        db[TSDB_DB_FNAME_LEN];
2604
  STimeWindow timeRange;
2605
  int32_t     sqlLen;
2606
  char*       sql;
2607
  SArray*     vgroupIds;
2608
  int32_t     compactId;
2609
  int8_t      metaOnly;
2610
  int8_t      force;
2611
} SCompactDbReq;
2612

2613
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2614
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2615
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2616

2617
typedef struct {
2618
  union {
2619
    int32_t compactId;
2620
    int32_t id;
2621
  };
2622
  int8_t bAccepted;
2623
} SCompactDbRsp;
2624

2625
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2626
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2627

2628
typedef struct {
2629
  union {
2630
    int32_t compactId;
2631
    int32_t id;
2632
  };
2633
  int32_t sqlLen;
2634
  char*   sql;
2635
} SKillCompactReq;
2636

2637
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2638
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2639
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2640

2641
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2642
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2643

2644
typedef struct {
2645
  char    name[TSDB_FUNC_NAME_LEN];
2646
  int8_t  igExists;
2647
  int8_t  funcType;
2648
  int8_t  scriptType;
2649
  int8_t  outputType;
2650
  int32_t outputLen;
2651
  int32_t bufSize;
2652
  int32_t codeLen;
2653
  int64_t signature;
2654
  char*   pComment;
2655
  char*   pCode;
2656
  int8_t  orReplace;
2657
} SCreateFuncReq;
2658

2659
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2660
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2661
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2662

2663
typedef struct {
2664
  char   name[TSDB_FUNC_NAME_LEN];
2665
  int8_t igNotExists;
2666
} SDropFuncReq;
2667

2668
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2669
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2670

2671
typedef struct {
2672
  int32_t numOfFuncs;
2673
  bool    ignoreCodeComment;
2674
  SArray* pFuncNames;
2675
} SRetrieveFuncReq;
2676

2677
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2678
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2679
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2680

2681
typedef struct {
2682
  char    name[TSDB_FUNC_NAME_LEN];
2683
  int8_t  funcType;
2684
  int8_t  scriptType;
2685
  int8_t  outputType;
2686
  int32_t outputLen;
2687
  int32_t bufSize;
2688
  int64_t signature;
2689
  int32_t commentSize;
2690
  int32_t codeSize;
2691
  char*   pComment;
2692
  char*   pCode;
2693
} SFuncInfo;
2694

2695
typedef struct {
2696
  int32_t funcVersion;
2697
  int64_t funcCreatedTime;
2698
} SFuncExtraInfo;
2699

2700
typedef struct {
2701
  int32_t numOfFuncs;
2702
  SArray* pFuncInfos;
2703
  SArray* pFuncExtraInfos;
2704
} SRetrieveFuncRsp;
2705

2706
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2707
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2708
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2709
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2710

2711
typedef struct {
2712
  int32_t       statusInterval;
2713
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2714
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2715
  char          locale[TD_LOCALE_LEN];      // tsLocale
2716
  char          charset[TD_LOCALE_LEN];     // tsCharset
2717
  int8_t        ttlChangeOnWrite;
2718
  int8_t        enableWhiteList;
2719
  int8_t        encryptionKeyStat;
2720
  uint32_t      encryptionKeyChksum;
2721
  SMonitorParas monitorParas;
2722
  int32_t       statusIntervalMs;
2723
} SClusterCfg;
2724

2725
typedef struct {
2726
  int32_t openVnodes;
2727
  int32_t dropVnodes;
2728
  int32_t totalVnodes;
2729
  int32_t masterNum;
2730
  int64_t numOfSelectReqs;
2731
  int64_t numOfInsertReqs;
2732
  int64_t numOfInsertSuccessReqs;
2733
  int64_t numOfBatchInsertReqs;
2734
  int64_t numOfBatchInsertSuccessReqs;
2735
  int64_t errors;
2736
} SVnodesStat;
2737

2738
typedef struct {
2739
  int32_t vgId;
2740
  int8_t  syncState;
2741
  int8_t  syncRestore;
2742
  int64_t syncTerm;
2743
  int64_t roleTimeMs;
2744
  int64_t startTimeMs;
2745
  int8_t  syncCanRead;
2746
  int64_t cacheUsage;
2747
  int64_t numOfTables;
2748
  int64_t numOfTimeSeries;
2749
  int64_t totalStorage;
2750
  int64_t compStorage;
2751
  int64_t pointsWritten;
2752
  int64_t numOfSelectReqs;
2753
  int64_t numOfInsertReqs;
2754
  int64_t numOfInsertSuccessReqs;
2755
  int64_t numOfBatchInsertReqs;
2756
  int64_t numOfBatchInsertSuccessReqs;
2757
  int32_t numOfCachedTables;
2758
  int32_t learnerProgress;  // use one reservered
2759
  int64_t syncAppliedIndex;
2760
  int64_t syncCommitIndex;
2761
  int64_t bufferSegmentUsed;
2762
  int64_t bufferSegmentSize;
2763
  int32_t snapSeq;
2764
  int64_t syncTotalIndex;
2765
} SVnodeLoad;
2766

2767
typedef struct {
2768
  int64_t total_requests;
2769
  int64_t total_rows;
2770
  int64_t total_bytes;
2771
  double  write_size;
2772
  double  cache_hit_ratio;
2773
  int64_t rpc_queue_wait;
2774
  int64_t preprocess_time;
2775

2776
  int64_t memory_table_size;
2777
  int64_t commit_count;
2778
  int64_t merge_count;
2779
  double  commit_time;
2780
  double  merge_time;
2781
  int64_t block_commit_time;
2782
  int64_t memtable_wait_time;
2783
} SVnodeMetrics;
2784

2785
typedef struct {
2786
  int32_t     vgId;
2787
  int64_t     numOfTables;
2788
  int64_t     memSize;
2789
  int64_t     l1Size;
2790
  int64_t     l2Size;
2791
  int64_t     l3Size;
2792
  int64_t     cacheSize;
2793
  int64_t     walSize;
2794
  int64_t     metaSize;
2795
  int64_t     rawDataSize;
2796
  int64_t     ssSize;
2797
  const char* dbname;
2798
  int8_t      estimateRawData;
2799
} SDbSizeStatisInfo;
2800

2801
typedef struct {
2802
  int32_t vgId;
2803
  int64_t nTimeSeries;
2804
} SVnodeLoadLite;
2805

2806
typedef struct {
2807
  int8_t  syncState;
2808
  int64_t syncTerm;
2809
  int8_t  syncRestore;
2810
  int64_t roleTimeMs;
2811
} SMnodeLoad;
2812

2813
typedef struct {
2814
  int32_t dnodeId;
2815
  int64_t numOfProcessedQuery;
2816
  int64_t numOfProcessedCQuery;
2817
  int64_t numOfProcessedFetch;
2818
  int64_t numOfProcessedDrop;
2819
  int64_t numOfProcessedNotify;
2820
  int64_t numOfProcessedHb;
2821
  int64_t numOfProcessedDelete;
2822
  int64_t cacheDataSize;
2823
  int64_t numOfQueryInQueue;
2824
  int64_t numOfFetchInQueue;
2825
  int64_t timeInQueryQueue;
2826
  int64_t timeInFetchQueue;
2827
} SQnodeLoad;
2828

2829
typedef struct {
2830
  int32_t     sver;      // software version
2831
  int64_t     dnodeVer;  // dnode table version in sdb
2832
  int32_t     dnodeId;
2833
  int64_t     clusterId;
2834
  int64_t     rebootTime;
2835
  int64_t     updateTime;
2836
  float       numOfCores;
2837
  int32_t     numOfSupportVnodes;
2838
  int32_t     numOfDiskCfg;
2839
  int64_t     memTotal;
2840
  int64_t     memAvail;
2841
  char        dnodeEp[TSDB_EP_LEN];
2842
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2843
  SMnodeLoad  mload;
2844
  SQnodeLoad  qload;
2845
  SClusterCfg clusterCfg;
2846
  SArray*     pVloads;  // array of SVnodeLoad
2847
  int32_t     statusSeq;
2848
  int64_t     ipWhiteVer;
2849
  int64_t     timeWhiteVer;
2850
  int64_t     analVer;
2851
  int64_t     timestamp;
2852
  char        auditDB[TSDB_DB_FNAME_LEN];
2853
  char        auditToken[TSDB_TOKEN_LEN];
2854
  SEpSet      auditEpSet;
2855
  int32_t     auditVgId;
2856
} SStatusReq;
2857

2858
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2859
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2860
void    tFreeSStatusReq(SStatusReq* pReq);
2861

2862
typedef struct {
2863
  int32_t forceReadConfig;
2864
  int32_t cver;
2865
  SArray* array;
2866
} SConfigReq;
2867

2868
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2869
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2870
void    tFreeSConfigReq(SConfigReq* pReq);
2871

2872
typedef struct {
2873
  int32_t dnodeId;
2874
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2875
} SDnodeInfoReq;
2876

2877
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2878
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2879

2880
typedef enum {
2881
  MONITOR_TYPE_COUNTER = 0,
2882
  MONITOR_TYPE_SLOW_LOG = 1,
2883
} MONITOR_TYPE;
2884

2885
typedef struct {
2886
  int32_t      contLen;
2887
  char*        pCont;
2888
  MONITOR_TYPE type;
2889
} SStatisReq;
2890

2891
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2892
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2893
void    tFreeSStatisReq(SStatisReq* pReq);
2894

2895
typedef struct {
2896
  char    db[TSDB_DB_FNAME_LEN];
2897
  char    table[TSDB_TABLE_NAME_LEN];
2898
  char    operation[AUDIT_OPERATION_LEN];
2899
  int32_t sqlLen;
2900
  char*   pSql;
2901
  double  duration;
2902
  int64_t affectedRows;
2903
} SAuditReq;
2904
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2905
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2906
void    tFreeSAuditReq(SAuditReq* pReq);
2907

2908
typedef struct {
2909
  SArray* auditArr;
2910
} SBatchAuditReq;
2911
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2912
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2913
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2914

2915
typedef struct {
2916
  int32_t dnodeId;
2917
  int64_t clusterId;
2918
  SArray* pVloads;
2919
} SNotifyReq;
2920

2921
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2922
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2923
void    tFreeSNotifyReq(SNotifyReq* pReq);
2924

2925
typedef struct {
2926
  int32_t dnodeId;
2927
  int64_t clusterId;
2928
} SDnodeCfg;
2929

2930
typedef struct {
2931
  int32_t id;
2932
  int8_t  isMnode;
2933
  SEp     ep;
2934
} SDnodeEp;
2935

2936
typedef struct {
2937
  int32_t id;
2938
  int8_t  isMnode;
2939
  int8_t  offlineReason;
2940
  SEp     ep;
2941
  char    active[TSDB_ACTIVE_KEY_LEN];
2942
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2943
} SDnodeInfo;
2944

2945
typedef struct {
2946
  int64_t   dnodeVer;
2947
  SDnodeCfg dnodeCfg;
2948
  SArray*   pDnodeEps;  // Array of SDnodeEp
2949
  int32_t   statusSeq;
2950
  int64_t   ipWhiteVer;
2951
  int64_t   analVer;
2952
  int64_t   timeWhiteVer;
2953
  char      auditDB[TSDB_DB_FNAME_LEN];
2954
  char      auditToken[TSDB_TOKEN_LEN];
2955
  SEpSet    auditEpSet;
2956
  int32_t   auditVgId;
2957
} SStatusRsp;
2958

2959
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2960
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2961
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2962

2963
typedef struct {
2964
  int32_t forceReadConfig;
2965
  int32_t isConifgVerified;
2966
  int32_t isVersionVerified;
2967
  int32_t cver;
2968
  SArray* array;
2969
} SConfigRsp;
2970

2971
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2972
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2973
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2974

2975
typedef struct {
2976
  int32_t dnodeId;
2977
  int32_t keyVersion;  // Local key version
2978
} SKeySyncReq;
2979

2980
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2981
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2982

2983
typedef struct {
2984
  int32_t keyVersion;        // mnode's key version
2985
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2986
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2987
  char    svrKey[129];       // Server key (if needUpdate)
2988
  char    dbKey[129];        // Database key (if needUpdate)
2989
  char    cfgKey[129];       // Config key (if needUpdate)
2990
  char    metaKey[129];      // Metadata key (if needUpdate)
2991
  char    dataKey[129];      // Data key (if needUpdate)
2992
  int32_t algorithm;         // Encryption algorithm for master keys
2993
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2994
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2995
  int64_t createTime;        // Key creation time
2996
  int64_t svrKeyUpdateTime;  // Server key update time
2997
  int64_t dbKeyUpdateTime;   // Database key update time
2998
} SKeySyncRsp;
2999

3000
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3001
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3002

3003
typedef struct {
3004
  int32_t reserved;
3005
} SMTimerReq;
3006

3007
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3008
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3009

3010
typedef struct SOrphanTask {
3011
  int64_t streamId;
3012
  int32_t taskId;
3013
  int32_t nodeId;
3014
} SOrphanTask;
3015

3016
typedef struct SMStreamDropOrphanMsg {
3017
  SArray* pList;  // SArray<SOrphanTask>
3018
} SMStreamDropOrphanMsg;
3019

3020
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3021
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3022
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
3023

3024
typedef struct {
3025
  int32_t  id;
3026
  uint16_t port;                 // node sync Port
3027
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3028
} SReplica;
3029

3030
typedef struct {
3031
  int32_t  vgId;
3032
  char     db[TSDB_DB_FNAME_LEN];
3033
  int64_t  dbUid;
3034
  int32_t  vgVersion;
3035
  int32_t  numOfStables;
3036
  int32_t  buffer;
3037
  int32_t  pageSize;
3038
  int32_t  pages;
3039
  int32_t  cacheLastSize;
3040
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3041
  int32_t  daysPerFile;
3042
  int32_t  daysToKeep0;
3043
  int32_t  daysToKeep1;
3044
  int32_t  daysToKeep2;
3045
  int32_t  keepTimeOffset;
3046
  int32_t  minRows;
3047
  int32_t  maxRows;
3048
  int32_t  walFsyncPeriod;
3049
  uint32_t hashBegin;
3050
  uint32_t hashEnd;
3051
  int8_t   hashMethod;
3052
  int8_t   walLevel;
3053
  int8_t   precision;
3054
  int8_t   compression;
3055
  int8_t   strict;
3056
  int8_t   cacheLast;
3057
  int8_t   isTsma;
3058
  int8_t   replica;
3059
  int8_t   selfIndex;
3060
  SReplica replicas[TSDB_MAX_REPLICA];
3061
  int32_t  numOfRetensions;
3062
  SArray*  pRetensions;  // SRetention
3063
  void*    pTsma;
3064
  int32_t  walRetentionPeriod;
3065
  int64_t  walRetentionSize;
3066
  int32_t  walRollPeriod;
3067
  int64_t  walSegmentSize;
3068
  int16_t  sstTrigger;
3069
  int16_t  hashPrefix;
3070
  int16_t  hashSuffix;
3071
  int32_t  tsdbPageSize;
3072
  int32_t  ssChunkSize;
3073
  int32_t  ssKeepLocal;
3074
  int8_t   ssCompact;
3075
  int64_t  reserved[6];
3076
  int8_t   learnerReplica;
3077
  int8_t   learnerSelfIndex;
3078
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3079
  int32_t  changeVersion;
3080
  int8_t   encryptAlgorithm;
3081
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3082
  union {
3083
    uint8_t flags;
3084
    struct {
3085
      uint8_t isAudit : 1;
3086
      uint8_t allowDrop : 1;
3087
      uint8_t padding : 6;
3088
    };
3089
  };
3090
  int8_t secureDelete;
3091
} SCreateVnodeReq;
3092

3093
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3094
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3095
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3096

3097
typedef struct {
3098
  union {
3099
    int32_t compactId;
3100
    int32_t id;
3101
  };
3102
  int32_t vgId;
3103
  int32_t dnodeId;
3104
} SQueryCompactProgressReq;
3105

3106
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3107
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3108

3109
typedef struct {
3110
  union {
3111
    int32_t compactId;
3112
    int32_t id;
3113
  };
3114
  int32_t vgId;
3115
  int32_t dnodeId;
3116
  int32_t numberFileset;
3117
  int32_t finished;
3118
  int32_t progress;
3119
  int64_t remainingTime;
3120
} SQueryCompactProgressRsp;
3121

3122
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3123
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3124

3125
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3126
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3127

3128
typedef struct {
3129
  int32_t vgId;
3130
  int32_t dnodeId;
3131
  int64_t dbUid;
3132
  char    db[TSDB_DB_FNAME_LEN];
3133
  int64_t reserved[8];
3134
} SDropVnodeReq;
3135

3136
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3137
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3138

3139
typedef struct {
3140
  char    colName[TSDB_COL_NAME_LEN];
3141
  char    stb[TSDB_TABLE_FNAME_LEN];
3142
  int64_t stbUid;
3143
  int64_t dbUid;
3144
  int64_t reserved[8];
3145
} SDropIndexReq;
3146

3147
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3148
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3149

3150
typedef struct {
3151
  int64_t dbUid;
3152
  char    db[TSDB_DB_FNAME_LEN];
3153
  union {
3154
    int64_t compactStartTime;
3155
    int64_t startTime;
3156
  };
3157

3158
  STimeWindow tw;
3159
  union {
3160
    int32_t compactId;
3161
    int32_t id;
3162
  };
3163
  int8_t metaOnly;
3164
  union {
3165
    uint16_t flags;
3166
    struct {
3167
      uint16_t optrType : 3;     // ETsdbOpType
3168
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3169
      uint16_t reserved : 12;
3170
    };
3171
  };
3172
  int8_t force;  // force compact
3173
} SCompactVnodeReq;
3174

3175
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3176
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3177

3178
typedef struct {
3179
  union {
3180
    int32_t compactId;
3181
    int32_t taskId;
3182
  };
3183
  int32_t vgId;
3184
  int32_t dnodeId;
3185
} SVKillCompactReq;
3186

3187
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3188
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3189

3190
typedef SVKillCompactReq SVKillRetentionReq;
3191

3192
typedef struct {
3193
  char        db[TSDB_DB_FNAME_LEN];
3194
  int32_t     maxSpeed;
3195
  int32_t     sqlLen;
3196
  char*       sql;
3197
  SArray*     vgroupIds;
3198
  STimeWindow tw;  // unit is second
3199
  union {
3200
    uint32_t flags;
3201
    struct {
3202
      uint32_t optrType : 3;     // ETsdbOpType
3203
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3204
      uint32_t reserved : 28;
3205
    };
3206
  };
3207
} STrimDbReq;
3208

3209
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3210
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3211
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3212

3213
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3214

3215
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3216
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3217

3218
typedef struct {
3219
  int32_t vgVersion;
3220
  int32_t buffer;
3221
  int32_t pageSize;
3222
  int32_t pages;
3223
  int32_t cacheLastSize;
3224
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3225
  int32_t daysPerFile;
3226
  int32_t daysToKeep0;
3227
  int32_t daysToKeep1;
3228
  int32_t daysToKeep2;
3229
  int32_t keepTimeOffset;
3230
  int32_t walFsyncPeriod;
3231
  int8_t  walLevel;
3232
  int8_t  strict;
3233
  int8_t  cacheLast;
3234
  int64_t reserved[7];
3235
  // 1st modification
3236
  int16_t sttTrigger;
3237
  int32_t minRows;
3238
  // 2nd modification
3239
  int32_t walRetentionPeriod;
3240
  int32_t walRetentionSize;
3241
  int32_t ssKeepLocal;
3242
  int8_t  ssCompact;
3243
  int8_t  allowDrop;
3244
  int8_t  secureDelete;
3245
} SAlterVnodeConfigReq;
3246

3247
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3248
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3249

3250
typedef struct {
3251
  int32_t  vgId;
3252
  int8_t   strict;
3253
  int8_t   selfIndex;
3254
  int8_t   replica;
3255
  SReplica replicas[TSDB_MAX_REPLICA];
3256
  int64_t  reserved[8];
3257
  int8_t   learnerSelfIndex;
3258
  int8_t   learnerReplica;
3259
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3260
  int32_t  changeVersion;
3261
  int32_t  electBaseLine;
3262
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3263

3264
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3265
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3266

3267
typedef struct {
3268
  int32_t vgId;
3269
  int8_t  disable;
3270
} SDisableVnodeWriteReq;
3271

3272
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3273
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3274

3275
typedef struct {
3276
  int32_t  srcVgId;
3277
  int32_t  dstVgId;
3278
  uint32_t hashBegin;
3279
  uint32_t hashEnd;
3280
  int32_t  changeVersion;
3281
  int32_t  reserved;
3282
} SAlterVnodeHashRangeReq;
3283

3284
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3285
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3286

3287
#define REQ_OPT_TBNAME 0x0
3288
#define REQ_OPT_TBUID  0x01
3289
typedef struct {
3290
  SMsgHead header;
3291
  char     dbFName[TSDB_DB_FNAME_LEN];
3292
  char     tbName[TSDB_TABLE_NAME_LEN];
3293
  uint8_t  option;
3294
  uint8_t  autoCreateCtb;
3295
} STableInfoReq;
3296

3297
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3298
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3299

3300
typedef struct {
3301
  int8_t  metaClone;  // create local clone of the cached table meta
3302
  int32_t numOfVgroups;
3303
  int32_t numOfTables;
3304
  int32_t numOfUdfs;
3305
  char    tableNames[];
3306
} SMultiTableInfoReq;
3307

3308
// todo refactor
3309
typedef struct SVgroupInfo {
3310
  int32_t  vgId;
3311
  uint32_t hashBegin;
3312
  uint32_t hashEnd;
3313
  SEpSet   epSet;
3314
  union {
3315
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3316
    int32_t taskId;      // used in stream
3317
  };
3318
} SVgroupInfo;
3319

3320
typedef struct {
3321
  int32_t     numOfVgroups;
3322
  SVgroupInfo vgroups[];
3323
} SVgroupsInfo;
3324

3325
typedef struct {
3326
  STableMetaRsp* pMeta;
3327
} SMAlterStbRsp;
3328

3329
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3330
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3331
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3332

3333
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3334
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3335
void    tFreeSTableMetaRsp(void* pRsp);
3336
void    tFreeSTableIndexRsp(void* info);
3337

3338
typedef struct {
3339
  SArray* pMetaRsp;   // Array of STableMetaRsp
3340
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3341
} SSTbHbRsp;
3342

3343
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3344
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3345
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3346

3347
typedef struct {
3348
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3349
} SViewHbRsp;
3350

3351
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3352
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3353
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3354

3355
typedef struct {
3356
  int32_t numOfTables;
3357
  int32_t numOfVgroup;
3358
  int32_t numOfUdf;
3359
  int32_t contLen;
3360
  int8_t  compressed;  // denote if compressed or not
3361
  int32_t rawLen;      // size before compress
3362
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3363
  char    meta[];
3364
} SMultiTableMeta;
3365

3366
typedef struct {
3367
  int32_t dataLen;
3368
  char    name[TSDB_TABLE_FNAME_LEN];
3369
  char*   data;
3370
} STagData;
3371

3372
typedef struct {
3373
  int32_t  opType;
3374
  uint32_t valLen;
3375
  char*    val;
3376
} SShowVariablesReq;
3377

3378
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3379
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3380
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3381

3382
typedef struct {
3383
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3384
  char value[TSDB_CONFIG_PATH_LEN + 1];
3385
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3386
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3387
  char info[TSDB_CONFIG_INFO_LEN + 1];
3388
} SVariablesInfo;
3389

3390
typedef struct {
3391
  SArray* variables;  // SArray<SVariablesInfo>
3392
} SShowVariablesRsp;
3393

3394
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3395
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3396

3397
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3398

3399
/*
3400
 * sql: show tables like '%a_%'
3401
 * payload is the query condition, e.g., '%a_%'
3402
 * payloadLen is the length of payload
3403
 */
3404
typedef struct {
3405
  int32_t type;
3406
  char    db[TSDB_DB_FNAME_LEN];
3407
  int32_t payloadLen;
3408
  char*   payload;
3409
} SShowReq;
3410

3411
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3412
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3413
void tFreeSShowReq(SShowReq* pReq);
3414

3415
typedef struct {
3416
  int64_t       showId;
3417
  STableMetaRsp tableMeta;
3418
} SShowRsp, SVShowTablesRsp;
3419

3420
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3421
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3422
// void    tFreeSShowRsp(SShowRsp* pRsp);
3423

3424
typedef struct {
3425
  char    db[TSDB_DB_FNAME_LEN];
3426
  char    tb[TSDB_TABLE_NAME_LEN];
3427
  char    user[TSDB_USER_LEN];
3428
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3429
  int64_t showId;
3430
  int64_t compactId;  // for compact
3431
  bool    withFull;   // for show users full
3432
} SRetrieveTableReq;
3433

3434
typedef struct SSysTableSchema {
3435
  int8_t   type;
3436
  col_id_t colId;
3437
  int32_t  bytes;
3438
} SSysTableSchema;
3439

3440
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3441
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3442

3443
#define RETRIEVE_TABLE_RSP_VERSION         0
3444
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3445
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3446

3447
typedef struct {
3448
  int64_t useconds;
3449
  int8_t  completed;  // all results are returned to client
3450
  int8_t  precision;
3451
  int8_t  compressed;
3452
  int8_t  streamBlockType;
3453
  int32_t payloadLen;
3454
  int32_t compLen;
3455
  int32_t numOfBlocks;
3456
  int64_t numOfRows;  // from int32_t change to int64_t
3457
  int64_t numOfCols;
3458
  int64_t skey;
3459
  int64_t ekey;
3460
  int64_t version;                         // for stream
3461
  TSKEY   watermark;                       // for stream
3462
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3463
  char    data[];
3464
} SRetrieveTableRsp;
3465

3466
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3467

3468
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3469
  do {                                          \
3470
    ((int32_t*)(_p))[0] = (_compLen);           \
3471
    ((int32_t*)(_p))[1] = (_fullLen);           \
3472
  } while (0);
3473

3474
typedef struct {
3475
  int64_t version;
3476
  int64_t numOfRows;
3477
  int8_t  compressed;
3478
  int8_t  precision;
3479
  char    data[];
3480
} SRetrieveTableRspForTmq;
3481

3482
typedef struct {
3483
  int64_t handle;
3484
  int64_t useconds;
3485
  int8_t  completed;  // all results are returned to client
3486
  int8_t  precision;
3487
  int8_t  compressed;
3488
  int32_t compLen;
3489
  int32_t numOfRows;
3490
  int32_t fullLen;
3491
  char    data[];
3492
} SRetrieveMetaTableRsp;
3493

3494
typedef struct SExplainExecInfo {
3495
  /* the number of rows returned */
3496
  uint64_t numOfRows;
3497
  uint32_t verboseLen;
3498
  void*    verboseInfo;
3499

3500
  /* the timestamp when the operator is created */
3501
  TSKEY    execCreate;
3502
  /* the first timestamp when the operator's next interface is called */
3503
  TSKEY    execStart;
3504
  /* the timestamp when the first row is returned */
3505
  TSKEY    execFirstRow;
3506
  /* the timestamp when the last row is returned */
3507
  TSKEY    execLastRow;
3508
  /* the number of times the operator's next interface is called */
3509
  uint32_t execTimes;
3510
  /**
3511
    the time elapsed for executing the operator's next interface,
3512
    not including waiting time for data from downstream
3513
  */
3514
  TSKEY    execElapsed;
3515
  /* the time elapsed for waiting for data from downstream */
3516
  TSKEY    inputWaitElapsed;
3517
  /* the time elapsed for waiting call from upstream */
3518
  TSKEY    outputWaitElapsed;
3519
  /* the number of rows input */
3520
  uint64_t inputRows;
3521

3522
  int32_t  vgId;
3523
} SExplainExecInfo;
3524

3525
typedef struct {
3526
  int32_t           numOfPlans;
3527
  SExplainExecInfo* subplanInfo;
3528
} SExplainRsp;
3529

3530
typedef struct {
3531
  SExplainRsp rsp;
3532
  uint64_t    qId;
3533
  uint64_t    cId;
3534
  uint64_t    tId;
3535
  int64_t     rId;
3536
  int32_t     eId;
3537
} SExplainLocalRsp;
3538

3539
typedef struct STableScanAnalyzeInfo {
3540
  int64_t totalBlocks;
3541
  int64_t fileLoadBlocks;
3542
  double  fileLoadElapsed;
3543
  int64_t sttLoadBlocks;
3544
  double  sttLoadElapsed;
3545
  int64_t memLoadBlocks;
3546
  double  memLoadElapsed;
3547
  int64_t smaLoadBlocks;
3548
  double  smaLoadElapsed;
3549
  int64_t composedBlocks;
3550
  double  composedElapsed;
3551
  
3552
  uint64_t checkRows;
3553

3554
  uint64_t skipBlocks;
3555
  uint64_t filterOutBlocks;
3556
  double   filterTime;
3557
} STableScanAnalyzeInfo;
3558

3559
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3560
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3561
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3562

3563
typedef struct {
3564
  char    config[TSDB_DNODE_CONFIG_LEN];
3565
  char    value[TSDB_CLUSTER_VALUE_LEN];
3566
  int32_t sqlLen;
3567
  char*   sql;
3568
} SMCfgClusterReq;
3569

3570
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3571
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3572
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3573

3574
typedef struct {
3575
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3576
  int32_t port;
3577
  int32_t sqlLen;
3578
  char*   sql;
3579
} SCreateDnodeReq;
3580

3581
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3582
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3583
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3584

3585
typedef struct {
3586
  int32_t dnodeId;
3587
  char    fqdn[TSDB_FQDN_LEN];
3588
  int32_t port;
3589
  int8_t  force;
3590
  int8_t  unsafe;
3591
  int32_t sqlLen;
3592
  char*   sql;
3593
} SDropDnodeReq;
3594

3595
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3596
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3597
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3598

3599
enum {
3600
  RESTORE_TYPE__ALL = 1,
3601
  RESTORE_TYPE__MNODE,
3602
  RESTORE_TYPE__VNODE,
3603
  RESTORE_TYPE__QNODE,
3604
};
3605

3606
typedef struct {
3607
  int32_t dnodeId;
3608
  int8_t  restoreType;
3609
  int32_t sqlLen;
3610
  char*   sql;
3611
  int32_t vgId;
3612
} SRestoreDnodeReq;
3613

3614
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3615
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3616
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3617

3618
typedef struct {
3619
  int32_t dnodeId;
3620
  char    config[TSDB_DNODE_CONFIG_LEN];
3621
  char    value[TSDB_DNODE_VALUE_LEN];
3622
  int32_t sqlLen;
3623
  char*   sql;
3624
} SMCfgDnodeReq;
3625

3626
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3627
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3628
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3629

3630
typedef struct {
3631
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3632
  char    newKey[ENCRYPT_KEY_LEN + 1];
3633
  int32_t sqlLen;
3634
  char*   sql;
3635
} SMAlterEncryptKeyReq;
3636

3637
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3638
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3639
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3640

3641
typedef struct {
3642
  int32_t days;
3643
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3644
  int32_t sqlLen;
3645
  char*   sql;
3646
} SMAlterKeyExpirationReq;
3647

3648
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3649
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3650
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3651

3652
typedef struct {
3653
  char    config[TSDB_DNODE_CONFIG_LEN];
3654
  char    value[TSDB_DNODE_VALUE_LEN];
3655
  int32_t version;
3656
} SDCfgDnodeReq;
3657

3658
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3659
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3660

3661
typedef struct {
3662
  int32_t dnodeId;
3663
  int32_t sqlLen;
3664
  char*   sql;
3665
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3666
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3667

3668
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3669
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3670

3671
typedef struct {
3672
  int32_t nodeId;
3673
  SEpSet  epSet;
3674
} SNodeEpSet;
3675

3676
typedef struct {
3677
  int32_t    snodeId;
3678
  SNodeEpSet leaders[2];
3679
  SNodeEpSet replica;
3680
  int32_t    sqlLen;
3681
  char*      sql;
3682
} SDCreateSnodeReq;
3683

3684
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3685
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3686
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3687

3688
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3689
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3690
typedef struct {
3691
  int8_t   replica;
3692
  SReplica replicas[TSDB_MAX_REPLICA];
3693
  int8_t   learnerReplica;
3694
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3695
  int64_t  lastIndex;
3696
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3697
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3698

3699
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3700
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3701

3702
typedef struct {
3703
  int32_t urlLen;
3704
  int32_t sqlLen;
3705
  char*   url;
3706
  char*   sql;
3707
} SMCreateAnodeReq;
3708

3709
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3710
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3711
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3712

3713
typedef struct {
3714
  int32_t anodeId;
3715
  int32_t sqlLen;
3716
  char*   sql;
3717
} SMDropAnodeReq, SMUpdateAnodeReq;
3718

3719
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3720
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3721
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3722
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3723
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3724
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3725

3726
typedef struct {
3727
  int32_t dnodeId;
3728
  int32_t bnodeProto;
3729
  int32_t sqlLen;
3730
  char*   sql;
3731
} SMCreateBnodeReq, SDCreateBnodeReq;
3732

3733
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3734
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3735
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3736

3737
typedef struct {
3738
  int32_t dnodeId;
3739
  int32_t sqlLen;
3740
  char*   sql;
3741
} SMDropBnodeReq, SDDropBnodeReq;
3742

3743
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3744
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3745
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3746

3747
typedef struct {
3748
  bool        shouldFree;
3749
  int32_t     len;
3750
  const char* ptr;
3751
} CowStr;
3752
/**
3753
 * @brief Create a CowStr object.
3754
 *
3755
 * @param len: length of the string.
3756
 * @param ptr: pointer to the string input.
3757
 * @param shouldClone: whether to clone the string.
3758
 * @return CowStr object.
3759
 */
3760
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3761
/**
3762
 * @brief Set a CowStr object with given string.
3763
 *
3764
 * @param cow: pointer to the CowStr object.
3765
 * @param len: length of the string.
3766
 * @param ptr: pointer to the string input.
3767
 * @param shouldFree: whether to free the string.
3768
 */
3769
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3770
/**
3771
 * @brief Clone a CowStr object without copy the string.
3772
 *
3773
 * @param cow: pointer to the CowStr object.
3774
 * @return CowStr object.
3775
 */
3776
CowStr xCloneRefCowStr(CowStr* cow);
3777
/**
3778
 * @brief Convert a CowStr object to a string.
3779
 *
3780
 * @param cow: pointer to the CowStr object.
3781
 */
3782
char* xCowStrToStr(CowStr* cow);
3783
/**
3784
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3785
 *
3786
 * @param cow: pointer to the CowStr object.
3787
 */
3788
void xFreeCowStr(CowStr* cow);
3789
/**
3790
 * @brief Encode and push a CowStr object into the encoder.
3791
 *
3792
 * @param encoder
3793
 * @param cow
3794
 * @return int32_t
3795
 */
3796
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3797
/**
3798
 * @brief Decode a CowStr from the encoder.
3799
 *
3800
 * @param decoder
3801
 * @param cow
3802
 * @param shouldClone
3803
 * @return int32_t
3804
 */
3805
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3806

3807
typedef struct {
3808
  int32_t sqlLen;
3809
  int32_t urlLen;
3810
  int32_t userLen;
3811
  int32_t passLen;
3812
  int32_t passIsMd5;
3813
  char*   sql;
3814
  char*   url;
3815
  char*   user;
3816
  char*   pass;
3817
  CowStr  token;
3818
} SMCreateXnodeReq, SDCreateXnodeReq;
3819

3820
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3821
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3822
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3823

3824
typedef struct {
3825
  int32_t xnodeId;
3826
  int32_t force;
3827
  int32_t urlLen;
3828
  int32_t sqlLen;
3829
  char*   url;
3830
  char*   sql;
3831
} SMDropXnodeReq, SDDropXnodeReq;
3832

3833
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3834
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3835
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3836

3837
typedef struct {
3838
  int32_t id;
3839
  CowStr  token;
3840
  CowStr  user;
3841
  CowStr  pass;
3842
  int32_t urlLen;
3843
  int32_t sqlLen;
3844
  char*   url;
3845
  char*   sql;
3846
} SMUpdateXnodeReq;
3847
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3848
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3849
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3850

3851
typedef struct {
3852
  int32_t xnodeId;
3853
  int32_t sqlLen;
3854
  char*   sql;
3855
} SMDrainXnodeReq;
3856
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3857
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3858
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3859
typedef enum {
3860
  XNODE_TASK_SOURCE_DSN = 1,
3861
  XNODE_TASK_SOURCE_DATABASE,
3862
  XNODE_TASK_SOURCE_TOPIC,
3863
} ENodeXTaskSourceType;
3864

3865
typedef enum {
3866
  XNODE_TASK_SINK_DSN = 1,
3867
  XNODE_TASK_SINK_DATABASE,
3868
} ENodeXTaskSinkType;
3869

3870
typedef struct {
3871
  ENodeXTaskSourceType type;
3872
  CowStr               cstr;
3873
} xTaskSource;
3874
/**
3875
 * @brief Deallocate a xTaskSource object.
3876
 *
3877
 * @param source ptr
3878
 */
3879
void xFreeTaskSource(xTaskSource* source);
3880
/**
3881
 * @brief Create a xTaskSource object with cloned source string.
3882
 *
3883
 * @param sourceType: source type.
3884
 * @param len: length of source string.
3885
 * @param source: source string ptr.
3886
 * @return xTaskSource object
3887
 */
3888
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3889
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3890
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3891
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3892
const char* xGetTaskSourceStr(xTaskSource* source);
3893
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3894
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3895

3896
typedef struct {
3897
  ENodeXTaskSinkType type;
3898
  CowStr             cstr;
3899
} xTaskSink;
3900
/**
3901
 * @brief Deallocate a xTaskSink object.
3902
 *
3903
 * @param sink ptr
3904
 */
3905
void xFreeTaskSink(xTaskSink* sink);
3906
/**
3907
 * @brief Create a xTaskSink object with cloned name string.
3908
 *
3909
 * @param sinkType: sink type.
3910
 * @param len: length of sink string.
3911
 * @param ptr: sink string ptr.
3912
 * @return xTaskSink object
3913
 */
3914
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3915
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3916
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3917
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3918
const char* xGetTaskSinkStr(xTaskSink* sink);
3919
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3920
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3921

3922
typedef struct {
3923
  int32_t via;
3924
  CowStr  parser;
3925
  // CowStr  reason;
3926
  CowStr  trigger;
3927
  CowStr  health;
3928
  int32_t optionsNum;
3929
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3930
} xTaskOptions;
3931
/**
3932
 * @brief Deallocate a xTaskOptions object.
3933
 *
3934
 * @param options ptr
3935
 */
3936
void    xFreeTaskOptions(xTaskOptions* options);
3937
void    printXnodeTaskOptions(xTaskOptions* options);
3938
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3939
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3940

3941
typedef struct {
3942
  int32_t sqlLen;
3943
  char*   sql;
3944
  int32_t      xnodeId;
3945
  CowStr       name;
3946
  xTaskSource  source;
3947
  xTaskSink    sink;
3948
  xTaskOptions options;
3949
} SMCreateXnodeTaskReq;
3950
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3951
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3952
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3953

3954
typedef struct {
3955
  int32_t     tid;
3956
  CowStr      name;
3957
  int32_t     via;
3958
  int32_t     xnodeId;
3959
  CowStr      status;
3960
  xTaskSource source;
3961
  xTaskSink   sink;
3962
  CowStr      parser;
3963
  CowStr      reason;
3964
  CowStr      updateName;
3965
  CowStr      labels;
3966
  int32_t     sqlLen;
3967
  char*       sql;
3968
} SMUpdateXnodeTaskReq;
3969
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3970
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3971
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3972

3973
typedef struct {
3974
  int32_t id;
3975
  bool    force;
3976
  CowStr  name;
3977
  int32_t sqlLen;
3978
  char*   sql;
3979
} SMDropXnodeTaskReq;
3980
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3981
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3982
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3983

3984
typedef struct {
3985
  int32_t tid;
3986
  CowStr  name;
3987
  int32_t sqlLen;
3988
  char*   sql;
3989
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3990
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3991
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3992
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3993

3994
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3995
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3996
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3997

3998
typedef struct {
3999
  int32_t tid;
4000
  int32_t via;
4001
  int32_t xnodeId;
4002
  CowStr  status;
4003
  CowStr  config;
4004
  CowStr  reason;
4005
  int32_t sqlLen;
4006
  char*   sql;
4007
} SMCreateXnodeJobReq;
4008
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4009
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4010
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
4011

4012
typedef struct {
4013
  int32_t jid;
4014
  int32_t via;
4015
  int32_t xnodeId;
4016
  CowStr  status;
4017
  int32_t configLen;
4018
  int32_t reasonLen;
4019
  int32_t sqlLen;
4020
  char*   config;
4021
  char*   reason;
4022
  char*   sql;
4023
} SMUpdateXnodeJobReq;
4024
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4025
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4026
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4027

4028
typedef struct {
4029
  int32_t jid;
4030
  int32_t xnodeId;
4031
  int32_t sqlLen;
4032
  char*   sql;
4033
} SMRebalanceXnodeJobReq;
4034
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4035
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4036
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4037

4038
typedef struct {
4039
  CowStr  ast;
4040
  int32_t sqlLen;
4041
  char*   sql;
4042
} SMRebalanceXnodeJobsWhereReq;
4043
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4044
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4045
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4046

4047
typedef struct {
4048
  int32_t jid;
4049
  CowStr  ast;
4050
  int32_t sqlLen;
4051
  char*   sql;
4052
} SMDropXnodeJobReq;
4053
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4054
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4055
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4056

4057
typedef struct {
4058
  int32_t      sqlLen;
4059
  char*        sql;
4060
  CowStr       name;
4061
  CowStr       status;
4062
  xTaskOptions options;
4063
} SMCreateXnodeAgentReq;
4064
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4065
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4066
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4067

4068
typedef struct {
4069
  int32_t      sqlLen;
4070
  char*        sql;
4071
  int32_t      id;
4072
  CowStr       name;
4073
  xTaskOptions options;
4074
} SMUpdateXnodeAgentReq;
4075
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4076
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4077
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4078

4079
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4080
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4081
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4082
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4083

4084
typedef struct {
4085
  int32_t vgId;
4086
  int32_t hbSeq;
4087
} SVArbHbReqMember;
4088

4089
typedef struct {
4090
  int32_t dnodeId;
4091
  char*   arbToken;
4092
  int64_t arbTerm;
4093
  SArray* hbMembers;  // SVArbHbReqMember
4094
} SVArbHeartBeatReq;
4095

4096
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4097
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4098
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4099

4100
typedef struct {
4101
  int32_t vgId;
4102
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4103
  int32_t hbSeq;
4104
} SVArbHbRspMember;
4105

4106
typedef struct {
4107
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4108
  int32_t dnodeId;
4109
  SArray* hbMembers;  // SVArbHbRspMember
4110
} SVArbHeartBeatRsp;
4111

4112
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4113
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4114
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4115

4116
typedef struct {
4117
  char*   arbToken;
4118
  int64_t arbTerm;
4119
  char*   member0Token;
4120
  char*   member1Token;
4121
} SVArbCheckSyncReq;
4122

4123
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4124
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4125
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4126

4127
typedef struct {
4128
  char*   arbToken;
4129
  char*   member0Token;
4130
  char*   member1Token;
4131
  int32_t vgId;
4132
  int32_t errCode;
4133
} SVArbCheckSyncRsp;
4134

4135
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4136
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4137
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4138

4139
typedef struct {
4140
  char*   arbToken;
4141
  int64_t arbTerm;
4142
  char*   memberToken;
4143
  int8_t  force;
4144
} SVArbSetAssignedLeaderReq;
4145

4146
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4147
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4148
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4149

4150
typedef struct {
4151
  char* data;
4152
} SVAuditRecordReq;
4153
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4154
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4155
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4156

4157
typedef struct {
4158
  char*   arbToken;
4159
  char*   memberToken;
4160
  int32_t vgId;
4161
} SVArbSetAssignedLeaderRsp;
4162

4163
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4164
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4165
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4166

4167
typedef struct {
4168
  int32_t dnodeId;
4169
  char*   token;
4170
} SMArbUpdateGroupMember;
4171

4172
typedef struct {
4173
  int32_t dnodeId;
4174
  char*   token;
4175
  int8_t  acked;
4176
} SMArbUpdateGroupAssigned;
4177

4178
typedef struct {
4179
  int32_t                  vgId;
4180
  int64_t                  dbUid;
4181
  SMArbUpdateGroupMember   members[2];
4182
  int8_t                   isSync;
4183
  int8_t                   assignedAcked;
4184
  SMArbUpdateGroupAssigned assignedLeader;
4185
  int64_t                  version;
4186
  int32_t                  code;
4187
  int64_t                  updateTimeMs;
4188
} SMArbUpdateGroup;
4189

4190
typedef struct {
4191
  SArray* updateArray;  // SMArbUpdateGroup
4192
} SMArbUpdateGroupBatchReq;
4193

4194
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4195
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4196
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4197

4198
typedef struct {
4199
  char queryStrId[TSDB_QUERY_ID_LEN];
4200
} SKillQueryReq;
4201

4202
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4203
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4204

4205
typedef struct {
4206
  uint32_t connId;
4207
} SKillConnReq;
4208

4209
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4210
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4211

4212
typedef struct {
4213
  int32_t transId;
4214
} SKillTransReq;
4215

4216
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4217
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4218

4219
typedef struct {
4220
  int32_t useless;  // useless
4221
  int32_t sqlLen;
4222
  char*   sql;
4223
} SBalanceVgroupReq;
4224

4225
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4226
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4227
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4228

4229
typedef struct {
4230
  int32_t useless;  // useless
4231
  int32_t sqlLen;
4232
  char*   sql;
4233
} SAssignLeaderReq;
4234

4235
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4236
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4237
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4238
typedef struct {
4239
  int32_t vgId1;
4240
  int32_t vgId2;
4241
} SMergeVgroupReq;
4242

4243
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4244
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4245

4246
typedef struct {
4247
  int32_t vgId;
4248
  int32_t dnodeId1;
4249
  int32_t dnodeId2;
4250
  int32_t dnodeId3;
4251
  int32_t sqlLen;
4252
  char*   sql;
4253
} SRedistributeVgroupReq;
4254

4255
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4256
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4257
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4258

4259
typedef struct {
4260
  int32_t reserved;
4261
  int32_t vgId;
4262
  int32_t sqlLen;
4263
  char*   sql;
4264
  char    db[TSDB_DB_FNAME_LEN];
4265
} SBalanceVgroupLeaderReq;
4266

4267
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4268
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4269
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4270

4271
typedef struct {
4272
  int32_t vgId;
4273
} SForceBecomeFollowerReq;
4274

4275
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4276
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4277

4278
typedef struct {
4279
  int32_t vgId;
4280
  bool    force;
4281
} SSplitVgroupReq;
4282

4283
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4284
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4285

4286
typedef struct {
4287
  char user[TSDB_USER_LEN];
4288
  char spi;
4289
  char encrypt;
4290
  char secret[TSDB_PASSWORD_LEN];
4291
  char ckey[TSDB_PASSWORD_LEN];
4292
} SAuthReq, SAuthRsp;
4293

4294
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4295
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4296

4297
typedef struct {
4298
  int32_t statusCode;
4299
  char    details[1024];
4300
} SServerStatusRsp;
4301

4302
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4303
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4304

4305
/**
4306
 * The layout of the query message payload is as following:
4307
 * +--------------------+---------------------------------+
4308
 * |Sql statement       | Physical plan                   |
4309
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4310
 * +--------------------+---------------------------------+
4311
 */
4312
typedef struct SSubQueryMsg {
4313
  SMsgHead header;
4314
  uint64_t sId;
4315
  uint64_t queryId;
4316
  uint64_t clientId;
4317
  uint64_t taskId;
4318
  int64_t  refId;
4319
  int32_t  execId;
4320
  int32_t  msgMask;
4321
  int32_t  subQType;
4322
  int8_t   taskType;
4323
  int8_t   explain;
4324
  int8_t   needFetch;
4325
  int8_t   compress;
4326
  uint32_t sqlLen;
4327
  char*    sql;
4328
  uint32_t msgLen;
4329
  char*    msg;
4330
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4331
} SSubQueryMsg;
4332

4333
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4334
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4335
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4336

4337
typedef struct {
4338
  SMsgHead header;
4339
  uint64_t sId;
4340
  uint64_t queryId;
4341
  uint64_t taskId;
4342
} SSinkDataReq;
4343

4344
typedef struct {
4345
  SMsgHead header;
4346
  uint64_t sId;
4347
  uint64_t queryId;
4348
  uint64_t clientId;
4349
  uint64_t taskId;
4350
  int32_t  execId;
4351
} SQueryContinueReq;
4352

4353
typedef struct {
4354
  SMsgHead header;
4355
  uint64_t sId;
4356
  uint64_t queryId;
4357
  uint64_t taskId;
4358
} SResReadyReq;
4359

4360
typedef struct {
4361
  int32_t code;
4362
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4363
  int32_t sversion;
4364
  int32_t tversion;
4365
} SResReadyRsp;
4366

4367
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4368

4369
typedef struct SOperatorParam {
4370
  int32_t opType;
4371
  int32_t downstreamIdx;
4372
  void*   value;
4373
  SArray* pChildren;  // SArray<SOperatorParam*>
4374
  bool    reUse;
4375
} SOperatorParam;
4376

4377
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4378

4379
// virtual table's colId to origin table's colname
4380
typedef struct SColIdNameKV {
4381
  col_id_t colId;
4382
  char     colName[TSDB_COL_NAME_LEN];
4383
} SColIdNameKV;
4384

4385
#define COL_MASK_ON   ((int8_t)0x1)
4386
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4387
#define COL_SET_MASK_ON(c)     \
4388
  do {                         \
4389
    (c)->flags |= COL_MASK_ON; \
4390
  } while (0)
4391

4392
typedef struct SColNameFlag {
4393
  col_id_t colId;
4394
  char     colName[TSDB_COL_NAME_LEN];
4395
  int8_t   flags;  // 0x01: COL_MASK_ON
4396
} SColNameFlag;
4397

4398
typedef struct SColIdPair {
4399
  col_id_t  vtbColId;
4400
  col_id_t  orgColId;
4401
  SDataType type;
4402
} SColIdPair;
4403

4404
typedef struct SColIdSlotIdPair {
4405
  int32_t  vtbSlotId;
4406
  col_id_t orgColId;
4407
} SColIdSlotIdPair;
4408

4409
typedef struct SOrgTbInfo {
4410
  int32_t vgId;
4411
  char    tbName[TSDB_TABLE_FNAME_LEN];
4412
  SArray* colMap;  // SArray<SColIdNameKV>
4413
} SOrgTbInfo;
4414

4415
void destroySOrgTbInfo(void *info);
4416

4417
typedef enum {
4418
  DYN_TYPE_STB_JOIN = 1,
4419
  DYN_TYPE_VSTB_SINGLE_SCAN,
4420
  DYN_TYPE_VSTB_BATCH_SCAN,
4421
  DYN_TYPE_VSTB_WIN_SCAN,
4422
} ETableScanDynType;
4423

4424
typedef enum {
4425
  DYN_TYPE_SCAN_PARAM = 1,
4426
  NOTIFY_TYPE_SCAN_PARAM,
4427
} ETableScanGetParamType;
4428

4429
typedef struct STableScanOperatorParam {
4430
  ETableScanGetParamType paramType;
4431
  /* for building scan data source */
4432
  bool                   tableSeq;
4433
  bool                   isNewParam;
4434
  uint64_t               groupid;
4435
  SArray*                pUidList;
4436
  SOrgTbInfo*            pOrgTbInfo;
4437
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4438
  SArray*                pTagList;
4439
  STimeWindow            window;
4440
  ETableScanDynType      dynType;
4441
  /* for notifying source step done */
4442
  bool                   notifyToProcess;  // received notify STEP DONE message
4443
  TSKEY                  notifyTs;         // notify timestamp
4444
} STableScanOperatorParam;
4445

4446
typedef struct STagScanOperatorParam {
4447
  tb_uid_t vcUid;
4448
} STagScanOperatorParam;
4449

4450
typedef struct SRefColIdGroup {
4451
  SArray* pSlotIdList;  // SArray<int32_t>
4452
} SRefColIdGroup;
4453

4454
typedef struct SVTableScanOperatorParam {
4455
  uint64_t        uid;
4456
  STimeWindow     window;
4457
  SOperatorParam* pTagScanOp;
4458
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4459
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4460
} SVTableScanOperatorParam;
4461

4462
typedef struct SMergeOperatorParam {
4463
  int32_t         winNum;
4464
} SMergeOperatorParam;
4465

4466
typedef struct SAggOperatorParam {
4467
  bool            needCleanRes;
4468
} SAggOperatorParam;
4469

4470
typedef struct SExternalWindowOperatorParam {
4471
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4472
} SExternalWindowOperatorParam;
4473

4474
typedef struct SDynQueryCtrlOperatorParam {
4475
  STimeWindow    window;
4476
} SDynQueryCtrlOperatorParam;
4477

4478
struct SStreamRuntimeFuncInfo;
4479
typedef struct {
4480
  SMsgHead        header;
4481
  uint64_t        sId;
4482
  uint64_t        queryId;
4483
  uint64_t        clientId;
4484
  uint64_t        taskId;
4485
  uint64_t        srcTaskId;  // used for subQ
4486
  uint64_t        blockIdx;   // used for subQ
4487
  int32_t         execId;
4488
  SOperatorParam* pOpParam;
4489

4490
  // used for new-stream
4491
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4492
  bool                           reset;
4493
  bool                           dynTbname;
4494
  // used for new-stream
4495
} SResFetchReq;
4496

4497
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamRtInfo, bool needStreamGrpInfo);
4498
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4499
void    tDestroySResFetchReq(SResFetchReq* pReq);
4500
typedef struct {
4501
  SMsgHead header;
4502
  uint64_t clientId;
4503
} SSchTasksStatusReq;
4504

4505
typedef struct {
4506
  uint64_t queryId;
4507
  uint64_t clientId;
4508
  uint64_t taskId;
4509
  int64_t  refId;
4510
  int32_t  subJobId;
4511
  int32_t  execId;
4512
  int8_t   status;
4513
} STaskStatus;
4514

4515
typedef struct {
4516
  int64_t refId;
4517
  SArray* taskStatus;  // SArray<STaskStatus>
4518
} SSchedulerStatusRsp;
4519

4520
typedef struct {
4521
  uint64_t queryId;
4522
  uint64_t taskId;
4523
  int8_t   action;
4524
} STaskAction;
4525

4526
typedef struct SQueryNodeEpId {
4527
  int32_t nodeId;  // vgId or qnodeId
4528
  SEp     ep;
4529
} SQueryNodeEpId;
4530

4531
typedef struct {
4532
  SMsgHead       header;
4533
  uint64_t       clientId;
4534
  SQueryNodeEpId epId;
4535
  SArray*        taskAction;  // SArray<STaskAction>
4536
} SSchedulerHbReq;
4537

4538
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4539
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4540
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4541

4542
typedef struct {
4543
  SQueryNodeEpId epId;
4544
  SArray*        taskStatus;  // SArray<STaskStatus>
4545
} SSchedulerHbRsp;
4546

4547
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4548
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4549
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4550

4551
typedef struct {
4552
  SMsgHead header;
4553
  uint64_t sId;
4554
  uint64_t queryId;
4555
  uint64_t clientId;
4556
  uint64_t taskId;
4557
  int64_t  refId;
4558
  int32_t  execId;
4559
} STaskCancelReq;
4560

4561
typedef struct {
4562
  int32_t code;
4563
} STaskCancelRsp;
4564

4565
typedef struct {
4566
  SMsgHead header;
4567
  uint64_t sId;
4568
  uint64_t queryId;
4569
  uint64_t clientId;
4570
  uint64_t taskId;
4571
  int64_t  refId;
4572
  int32_t  execId;
4573
} STaskDropReq;
4574

4575
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4576
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4577

4578
typedef enum {
4579
  TASK_NOTIFY_FINISHED = 1,
4580
} ETaskNotifyType;
4581

4582
typedef struct {
4583
  SMsgHead        header;
4584
  uint64_t        sId;
4585
  uint64_t        queryId;
4586
  uint64_t        clientId;
4587
  uint64_t        taskId;
4588
  int64_t         refId;
4589
  int32_t         execId;
4590
  ETaskNotifyType type;
4591
} STaskNotifyReq;
4592

4593
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4594
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4595

4596
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4597
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4598

4599
typedef struct {
4600
  int32_t code;
4601
} STaskDropRsp;
4602

4603
#define STREAM_TRIGGER_AT_ONCE                 1
4604
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4605
#define STREAM_TRIGGER_MAX_DELAY               3
4606
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4607
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4608

4609
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4610
#define STREAM_FILL_HISTORY_ON        1
4611
#define STREAM_FILL_HISTORY_OFF       0
4612
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4613
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4614
#define STREAM_CREATE_STABLE_TRUE     1
4615
#define STREAM_CREATE_STABLE_FALSE    0
4616

4617
typedef struct SVgroupVer {
4618
  int32_t vgId;
4619
  int64_t ver;
4620
} SVgroupVer;
4621

4622
enum {
4623
  TOPIC_SUB_TYPE__DB = 1,
4624
  TOPIC_SUB_TYPE__TABLE,
4625
  TOPIC_SUB_TYPE__COLUMN,
4626
};
4627

4628
#define DEFAULT_MAX_POLL_INTERVAL  300000
4629
#define DEFAULT_SESSION_TIMEOUT    12000
4630
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4631
#define DEFAULT_MIN_POLL_ROWS      4096
4632

4633
typedef struct {
4634
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4635
  int8_t igExists;
4636
  int8_t subType;
4637
  int8_t withMeta;
4638
  char*  sql;
4639
  char   subDbName[TSDB_DB_FNAME_LEN];
4640
  char*  ast;
4641
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4642
  int8_t reload;
4643
} SCMCreateTopicReq;
4644

4645
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4646
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4647
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4648

4649
typedef struct {
4650
  int64_t consumerId;
4651
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4652

4653
typedef struct {
4654
  int64_t consumerId;
4655
  char    cgroup[TSDB_CGROUP_LEN];
4656
  char    clientId[TSDB_CLIENT_ID_LEN];
4657
  char    user[TSDB_USER_LEN];
4658
  char    fqdn[TSDB_FQDN_LEN];
4659
  SArray* topicNames;  // SArray<char**>
4660

4661
  int8_t  withTbName;
4662
  int8_t  autoCommit;
4663
  int32_t autoCommitInterval;
4664
  int8_t  resetOffsetCfg;
4665
  int8_t  enableReplay;
4666
  int8_t  enableBatchMeta;
4667
  int32_t sessionTimeoutMs;
4668
  int32_t maxPollIntervalMs;
4669
  int64_t ownerId;
4670
} SCMSubscribeReq;
4671

4672
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4673
  int32_t tlen = 0;
676,152✔
4674
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
676,152✔
4675
  tlen += taosEncodeString(buf, pReq->cgroup);
676,152✔
4676
  tlen += taosEncodeString(buf, pReq->clientId);
676,152✔
4677

4678
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
676,152✔
4679
  tlen += taosEncodeFixedI32(buf, topicNum);
676,152✔
4680

4681
  for (int32_t i = 0; i < topicNum; i++) {
934,503✔
4682
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
516,702✔
4683
  }
4684

4685
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
676,152✔
4686
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
676,152✔
4687
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
676,152✔
4688
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
676,152✔
4689
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
676,152✔
4690
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
676,152✔
4691
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
676,152✔
4692
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
676,152✔
4693
  tlen += taosEncodeString(buf, pReq->user);
676,152✔
4694
  tlen += taosEncodeString(buf, pReq->fqdn);
676,152✔
4695

4696
  return tlen;
676,152✔
4697
}
4698

4699
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4700
  void* start = buf;
366,881✔
4701
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
366,881✔
4702
  buf = taosDecodeStringTo(buf, pReq->cgroup);
366,881✔
4703
  buf = taosDecodeStringTo(buf, pReq->clientId);
366,881✔
4704

4705
  int32_t topicNum = 0;
366,881✔
4706
  buf = taosDecodeFixedI32(buf, &topicNum);
366,881✔
4707

4708
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
366,881✔
4709
  if (pReq->topicNames == NULL) {
366,881✔
UNCOV
4710
    return terrno;
×
4711
  }
4712
  for (int32_t i = 0; i < topicNum; i++) {
530,263✔
4713
    char* name = NULL;
163,382✔
4714
    buf = taosDecodeString(buf, &name);
163,382✔
4715
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
326,764✔
UNCOV
4716
      return terrno;
×
4717
    }
4718
  }
4719

4720
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
366,881✔
4721
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
366,881✔
4722
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
366,881✔
4723
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
366,881✔
4724
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
366,881✔
4725
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
366,881✔
4726
  if ((char*)buf - (char*)start < len) {
366,881✔
4727
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
366,881✔
4728
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
366,881✔
4729
    buf = taosDecodeStringTo(buf, pReq->user);
366,881✔
4730
    buf = taosDecodeStringTo(buf, pReq->fqdn);
733,762✔
4731
  } else {
UNCOV
4732
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4733
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4734
  }
4735

4736
  return 0;
366,881✔
4737
}
4738

4739
typedef struct {
4740
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4741
  SArray* removedConsumers;  // SArray<int64_t>
4742
  SArray* newConsumers;      // SArray<int64_t>
4743
} SMqRebInfo;
4744

4745
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4746
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
326,189✔
4747
  if (pRebInfo == NULL) {
326,189✔
UNCOV
4748
    return NULL;
×
4749
  }
4750
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
326,189✔
4751
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
326,189✔
4752
  if (pRebInfo->removedConsumers == NULL) {
326,189✔
UNCOV
4753
    goto _err;
×
4754
  }
4755
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
326,189✔
4756
  if (pRebInfo->newConsumers == NULL) {
326,189✔
UNCOV
4757
    goto _err;
×
4758
  }
4759
  return pRebInfo;
326,189✔
UNCOV
4760
_err:
×
UNCOV
4761
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4762
  taosArrayDestroy(pRebInfo->newConsumers);
×
4763
  taosMemoryFreeClear(pRebInfo);
×
4764
  return NULL;
×
4765
}
4766

4767
typedef struct {
4768
  int64_t streamId;
4769
  int64_t checkpointId;
4770
  char    streamName[TSDB_STREAM_FNAME_LEN];
4771
} SMStreamDoCheckpointMsg;
4772

4773
typedef struct {
4774
  int64_t status;
4775
} SMVSubscribeRsp;
4776

4777
typedef struct {
4778
  char    name[TSDB_TOPIC_FNAME_LEN];
4779
  int8_t  igNotExists;
4780
  int32_t sqlLen;
4781
  char*   sql;
4782
  int8_t  force;
4783
} SMDropTopicReq;
4784

4785
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4786
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4787
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4788

4789
typedef struct {
4790
  char    name[TSDB_TOPIC_FNAME_LEN];
4791
  int8_t  igNotExists;
4792
  int32_t sqlLen;
4793
  char*   sql;
4794
} SMReloadTopicReq;
4795

4796
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4797
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4798
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4799

4800
typedef struct {
4801
  char   topic[TSDB_TOPIC_FNAME_LEN];
4802
  char   cgroup[TSDB_CGROUP_LEN];
4803
  int8_t igNotExists;
4804
  int8_t force;
4805
} SMDropCgroupReq;
4806

4807
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4808
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4809

4810
typedef struct {
4811
  int8_t reserved;
4812
} SMDropCgroupRsp;
4813

4814
typedef struct {
4815
  char    name[TSDB_TABLE_FNAME_LEN];
4816
  int8_t  alterType;
4817
  SSchema schema;
4818
} SAlterTopicReq;
4819

4820
typedef struct {
4821
  SMsgHead head;
4822
  char     name[TSDB_TABLE_FNAME_LEN];
4823
  int64_t  tuid;
4824
  int32_t  sverson;
4825
  int32_t  execLen;
4826
  char*    executor;
4827
  int32_t  sqlLen;
4828
  char*    sql;
4829
} SDCreateTopicReq;
4830

4831
typedef struct {
4832
  SMsgHead head;
4833
  char     name[TSDB_TABLE_FNAME_LEN];
4834
  int64_t  tuid;
4835
} SDDropTopicReq;
4836

4837
typedef struct {
4838
  char*      name;
4839
  int64_t    uid;
4840
  int64_t    interval[2];
4841
  int8_t     intervalUnit;
4842
  int16_t    nFuncs;
4843
  col_id_t*  funcColIds;  // column ids specified by user
4844
  func_id_t* funcIds;     // function ids specified by user
4845
} SRSmaParam;
4846

4847
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4848
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4849

4850
// TDMT_VND_CREATE_STB ==============
4851
typedef struct SVCreateStbReq {
4852
  char*           name;
4853
  tb_uid_t        suid;
4854
  int8_t          rollup;
4855
  SSchemaWrapper  schemaRow;
4856
  SSchemaWrapper  schemaTag;
4857
  SRSmaParam      rsmaParam;
4858
  int32_t         alterOriDataLen;
4859
  void*           alterOriData;
4860
  int8_t          source;
4861
  int8_t          colCmpred;
4862
  SColCmprWrapper colCmpr;
4863
  int64_t         keep;
4864
  int64_t         ownerId;
4865
  SExtSchema*     pExtSchemas;
4866
  int8_t          virtualStb;
4867
  int8_t          secureDelete;
4868
} SVCreateStbReq;
4869

4870
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4871
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4872

4873
// TDMT_VND_DROP_STB ==============
4874
typedef struct SVDropStbReq {
4875
  char*    name;
4876
  tb_uid_t suid;
4877
} SVDropStbReq;
4878

4879
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4880
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4881

4882
// TDMT_VND_CREATE_TABLE ==============
4883
#define TD_CREATE_IF_NOT_EXISTS       0x1
4884
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4885
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4886
typedef struct SVCreateTbReq {
4887
  int32_t  flags;
4888
  char*    name;
4889
  tb_uid_t uid;
4890
  int64_t  btime;
4891
  int32_t  ttl;
4892
  int32_t  commentLen;
4893
  char*    comment;
4894
  int8_t   type;
4895
  union {
4896
    struct {
4897
      char*    stbName;  // super table name
4898
      uint8_t  tagNum;
4899
      tb_uid_t suid;
4900
      SArray*  tagName;
4901
      uint8_t* pTag;
4902
    } ctb;
4903
    struct {
4904
      SSchemaWrapper schemaRow;
4905
      int64_t        userId;
4906
    } ntb;
4907
  };
4908
  int32_t         sqlLen;
4909
  char*           sql;
4910
  SColCmprWrapper colCmpr;
4911
  SExtSchema*     pExtSchemas;
4912
  SColRefWrapper  colRef;  // col reference for virtual table
4913
} SVCreateTbReq;
4914

4915
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4916
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4917
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4918
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4919

4920
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4921
  if (NULL == req) {
2,147,483,647✔
4922
    return;
2,147,483,647✔
4923
  }
4924

4925
  taosMemoryFreeClear(req->sql);
81,439,147✔
4926
  taosMemoryFreeClear(req->name);
81,440,933✔
4927
  taosMemoryFreeClear(req->comment);
81,436,019✔
4928
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
81,427,839✔
4929
    taosMemoryFreeClear(req->ctb.pTag);
73,304,929✔
4930
    taosMemoryFreeClear(req->ctb.stbName);
73,298,566✔
4931
    taosArrayDestroy(req->ctb.tagName);
73,340,781✔
4932
    req->ctb.tagName = NULL;
73,269,096✔
4933
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,123,858✔
4934
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
8,123,858✔
4935
  }
4936
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
81,396,836✔
4937
  taosMemoryFreeClear(req->pExtSchemas);
81,431,488✔
4938
  taosMemoryFreeClear(req->colRef.pColRef);
81,427,277✔
4939
  taosMemoryFreeClear(req->colRef.pTagRef);
81,423,481✔
4940
}
4941

4942
typedef struct {
4943
  int32_t nReqs;
4944
  union {
4945
    SVCreateTbReq* pReqs;
4946
    SArray*        pArray;
4947
  };
4948
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4949
} SVCreateTbBatchReq;
4950

4951
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4952
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4953
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4954

4955
typedef struct {
4956
  int32_t        code;
4957
  int32_t        index;  // index in batch req, start from 0
4958
  STableMetaRsp* pMeta;
4959
} SVCreateTbRsp, SVUpdateTbRsp;
4960

4961
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4962
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4963
void tFreeSVCreateTbRsp(void* param);
4964

4965
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4966
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4967

4968
typedef struct {
4969
  int32_t nRsps;
4970
  union {
4971
    SVCreateTbRsp* pRsps;
4972
    SArray*        pArray;
4973
  };
4974
} SVCreateTbBatchRsp;
4975

4976
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4977
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4978

4979
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4980
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4981

4982
// TDMT_VND_DROP_TABLE =================
4983
typedef struct {
4984
  char*    name;
4985
  uint64_t suid;  // for tmq in wal format
4986
  int64_t  uid;
4987
  int8_t   igNotExists;
4988
  int8_t   isVirtual;
4989
} SVDropTbReq;
4990

4991
typedef struct {
4992
  int32_t code;
4993
} SVDropTbRsp;
4994

4995
typedef struct {
4996
  int32_t nReqs;
4997
  union {
4998
    SVDropTbReq* pReqs;
4999
    SArray*      pArray;
5000
  };
5001
} SVDropTbBatchReq;
5002

5003
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
5004
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
5005

5006
typedef struct {
5007
  int32_t nRsps;
5008
  union {
5009
    SVDropTbRsp* pRsps;
5010
    SArray*      pArray;
5011
  };
5012
} SVDropTbBatchRsp;
5013

5014
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
5015
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
5016

5017
// TDMT_VND_ALTER_TABLE =====================
5018
typedef struct SUpdatedTagVal {
5019
  char*    tagName;
5020
  int32_t  colId;
5021
  int8_t   tagType;
5022
  int8_t   tagFree;
5023
  uint32_t nTagVal;
5024
  uint8_t* pTagVal;
5025
  int8_t   isNull;
5026
  SArray*  pTagArray;
5027
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5028
  // they should be replaced by a more generic solution in the future for full expression
5029
  // support
5030
  char*    regexp;
5031
  char*    replacement;
5032
} SUpdatedTagVal;
5033

5034
typedef struct SUpdateTableTagVal {
5035
  char *tbName;
5036
  SArray* tags; // Array of SUpdatedTagVal
5037
} SUpdateTableTagVal;
5038

5039
typedef struct SVAlterTbReq {
5040
  char*   tbName;
5041
  int8_t  action;
5042
  char*   colName;
5043
  int32_t colId;
5044
  // TSDB_ALTER_TABLE_ADD_COLUMN
5045
  int8_t  type;
5046
  int8_t  flags;
5047
  int32_t bytes;
5048
  // TSDB_ALTER_TABLE_DROP_COLUMN
5049
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5050
  int8_t   colModType;
5051
  int32_t  colModBytes;
5052
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5053
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5054
  int8_t   isNull;
5055
  int8_t   tagType;
5056
  int8_t   tagFree;
5057
  uint32_t nTagVal;
5058
  uint8_t* pTagVal;
5059
  SArray*  pTagArray;
5060
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5061
  int8_t   updateTTL;
5062
  int32_t  newTTL;
5063
  int32_t  newCommentLen;
5064
  char*    newComment;
5065
  int64_t  ctimeMs;    // fill by vnode
5066
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5067
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5068
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5069
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5070
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5071
  uint8_t* where;      // [where] is the encode where condition.
5072
  // for Add column
5073
  STypeMod typeMod;
5074
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5075
  char* refDbName;
5076
  char* refTbName;
5077
  char* refColName;
5078
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5079
} SVAlterTbReq;
5080

5081
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5082
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5083
void    destroyAlterTbReq(SVAlterTbReq* pReq);
5084
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5085
void    tfreeMultiTagUpateVal(void* pMultiTag);
5086
void    tfreeUpdateTableTagVal(void* pMultiTable);
5087

5088
typedef struct {
5089
  int32_t        code;
5090
  STableMetaRsp* pMeta;
5091
} SVAlterTbRsp;
5092

5093
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5094
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5095
// ======================
5096

5097
typedef struct {
5098
  SMsgHead head;
5099
  int64_t  uid;
5100
  int32_t  tid;
5101
  int16_t  tversion;
5102
  int16_t  colId;
5103
  int8_t   type;
5104
  int16_t  bytes;
5105
  int32_t  tagValLen;
5106
  int16_t  numOfTags;
5107
  int32_t  schemaLen;
5108
  char     data[];
5109
} SUpdateTagValReq;
5110

5111
typedef struct {
5112
  SMsgHead head;
5113
} SUpdateTagValRsp;
5114

5115
typedef struct {
5116
  SMsgHead head;
5117
} SVShowTablesReq;
5118

5119
typedef struct {
5120
  SMsgHead head;
5121
  int32_t  id;
5122
} SVShowTablesFetchReq;
5123

5124
typedef struct {
5125
  int64_t useconds;
5126
  int8_t  completed;  // all results are returned to client
5127
  int8_t  precision;
5128
  int8_t  compressed;
5129
  int32_t compLen;
5130
  int32_t numOfRows;
5131
  char    data[];
5132
} SVShowTablesFetchRsp;
5133

5134
typedef struct {
5135
  int64_t consumerId;
5136
  int32_t epoch;
5137
  char    cgroup[TSDB_CGROUP_LEN];
5138
} SMqAskEpReq;
5139

5140
typedef struct {
5141
  int32_t key;
5142
  int32_t valueLen;
5143
  void*   value;
5144
} SKv;
5145

5146
typedef struct {
5147
  int64_t tscRid;
5148
  int8_t  connType;
5149
} SClientHbKey;
5150

5151
typedef struct {
5152
  int64_t tid;
5153
  char    status[TSDB_JOB_STATUS_LEN];
5154
  int64_t startTs;  // sub-task first execution start time, us
5155
} SQuerySubDesc;
5156

5157
typedef enum EQueryExecPhase {
5158
  /* Main phases: 0-9 */
5159
  QUERY_PHASE_NONE     = 0,
5160
  QUERY_PHASE_PARSE    = 1,
5161
  QUERY_PHASE_CATALOG  = 2,
5162
  QUERY_PHASE_PLAN     = 3,
5163
  QUERY_PHASE_SCHEDULE = 4,
5164
  QUERY_PHASE_EXECUTE  = 5,
5165
  QUERY_PHASE_FETCH    = 6,
5166
  QUERY_PHASE_DONE     = 7,
5167

5168
  /* SCHEDULE sub-phases: 4x */
5169
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5170
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5171
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5172

5173
  /* EXECUTE sub-phases: 5x */
5174
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5175
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5176
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5177

5178
  /* FETCH sub-phases: 6x */
5179
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5180
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5181
} EQueryExecPhase;
5182

5183
const char* queryPhaseStr(int32_t phase);
5184

5185
typedef struct {
5186
  char     sql[TSDB_SHOW_SQL_LEN];
5187
  uint64_t queryId;
5188
  int64_t  useconds;
5189
  int64_t  stime;  // timestamp precision ms
5190
  int64_t  reqRid;
5191
  bool     stableQuery;
5192
  bool     isSubQuery;
5193
  char     fqdn[TSDB_FQDN_LEN];
5194
  int32_t  subPlanNum;
5195
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5196
  int32_t  execPhase;       // EQueryExecPhase
5197
  int64_t  phaseStartTime;  // when current phase started, ms
5198
} SQueryDesc;
5199

5200
typedef struct {
5201
  uint32_t connId;
5202
  SArray*  queryDesc;  // SArray<SQueryDesc>
5203
} SQueryHbReqBasic;
5204

5205
typedef struct {
5206
  uint32_t connId;
5207
  uint64_t killRid;
5208
  int32_t  totalDnodes;
5209
  int32_t  onlineDnodes;
5210
  int8_t   killConnection;
5211
  int8_t   align[3];
5212
  SEpSet   epSet;
5213
  SArray*  pQnodeList;
5214
} SQueryHbRspBasic;
5215

5216
typedef struct SAppClusterSummary {
5217
  uint64_t numOfInsertsReq;
5218
  uint64_t numOfInsertRows;
5219
  uint64_t insertElapsedTime;
5220
  uint64_t insertBytes;  // submit to tsdb since launched.
5221

5222
  uint64_t fetchBytes;
5223
  uint64_t numOfQueryReq;
5224
  uint64_t queryElapsedTime;
5225
  uint64_t numOfSlowQueries;
5226
  uint64_t totalRequests;
5227
  uint64_t currentRequests;  // the number of SRequestObj
5228
} SAppClusterSummary;
5229

5230
typedef struct {
5231
  int64_t            appId;
5232
  int32_t            pid;
5233
  char               name[TSDB_APP_NAME_LEN];
5234
  int64_t            startTime;
5235
  SAppClusterSummary summary;
5236
} SAppHbReq;
5237

5238
typedef struct {
5239
  SClientHbKey      connKey;
5240
  int64_t           clusterId;
5241
  SAppHbReq         app;
5242
  SQueryHbReqBasic* query;
5243
  SHashObj*         info;  // hash<Skv.key, Skv>
5244
  char              user[TSDB_USER_LEN];
5245
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5246
  char              userApp[TSDB_APP_NAME_LEN];
5247
  uint32_t          userIp;
5248
  SIpRange          userDualIp;
5249
  char              sVer[TSDB_VERSION_LEN];
5250
  char              cInfo[CONNECTOR_INFO_LEN];
5251
} SClientHbReq;
5252

5253
typedef struct {
5254
  int64_t reqId;
5255
  SArray* reqs;  // SArray<SClientHbReq>
5256
  int64_t ipWhiteListVer;
5257
} SClientHbBatchReq;
5258

5259
typedef struct {
5260
  SClientHbKey      connKey;
5261
  int32_t           status;
5262
  SQueryHbRspBasic* query;
5263
  SArray*           info;  // Array<Skv>
5264
} SClientHbRsp;
5265

5266
typedef struct {
5267
  int64_t       reqId;
5268
  int64_t       rspId;
5269
  int32_t       svrTimestamp;
5270
  SArray*       rsps;  // SArray<SClientHbRsp>
5271
  SMonitorParas monitorParas;
5272
  int8_t        enableAuditDelete;
5273
  int8_t        enableStrongPass;
5274
  int8_t        enableAuditSelect;
5275
  int8_t        enableAuditInsert;
5276
  int8_t        auditLevel;
5277
} SClientHbBatchRsp;
5278

5279
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
436,429,509✔
5280

5281
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5282
  void* pIter = taosHashIterate(info, NULL);
61,963,786✔
5283
  while (pIter != NULL) {
148,839,443✔
5284
    SKv* kv = (SKv*)pIter;
86,872,527✔
5285
    taosMemoryFreeClear(kv->value);
86,872,527✔
5286
    pIter = taosHashIterate(info, pIter);
86,872,093✔
5287
  }
5288
}
61,966,916✔
5289

5290
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
42,028,352✔
5291
  SQueryDesc* desc = (SQueryDesc*)pDesc;
42,028,352✔
5292
  if (desc->subDesc) {
42,028,352✔
5293
    taosArrayDestroy(desc->subDesc);
29,421,451✔
5294
    desc->subDesc = NULL;
29,419,232✔
5295
  }
5296
}
42,026,045✔
5297

5298
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
70,461,838✔
5299
  SClientHbReq* req = (SClientHbReq*)pReq;
159,863,046✔
5300
  if (req->query) {
159,863,046✔
5301
    if (req->query->queryDesc) {
70,461,355✔
5302
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
32,937,448✔
5303
    }
5304
    taosMemoryFreeClear(req->query);
70,460,949✔
5305
  }
5306

5307
  if (req->info) {
159,865,155✔
5308
    tFreeReqKvHash(req->info);
61,963,930✔
5309
    taosHashCleanup(req->info);
61,966,916✔
5310
    req->info = NULL;
61,965,014✔
5311
  }
5312
}
123,475,742✔
5313

5314
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5315
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5316

5317
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5318
  if (pReq == NULL) return;
30,232,438✔
5319
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
30,232,438✔
5320
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
30,232,438✔
5321
  taosMemoryFree(pReq);
30,232,438✔
5322
}
5323

5324
static FORCE_INLINE void tFreeClientKv(void* pKv) {
86,591,021✔
5325
  SKv* kv = (SKv*)pKv;
86,591,021✔
5326
  if (kv) {
86,591,021✔
5327
    taosMemoryFreeClear(kv->value);
86,590,715✔
5328
  }
5329
}
86,591,755✔
5330

5331
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
70,169,699✔
5332
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
70,169,699✔
5333
  if (rsp->query) {
70,169,699✔
5334
    taosArrayDestroy(rsp->query->pQnodeList);
70,165,320✔
5335
    taosMemoryFreeClear(rsp->query);
70,151,321✔
5336
  }
5337
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
70,158,550✔
5338
}
36,099,323✔
5339

5340
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5341
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
58,841,234✔
5342
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
58,841,234✔
5343
}
58,839,726✔
5344

5345
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5346
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5347
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5348

5349
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5350
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
341,589,594✔
5351
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
341,593,203✔
5352
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
341,594,285✔
5353
  return 0;
170,796,567✔
5354
}
5355

5356
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5357
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
170,245,159✔
5358
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
170,246,683✔
5359

5360
  if (pKv->valueLen < 0) {
85,123,458✔
UNCOV
5361
    return TSDB_CODE_INVALID_MSG;
×
5362
  }
5363

5364
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
85,123,788✔
5365
  if (pKv->value == NULL) {
85,122,517✔
UNCOV
5366
    return TSDB_CODE_OUT_OF_MEMORY;
×
5367
  }
5368
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
85,123,191✔
5369
  return 0;
85,123,960✔
5370
}
5371

5372
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5373
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
276,400,393✔
5374
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
276,395,753✔
5375
  return 0;
138,195,727✔
5376
}
5377

5378
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5379
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
137,627,148✔
5380
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
137,627,005✔
5381
  return 0;
68,813,693✔
5382
}
5383

5384
typedef struct {
5385
  int32_t vgId;
5386
  // TODO stas
5387
} SMqReportVgInfo;
5388

5389
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5390
  int32_t tlen = 0;
5391
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5392
  return tlen;
5393
}
5394

5395
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5396
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5397
  return buf;
5398
}
5399

5400
typedef struct {
5401
  int32_t epoch;
5402
  int64_t topicUid;
5403
  char    name[TSDB_TOPIC_FNAME_LEN];
5404
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5405
} SMqTopicInfo;
5406

5407
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5408
  int32_t tlen = 0;
5409
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5410
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5411
  tlen += taosEncodeString(buf, pTopicInfo->name);
5412
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5413
  tlen += taosEncodeFixedI32(buf, sz);
5414
  for (int32_t i = 0; i < sz; i++) {
5415
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5416
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5417
  }
5418
  return tlen;
5419
}
5420

5421
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5422
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5423
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5424
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5425
  int32_t sz;
5426
  buf = taosDecodeFixedI32(buf, &sz);
5427
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5428
    return NULL;
5429
  }
5430
  for (int32_t i = 0; i < sz; i++) {
5431
    SMqReportVgInfo vgInfo;
5432
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5433
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5434
      return NULL;
5435
    }
5436
  }
5437
  return buf;
5438
}
5439

5440
typedef struct {
5441
  int32_t status;  // ask hb endpoint
5442
  int32_t epoch;
5443
  int64_t consumerId;
5444
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5445
} SMqReportReq;
5446

5447
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5448
  int32_t tlen = 0;
5449
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5450
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5451
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5452
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5453
  tlen += taosEncodeFixedI32(buf, sz);
5454
  for (int32_t i = 0; i < sz; i++) {
5455
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5456
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5457
  }
5458
  return tlen;
5459
}
5460

5461
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5462
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5463
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5464
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5465
  int32_t sz;
5466
  buf = taosDecodeFixedI32(buf, &sz);
5467
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5468
    return NULL;
5469
  }
5470
  for (int32_t i = 0; i < sz; i++) {
5471
    SMqTopicInfo topicInfo;
5472
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5473
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5474
      return NULL;
5475
    }
5476
  }
5477
  return buf;
5478
}
5479

5480
typedef struct {
5481
  SMsgHead head;
5482
  int64_t  leftForVer;
5483
  int32_t  vgId;
5484
  int64_t  consumerId;
5485
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5486
} SMqVDeleteReq;
5487

5488
typedef struct {
5489
  int8_t reserved;
5490
} SMqVDeleteRsp;
5491

5492
typedef struct {
5493
  char**  name;
5494
  int32_t count;
5495
  int8_t  igNotExists;
5496
} SMDropStreamReq;
5497

5498
typedef struct {
5499
  int8_t reserved;
5500
} SMDropStreamRsp;
5501

5502
typedef struct {
5503
  SMsgHead head;
5504
  int64_t  resetRelHalt;  // reset related stream task halt status
5505
  int64_t  streamId;
5506
  int32_t  taskId;
5507
} SVDropStreamTaskReq;
5508

5509
typedef struct {
5510
  int8_t reserved;
5511
} SVDropStreamTaskRsp;
5512

5513
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5514
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5515
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5516

5517
typedef struct {
5518
  char*  name;
5519
  int8_t igNotExists;
5520
} SMPauseStreamReq;
5521

5522
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5523
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5524
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5525

5526
typedef struct {
5527
  char*  name;
5528
  int8_t igNotExists;
5529
  int8_t igUntreated;
5530
} SMResumeStreamReq;
5531

5532
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5533
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5534
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5535

5536
typedef struct {
5537
  char*       name;
5538
  int8_t      calcAll;
5539
  STimeWindow timeRange;
5540
} SMRecalcStreamReq;
5541

5542
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5543
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5544
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5545

5546
typedef struct SVndSetKeepVersionReq {
5547
  int64_t keepVersion;
5548
} SVndSetKeepVersionReq;
5549

5550
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5551
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5552

5553
typedef struct SVUpdateCheckpointInfoReq {
5554
  SMsgHead head;
5555
  int64_t  streamId;
5556
  int32_t  taskId;
5557
  int64_t  checkpointId;
5558
  int64_t  checkpointVer;
5559
  int64_t  checkpointTs;
5560
  int32_t  transId;
5561
  int64_t  hStreamId;  // add encode/decode
5562
  int64_t  hTaskId;
5563
  int8_t   dropRelHTask;
5564
} SVUpdateCheckpointInfoReq;
5565

5566
typedef struct {
5567
  int64_t        leftForVer;
5568
  int32_t        vgId;
5569
  int64_t        oldConsumerId;
5570
  int64_t        newConsumerId;
5571
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5572
  int8_t         subType;
5573
  int8_t         withMeta;
5574
  char*          qmsg;  // SubPlanToString
5575
  SSchemaWrapper schema;
5576
  int64_t        suid;
5577
} SMqRebVgReq;
5578

5579
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5580
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5581

5582
// tqOffset
5583
enum {
5584
  TMQ_OFFSET__RESET_NONE = -3,
5585
  TMQ_OFFSET__RESET_EARLIEST = -2,
5586
  TMQ_OFFSET__RESET_LATEST = -1,
5587
  TMQ_OFFSET__LOG = 1,
5588
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5589
  TMQ_OFFSET__SNAPSHOT_META = 3,
5590
};
5591

5592
enum {
5593
  WITH_DATA = 0,
5594
  WITH_META = 1,
5595
  ONLY_META = 2,
5596
};
5597

5598
#define TQ_OFFSET_VERSION 1
5599

5600
typedef struct {
5601
  int8_t type;
5602
  union {
5603
    // snapshot
5604
    struct {
5605
      int64_t uid;
5606
      int64_t ts;
5607
      SValue  primaryKey;
5608
    };
5609
    // log
5610
    struct {
5611
      int64_t version;
5612
    };
5613
  };
5614
} STqOffsetVal;
5615

5616
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5617
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
8,174,603✔
5618
  pOffsetVal->uid = uid;
8,173,967✔
5619
  pOffsetVal->ts = ts;
8,175,932✔
5620
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
8,176,621✔
5621
    taosMemoryFree(pOffsetVal->primaryKey.pData);
310✔
5622
  }
5623
  pOffsetVal->primaryKey = primaryKey;
8,170,446✔
5624
}
8,172,677✔
5625

5626
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5627
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
12,194✔
5628
  pOffsetVal->uid = uid;
12,194✔
5629
}
12,194✔
5630

5631
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5632
  pOffsetVal->type = TMQ_OFFSET__LOG;
14,898,906✔
5633
  pOffsetVal->version = ver;
14,897,865✔
5634
}
14,897,912✔
5635

5636
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5637
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5638
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5639
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5640
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5641
void    tOffsetDestroy(void* pVal);
5642

5643
typedef struct {
5644
  STqOffsetVal val;
5645
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5646
} STqOffset;
5647

5648
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5649
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5650
void    tDeleteSTqOffset(void* val);
5651

5652
typedef struct SMqVgOffset {
5653
  int64_t   consumerId;
5654
  STqOffset offset;
5655
} SMqVgOffset;
5656

5657
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5658
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5659

5660
typedef struct {
5661
  char    name[TSDB_TABLE_FNAME_LEN];
5662
  char    stb[TSDB_TABLE_FNAME_LEN];
5663
  int8_t  igExists;
5664
  int8_t  intervalUnit;
5665
  int8_t  slidingUnit;
5666
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5667
  int32_t dstVgId;   // for stream
5668
  int64_t interval;
5669
  int64_t offset;
5670
  int64_t sliding;
5671
  int64_t maxDelay;
5672
  int64_t watermark;
5673
  int32_t exprLen;        // strlen + 1
5674
  int32_t tagsFilterLen;  // strlen + 1
5675
  int32_t sqlLen;         // strlen + 1
5676
  int32_t astLen;         // strlen + 1
5677
  char*   expr;
5678
  char*   tagsFilter;
5679
  char*   sql;
5680
  char*   ast;
5681
  int64_t deleteMark;
5682
  int64_t lastTs;
5683
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5684
  SArray* pVgroupVerList;
5685
  int8_t  recursiveTsma;
5686
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5687
  char*   createStreamReq;
5688
  int32_t streamReqLen;
5689
  char*   dropStreamReq;
5690
  int32_t dropStreamReqLen;
5691
  int64_t uid;
5692
} SMCreateSmaReq;
5693

5694
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5695
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5696
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5697

5698
typedef struct {
5699
  char    name[TSDB_TABLE_FNAME_LEN];
5700
  int8_t  igNotExists;
5701
  char*   dropStreamReq;
5702
  int32_t dropStreamReqLen;
5703
} SMDropSmaReq;
5704

5705
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5706
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5707
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5708

5709
typedef struct {
5710
  char name[TSDB_TABLE_NAME_LEN];
5711
  union {
5712
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5713
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5714
  };
5715
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5716
  union {
5717
    int8_t igExists;   // used by mnode
5718
    int8_t alterType;  // used by vnode
5719
  };
5720
  int8_t     intervalUnit;
5721
  int16_t    nFuncs;       // number of functions specified by user
5722
  col_id_t*  funcColIds;   // column ids specified by user
5723
  func_id_t* funcIds;      // function ids specified by user
5724
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5725
  int64_t    tbUid;
5726
  int64_t    uid;     // rsma uid
5727
  int32_t    sqlLen;  // strlen + 1
5728
  char*      sql;
5729
} SMCreateRsmaReq;
5730

5731
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5732
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5733
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5734

5735
typedef SMCreateRsmaReq SVCreateRsmaReq;
5736

5737
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5738
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5739
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5740

5741
typedef SMCreateRsmaReq SVAlterRsmaReq;
5742

5743
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5744
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5745
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5746

5747
typedef struct {
5748
  char       name[TSDB_TABLE_NAME_LEN];
5749
  int8_t     alterType;
5750
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5751
  int8_t     igNotExists;
5752
  int16_t    nFuncs;      // number of functions specified by user
5753
  col_id_t*  funcColIds;  // column ids specified by user
5754
  func_id_t* funcIds;     // function ids specified by user
5755
  int32_t    sqlLen;      // strlen + 1
5756
  char*      sql;
5757
} SMAlterRsmaReq;
5758

5759
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5760
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5761
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5762

5763
typedef struct {
5764
  int64_t    id;
5765
  char       name[TSDB_TABLE_NAME_LEN];
5766
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5767
  int64_t    ownerId;
5768
  int32_t    code;
5769
  int32_t    version;
5770
  int8_t     tbType;
5771
  int8_t     intervalUnit;
5772
  col_id_t   nFuncs;
5773
  col_id_t   nColNames;
5774
  int64_t    interval[2];
5775
  col_id_t*  funcColIds;
5776
  func_id_t* funcIds;
5777
  SArray*    colNames;
5778
} SRsmaInfoRsp;
5779

5780
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5781
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5782
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5783

5784
typedef struct {
5785
  char   name[TSDB_TABLE_FNAME_LEN];
5786
  int8_t igNotExists;
5787
} SMDropRsmaReq;
5788

5789
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5790
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5791

5792
typedef struct {
5793
  char    name[TSDB_TABLE_NAME_LEN];
5794
  char    tbName[TSDB_TABLE_NAME_LEN];
5795
  int64_t uid;
5796
  int64_t tbUid;
5797
  int8_t  tbType;
5798
} SVDropRsmaReq;
5799

5800
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5801
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5802

5803
typedef struct {
5804
  char   dbFName[TSDB_DB_FNAME_LEN];
5805
  char   stbName[TSDB_TABLE_NAME_LEN];
5806
  char   colName[TSDB_COL_NAME_LEN];
5807
  char   idxName[TSDB_INDEX_FNAME_LEN];
5808
  int8_t idxType;
5809
} SCreateTagIndexReq;
5810

5811
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5812
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5813

5814
typedef SMDropSmaReq SDropTagIndexReq;
5815

5816
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5817
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5818

5819
typedef struct {
5820
  int8_t         version;       // for compatibility(default 0)
5821
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5822
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5823
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5824
  int32_t        dstVgId;
5825
  char           indexName[TSDB_INDEX_NAME_LEN];
5826
  int32_t        exprLen;
5827
  int32_t        tagsFilterLen;
5828
  int64_t        indexUid;
5829
  tb_uid_t       tableUid;  // super/child/common table uid
5830
  tb_uid_t       dstTbUid;  // for dstVgroup
5831
  int64_t        interval;
5832
  int64_t        offset;  // use unit by precision of DB
5833
  int64_t        sliding;
5834
  char*          dstTbName;  // for dstVgroup
5835
  char*          expr;       // sma expression
5836
  char*          tagsFilter;
5837
  SSchemaWrapper schemaRow;  // for dstVgroup
5838
  SSchemaWrapper schemaTag;  // for dstVgroup
5839
} STSma;                     // Time-range-wise SMA
5840

5841
typedef STSma SVCreateTSmaReq;
5842

5843
typedef struct {
5844
  int8_t  type;  // 0 status report, 1 update data
5845
  int64_t indexUid;
5846
  int64_t skey;  // start TS key of interval/sliding window
5847
} STSmaMsg;
5848

5849
typedef struct {
5850
  int64_t indexUid;
5851
  char    indexName[TSDB_INDEX_NAME_LEN];
5852
} SVDropTSmaReq;
5853

5854
typedef struct {
5855
  int tmp;  // TODO: to avoid compile error
5856
} SVCreateTSmaRsp, SVDropTSmaRsp;
5857

5858
#if 0
5859
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5860
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5861
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5862
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5863
#endif
5864

5865
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5866
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5867
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5868
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5869

5870
typedef struct {
5871
  int32_t number;
5872
  STSma*  tSma;
5873
} STSmaWrapper;
5874

5875
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5876
  if (pSma) {
×
UNCOV
5877
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5878
    taosMemoryFreeClear(pSma->expr);
×
5879
    taosMemoryFreeClear(pSma->tagsFilter);
×
5880
  }
5881
}
×
5882

5883
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5884
  if (pSW) {
×
UNCOV
5885
    if (pSW->tSma) {
×
UNCOV
5886
      if (deepCopy) {
×
5887
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5888
          tDestroyTSma(pSW->tSma + i);
×
5889
        }
5890
      }
5891
      taosMemoryFreeClear(pSW->tSma);
×
5892
    }
5893
  }
5894
}
×
5895

5896
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5897
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5898
  taosMemoryFreeClear(pSW);
×
UNCOV
5899
  return NULL;
×
5900
}
5901

5902
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5903
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5904

5905
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5906
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5907

UNCOV
5908
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5909
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5910
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5911
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5912
  }
5913
  return 0;
×
5914
}
5915

5916
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5917
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5918
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5919
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5920
  }
5921
  return 0;
×
5922
}
5923

5924
typedef struct {
5925
  int idx;
5926
} SMCreateFullTextReq;
5927

5928
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5929
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5930
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5931

5932
typedef struct {
5933
  char   name[TSDB_TABLE_FNAME_LEN];
5934
  int8_t igNotExists;
5935
} SMDropFullTextReq;
5936

5937
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5938
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5939

5940
typedef struct {
5941
  char indexFName[TSDB_INDEX_FNAME_LEN];
5942
} SUserIndexReq;
5943

5944
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5945
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5946

5947
typedef struct {
5948
  char dbFName[TSDB_DB_FNAME_LEN];
5949
  char tblFName[TSDB_TABLE_FNAME_LEN];
5950
  char colName[TSDB_COL_NAME_LEN];
5951
  char owner[TSDB_USER_LEN];
5952
  char indexType[TSDB_INDEX_TYPE_LEN];
5953
  char indexExts[TSDB_INDEX_EXTS_LEN];
5954
} SUserIndexRsp;
5955

5956
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5957
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5958

5959
typedef struct {
5960
  char tbFName[TSDB_TABLE_FNAME_LEN];
5961
} STableIndexReq;
5962

5963
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5964
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5965

5966
typedef struct {
5967
  int8_t  intervalUnit;
5968
  int8_t  slidingUnit;
5969
  int64_t interval;
5970
  int64_t offset;
5971
  int64_t sliding;
5972
  int64_t dstTbUid;
5973
  int32_t dstVgId;
5974
  SEpSet  epSet;
5975
  char*   expr;
5976
} STableIndexInfo;
5977

5978
typedef struct {
5979
  char     tbName[TSDB_TABLE_NAME_LEN];
5980
  char     dbFName[TSDB_DB_FNAME_LEN];
5981
  uint64_t suid;
5982
  int32_t  version;
5983
  int32_t  indexSize;
5984
  SArray*  pIndex;  // STableIndexInfo
5985
} STableIndexRsp;
5986

5987
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5988
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5989
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5990

5991
void tFreeSTableIndexInfo(void* pInfo);
5992

5993
typedef struct {
5994
  int8_t  mqMsgType;
5995
  int32_t code;
5996
  int32_t epoch;
5997
  int64_t consumerId;
5998
  int64_t walsver;
5999
  int64_t walever;
6000
} SMqRspHead;
6001

6002
typedef struct {
6003
  SMsgHead     head;
6004
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
6005
  int8_t       withTbName;
6006
  int8_t       useSnapshot;
6007
  int32_t      epoch;
6008
  uint64_t     reqId;
6009
  int64_t      consumerId;
6010
  int64_t      timeout;
6011
  STqOffsetVal reqOffset;
6012
  int8_t       enableReplay;
6013
  int8_t       sourceExcluded;
6014
  int8_t       rawData;
6015
  int32_t      minPollRows;
6016
  int8_t       enableBatchMeta;
6017
  SHashObj*    uidHash;  // to find if uid is duplicated
6018
} SMqPollReq;
6019

6020
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6021
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6022
void    tDestroySMqPollReq(SMqPollReq* pReq);
6023

6024
typedef struct {
6025
  int32_t vgId;
6026
  int64_t offset;
6027
  SEpSet  epSet;
6028
} SMqSubVgEp;
6029

6030
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6031
  int32_t tlen = 0;
2,170,122✔
6032
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,170,122✔
6033
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,170,122✔
6034
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,170,122✔
6035
  return tlen;
2,170,122✔
6036
}
6037

6038
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6039
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,068,395✔
6040
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,068,395✔
6041
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,068,395✔
6042
  return buf;
1,068,395✔
6043
}
6044

6045
typedef struct {
6046
  char    topic[TSDB_TOPIC_FNAME_LEN];
6047
  char    db[TSDB_DB_FNAME_LEN];
6048
  SArray* vgs;  // SArray<SMqSubVgEp>
6049
} SMqSubTopicEp;
6050

6051
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6052
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6053
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6054

6055
typedef struct {
6056
  SMqRspHead   head;
6057
  STqOffsetVal rspOffset;
6058
  int16_t      resMsgType;
6059
  int32_t      metaRspLen;
6060
  void*        metaRsp;
6061
} SMqMetaRsp;
6062

6063
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6064
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6065
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6066

6067
#define MQ_DATA_RSP_VERSION 100
6068

6069
typedef struct {
6070
  SMqRspHead   head;
6071
  STqOffsetVal rspOffset;
6072
  STqOffsetVal reqOffset;
6073
  int32_t      blockNum;
6074
  int8_t       withTbName;
6075
  int8_t       withSchema;
6076
  SArray*      blockDataLen;
6077
  SArray*      blockData;
6078
  SArray*      blockTbName;
6079
  SArray*      blockSchema;
6080

6081
  union {
6082
    struct {
6083
      int64_t sleepTime;
6084
    };
6085
    struct {
6086
      int32_t createTableNum;
6087
      SArray* createTableLen;
6088
      SArray* createTableReq;
6089
    };
6090
    struct {
6091
      int32_t len;
6092
      void*   rawData;
6093
    };
6094
  };
6095
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6096
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6097
  bool  timeout;
6098
} SMqDataRsp;
6099

6100
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6101
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6102
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6103
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6104
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6105

6106
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6107
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6108
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6109

6110
typedef struct SMqBatchMetaRsp {
6111
  SMqRspHead   head;  // not serialize
6112
  STqOffsetVal rspOffset;
6113
  SArray*      batchMetaLen;
6114
  SArray*      batchMetaReq;
6115
  void*        pMetaBuff;    // not serialize
6116
  uint32_t     metaBuffLen;  // not serialize
6117
} SMqBatchMetaRsp;
6118

6119
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6120
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6121
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6122
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6123

6124
typedef struct {
6125
  int32_t code;
6126
  SArray* topics;  // SArray<SMqSubTopicEp>
6127
} SMqAskEpRsp;
6128

6129
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6130
  int32_t tlen = 0;
8,165,068✔
6131
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6132
  int32_t sz = taosArrayGetSize(pRsp->topics);
8,165,068✔
6133
  tlen += taosEncodeFixedI32(buf, sz);
8,165,068✔
6134
  for (int32_t i = 0; i < sz; i++) {
9,851,628✔
6135
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,686,560✔
6136
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,686,560✔
6137
  }
6138
  tlen += taosEncodeFixedI32(buf, pRsp->code);
8,165,068✔
6139

6140
  return tlen;
8,165,068✔
6141
}
6142

6143
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6144
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6145
  int32_t sz;
3,292,951✔
6146
  buf = taosDecodeFixedI32(buf, &sz);
3,370,785✔
6147
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,370,785✔
6148
  if (pRsp->topics == NULL) {
3,370,785✔
UNCOV
6149
    return NULL;
×
6150
  }
6151
  for (int32_t i = 0; i < sz; i++) {
4,163,974✔
6152
    SMqSubTopicEp topicEp;
780,502✔
6153
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
793,240✔
6154
    if (buf == NULL) {
793,240✔
UNCOV
6155
      return NULL;
×
6156
    }
6157
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,586,429✔
6158
      return NULL;
×
6159
    }
6160
  }
6161
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,370,734✔
6162

6163
  return buf;
3,370,734✔
6164
}
6165

6166
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6167
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,847,563✔
6168
}
9,847,563✔
6169

6170
typedef struct {
6171
  int32_t      vgId;
6172
  STqOffsetVal offset;
6173
  int64_t      rows;
6174
  int64_t      ever;
6175
} OffsetRows;
6176

6177
typedef struct {
6178
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6179
  SArray* offsetRows;
6180
} TopicOffsetRows;
6181

6182
typedef struct {
6183
  int64_t consumerId;
6184
  int32_t epoch;
6185
  SArray* topics;
6186
  int8_t  pollFlag;
6187
} SMqHbReq;
6188

6189
typedef struct {
6190
  char   topic[TSDB_TOPIC_FNAME_LEN];
6191
  int8_t noPrivilege;
6192
} STopicPrivilege;
6193

6194
typedef struct {
6195
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6196
  int32_t debugFlag;
6197
} SMqHbRsp;
6198

6199
typedef struct {
6200
  SMsgHead head;
6201
  int64_t  consumerId;
6202
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6203
} SMqSeekReq;
6204

6205
#define TD_AUTO_CREATE_TABLE 0x1
6206
typedef struct {
6207
  int64_t       suid;
6208
  int64_t       uid;
6209
  int32_t       sver;
6210
  uint32_t      nData;
6211
  uint8_t*      pData;
6212
  SVCreateTbReq cTbReq;
6213
} SVSubmitBlk;
6214

6215
typedef struct {
6216
  SMsgHead header;
6217
  uint64_t sId;
6218
  uint64_t queryId;
6219
  uint64_t clientId;
6220
  uint64_t taskId;
6221
  uint32_t sqlLen;
6222
  uint32_t phyLen;
6223
  char*    sql;
6224
  char*    msg;
6225
  int8_t   source;
6226
  int8_t   secureDelete;
6227
} SVDeleteReq;
6228

6229
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6230
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6231

6232
typedef struct {
6233
  int64_t affectedRows;
6234
} SVDeleteRsp;
6235

6236
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6237
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6238

6239
typedef struct SDeleteRes {
6240
  uint64_t suid;
6241
  SArray*  uidList;
6242
  int64_t  skey;
6243
  int64_t  ekey;
6244
  int64_t  affectedRows;
6245
  char     tableFName[TSDB_TABLE_NAME_LEN];
6246
  char     tsColName[TSDB_COL_NAME_LEN];
6247
  int64_t  ctimeMs;  // fill by vnode
6248
  int8_t   source;
6249
  int8_t   secureDelete;  // force physical overwrite
6250
} SDeleteRes;
6251

6252
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6253
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6254

6255
typedef struct {
6256
  // int64_t uid;
6257
  char    tbname[TSDB_TABLE_NAME_LEN];
6258
  int64_t startTs;
6259
  int64_t endTs;
6260
} SSingleDeleteReq;
6261

6262
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6263
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6264

6265
typedef struct {
6266
  int64_t suid;
6267
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6268
  int64_t ctimeMs;     // fill by vnode
6269
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6270
} SBatchDeleteReq;
6271

6272
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6273
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6274
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6275

6276
typedef struct {
6277
  int32_t msgIdx;
6278
  int32_t msgType;
6279
  int32_t msgLen;
6280
  void*   msg;
6281
} SBatchMsg;
6282

6283
typedef struct {
6284
  SMsgHead header;
6285
  SArray*  pMsgs;  // SArray<SBatchMsg>
6286
} SBatchReq;
6287

6288
typedef struct {
6289
  int32_t reqType;
6290
  int32_t msgIdx;
6291
  int32_t msgLen;
6292
  int32_t rspCode;
6293
  void*   msg;
6294
} SBatchRspMsg;
6295

6296
typedef struct {
6297
  SArray* pRsps;  // SArray<SBatchRspMsg>
6298
} SBatchRsp;
6299

6300
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6301
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6302
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
102,425,275✔
6303
  if (NULL == msg) {
102,425,275✔
UNCOV
6304
    return;
×
6305
  }
6306
  SBatchMsg* pMsg = (SBatchMsg*)msg;
102,425,275✔
6307
  taosMemoryFree(pMsg->msg);
102,425,275✔
6308
}
6309

6310
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6311
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6312

6313
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
141,286,378✔
6314
  if (NULL == p) {
141,286,378✔
UNCOV
6315
    return;
×
6316
  }
6317

6318
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
141,286,378✔
6319
  taosMemoryFree(pRsp->msg);
141,286,378✔
6320
}
6321

6322
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6323
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6324
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6325
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6326
void    tDestroySMqHbReq(SMqHbReq* pReq);
6327

6328
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6329
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6330
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6331

6332
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6333
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6334

6335
#define TD_REQ_FROM_APP               0x0
6336
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6337
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6338
#define SUBMIT_REQ_FROM_FILE          0x4
6339
#define TD_REQ_FROM_TAOX              0x8
6340
#define TD_REQ_FROM_SML               0x10
6341
#define SUBMIT_REQUEST_VERSION        (2)
6342
#define SUBMIT_REQ_WITH_BLOB          0x10
6343
#define SUBMIT_REQ_SCHEMA_RES         0x20
6344
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6345

6346
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6347

6348
typedef struct {
6349
  int32_t        flags;
6350
  SVCreateTbReq* pCreateTbReq;
6351
  int64_t        suid;
6352
  int64_t        uid;
6353
  int32_t        sver;
6354
  union {
6355
    SArray* aRowP;
6356
    SArray* aCol;
6357
  };
6358
  int64_t   ctimeMs;
6359
  SBlobSet* pBlobSet;
6360
} SSubmitTbData;
6361

6362
typedef struct {
6363
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6364
  SArray* aSubmitBlobData;
6365
  bool    raw;
6366
} SSubmitReq2;
6367

6368
typedef struct {
6369
  SMsgHead header;
6370
  int64_t  version;
6371
  char     data[];  // SSubmitReq2
6372
} SSubmitReq2Msg;
6373

6374
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6375
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6376
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6377
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6378
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6379

6380
typedef struct {
6381
  int32_t affectedRows;
6382
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6383
} SSubmitRsp2;
6384

6385
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6386
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6387
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6388

6389
#define TSDB_MSG_FLG_ENCODE 0x1
6390
#define TSDB_MSG_FLG_DECODE 0x2
6391
#define TSDB_MSG_FLG_CMPT   0x3
6392

6393
typedef struct {
6394
  union {
6395
    struct {
6396
      void*   msgStr;
6397
      int32_t msgLen;
6398
      int64_t ver;
6399
    };
6400
    void* pDataBlock;
6401
  };
6402
} SPackedData;
6403

6404
typedef struct {
6405
  char     fullname[TSDB_VIEW_FNAME_LEN];
6406
  char     name[TSDB_VIEW_NAME_LEN];
6407
  char     dbFName[TSDB_DB_FNAME_LEN];
6408
  char*    querySql;
6409
  char*    sql;
6410
  int8_t   orReplace;
6411
  int8_t   precision;
6412
  int32_t  numOfCols;
6413
  SSchema* pSchema;
6414
} SCMCreateViewReq;
6415

6416
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6417
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6418
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6419

6420
typedef struct {
6421
  char   fullname[TSDB_VIEW_FNAME_LEN];
6422
  char   name[TSDB_VIEW_NAME_LEN];
6423
  char   dbFName[TSDB_DB_FNAME_LEN];
6424
  char*  sql;
6425
  int8_t igNotExists;
6426
} SCMDropViewReq;
6427

6428
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6429
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6430
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6431

6432
typedef struct {
6433
  char fullname[TSDB_VIEW_FNAME_LEN];
6434
} SViewMetaReq;
6435
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6436
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6437

6438
typedef struct {
6439
  char     name[TSDB_VIEW_NAME_LEN];
6440
  char     dbFName[TSDB_DB_FNAME_LEN];
6441
  char*    createUser;
6442
  int64_t  ownerId;
6443
  uint64_t dbId;
6444
  uint64_t viewId;
6445
  char*    querySql;
6446
  int8_t   precision;
6447
  int8_t   type;
6448
  int32_t  version;
6449
  int32_t  numOfCols;
6450
  SSchema* pSchema;
6451
} SViewMetaRsp;
6452
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6453
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6454
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6455
typedef struct {
6456
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6457
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6458
} STableTSMAInfoReq;
6459

6460
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6461
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6462

6463
typedef struct {
6464
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6465
  union {
6466
    uint8_t flags;
6467
    struct {
6468
      uint8_t withColName : 1;
6469
      uint8_t reserved : 7;
6470
    };
6471
  };
6472

6473
} SRsmaInfoReq;
6474

6475
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6476
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6477

6478
typedef struct {
6479
  int32_t  funcId;
6480
  col_id_t colId;
6481
} STableTSMAFuncInfo;
6482

6483
typedef struct {
6484
  char     name[TSDB_TABLE_NAME_LEN];
6485
  uint64_t tsmaId;
6486
  char     targetTb[TSDB_TABLE_NAME_LEN];
6487
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6488
  char     tb[TSDB_TABLE_NAME_LEN];
6489
  char     dbFName[TSDB_DB_FNAME_LEN];
6490
  uint64_t suid;
6491
  uint64_t destTbUid;
6492
  uint64_t dbId;
6493
  int32_t  version;
6494
  int64_t  interval;
6495
  int8_t   unit;
6496
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6497
  SArray*  pTags;      // SArray<SSchema>
6498
  SArray*  pUsedCols;  // SArray<SSchema>
6499
  char*    ast;
6500

6501
  int64_t streamUid;
6502
  int64_t reqTs;
6503
  int64_t rspTs;
6504
  int64_t delayDuration;  // ms
6505
  bool    fillHistoryFinished;
6506

6507
  void* streamAddr;  // for stream task, the address of the stream task
6508
} STableTSMAInfo;
6509

6510
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6511
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6512
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6513
void    tFreeTableTSMAInfo(void* p);
6514
void    tFreeAndClearTableTSMAInfo(void* p);
6515
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6516

6517
#define STSMAHbRsp            STableTSMAInfoRsp
6518
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6519
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6520
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6521

6522
typedef struct SDropCtbWithTsmaSingleVgReq {
6523
  SVgroupInfo vgInfo;
6524
  SArray*     pTbs;  // SVDropTbReq
6525
} SMDropTbReqsOnSingleVg;
6526

6527
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6528
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6529
void    tFreeSMDropTbReqOnSingleVg(void* p);
6530

6531
typedef struct SDropTbsReq {
6532
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6533
} SMDropTbsReq;
6534

6535
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6536
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6537
void    tFreeSMDropTbsReq(void*);
6538

6539
typedef struct SVFetchTtlExpiredTbsRsp {
6540
  SArray* pExpiredTbs;  // SVDropTbReq
6541
  int32_t vgId;
6542
} SVFetchTtlExpiredTbsRsp;
6543

6544
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6545
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6546

6547
void tFreeFetchTtlExpiredTbsRsp(void* p);
6548

6549
void setDefaultOptionsForField(SFieldWithOptions* field);
6550
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6551

6552
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6553
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6554

6555
typedef struct {
6556
  char    id[TSDB_INSTANCE_ID_LEN];
6557
  char    type[TSDB_INSTANCE_TYPE_LEN];
6558
  char    desc[TSDB_INSTANCE_DESC_LEN];
6559
  int32_t expire;
6560
} SInstanceRegisterReq;
6561

6562
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6563
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6564

6565
typedef struct {
6566
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6567
} SInstanceListReq;
6568

6569
typedef struct {
6570
  int32_t count;
6571
  char**  ids;  // Array of instance IDs
6572
} SInstanceListRsp;
6573

6574
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6575
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6576
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6577
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6578

6579
#ifdef USE_MOUNT
6580
typedef struct {
6581
  char     mountName[TSDB_MOUNT_NAME_LEN];
6582
  int8_t   ignoreExist;
6583
  int16_t  nMounts;
6584
  int32_t* dnodeIds;
6585
  char**   mountPaths;
6586
  int32_t  sqlLen;
6587
  char*    sql;
6588
} SCreateMountReq;
6589

6590
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6591
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6592
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6593

6594
typedef struct {
6595
  char    mountName[TSDB_MOUNT_NAME_LEN];
6596
  int8_t  ignoreNotExists;
6597
  int32_t sqlLen;
6598
  char*   sql;
6599
} SDropMountReq;
6600

6601
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6602
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6603
void    tFreeSDropMountReq(SDropMountReq* pReq);
6604

6605
typedef struct {
6606
  char     mountName[TSDB_MOUNT_NAME_LEN];
6607
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6608
  int64_t  mountUid;
6609
  int32_t  dnodeId;
6610
  uint32_t valLen;
6611
  int8_t   ignoreExist;
6612
  void*    pVal;
6613
} SRetrieveMountPathReq;
6614

6615
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6616
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6617

6618
typedef struct {
6619
  // path
6620
  int32_t diskPrimary;
6621
  // vgInfo
6622
  int32_t  vgId;
6623
  int32_t  cacheLastSize;
6624
  int32_t  szPage;
6625
  int32_t  szCache;
6626
  uint64_t szBuf;
6627
  int8_t   cacheLast;
6628
  int8_t   standby;
6629
  int8_t   hashMethod;
6630
  uint32_t hashBegin;
6631
  uint32_t hashEnd;
6632
  int16_t  hashPrefix;
6633
  int16_t  hashSuffix;
6634
  int16_t  sttTrigger;
6635
  // syncInfo
6636
  int32_t replications;
6637
  // tsdbInfo
6638
  int8_t  precision;
6639
  int8_t  compression;
6640
  int8_t  slLevel;
6641
  int32_t daysPerFile;
6642
  int32_t keep0;
6643
  int32_t keep1;
6644
  int32_t keep2;
6645
  int32_t keepTimeOffset;
6646
  int32_t minRows;
6647
  int32_t maxRows;
6648
  int32_t tsdbPageSize;
6649
  int32_t ssChunkSize;
6650
  int32_t ssKeepLocal;
6651
  int8_t  ssCompact;
6652
  union {
6653
    uint8_t flags;
6654
    struct {
6655
      uint8_t isAudit : 1;
6656
      uint8_t allowDrop : 1;
6657
      uint8_t reserved : 6;
6658
    };
6659
  };
6660
  int8_t secureDelete;
6661
  // walInfo
6662
  int32_t walFsyncPeriod;      // millisecond
6663
  int32_t walRetentionPeriod;  // secs
6664
  int32_t walRollPeriod;       // secs
6665
  int64_t walRetentionSize;
6666
  int64_t walSegSize;
6667
  int32_t walLevel;
6668
  // encryptInfo
6669
  int32_t encryptAlgorithm;
6670
  // SVState
6671
  int64_t committed;
6672
  int64_t commitID;
6673
  int64_t commitTerm;
6674
  // stats
6675
  int64_t numOfSTables;
6676
  int64_t numOfCTables;
6677
  int64_t numOfNTables;
6678
  // dbInfo
6679
  uint64_t dbId;
6680
} SMountVgInfo;
6681

6682
typedef struct {
6683
  SMCreateStbReq req;
6684
  SArray*        pColExts;  // element: column id
6685
  SArray*        pTagExts;  // element: tag id
6686
} SMountStbInfo;
6687

6688
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6689
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6690

6691
typedef struct {
6692
  char     dbName[TSDB_DB_FNAME_LEN];
6693
  uint64_t dbId;
6694
  SArray*  pVgs;   // SMountVgInfo
6695
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6696
} SMountDbInfo;
6697

6698
typedef struct {
6699
  // common fields
6700
  char     mountName[TSDB_MOUNT_NAME_LEN];
6701
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6702
  int8_t   ignoreExist;
6703
  int64_t  mountUid;
6704
  int64_t  clusterId;
6705
  int32_t  dnodeId;
6706
  uint32_t valLen;
6707
  void*    pVal;
6708

6709
  // response fields
6710
  SArray* pDbs;  // SMountDbInfo
6711

6712
  // memory fields, no serialized
6713
  SArray*   pDisks[TFS_MAX_TIERS];
6714
  TdFilePtr pFile;
6715
} SMountInfo;
6716

6717
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6718
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6719
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6720

6721
typedef struct {
6722
  SCreateVnodeReq createReq;
6723
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6724
  char            mountName[TSDB_MOUNT_NAME_LEN];
6725
  int64_t         mountId;
6726
  int32_t         diskPrimary;
6727
  int32_t         mountVgId;
6728
  int64_t         committed;
6729
  int64_t         commitID;
6730
  int64_t         commitTerm;
6731
  int64_t         numOfSTables;
6732
  int64_t         numOfCTables;
6733
  int64_t         numOfNTables;
6734
} SMountVnodeReq;
6735

6736
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6737
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6738
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6739

6740
#endif  // USE_MOUNT
6741

6742
#pragma pack(pop)
6743

6744
typedef struct {
6745
  char        db[TSDB_DB_FNAME_LEN];
6746
  STimeWindow timeRange;
6747
  int32_t     sqlLen;
6748
  char*       sql;
6749
  SArray*     vgroupIds;
6750
} SScanDbReq;
6751

6752
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6753
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6754
void    tFreeSScanDbReq(SScanDbReq* pReq);
6755

6756
typedef struct {
6757
  int32_t scanId;
6758
  int8_t  bAccepted;
6759
} SScanDbRsp;
6760

6761
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6762
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6763

6764
typedef struct {
6765
  int32_t scanId;
6766
  int32_t sqlLen;
6767
  char*   sql;
6768
} SKillScanReq;
6769

6770
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6771
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6772
void    tFreeSKillScanReq(SKillScanReq* pReq);
6773

6774
typedef struct {
6775
  int32_t scanId;
6776
  int32_t vgId;
6777
  int32_t dnodeId;
6778
} SVKillScanReq;
6779

6780
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6781
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6782

6783
typedef struct {
6784
  int32_t scanId;
6785
  int32_t vgId;
6786
  int32_t dnodeId;
6787
  int32_t numberFileset;
6788
  int32_t finished;
6789
  int32_t progress;
6790
  int64_t remainingTime;
6791
} SQueryScanProgressRsp;
6792

6793
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6794
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6795

6796
typedef struct {
6797
  int32_t scanId;
6798
  int32_t vgId;
6799
  int32_t dnodeId;
6800
} SQueryScanProgressReq;
6801

6802
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6803
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6804

6805
typedef struct {
6806
  int64_t     dbUid;
6807
  char        db[TSDB_DB_FNAME_LEN];
6808
  int64_t     scanStartTime;
6809
  STimeWindow tw;
6810
  int32_t     scanId;
6811
} SScanVnodeReq;
6812

6813
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6814
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6815

6816
#ifdef __cplusplus
6817
}
6818
#endif
6819

6820
#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