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

taosdata / TDengine / #4897

25 Dec 2025 10:17AM UTC coverage: 65.717% (-0.2%) from 65.929%
#4897

push

travis-ci

web-flow
fix: [6622889291] Fix invalid rowSize. (#34043)

186011 of 283047 relevant lines covered (65.72%)

113853896.64 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34

35
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
36

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

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

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

61
extern char*   tMsgInfo[];
62
extern int32_t tMsgDict[];
63
extern int32_t tMsgRangeDict[];
64

65
typedef uint16_t tmsg_t;
66

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

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

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

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

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

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

109
static inline bool vnodeIsMsgBlock(tmsg_t type) {
789,471,290✔
110
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
730,925,028✔
111
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,520,396,318✔
112
         (type == TDMT_SYNC_CONFIG_CHANGE);
113
}
114

115
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,028,611,418✔
116
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,028,611,418✔
117
}
118

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

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

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

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

210
typedef enum {
211
  TSDB_OPTR_NORMAL = 0,  // default
212
  TSDB_OPTR_SSMIGRATE = 1,
213
  TSDB_OPTR_ROLLUP = 2,
214
} ETsdbOpType;
215

216
typedef enum {
217
  TSDB_TRIGGER_MANUAL = 0,  // default
218
  TSDB_TRIGGER_AUTO = 1,
219
} ETriggerType;
220

221
#define TSDB_ALTER_TABLE_ADD_TAG                         1
222
#define TSDB_ALTER_TABLE_DROP_TAG                        2
223
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
224
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
225
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
226
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
227
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
228
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
229
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
230
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
231
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
232
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
233
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
234
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
235
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
236
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
237
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
238
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
239

240
#define TSDB_FILL_NONE        0
241
#define TSDB_FILL_NULL        1
242
#define TSDB_FILL_NULL_F      2
243
#define TSDB_FILL_SET_VALUE   3
244
#define TSDB_FILL_SET_VALUE_F 4
245
#define TSDB_FILL_LINEAR      5
246
#define TSDB_FILL_PREV        6
247
#define TSDB_FILL_NEXT        7
248
#define TSDB_FILL_NEAR        8
249

250

251
#define TSDB_ALTER_USER_BASIC_INFO             1
252
// these definitions start from 5 is to keep compatible with old versions
253
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
254
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
255

256

257
#define TSDB_ALTER_RSMA_FUNCTION 0x1
258

259
#define TSDB_KILL_MSG_LEN 30
260

261
#define TSDB_TABLE_NUM_UNIT 100000
262

263
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
264
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
265
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
266

267
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
268
#define TSDB_COL_TAG    0x1u  // the tag column type
269
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
270
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
271
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
272

273
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
274
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
275
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
276
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
277

278
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
279
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
280
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
281
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
282
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
283

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

347
  // Statement nodes are used in parser and planner module.
348
  QUERY_NODE_SET_OPERATOR = 100,
349
  QUERY_NODE_SELECT_STMT,
350
  QUERY_NODE_VNODE_MODIFY_STMT,
351
  QUERY_NODE_CREATE_DATABASE_STMT,
352
  QUERY_NODE_DROP_DATABASE_STMT,
353
  QUERY_NODE_ALTER_DATABASE_STMT,
354
  QUERY_NODE_FLUSH_DATABASE_STMT,
355
  QUERY_NODE_TRIM_DATABASE_STMT,
356
  QUERY_NODE_CREATE_TABLE_STMT,
357
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
358
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
359
  QUERY_NODE_DROP_TABLE_CLAUSE,
360
  QUERY_NODE_DROP_TABLE_STMT,
361
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
362
  QUERY_NODE_ALTER_TABLE_STMT,
363
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
364
  QUERY_NODE_CREATE_USER_STMT,
365
  QUERY_NODE_ALTER_USER_STMT,
366
  QUERY_NODE_DROP_USER_STMT,
367
  QUERY_NODE_USE_DATABASE_STMT,
368
  QUERY_NODE_CREATE_DNODE_STMT,
369
  QUERY_NODE_DROP_DNODE_STMT,
370
  QUERY_NODE_ALTER_DNODE_STMT,
371
  QUERY_NODE_CREATE_INDEX_STMT,
372
  QUERY_NODE_DROP_INDEX_STMT,
373
  QUERY_NODE_CREATE_QNODE_STMT,
374
  QUERY_NODE_DROP_QNODE_STMT,
375
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
376
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
377
  QUERY_NODE_CREATE_SNODE_STMT,
378
  QUERY_NODE_DROP_SNODE_STMT,
379
  QUERY_NODE_CREATE_MNODE_STMT,
380
  QUERY_NODE_DROP_MNODE_STMT,
381
  QUERY_NODE_CREATE_TOPIC_STMT,
382
  QUERY_NODE_DROP_TOPIC_STMT,
383
  QUERY_NODE_DROP_CGROUP_STMT,
384
  QUERY_NODE_ALTER_LOCAL_STMT,
385
  QUERY_NODE_EXPLAIN_STMT,
386
  QUERY_NODE_DESCRIBE_STMT,
387
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
388
  QUERY_NODE_COMPACT_DATABASE_STMT,
389
  QUERY_NODE_COMPACT_VGROUPS_STMT,
390
  QUERY_NODE_CREATE_FUNCTION_STMT,
391
  QUERY_NODE_DROP_FUNCTION_STMT,
392
  QUERY_NODE_CREATE_STREAM_STMT,
393
  QUERY_NODE_DROP_STREAM_STMT,
394
  QUERY_NODE_BALANCE_VGROUP_STMT,
395
  QUERY_NODE_MERGE_VGROUP_STMT,
396
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
397
  QUERY_NODE_SPLIT_VGROUP_STMT,
398
  QUERY_NODE_SYNCDB_STMT,
399
  QUERY_NODE_GRANT_STMT,
400
  QUERY_NODE_REVOKE_STMT,
401
  QUERY_NODE_ALTER_CLUSTER_STMT,
402
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
403
  QUERY_NODE_CREATE_TSMA_STMT,
404
  QUERY_NODE_DROP_TSMA_STMT,
405
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
406
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
407
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
408
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
409
  QUERY_NODE_CREATE_MOUNT_STMT,
410
  QUERY_NODE_DROP_MOUNT_STMT,
411
  QUERY_NODE_SCAN_DATABASE_STMT,
412
  QUERY_NODE_SCAN_VGROUPS_STMT,
413
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
414
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
415
  QUERY_NODE_CREATE_TOKEN_STMT,
416
  QUERY_NODE_ALTER_TOKEN_STMT,
417
  QUERY_NODE_DROP_TOKEN_STMT,
418

419
  // placeholder for [154, 180]
420
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
421
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
422
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
423
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
424
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
425
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
426
  QUERY_NODE_SHOW_SCORES_STMT,
427
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
428
  QUERY_NODE_KILL_CONNECTION_STMT,
429
  QUERY_NODE_KILL_QUERY_STMT,
430
  QUERY_NODE_KILL_TRANSACTION_STMT,
431
  QUERY_NODE_KILL_COMPACT_STMT,
432
  QUERY_NODE_DELETE_STMT,
433
  QUERY_NODE_INSERT_STMT,
434
  QUERY_NODE_QUERY,
435
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
436
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
437
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
438
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
439
  QUERY_NODE_RESTORE_DNODE_STMT,
440
  QUERY_NODE_RESTORE_QNODE_STMT,
441
  QUERY_NODE_RESTORE_MNODE_STMT,
442
  QUERY_NODE_RESTORE_VNODE_STMT,
443
  QUERY_NODE_PAUSE_STREAM_STMT,
444
  QUERY_NODE_RESUME_STREAM_STMT,
445
  QUERY_NODE_CREATE_VIEW_STMT,
446
  QUERY_NODE_DROP_VIEW_STMT,
447
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
448
  QUERY_NODE_CREATE_ANODE_STMT,
449
  QUERY_NODE_DROP_ANODE_STMT,
450
  QUERY_NODE_UPDATE_ANODE_STMT,
451
  QUERY_NODE_ASSIGN_LEADER_STMT,
452
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
453
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
454
  QUERY_NODE_RECALCULATE_STREAM_STMT,
455
  QUERY_NODE_CREATE_BNODE_STMT,
456
  QUERY_NODE_DROP_BNODE_STMT,
457
  QUERY_NODE_KILL_SSMIGRATE_STMT,
458
  QUERY_NODE_KILL_SCAN_STMT,
459
  QUERY_NODE_CREATE_RSMA_STMT,
460
  QUERY_NODE_DROP_RSMA_STMT,
461
  QUERY_NODE_ALTER_RSMA_STMT,
462
  QUERY_NODE_SHOW_CREATE_RSMA_STMT,
463
  QUERY_NODE_ROLLUP_DATABASE_STMT,
464
  QUERY_NODE_ROLLUP_VGROUPS_STMT,
465
  QUERY_NODE_KILL_RETENTION_STMT,
466
  QUERY_NODE_SET_VGROUP_KEEP_VERSION_STMT,
467
  QUERY_NODE_CREATE_ENCRYPT_ALGORITHMS_STMT,
468
  QUERY_NODE_DROP_ENCRYPT_ALGR_STMT,
469

470
  // show statement nodes
471
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
472
  QUERY_NODE_SHOW_DNODES_STMT = 400,
473
  QUERY_NODE_SHOW_MNODES_STMT,
474
  QUERY_NODE_SHOW_MODULES_STMT,
475
  QUERY_NODE_SHOW_QNODES_STMT,
476
  QUERY_NODE_SHOW_SNODES_STMT,
477
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
478
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
479
  QUERY_NODE_SHOW_CLUSTER_STMT,
480
  QUERY_NODE_SHOW_DATABASES_STMT,
481
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
482
  QUERY_NODE_SHOW_INDEXES_STMT,
483
  QUERY_NODE_SHOW_STABLES_STMT,
484
  QUERY_NODE_SHOW_STREAMS_STMT,
485
  QUERY_NODE_SHOW_TABLES_STMT,
486
  QUERY_NODE_SHOW_TAGS_STMT,
487
  QUERY_NODE_SHOW_USERS_STMT,
488
  QUERY_NODE_SHOW_USERS_FULL_STMT,
489
  QUERY_NODE_SHOW_LICENCES_STMT,
490
  QUERY_NODE_SHOW_VGROUPS_STMT,
491
  QUERY_NODE_SHOW_TOPICS_STMT,
492
  QUERY_NODE_SHOW_CONSUMERS_STMT,
493
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
494
  QUERY_NODE_SHOW_QUERIES_STMT,
495
  QUERY_NODE_SHOW_APPS_STMT,
496
  QUERY_NODE_SHOW_VARIABLES_STMT,
497
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
498
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
499
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
500
  QUERY_NODE_SHOW_VNODES_STMT,
501
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
502
  QUERY_NODE_SHOW_VIEWS_STMT,
503
  QUERY_NODE_SHOW_COMPACTS_STMT,
504
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
505
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
506
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
507
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
508
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
509
  QUERY_NODE_SHOW_TSMAS_STMT,
510
  QUERY_NODE_SHOW_ANODES_STMT,
511
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
512
  QUERY_NODE_SHOW_USAGE_STMT,
513
  QUERY_NODE_SHOW_FILESETS_STMT,
514
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
515
  QUERY_NODE_SHOW_VTABLES_STMT,
516
  QUERY_NODE_SHOW_BNODES_STMT,
517
  QUERY_NODE_SHOW_MOUNTS_STMT,
518
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
519
  QUERY_NODE_SHOW_SCANS_STMT,
520
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
521
  QUERY_NODE_SHOW_RSMAS_STMT,
522
  QUERY_NODE_SHOW_RETENTIONS_STMT,
523
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
524
  QUERY_NODE_SHOW_INSTANCES_STMT,
525
  QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT,
526
  QUERY_NODE_SHOW_TOKENS_STMT,
527

528
  // logic plan node
529
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
530
  QUERY_NODE_LOGIC_PLAN_JOIN,
531
  QUERY_NODE_LOGIC_PLAN_AGG,
532
  QUERY_NODE_LOGIC_PLAN_PROJECT,
533
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
534
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
535
  QUERY_NODE_LOGIC_PLAN_MERGE,
536
  QUERY_NODE_LOGIC_PLAN_WINDOW,
537
  QUERY_NODE_LOGIC_PLAN_FILL,
538
  QUERY_NODE_LOGIC_PLAN_SORT,
539
  QUERY_NODE_LOGIC_PLAN_PARTITION,
540
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
541
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
542
  QUERY_NODE_LOGIC_SUBPLAN,
543
  QUERY_NODE_LOGIC_PLAN,
544
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
545
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
546
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
547
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
548
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
549

550
  // physical plan node
551
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
552
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
553
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
554
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
555
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
556
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
557
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
558
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
559
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
560
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
561
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
562
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
563
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
564
  QUERY_NODE_PHYSICAL_PLAN_SORT,
565
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
566
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
567
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
568
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
569
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
570
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
571
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
572
  QUERY_NODE_PHYSICAL_PLAN_FILL,
573
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
574
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
575
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
576
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
577
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
578
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
579
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
580
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
581
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
582
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
583
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
584
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
585
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
586
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
587
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
588
  QUERY_NODE_PHYSICAL_SUBPLAN,
589
  QUERY_NODE_PHYSICAL_PLAN,
590
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
591
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
592
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
593
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
594
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
595
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
596
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
597
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
598
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
599
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
600
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
601
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
602
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
603
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
604
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
605
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
606
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
607
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
608
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
609
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
610
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
611
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
612
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
613
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
614
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
615
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
616
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
617
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
618
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
619
} ENodeType;
620

621
typedef struct {
622
  int32_t     vgId;
623
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
624
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
625
  const char* dbFName;
626
  const char* tbName;
627
} SBuildTableInput;
628

629
typedef struct {
630
  char    db[TSDB_DB_FNAME_LEN];
631
  int64_t dbId;
632
  int32_t vgVersion;
633
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
634
  int64_t stateTs;
635
} SBuildUseDBInput;
636

637
typedef struct SField {
638
  char    name[TSDB_COL_NAME_LEN];
639
  uint8_t type;
640
  int8_t  flags;
641
  int32_t bytes;
642
} SField;
643

644
typedef struct SFieldWithOptions {
645
  char     name[TSDB_COL_NAME_LEN];
646
  uint8_t  type;
647
  int8_t   flags;
648
  int32_t  bytes;
649
  uint32_t compress;
650
  STypeMod typeMod;
651
} SFieldWithOptions;
652

653
typedef struct SRetention {
654
  int64_t freq;
655
  int64_t keep;
656
  int8_t  freqUnit;
657
  int8_t  keepUnit;
658
} SRetention;
659

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

662
#pragma pack(push, 1)
663
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
664
typedef struct SEp {
665
  char     fqdn[TSDB_FQDN_LEN];
666
  uint16_t port;
667
} SEp;
668

669
typedef struct {
670
  int32_t contLen;
671
  int32_t vgId;
672
} SMsgHead;
673

674
// Submit message for one table
675
typedef struct SSubmitBlk {
676
  int64_t uid;        // table unique id
677
  int64_t suid;       // stable id
678
  int32_t sversion;   // data schema version
679
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
680
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
681
  int32_t numOfRows;  // total number of rows in current submit block
682
  char    data[];
683
} SSubmitBlk;
684

685
// Submit message for this TSDB
686
typedef struct {
687
  SMsgHead header;
688
  int64_t  version;
689
  int32_t  length;
690
  int32_t  numOfBlocks;
691
  char     blocks[];
692
} SSubmitReq;
693

694
typedef struct {
695
  int32_t totalLen;
696
  int32_t len;
697
  STSRow* row;
698
} SSubmitBlkIter;
699

700
typedef struct {
701
  int32_t totalLen;
702
  int32_t len;
703
  // head of SSubmitBlk
704
  int64_t uid;        // table unique id
705
  int64_t suid;       // stable id
706
  int32_t sversion;   // data schema version
707
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
708
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
709
  int32_t numOfRows;  // total number of rows in current submit block
710
  // head of SSubmitBlk
711
  int32_t     numOfBlocks;
712
  const void* pMsg;
713
} SSubmitMsgIter;
714

715
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
716
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
717
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
718
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
719
// for debug
720
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
721

722
typedef struct {
723
  bool     hasRef;
724
  col_id_t id;
725
  char     refDbName[TSDB_DB_NAME_LEN];
726
  char     refTableName[TSDB_TABLE_NAME_LEN];
727
  char     refColName[TSDB_COL_NAME_LEN];
728
} SColRef;
729

730
typedef struct {
731
  int32_t  nCols;
732
  int32_t  version;
733
  SColRef* pColRef;
734
} SColRefWrapper;
735

736
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
737
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
738
typedef struct {
739
  int32_t vgId;
740
  SColRef colRef;
741
} SColRefEx;
742

743
typedef struct {
744
  int16_t colId;
745
  char    refDbName[TSDB_DB_NAME_LEN];
746
  char    refTableName[TSDB_TABLE_NAME_LEN];
747
  char    refColName[TSDB_COL_NAME_LEN];
748
} SRefColInfo;
749

750
typedef struct SVCTableRefCols {
751
  uint64_t     uid;
752
  int32_t      numOfSrcTbls;
753
  int32_t      numOfColRefs;
754
  SRefColInfo* refCols;
755
} SVCTableRefCols;
756

757
typedef struct SVCTableMergeInfo {
758
  uint64_t uid;
759
  int32_t  numOfSrcTbls;
760
} SVCTableMergeInfo;
761

762
typedef struct {
763
  int32_t    nCols;
764
  SColRefEx* pColRefEx;
765
} SColRefExWrapper;
766

767
struct SSchema {
768
  int8_t   type;
769
  int8_t   flags;
770
  col_id_t colId;
771
  int32_t  bytes;
772
  char     name[TSDB_COL_NAME_LEN];
773
};
774
struct SSchemaExt {
775
  col_id_t colId;
776
  uint32_t compress;
777
  STypeMod typeMod;
778
};
779

780
struct SSchemaRsma {
781
  int64_t    interval[2];
782
  int32_t    nFuncs;
783
  int8_t     tbType;
784
  tb_uid_t   tbUid;
785
  func_id_t* funcIds;
786
  char       tbName[TSDB_TABLE_NAME_LEN];
787
};
788

789
struct SSchema2 {
790
  int8_t   type;
791
  int8_t   flags;
792
  col_id_t colId;
793
  int32_t  bytes;
794
  char     name[TSDB_COL_NAME_LEN];
795
  uint32_t compress;
796
};
797

798
typedef struct {
799
  char        tbName[TSDB_TABLE_NAME_LEN];
800
  char        stbName[TSDB_TABLE_NAME_LEN];
801
  char        dbFName[TSDB_DB_FNAME_LEN];
802
  int64_t     dbId;
803
  int32_t     numOfTags;
804
  int32_t     numOfColumns;
805
  int8_t      precision;
806
  int8_t      tableType;
807
  int32_t     sversion;
808
  int32_t     tversion;
809
  int32_t     rversion;
810
  uint64_t    suid;
811
  uint64_t    tuid;
812
  int32_t     vgId;
813
  int8_t      sysInfo;
814
  SSchema*    pSchemas;
815
  SSchemaExt* pSchemaExt;
816
  int8_t      virtualStb;
817
  int32_t     numOfColRefs;
818
  SColRef*    pColRefs;
819
} STableMetaRsp;
820

821
typedef struct {
822
  int32_t        code;
823
  int64_t        uid;
824
  char*          tblFName;
825
  int32_t        numOfRows;
826
  int32_t        affectedRows;
827
  int64_t        sver;
828
  STableMetaRsp* pMeta;
829
} SSubmitBlkRsp;
830

831
typedef struct {
832
  int32_t numOfRows;
833
  int32_t affectedRows;
834
  int32_t nBlocks;
835
  union {
836
    SArray*        pArray;
837
    SSubmitBlkRsp* pBlocks;
838
  };
839
} SSubmitRsp;
840

841
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
842
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
843
// void    tFreeSSubmitBlkRsp(void* param);
844
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
845

846
#define COL_SMA_ON       ((int8_t)0x1)
847
#define COL_IDX_ON       ((int8_t)0x2)
848
#define COL_IS_KEY       ((int8_t)0x4)
849
#define COL_SET_NULL     ((int8_t)0x10)
850
#define COL_SET_VAL      ((int8_t)0x20)
851
#define COL_IS_SYSINFO   ((int8_t)0x40)
852
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
853
#define COL_REF_BY_STM   ((int8_t)0x08)
854

855
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
856
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
857

858
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
859
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
860
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
861

862
#define SSCHMEA_SET_IDX_ON(s) \
863
  do {                        \
864
    (s)->flags |= COL_IDX_ON; \
865
  } while (0)
866

867
#define SSCHMEA_SET_IDX_OFF(s)   \
868
  do {                           \
869
    (s)->flags &= (~COL_IDX_ON); \
870
  } while (0)
871

872
#define SSCHEMA_SET_TYPE_MOD(s)     \
873
  do {                              \
874
    (s)->flags |= COL_HAS_TYPE_MOD; \
875
  } while (0)
876

877
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
878

879
#define SSCHMEA_TYPE(s)  ((s)->type)
880
#define SSCHMEA_FLAGS(s) ((s)->flags)
881
#define SSCHMEA_COLID(s) ((s)->colId)
882
#define SSCHMEA_BYTES(s) ((s)->bytes)
883
#define SSCHMEA_NAME(s)  ((s)->name)
884

885
typedef struct {
886
  bool    tsEnableMonitor;
887
  int32_t tsMonitorInterval;
888
  int32_t tsSlowLogThreshold;
889
  int32_t tsSlowLogMaxLen;
890
  int32_t tsSlowLogScope;
891
  int32_t tsSlowLogThresholdTest;  // Obsolete
892
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
893
} SMonitorParas;
894

895
typedef struct {
896
  STypeMod typeMod;
897
} SExtSchema;
898

899
bool hasExtSchema(const SExtSchema* pExtSchema);
900

901
typedef struct {
902
  int32_t      nCols;
903
  int32_t      version;
904
  SSchema*     pSchema;
905
  SSchemaRsma* pRsma;
906
} SSchemaWrapper;
907

908
typedef struct {
909
  col_id_t id;
910
  uint32_t alg;
911
} SColCmpr;
912

913
typedef struct {
914
  int32_t   nCols;
915
  int32_t   version;
916
  SColCmpr* pColCmpr;
917
} SColCmprWrapper;
918

919
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
920
  if (pRef->pColRef) {
351,164✔
921
    return TSDB_CODE_INVALID_PARA;
×
922
  }
923
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
351,164✔
924
  if (pRef->pColRef == NULL) {
351,164✔
925
    return terrno;
×
926
  }
927
  pRef->nCols = nCols;
351,164✔
928
  for (int32_t i = 0; i < nCols; i++) {
143,811,794✔
929
    pRef->pColRef[i].hasRef = false;
143,460,630✔
930
    pRef->pColRef[i].id = (col_id_t)(i + 1);
143,460,630✔
931
  }
932
  return 0;
351,164✔
933
}
934

935
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
936
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
937
    terrno = TSDB_CODE_INVALID_PARA;
938
    return NULL;
939
  }
940

941
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
942
  if (pDstWrapper == NULL) {
943
    return NULL;
944
  }
945
  pDstWrapper->nCols = pSrcWrapper->nCols;
946
  pDstWrapper->version = pSrcWrapper->version;
947

948
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
949
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
950
  if (pDstWrapper->pColCmpr == NULL) {
951
    taosMemoryFree(pDstWrapper);
952
    return NULL;
953
  }
954
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
955

956
  return pDstWrapper;
957
}
958

959
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
960
  if (!(!pCmpr->pColCmpr)) {
19,695,156✔
961
    return TSDB_CODE_INVALID_PARA;
×
962
  }
963
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
19,695,156✔
964
  if (pCmpr->pColCmpr == NULL) {
19,695,156✔
965
    return terrno;
×
966
  }
967
  pCmpr->nCols = nCols;
19,695,156✔
968
  return 0;
19,695,156✔
969
}
970

971
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
972
  pCmpr->nCols = pSchema->nCols;
973
  if (!(!pCmpr->pColCmpr)) {
974
    return TSDB_CODE_INVALID_PARA;
975
  }
976
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
977
  if (pCmpr->pColCmpr == NULL) {
978
    return terrno;
979
  }
980
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
981
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
982
    SSchema*  pColSchema = &pSchema->pSchema[i];
983
    pColCmpr->id = pColSchema->colId;
984
    pColCmpr->alg = 0;
985
  }
986
  return 0;
987
}
988

989
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
990
  if (pWrapper == NULL) return;
991

992
  taosMemoryFreeClear(pWrapper->pColCmpr);
993
  taosMemoryFreeClear(pWrapper);
994
}
995
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
996
  if (pSchemaWrapper->pSchema == NULL) return NULL;
521,325,906✔
997

998
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
521,243,905✔
999
  if (pSW == NULL) {
521,177,175✔
1000
    return NULL;
×
1001
  }
1002
  pSW->nCols = pSchemaWrapper->nCols;
521,177,175✔
1003
  pSW->version = pSchemaWrapper->version;
521,142,349✔
1004
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
521,267,370✔
1005
  if (pSW->pSchema == NULL) {
520,865,356✔
1006
    taosMemoryFree(pSW);
×
1007
    return NULL;
×
1008
  }
1009

1010
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
521,047,697✔
1011
  return pSW;
521,313,663✔
1012
}
1013

1014
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
117,922,600✔
1015
  if (pSchemaWrapper) {
1,412,220,885✔
1016
    taosMemoryFree(pSchemaWrapper->pSchema);
800,536,939✔
1017
    if (pSchemaWrapper->pRsma) {
800,288,289✔
1018
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
28,404✔
1019
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
28,404✔
1020
    }
1021
    taosMemoryFree(pSchemaWrapper);
800,316,981✔
1022
  }
1023
}
1,397,241,058✔
1024

1025
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1026
  if (pSchemaWrapper) {
1027
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1028
    if (pSchemaWrapper->pRsma) {
1029
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1030
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1031
    }
1032
  }
1033
}
1034

1035
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,817,782✔
1036
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,817,782✔
1037
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
1,817,782✔
1038
  }
1039
}
1,817,142✔
1040

1041
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1042
  int32_t tlen = 0;
1,345,630✔
1043
  tlen += taosEncodeFixedI8(buf, pSchema->type);
1,345,702✔
1044
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
1,345,630✔
1045
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
1,345,630✔
1046
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
1,345,630✔
1047
  tlen += taosEncodeString(buf, pSchema->name);
1,345,630✔
1048
  return tlen;
1,345,630✔
1049
}
1050

1051
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1052
  buf = taosDecodeFixedI8(buf, &pSchema->type);
592,086✔
1053
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
592,068✔
1054
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
592,068✔
1055
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
592,068✔
1056
  buf = taosDecodeStringTo(buf, pSchema->name);
592,068✔
1057
  return (void*)buf;
592,068✔
1058
}
1059

1060
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1061
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1062
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1063
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1064
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1065
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1066
  return 0;
2,147,483,647✔
1067
}
1068

1069
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1070
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1071
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1072
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1073
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1074
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1075
  return 0;
2,147,483,647✔
1076
}
1077

1078
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1079
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1080
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1081
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1082
  return 0;
2,147,483,647✔
1083
}
1084

1085
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1086
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1087
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1088
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1089
  return 0;
2,147,483,647✔
1090
}
1091

1092
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1093
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
723,316,552✔
1094
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
723,316,552✔
1095
  if (pColRef->hasRef) {
361,658,276✔
1096
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
433,695,976✔
1097
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
433,695,976✔
1098
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
433,695,976✔
1099
  }
1100
  return 0;
361,658,276✔
1101
}
1102

1103
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1104
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
364,874,960✔
1105
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
364,874,960✔
1106
  if (pColRef->hasRef) {
182,437,480✔
1107
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
109,238,970✔
1108
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
109,238,970✔
1109
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
109,238,970✔
1110
  }
1111

1112
  return 0;
182,437,480✔
1113
}
1114

1115
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1116
  int32_t tlen = 0;
175,650✔
1117
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
175,650✔
1118
  tlen += taosEncodeVariantI32(buf, pSW->version);
175,650✔
1119
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,521,280✔
1120
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
2,691,260✔
1121
  }
1122
  return tlen;
175,650✔
1123
}
1124

1125
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1126
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
74,418✔
1127
  buf = taosDecodeVariantI32(buf, &pSW->version);
74,418✔
1128
  if (pSW->nCols > 0) {
74,418✔
1129
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
74,418✔
1130
    if (pSW->pSchema == NULL) {
74,418✔
1131
      return NULL;
×
1132
    }
1133

1134
    for (int32_t i = 0; i < pSW->nCols; i++) {
666,486✔
1135
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
1,184,136✔
1136
    }
1137
  } else {
1138
    pSW->pSchema = NULL;
×
1139
  }
1140
  return (void*)buf;
74,418✔
1141
}
1142

1143
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1144
  if (pSW == NULL) {
399,153,228✔
1145
    return TSDB_CODE_INVALID_PARA;
×
1146
  }
1147
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
798,317,173✔
1148
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
798,238,205✔
1149
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1150
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1151
  }
1152
  return 0;
399,270,001✔
1153
}
1154

1155
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1156
  if (pSW == NULL) {
121,425,938✔
1157
    return TSDB_CODE_INVALID_PARA;
×
1158
  }
1159
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
242,840,595✔
1160
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
242,829,017✔
1161

1162
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
121,414,360✔
1163
  if (pSW->pSchema == NULL) {
121,351,683✔
1164
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1165
  }
1166
  for (int32_t i = 0; i < pSW->nCols; i++) {
921,117,784✔
1167
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,599,300,977✔
1168
  }
1169

1170
  return 0;
121,448,765✔
1171
}
1172

1173
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1174
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1175
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1176

1177
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1178
  if (pSW->pSchema == NULL) {
1,846,556,202✔
1179
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1180
  }
1181
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1182
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1183
  }
1184

1185
  return 0;
1,847,314,830✔
1186
}
1187

1188
typedef struct {
1189
  char     name[TSDB_TABLE_FNAME_LEN];
1190
  int8_t   igExists;
1191
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1192
  int8_t   reserved[6];
1193
  tb_uid_t suid;
1194
  int64_t  delay1;
1195
  int64_t  delay2;
1196
  int64_t  watermark1;
1197
  int64_t  watermark2;
1198
  int32_t  ttl;
1199
  int32_t  colVer;
1200
  int32_t  tagVer;
1201
  int32_t  numOfColumns;
1202
  int32_t  numOfTags;
1203
  int32_t  numOfFuncs;
1204
  int32_t  commentLen;
1205
  int32_t  ast1Len;
1206
  int32_t  ast2Len;
1207
  SArray*  pColumns;  // array of SFieldWithOptions
1208
  SArray*  pTags;     // array of SField
1209
  SArray*  pFuncs;
1210
  char*    pComment;
1211
  char*    pAst1;
1212
  char*    pAst2;
1213
  int64_t  deleteMark1;
1214
  int64_t  deleteMark2;
1215
  int32_t  sqlLen;
1216
  char*    sql;
1217
  int64_t  keep;
1218
  int8_t   virtualStb;
1219
} SMCreateStbReq;
1220

1221
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1222
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1223
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1224

1225
typedef struct {
1226
  STableMetaRsp* pMeta;
1227
} SMCreateStbRsp;
1228

1229
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1230
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1231
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1232

1233
typedef struct {
1234
  char     name[TSDB_TABLE_FNAME_LEN];
1235
  int8_t   igNotExists;
1236
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1237
  int8_t   reserved[6];
1238
  tb_uid_t suid;
1239
  int32_t  sqlLen;
1240
  char*    sql;
1241
} SMDropStbReq;
1242

1243
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1244
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1245
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1246

1247
typedef struct {
1248
  char    name[TSDB_TABLE_FNAME_LEN];
1249
  int8_t  alterType;
1250
  int32_t numOfFields;
1251
  SArray* pFields;
1252
  int32_t ttl;
1253
  int32_t commentLen;
1254
  char*   comment;
1255
  int32_t sqlLen;
1256
  char*   sql;
1257
  int64_t keep;
1258
  SArray* pTypeMods;
1259
} SMAlterStbReq;
1260

1261
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1262
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1263
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1264

1265
typedef struct SEpSet {
1266
  int8_t inUse;
1267
  int8_t numOfEps;
1268
  SEp    eps[TSDB_MAX_REPLICA];
1269
} SEpSet;
1270

1271
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1272
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1273
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1274
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1275

1276
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1277
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1278

1279
typedef struct {
1280
  int8_t  connType;
1281
  int32_t pid;
1282
  char    app[TSDB_APP_NAME_LEN];
1283
  char    db[TSDB_DB_NAME_LEN];
1284
  char    user[TSDB_USER_LEN];
1285
  char    passwd[TSDB_PASSWORD_LEN];
1286
  char    token[TSDB_TOKEN_LEN];
1287
  int64_t startTime;
1288
  char    sVer[TSDB_VERSION_LEN];
1289
  int32_t totpCode;
1290
} SConnectReq;
1291

1292
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1293
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1294

1295
typedef struct {
1296
  int64_t       clusterId;
1297
  int32_t       acctId;
1298
  uint32_t      connId;
1299
  int32_t       dnodeNum;
1300
  int8_t        superUser;
1301
  int8_t        sysInfo;
1302
  int8_t        connType;
1303
  int8_t        enableAuditDelete;
1304
  SEpSet        epSet;
1305
  int32_t       svrTimestamp;
1306
  int32_t       passVer;
1307
  int32_t       authVer;
1308
  char          sVer[TSDB_VERSION_LEN];
1309
  char          sDetailVer[128];
1310
  int64_t       whiteListVer;
1311
  int64_t       timeWhiteListVer;
1312
  SMonitorParas monitorParas;
1313
  char          user[TSDB_USER_LEN];
1314
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1315
  int8_t        enableAuditSelect;
1316
  int8_t        enableAuditInsert;
1317
  int8_t        auditLevel;
1318
} SConnectRsp;
1319

1320
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1321
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1322

1323
typedef struct {
1324
  char    user[TSDB_USER_LEN];
1325
  char    pass[TSDB_PASSWORD_LEN];
1326
  int32_t maxUsers;
1327
  int32_t maxDbs;
1328
  int32_t maxTimeSeries;
1329
  int32_t maxStreams;
1330
  int32_t accessState;  // Configured only by command
1331
  int64_t maxStorage;
1332
} SCreateAcctReq, SAlterAcctReq;
1333

1334
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1335
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1336

1337
typedef struct {
1338
  char    user[TSDB_USER_LEN];
1339
  int32_t sqlLen;
1340
  char*   sql;
1341
} SDropUserReq, SDropAcctReq;
1342

1343
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1344
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1345
void    tFreeSDropUserReq(SDropUserReq* pReq);
1346

1347
typedef struct {
1348
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1349
  int32_t sqlLen;
1350
  char*   sql;
1351
} SDropEncryptAlgrReq;
1352

1353
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1354
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1355
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1356

1357
typedef struct SIpV4Range {
1358
  uint32_t ip;
1359
  uint32_t mask;
1360
} SIpV4Range;
1361

1362
typedef struct SIpv6Range {
1363
  uint64_t addr[2];
1364
  uint32_t mask;
1365
} SIpV6Range;
1366

1367
typedef struct {
1368
  int8_t type;   // 0: IPv4, 1: IPv6
1369
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1370
  union {
1371
    SIpV4Range ipV4;
1372
    SIpV6Range ipV6;
1373
  };
1374
} SIpRange;
1375

1376
typedef struct {
1377
  int32_t    num;
1378
  SIpV4Range pIpRange[];
1379
} SIpWhiteList;
1380

1381
typedef struct {
1382
  int32_t  num;
1383
  SIpRange pIpRanges[];
1384
} SIpWhiteListDual;
1385

1386
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1387
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1388
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1389
int32_t           createDefaultIp6Range(SIpRange* pRange);
1390
int32_t           createDefaultIp4Range(SIpRange* pRange);
1391

1392
typedef struct {
1393
  int32_t sessPerUser;
1394
  int32_t sessConnTime;
1395
  int32_t sessConnIdleTime;
1396
  int32_t sessMaxConcurrency;
1397
  int32_t sessMaxCallVnodeNum;
1398
} SUserSessCfg;
1399

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

1404
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1405
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1406
typedef struct {
1407
  int16_t year;
1408
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1409
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1410
  int8_t hour;
1411
  int8_t minute;
1412
  int8_t neg;   // this is a negative entry
1413
  int32_t duration; // duration in minute
1414
} SDateTimeRange;
1415

1416
bool isValidDateTimeRange(SDateTimeRange* pRange);
1417
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1418
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1419

1420

1421
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1422
typedef struct {
1423
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1424
  bool neg;         // this is a negative entry
1425
  int32_t duration; // duration in seconds
1426
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1427
} SDateTimeWhiteListItem;
1428

1429
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1430
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1431

1432
typedef struct {
1433
  int32_t num;
1434
  SDateTimeWhiteListItem ranges[];
1435
} SDateTimeWhiteList;
1436

1437
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1438
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1439

1440

1441
typedef struct {
1442
  int8_t createType;
1443
  int8_t superUser;  // denote if it is a super user or not
1444
  int8_t ignoreExists;
1445

1446
  char   user[TSDB_USER_LEN];
1447
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1448
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1449

1450
  int8_t sysInfo;
1451
  int8_t createDb;
1452
  int8_t isImport;
1453
  int8_t changepass;
1454
  int8_t enable;
1455

1456
  int8_t negIpRanges;
1457
  int8_t negTimeRanges;
1458

1459
  int32_t sessionPerUser;
1460
  int32_t connectTime;
1461
  int32_t connectIdleTime;
1462
  int32_t callPerSession;
1463
  int32_t vnodePerCall;
1464
  int32_t failedLoginAttempts;
1465
  int32_t passwordLifeTime;
1466
  int32_t passwordReuseTime;
1467
  int32_t passwordReuseMax;
1468
  int32_t passwordLockTime;
1469
  int32_t passwordGraceTime;
1470
  int32_t inactiveAccountTime;
1471
  int32_t allowTokenNum;
1472

1473
  int32_t         numIpRanges;
1474
  SIpRange*       pIpDualRanges;
1475
  int32_t         numTimeRanges;
1476
  SDateTimeRange* pTimeRanges;
1477

1478
  int32_t sqlLen;
1479
  char*   sql;
1480
} SCreateUserReq;
1481

1482
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1483
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1484
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1485

1486
typedef struct {
1487
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1488
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1489
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1490
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1491
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1492
  int32_t sqlLen;
1493
  char*   sql;
1494
} SCreateEncryptAlgrReq;
1495

1496
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1497
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1498
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1499

1500
typedef struct {
1501
  int32_t dnodeId;
1502
  int64_t analVer;
1503
} SRetrieveAnalyticsAlgoReq;
1504

1505
typedef struct {
1506
  int64_t   ver;
1507
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1508
} SRetrieveAnalyticAlgoRsp;
1509

1510
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1511
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1512
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1513
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1514
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1515

1516
typedef struct {
1517
  int8_t alterType;
1518

1519
  int8_t isView;
1520
  
1521
  int8_t hasPassword;
1522
  int8_t hasTotpseed;
1523
  int8_t hasEnable;
1524
  int8_t hasSysinfo;
1525
  int8_t hasCreatedb;
1526
  int8_t hasChangepass;
1527
  int8_t hasSessionPerUser;
1528
  int8_t hasConnectTime;
1529
  int8_t hasConnectIdleTime;
1530
  int8_t hasCallPerSession;
1531
  int8_t hasVnodePerCall;
1532
  int8_t hasFailedLoginAttempts;
1533
  int8_t hasPasswordLifeTime;
1534
  int8_t hasPasswordReuseTime;
1535
  int8_t hasPasswordReuseMax;
1536
  int8_t hasPasswordLockTime;
1537
  int8_t hasPasswordGraceTime;
1538
  int8_t hasInactiveAccountTime;
1539
  int8_t hasAllowTokenNum;
1540

1541
  int8_t enable;
1542
  int8_t sysinfo;
1543
  int8_t createdb;
1544
  int8_t changepass;
1545

1546
  char   user[TSDB_USER_LEN];
1547
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1548
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1549
  int32_t sessionPerUser;
1550
  int32_t connectTime;
1551
  int32_t connectIdleTime;
1552
  int32_t callPerSession;
1553
  int32_t vnodePerCall;
1554
  int32_t failedLoginAttempts;
1555
  int32_t passwordLifeTime;
1556
  int32_t passwordReuseTime;
1557
  int32_t passwordReuseMax;
1558
  int32_t passwordLockTime;
1559
  int32_t passwordGraceTime;
1560
  int32_t inactiveAccountTime;
1561
  int32_t allowTokenNum;
1562

1563
  int32_t         numIpRanges;
1564
  int32_t         numTimeRanges;
1565
  int32_t         numDropIpRanges;
1566
  int32_t         numDropTimeRanges;
1567
  SIpRange*       pIpRanges;
1568
  SDateTimeRange* pTimeRanges;
1569
  SIpRange*       pDropIpRanges;
1570
  SDateTimeRange* pDropTimeRanges;
1571

1572
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1573
  char        tabName[TSDB_TABLE_NAME_LEN];
1574
  char*       tagCond;
1575
  int32_t     tagCondLen;
1576
  int32_t     sqlLen;
1577
  char*       sql;
1578
  int64_t     privileges;
1579
} SAlterUserReq;
1580

1581
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1582
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1583
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1584

1585
typedef struct {
1586
  char    name[TSDB_TOKEN_NAME_LEN];
1587
  char    user[TSDB_USER_LEN];
1588
  int8_t  enable;
1589
  int8_t  ignoreExists;
1590
  int32_t ttl;
1591
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1592
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1593

1594
  int32_t sqlLen;
1595
  char*   sql;
1596
} SCreateTokenReq;
1597

1598
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1599
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1600
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1601

1602
typedef struct {
1603
  char name[TSDB_TOKEN_NAME_LEN];
1604
  char user[TSDB_USER_LEN];
1605
  char token[TSDB_TOKEN_LEN];
1606
} SCreateTokenRsp;
1607

1608
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1609
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1610
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1611

1612
typedef struct {
1613
  char    name[TSDB_TOKEN_NAME_LEN];
1614

1615
  int8_t hasEnable;
1616
  int8_t hasTtl;
1617
  int8_t hasProvider;
1618
  int8_t hasExtraInfo;
1619

1620
  int8_t  enable;
1621
  int32_t ttl;
1622
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1623
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1624

1625
  int32_t     sqlLen;
1626
  char*       sql;
1627
} SAlterTokenReq;
1628

1629
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1630
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1631
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1632

1633
typedef struct {
1634
  char    name[TSDB_TOKEN_NAME_LEN];
1635
  int32_t sqlLen;
1636
  char*   sql;
1637
} SDropTokenReq;
1638

1639
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1640
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1641
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1642

1643
typedef struct {
1644
  char user[TSDB_USER_LEN];
1645
} SGetUserAuthReq;
1646

1647
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1648
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1649

1650
typedef struct {
1651
  char      user[TSDB_USER_LEN];
1652
  int32_t   version;
1653
  int32_t   passVer;
1654
  int8_t    superAuth;
1655
  int8_t    sysInfo;
1656
  int8_t    enable;
1657
  int8_t    dropped;
1658
  SHashObj* createdDbs;
1659
  SHashObj* readDbs;
1660
  SHashObj* writeDbs;
1661
  SHashObj* readTbs;
1662
  SHashObj* writeTbs;
1663
  SHashObj* alterTbs;
1664
  SHashObj* readViews;
1665
  SHashObj* writeViews;
1666
  SHashObj* alterViews;
1667
  SHashObj* useDbs;
1668
  int64_t   whiteListVer;
1669

1670
  SUserSessCfg sessCfg;
1671
  int64_t      timeWhiteListVer;
1672
} SGetUserAuthRsp;
1673

1674
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1675
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1676
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1677

1678
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1679
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1680
typedef struct {
1681
  int64_t ver;
1682
  char    user[TSDB_USER_LEN];
1683
  int32_t numOfRange;
1684
  union {
1685
    SIpV4Range* pIpRanges;
1686
    SIpRange*   pIpDualRanges;
1687
  };
1688
} SUpdateUserIpWhite;
1689

1690
typedef struct {
1691
  int64_t             ver;
1692
  int                 numOfUser;
1693
  SUpdateUserIpWhite* pUserIpWhite;
1694
} SUpdateIpWhite;
1695

1696
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1697
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1698
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1699
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1700

1701
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1702
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1703
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1704

1705

1706
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1707
// corresponding response struct is different.
1708
typedef struct {
1709
  int64_t ver;
1710
} SRetrieveWhiteListReq;
1711

1712
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1713
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1714

1715

1716
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1717
// corresponding response struct is different.
1718
typedef struct {
1719
  char user[TSDB_USER_LEN];
1720
} SGetUserWhiteListReq;
1721

1722
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1723
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1724

1725
typedef struct {
1726
  char    user[TSDB_USER_LEN];
1727
  int32_t numWhiteLists;
1728
  union {
1729
    SIpV4Range* pWhiteLists;
1730
    SIpRange*   pWhiteListsDual;
1731
  };
1732
} SGetUserIpWhiteListRsp;
1733

1734
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1735
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1736
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1737
void    tIpRangeSetDefaultMask(SIpRange* range);
1738

1739
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1740
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1741
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1742

1743
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1744
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1745
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1746

1747
typedef struct {
1748
  int64_t ver;
1749
  char    user[TSDB_USER_LEN];
1750
  int32_t numWhiteLists;
1751
  SDateTimeWhiteListItem* pWhiteLists;
1752
} SUserDateTimeWhiteList;
1753

1754

1755
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1756
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1757
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1758
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1759

1760
typedef struct {
1761
  int64_t             ver;
1762
  int                 numOfUser;
1763
  SUserDateTimeWhiteList *pUsers;
1764
} SRetrieveDateTimeWhiteListRsp;
1765

1766
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1767
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1768
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1769
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1770

1771
/*
1772
 * for client side struct, only column id, type, bytes are necessary
1773
 * But for data in vnode side, we need all the following information.
1774
 */
1775
typedef struct {
1776
  union {
1777
    col_id_t colId;
1778
    int16_t  slotId;
1779
  };
1780

1781
  uint8_t precision;
1782
  uint8_t scale;
1783
  int32_t bytes;
1784
  int8_t  type;
1785
  uint8_t pk;
1786
  bool    noData;
1787
} SColumnInfo;
1788

1789
typedef struct STimeWindow {
1790
  TSKEY skey;
1791
  TSKEY ekey;
1792
} STimeWindow;
1793

1794
typedef struct SQueryHint {
1795
  bool batchScan;
1796
} SQueryHint;
1797

1798
typedef struct {
1799
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1800
  int32_t tsLen;          // total length of ts comp block
1801
  int32_t tsNumOfBlocks;  // ts comp block numbers
1802
  int32_t tsOrder;        // ts comp block order
1803
} STsBufInfo;
1804

1805
typedef struct {
1806
  void*       timezone;
1807
  char        intervalUnit;
1808
  char        slidingUnit;
1809
  char        offsetUnit;
1810
  int8_t      precision;
1811
  int64_t     interval;
1812
  int64_t     sliding;
1813
  int64_t     offset;
1814
  STimeWindow timeRange;
1815
} SInterval;
1816

1817
typedef struct STbVerInfo {
1818
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1819
  int32_t sversion;
1820
  int32_t tversion;
1821
  int32_t rversion;  // virtual table's column ref's version
1822
} STbVerInfo;
1823

1824
typedef struct {
1825
  int32_t code;
1826
  int64_t affectedRows;
1827
  SArray* tbVerInfo;  // STbVerInfo
1828
} SQueryTableRsp;
1829

1830
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1831

1832
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1833

1834
typedef struct {
1835
  SMsgHead header;
1836
  char     dbFName[TSDB_DB_FNAME_LEN];
1837
  char     tbName[TSDB_TABLE_NAME_LEN];
1838
} STableCfgReq;
1839

1840
typedef struct {
1841
  char        tbName[TSDB_TABLE_NAME_LEN];
1842
  char        stbName[TSDB_TABLE_NAME_LEN];
1843
  char        dbFName[TSDB_DB_FNAME_LEN];
1844
  int32_t     numOfTags;
1845
  int32_t     numOfColumns;
1846
  int8_t      tableType;
1847
  int64_t     delay1;
1848
  int64_t     delay2;
1849
  int64_t     watermark1;
1850
  int64_t     watermark2;
1851
  int32_t     ttl;
1852
  int32_t     keep;
1853
  SArray*     pFuncs;
1854
  int32_t     commentLen;
1855
  char*       pComment;
1856
  SSchema*    pSchemas;
1857
  int32_t     tagsLen;
1858
  char*       pTags;
1859
  SSchemaExt* pSchemaExt;
1860
  int8_t      virtualStb;
1861
  SColRef*    pColRefs;
1862
} STableCfg;
1863

1864
typedef STableCfg STableCfgRsp;
1865

1866
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1867
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1868

1869
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1870
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1871
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1872

1873
typedef struct {
1874
  SMsgHead header;
1875
  tb_uid_t suid;
1876
} SVSubTablesReq;
1877

1878
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1879
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1880

1881
typedef struct {
1882
  int32_t vgId;
1883
  SArray* pTables;  // SArray<SVCTableRefCols*>
1884
} SVSubTablesRsp;
1885

1886
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1887
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1888
void    tDestroySVSubTablesRsp(void* rsp);
1889

1890
typedef struct {
1891
  SMsgHead header;
1892
  tb_uid_t suid;
1893
} SVStbRefDbsReq;
1894

1895
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1896
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1897

1898
typedef struct {
1899
  int32_t vgId;
1900
  SArray* pDbs;  // SArray<char* (db name)>
1901
} SVStbRefDbsRsp;
1902

1903
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1904
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1905
void    tDestroySVStbRefDbsRsp(void* rsp);
1906

1907
typedef struct {
1908
  char    db[TSDB_DB_FNAME_LEN];
1909
  int32_t numOfVgroups;
1910
  int32_t numOfStables;  // single_stable
1911
  int32_t buffer;        // MB
1912
  int32_t pageSize;
1913
  int32_t pages;
1914
  int32_t cacheLastSize;
1915
  int32_t daysPerFile;
1916
  int32_t daysToKeep0;
1917
  int32_t daysToKeep1;
1918
  int32_t daysToKeep2;
1919
  int32_t keepTimeOffset;
1920
  int32_t minRows;
1921
  int32_t maxRows;
1922
  int32_t walFsyncPeriod;
1923
  int8_t  walLevel;
1924
  int8_t  precision;  // time resolution
1925
  int8_t  compression;
1926
  int8_t  replications;
1927
  int8_t  strict;
1928
  int8_t  cacheLast;
1929
  int8_t  schemaless;
1930
  int8_t  ignoreExist;
1931
  int32_t numOfRetensions;
1932
  SArray* pRetensions;  // SRetention
1933
  int32_t walRetentionPeriod;
1934
  int64_t walRetentionSize;
1935
  int32_t walRollPeriod;
1936
  int64_t walSegmentSize;
1937
  int32_t sstTrigger;
1938
  int16_t hashPrefix;
1939
  int16_t hashSuffix;
1940
  int32_t ssChunkSize;
1941
  int32_t ssKeepLocal;
1942
  int8_t  ssCompact;
1943
  int32_t tsdbPageSize;
1944
  int32_t sqlLen;
1945
  char*   sql;
1946
  int8_t  withArbitrator;
1947
  int8_t  encryptAlgorithm;
1948
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1949
  // 1. add auto-compact parameters
1950
  int32_t compactInterval;    // minutes
1951
  int32_t compactStartTime;   // minutes
1952
  int32_t compactEndTime;     // minutes
1953
  int8_t  compactTimeOffset;  // hour
1954
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1955
  int8_t  isAudit;
1956
} SCreateDbReq;
1957

1958
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1959
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1960
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1961

1962
typedef struct {
1963
  char    db[TSDB_DB_FNAME_LEN];
1964
  int32_t buffer;
1965
  int32_t pageSize;
1966
  int32_t pages;
1967
  int32_t cacheLastSize;
1968
  int32_t daysPerFile;
1969
  int32_t daysToKeep0;
1970
  int32_t daysToKeep1;
1971
  int32_t daysToKeep2;
1972
  int32_t keepTimeOffset;
1973
  int32_t walFsyncPeriod;
1974
  int8_t  walLevel;
1975
  int8_t  strict;
1976
  int8_t  cacheLast;
1977
  int8_t  replications;
1978
  int32_t sstTrigger;
1979
  int32_t minRows;
1980
  int32_t walRetentionPeriod;
1981
  int32_t walRetentionSize;
1982
  int32_t ssKeepLocal;
1983
  int8_t  ssCompact;
1984
  int32_t sqlLen;
1985
  char*   sql;
1986
  int8_t  withArbitrator;
1987
  // 1. add auto-compact parameters
1988
  int32_t compactInterval;
1989
  int32_t compactStartTime;
1990
  int32_t compactEndTime;
1991
  int8_t  compactTimeOffset;
1992
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1993
  int8_t  isAudit;
1994
} SAlterDbReq;
1995

1996
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1997
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1998
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1999

2000
typedef struct {
2001
  char    db[TSDB_DB_FNAME_LEN];
2002
  int8_t  ignoreNotExists;
2003
  int8_t  force;
2004
  int32_t sqlLen;
2005
  char*   sql;
2006
} SDropDbReq;
2007

2008
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2009
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2010
void    tFreeSDropDbReq(SDropDbReq* pReq);
2011

2012
typedef struct {
2013
  char    db[TSDB_DB_FNAME_LEN];
2014
  int64_t uid;
2015
} SDropDbRsp;
2016

2017
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2018
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2019

2020
typedef struct {
2021
  char    name[TSDB_MOUNT_NAME_LEN];
2022
  int64_t uid;
2023
} SDropMountRsp;
2024

2025
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2026
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2027

2028
typedef struct {
2029
  char    db[TSDB_DB_FNAME_LEN];
2030
  int64_t dbId;
2031
  int32_t vgVersion;
2032
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2033
  int64_t stateTs;     // ms
2034
} SUseDbReq;
2035

2036
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2037
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2038

2039
typedef struct {
2040
  char    db[TSDB_DB_FNAME_LEN];
2041
  int64_t uid;
2042
  int32_t vgVersion;
2043
  int32_t vgNum;
2044
  int16_t hashPrefix;
2045
  int16_t hashSuffix;
2046
  int8_t  hashMethod;
2047
  union {
2048
    uint8_t flags;
2049
    struct {
2050
      uint8_t isMount : 1;  // TS-5868
2051
      uint8_t padding : 7;
2052
    };
2053
  };
2054
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2055
  int32_t errCode;
2056
  int64_t stateTs;  // ms
2057
} SUseDbRsp;
2058

2059
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2060
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2061
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2062
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2063
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2064

2065
typedef struct {
2066
  char db[TSDB_DB_FNAME_LEN];
2067
} SDbCfgReq;
2068

2069
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2070
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2071

2072
typedef struct {
2073
  char db[TSDB_DB_FNAME_LEN];
2074
} SSsMigrateDbReq;
2075

2076
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2077
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2078

2079
typedef struct {
2080
  int32_t ssMigrateId;
2081
  bool    bAccepted;
2082
} SSsMigrateDbRsp;
2083

2084
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2085
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2086

2087
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2088
typedef struct {
2089
  int32_t ssMigrateId;
2090
} SListSsMigrateFileSetsReq;
2091

2092
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2093
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2094

2095
typedef struct {
2096
  int32_t ssMigrateId;
2097
  int32_t vgId;       // vgroup id
2098
  SArray* pFileSets;  // SArray<int32_t>
2099
} SListSsMigrateFileSetsRsp;
2100

2101
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2102
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2103
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2104

2105
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2106
typedef struct {
2107
  int32_t ssMigrateId;
2108
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2109
  int32_t fid;
2110
  int64_t startTimeSec;
2111
} SSsMigrateFileSetReq;
2112

2113
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2114
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2115

2116
typedef struct {
2117
  int32_t ssMigrateId;
2118
  int32_t nodeId;  // node id of the leader vnode
2119
  int32_t vgId;
2120
  int32_t fid;
2121
} SSsMigrateFileSetRsp;
2122

2123
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2124
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2125

2126
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2127
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2128
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2129
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2130
#define SSMIGRATE_FILESET_STATE_FAILED      4
2131

2132
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2133
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2134
// while as a request, the 'state' field is not used.
2135
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2136
typedef struct {
2137
  int32_t ssMigrateId;  // ss migrate id
2138
  int32_t nodeId;       // node id of the leader vnode
2139
  int32_t vgId;         // vgroup id
2140
  int32_t fid;          // file set id
2141
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2142
} SSsMigrateProgress;
2143

2144
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2145
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2146

2147
// Request for TDMT_MND_KILL_SSMIGRATE
2148
typedef struct {
2149
  int32_t ssMigrateId;
2150
  int32_t sqlLen;
2151
  char*   sql;
2152
} SKillSsMigrateReq;
2153

2154
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2155
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2156
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2157

2158
// Request for TDMT_VND_KILL_SSMIGRATE
2159
typedef struct {
2160
  int32_t ssMigrateId;
2161
} SVnodeKillSsMigrateReq;
2162

2163
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2164
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2165

2166
typedef struct {
2167
  int32_t vgId;
2168
  int64_t keepVersion;
2169
} SMndSetVgroupKeepVersionReq;
2170

2171
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2172
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2173

2174
typedef struct {
2175
  int32_t timestampSec;
2176
  int32_t ttlDropMaxCount;
2177
  int32_t nUids;
2178
  SArray* pTbUids;
2179
} SVDropTtlTableReq;
2180

2181
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2182
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2183

2184
typedef struct {
2185
  char    db[TSDB_DB_FNAME_LEN];
2186
  int64_t dbId;
2187
  int32_t cfgVersion;
2188
  int32_t numOfVgroups;
2189
  int32_t numOfStables;
2190
  int32_t buffer;
2191
  int32_t cacheSize;
2192
  int32_t pageSize;
2193
  int32_t pages;
2194
  int32_t daysPerFile;
2195
  int32_t daysToKeep0;
2196
  int32_t daysToKeep1;
2197
  int32_t daysToKeep2;
2198
  int32_t keepTimeOffset;
2199
  int32_t minRows;
2200
  int32_t maxRows;
2201
  int32_t walFsyncPeriod;
2202
  int16_t hashPrefix;
2203
  int16_t hashSuffix;
2204
  int8_t  hashMethod;
2205
  int8_t  walLevel;
2206
  int8_t  precision;
2207
  int8_t  compression;
2208
  int8_t  replications;
2209
  int8_t  strict;
2210
  int8_t  cacheLast;
2211
  int8_t  encryptAlgr;
2212
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2213
  int32_t ssChunkSize;
2214
  int32_t ssKeepLocal;
2215
  int8_t  ssCompact;
2216
  union {
2217
    uint8_t flags;
2218
    struct {
2219
      uint8_t isMount : 1;  // TS-5868
2220
      uint8_t padding : 7;
2221
    };
2222
  };
2223
  int8_t  compactTimeOffset;
2224
  int32_t compactInterval;
2225
  int32_t compactStartTime;
2226
  int32_t compactEndTime;
2227
  int32_t tsdbPageSize;
2228
  int32_t walRetentionPeriod;
2229
  int32_t walRollPeriod;
2230
  int64_t walRetentionSize;
2231
  int64_t walSegmentSize;
2232
  int32_t numOfRetensions;
2233
  SArray* pRetensions;
2234
  int8_t  schemaless;
2235
  int16_t sstTrigger;
2236
  int8_t  withArbitrator;
2237
  int8_t  isAudit;
2238
} SDbCfgRsp;
2239

2240
typedef SDbCfgRsp SDbCfgInfo;
2241

2242
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2243
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2244
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2245
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2246
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2247

2248
typedef struct {
2249
  int32_t rowNum;
2250
} SQnodeListReq;
2251

2252
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2253
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2254

2255
typedef struct {
2256
  int32_t rowNum;
2257
} SDnodeListReq;
2258

2259
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2260

2261
typedef struct {
2262
  int32_t useless;  // useless
2263
} SServerVerReq;
2264

2265
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2266
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2267

2268
typedef struct {
2269
  char ver[TSDB_VERSION_LEN];
2270
} SServerVerRsp;
2271

2272
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2273
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2274

2275
typedef struct SQueryNodeAddr {
2276
  int32_t nodeId;  // vgId or qnodeId
2277
  SEpSet  epSet;
2278
} SQueryNodeAddr;
2279

2280
typedef struct {
2281
  SQueryNodeAddr addr;
2282
  uint64_t       load;
2283
} SQueryNodeLoad;
2284

2285
typedef struct {
2286
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2287
} SQnodeListRsp;
2288

2289
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2290
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2291
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2292

2293

2294
typedef struct SDownstreamSourceNode {
2295
  ENodeType      type;
2296
  SQueryNodeAddr addr;
2297
  uint64_t       clientId;
2298
  uint64_t       taskId;
2299
  uint64_t       sId;
2300
  int32_t        execId;
2301
  int32_t        fetchMsgType;
2302
  bool           localExec;
2303
} SDownstreamSourceNode;
2304

2305

2306

2307
typedef struct SDNodeAddr {
2308
  int32_t nodeId;  // dnodeId
2309
  SEpSet  epSet;
2310
} SDNodeAddr;
2311

2312
typedef struct {
2313
  SArray* dnodeList;  // SArray<SDNodeAddr>
2314
} SDnodeListRsp;
2315

2316
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2317
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2318
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2319

2320
typedef struct {
2321
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2322
} STableTSMAInfoRsp;
2323

2324
typedef struct {
2325
  SUseDbRsp*         useDbRsp;
2326
  SDbCfgRsp*         cfgRsp;
2327
  STableTSMAInfoRsp* pTsmaRsp;
2328
  int32_t            dbTsmaVersion;
2329
  char               db[TSDB_DB_FNAME_LEN];
2330
  int64_t            dbId;
2331
} SDbHbRsp;
2332

2333
typedef struct {
2334
  SArray* pArray;  // Array of SDbHbRsp
2335
} SDbHbBatchRsp;
2336

2337
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2338
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2339
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2340

2341
typedef struct {
2342
  SArray* pArray;  // Array of SGetUserAuthRsp
2343
} SUserAuthBatchRsp;
2344

2345
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2346
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2347
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2348

2349
typedef struct {
2350
  char        db[TSDB_DB_FNAME_LEN];
2351
  STimeWindow timeRange;
2352
  int32_t     sqlLen;
2353
  char*       sql;
2354
  SArray*     vgroupIds;
2355
  int32_t     compactId;
2356
  int8_t      metaOnly;
2357
  int8_t      force;
2358
} SCompactDbReq;
2359

2360
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2361
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2362
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2363

2364
typedef struct {
2365
  union {
2366
    int32_t compactId;
2367
    int32_t id;
2368
  };
2369
  int8_t bAccepted;
2370
} SCompactDbRsp;
2371

2372
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2373
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2374

2375
typedef struct {
2376
  union {
2377
    int32_t compactId;
2378
    int32_t id;
2379
  };
2380
  int32_t sqlLen;
2381
  char*   sql;
2382
} SKillCompactReq;
2383

2384
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2385
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2386
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2387

2388
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2389
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2390

2391
typedef struct {
2392
  char    name[TSDB_FUNC_NAME_LEN];
2393
  int8_t  igExists;
2394
  int8_t  funcType;
2395
  int8_t  scriptType;
2396
  int8_t  outputType;
2397
  int32_t outputLen;
2398
  int32_t bufSize;
2399
  int32_t codeLen;
2400
  int64_t signature;
2401
  char*   pComment;
2402
  char*   pCode;
2403
  int8_t  orReplace;
2404
} SCreateFuncReq;
2405

2406
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2407
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2408
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2409

2410
typedef struct {
2411
  char   name[TSDB_FUNC_NAME_LEN];
2412
  int8_t igNotExists;
2413
} SDropFuncReq;
2414

2415
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2416
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2417

2418
typedef struct {
2419
  int32_t numOfFuncs;
2420
  bool    ignoreCodeComment;
2421
  SArray* pFuncNames;
2422
} SRetrieveFuncReq;
2423

2424
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2425
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2426
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2427

2428
typedef struct {
2429
  char    name[TSDB_FUNC_NAME_LEN];
2430
  int8_t  funcType;
2431
  int8_t  scriptType;
2432
  int8_t  outputType;
2433
  int32_t outputLen;
2434
  int32_t bufSize;
2435
  int64_t signature;
2436
  int32_t commentSize;
2437
  int32_t codeSize;
2438
  char*   pComment;
2439
  char*   pCode;
2440
} SFuncInfo;
2441

2442
typedef struct {
2443
  int32_t funcVersion;
2444
  int64_t funcCreatedTime;
2445
} SFuncExtraInfo;
2446

2447
typedef struct {
2448
  int32_t numOfFuncs;
2449
  SArray* pFuncInfos;
2450
  SArray* pFuncExtraInfos;
2451
} SRetrieveFuncRsp;
2452

2453
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2454
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2455
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2456
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2457

2458
typedef struct {
2459
  int32_t       statusInterval;
2460
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2461
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2462
  char          locale[TD_LOCALE_LEN];      // tsLocale
2463
  char          charset[TD_LOCALE_LEN];     // tsCharset
2464
  int8_t        ttlChangeOnWrite;
2465
  int8_t        enableWhiteList;
2466
  int8_t        encryptionKeyStat;
2467
  uint32_t      encryptionKeyChksum;
2468
  SMonitorParas monitorParas;
2469
  int32_t       statusIntervalMs;
2470
} SClusterCfg;
2471

2472
typedef struct {
2473
  int32_t openVnodes;
2474
  int32_t dropVnodes;
2475
  int32_t totalVnodes;
2476
  int32_t masterNum;
2477
  int64_t numOfSelectReqs;
2478
  int64_t numOfInsertReqs;
2479
  int64_t numOfInsertSuccessReqs;
2480
  int64_t numOfBatchInsertReqs;
2481
  int64_t numOfBatchInsertSuccessReqs;
2482
  int64_t errors;
2483
} SVnodesStat;
2484

2485
typedef struct {
2486
  int32_t vgId;
2487
  int8_t  syncState;
2488
  int8_t  syncRestore;
2489
  int64_t syncTerm;
2490
  int64_t roleTimeMs;
2491
  int64_t startTimeMs;
2492
  int8_t  syncCanRead;
2493
  int64_t cacheUsage;
2494
  int64_t numOfTables;
2495
  int64_t numOfTimeSeries;
2496
  int64_t totalStorage;
2497
  int64_t compStorage;
2498
  int64_t pointsWritten;
2499
  int64_t numOfSelectReqs;
2500
  int64_t numOfInsertReqs;
2501
  int64_t numOfInsertSuccessReqs;
2502
  int64_t numOfBatchInsertReqs;
2503
  int64_t numOfBatchInsertSuccessReqs;
2504
  int32_t numOfCachedTables;
2505
  int32_t learnerProgress;  // use one reservered
2506
  int64_t syncAppliedIndex;
2507
  int64_t syncCommitIndex;
2508
  int64_t bufferSegmentUsed;
2509
  int64_t bufferSegmentSize;
2510
} SVnodeLoad;
2511

2512
typedef struct {
2513
  int64_t total_requests;
2514
  int64_t total_rows;
2515
  int64_t total_bytes;
2516
  double  write_size;
2517
  double  cache_hit_ratio;
2518
  int64_t rpc_queue_wait;
2519
  int64_t preprocess_time;
2520

2521
  int64_t memory_table_size;
2522
  int64_t commit_count;
2523
  int64_t merge_count;
2524
  double  commit_time;
2525
  double  merge_time;
2526
  int64_t block_commit_time;
2527
  int64_t memtable_wait_time;
2528
} SVnodeMetrics;
2529

2530
typedef struct {
2531
  int32_t     vgId;
2532
  int64_t     numOfTables;
2533
  int64_t     memSize;
2534
  int64_t     l1Size;
2535
  int64_t     l2Size;
2536
  int64_t     l3Size;
2537
  int64_t     cacheSize;
2538
  int64_t     walSize;
2539
  int64_t     metaSize;
2540
  int64_t     rawDataSize;
2541
  int64_t     ssSize;
2542
  const char* dbname;
2543
  int8_t      estimateRawData;
2544
} SDbSizeStatisInfo;
2545

2546
typedef struct {
2547
  int32_t vgId;
2548
  int64_t nTimeSeries;
2549
} SVnodeLoadLite;
2550

2551
typedef struct {
2552
  int8_t  syncState;
2553
  int64_t syncTerm;
2554
  int8_t  syncRestore;
2555
  int64_t roleTimeMs;
2556
} SMnodeLoad;
2557

2558
typedef struct {
2559
  int32_t dnodeId;
2560
  int64_t numOfProcessedQuery;
2561
  int64_t numOfProcessedCQuery;
2562
  int64_t numOfProcessedFetch;
2563
  int64_t numOfProcessedDrop;
2564
  int64_t numOfProcessedNotify;
2565
  int64_t numOfProcessedHb;
2566
  int64_t numOfProcessedDelete;
2567
  int64_t cacheDataSize;
2568
  int64_t numOfQueryInQueue;
2569
  int64_t numOfFetchInQueue;
2570
  int64_t timeInQueryQueue;
2571
  int64_t timeInFetchQueue;
2572
} SQnodeLoad;
2573

2574
typedef struct {
2575
  int32_t     sver;      // software version
2576
  int64_t     dnodeVer;  // dnode table version in sdb
2577
  int32_t     dnodeId;
2578
  int64_t     clusterId;
2579
  int64_t     rebootTime;
2580
  int64_t     updateTime;
2581
  float       numOfCores;
2582
  int32_t     numOfSupportVnodes;
2583
  int32_t     numOfDiskCfg;
2584
  int64_t     memTotal;
2585
  int64_t     memAvail;
2586
  char        dnodeEp[TSDB_EP_LEN];
2587
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2588
  SMnodeLoad  mload;
2589
  SQnodeLoad  qload;
2590
  SClusterCfg clusterCfg;
2591
  SArray*     pVloads;  // array of SVnodeLoad
2592
  int32_t     statusSeq;
2593
  int64_t     ipWhiteVer;
2594
  int64_t     timeWhiteVer;
2595
  int64_t     analVer;
2596
  int64_t     timestamp;
2597
  char        auditDB[TSDB_DB_FNAME_LEN];
2598
  char        auditToken[TSDB_TOKEN_LEN];
2599
} SStatusReq;
2600

2601
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2602
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2603
void    tFreeSStatusReq(SStatusReq* pReq);
2604

2605
typedef struct {
2606
  int32_t forceReadConfig;
2607
  int32_t cver;
2608
  SArray* array;
2609
} SConfigReq;
2610

2611
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2612
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2613
void    tFreeSConfigReq(SConfigReq* pReq);
2614

2615
typedef struct {
2616
  int32_t dnodeId;
2617
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2618
} SDnodeInfoReq;
2619

2620
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2621
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2622

2623
typedef enum {
2624
  MONITOR_TYPE_COUNTER = 0,
2625
  MONITOR_TYPE_SLOW_LOG = 1,
2626
} MONITOR_TYPE;
2627

2628
typedef struct {
2629
  int32_t      contLen;
2630
  char*        pCont;
2631
  MONITOR_TYPE type;
2632
} SStatisReq;
2633

2634
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2635
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2636
void    tFreeSStatisReq(SStatisReq* pReq);
2637

2638
typedef struct {
2639
  char    db[TSDB_DB_FNAME_LEN];
2640
  char    table[TSDB_TABLE_NAME_LEN];
2641
  char    operation[AUDIT_OPERATION_LEN];
2642
  int32_t sqlLen;
2643
  char*   pSql;
2644
  double  duration;
2645
  int64_t affectedRows;
2646
} SAuditReq;
2647
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2648
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2649
void    tFreeSAuditReq(SAuditReq* pReq);
2650

2651
typedef struct {
2652
  SArray* auditArr;
2653
} SBatchAuditReq;
2654
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2655
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2656
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2657

2658
typedef struct {
2659
  int32_t dnodeId;
2660
  int64_t clusterId;
2661
  SArray* pVloads;
2662
} SNotifyReq;
2663

2664
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2665
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2666
void    tFreeSNotifyReq(SNotifyReq* pReq);
2667

2668
typedef struct {
2669
  int32_t dnodeId;
2670
  int64_t clusterId;
2671
} SDnodeCfg;
2672

2673
typedef struct {
2674
  int32_t id;
2675
  int8_t  isMnode;
2676
  SEp     ep;
2677
} SDnodeEp;
2678

2679
typedef struct {
2680
  int32_t id;
2681
  int8_t  isMnode;
2682
  int8_t  offlineReason;
2683
  SEp     ep;
2684
  char    active[TSDB_ACTIVE_KEY_LEN];
2685
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2686
} SDnodeInfo;
2687

2688
typedef struct {
2689
  int64_t   dnodeVer;
2690
  SDnodeCfg dnodeCfg;
2691
  SArray*   pDnodeEps;  // Array of SDnodeEp
2692
  int32_t   statusSeq;
2693
  int64_t   ipWhiteVer;
2694
  int64_t   analVer;
2695
  int64_t   timeWhiteVer;
2696
  char      auditDB[TSDB_DB_FNAME_LEN];
2697
  char      auditToken[TSDB_TOKEN_LEN];
2698
} SStatusRsp;
2699

2700
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2701
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2702
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2703

2704
typedef struct {
2705
  int32_t forceReadConfig;
2706
  int32_t isConifgVerified;
2707
  int32_t isVersionVerified;
2708
  int32_t cver;
2709
  SArray* array;
2710
} SConfigRsp;
2711

2712
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2713
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2714
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2715

2716
typedef struct {
2717
  int32_t reserved;
2718
} SMTimerReq;
2719

2720
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2721
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2722

2723
typedef struct SOrphanTask {
2724
  int64_t streamId;
2725
  int32_t taskId;
2726
  int32_t nodeId;
2727
} SOrphanTask;
2728

2729
typedef struct SMStreamDropOrphanMsg {
2730
  SArray* pList;  // SArray<SOrphanTask>
2731
} SMStreamDropOrphanMsg;
2732

2733
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2734
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2735
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2736

2737
typedef struct {
2738
  int32_t  id;
2739
  uint16_t port;                 // node sync Port
2740
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2741
} SReplica;
2742

2743
typedef struct {
2744
  int32_t  vgId;
2745
  char     db[TSDB_DB_FNAME_LEN];
2746
  int64_t  dbUid;
2747
  int32_t  vgVersion;
2748
  int32_t  numOfStables;
2749
  int32_t  buffer;
2750
  int32_t  pageSize;
2751
  int32_t  pages;
2752
  int32_t  cacheLastSize;
2753
  int32_t  daysPerFile;
2754
  int32_t  daysToKeep0;
2755
  int32_t  daysToKeep1;
2756
  int32_t  daysToKeep2;
2757
  int32_t  keepTimeOffset;
2758
  int32_t  minRows;
2759
  int32_t  maxRows;
2760
  int32_t  walFsyncPeriod;
2761
  uint32_t hashBegin;
2762
  uint32_t hashEnd;
2763
  int8_t   hashMethod;
2764
  int8_t   walLevel;
2765
  int8_t   precision;
2766
  int8_t   compression;
2767
  int8_t   strict;
2768
  int8_t   cacheLast;
2769
  int8_t   isTsma;
2770
  int8_t   replica;
2771
  int8_t   selfIndex;
2772
  SReplica replicas[TSDB_MAX_REPLICA];
2773
  int32_t  numOfRetensions;
2774
  SArray*  pRetensions;  // SRetention
2775
  void*    pTsma;
2776
  int32_t  walRetentionPeriod;
2777
  int64_t  walRetentionSize;
2778
  int32_t  walRollPeriod;
2779
  int64_t  walSegmentSize;
2780
  int16_t  sstTrigger;
2781
  int16_t  hashPrefix;
2782
  int16_t  hashSuffix;
2783
  int32_t  tsdbPageSize;
2784
  int32_t  ssChunkSize;
2785
  int32_t  ssKeepLocal;
2786
  int8_t   ssCompact;
2787
  int64_t  reserved[6];
2788
  int8_t   learnerReplica;
2789
  int8_t   learnerSelfIndex;
2790
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2791
  int32_t  changeVersion;
2792
  int8_t   encryptAlgorithm;
2793
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2794
} SCreateVnodeReq;
2795

2796
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2797
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2798
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2799

2800
typedef struct {
2801
  union {
2802
    int32_t compactId;
2803
    int32_t id;
2804
  };
2805
  int32_t vgId;
2806
  int32_t dnodeId;
2807
} SQueryCompactProgressReq;
2808

2809
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2810
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2811

2812
typedef struct {
2813
  union {
2814
    int32_t compactId;
2815
    int32_t id;
2816
  };
2817
  int32_t vgId;
2818
  int32_t dnodeId;
2819
  int32_t numberFileset;
2820
  int32_t finished;
2821
  int32_t progress;
2822
  int64_t remainingTime;
2823
} SQueryCompactProgressRsp;
2824

2825
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2826
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2827

2828
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2829
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2830

2831
typedef struct {
2832
  int32_t vgId;
2833
  int32_t dnodeId;
2834
  int64_t dbUid;
2835
  char    db[TSDB_DB_FNAME_LEN];
2836
  int64_t reserved[8];
2837
} SDropVnodeReq;
2838

2839
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2840
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2841

2842
typedef struct {
2843
  char    colName[TSDB_COL_NAME_LEN];
2844
  char    stb[TSDB_TABLE_FNAME_LEN];
2845
  int64_t stbUid;
2846
  int64_t dbUid;
2847
  int64_t reserved[8];
2848
} SDropIndexReq;
2849

2850
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2851
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2852

2853
typedef struct {
2854
  int64_t dbUid;
2855
  char    db[TSDB_DB_FNAME_LEN];
2856
  union {
2857
    int64_t compactStartTime;
2858
    int64_t startTime;
2859
  };
2860

2861
  STimeWindow tw;
2862
  union {
2863
    int32_t compactId;
2864
    int32_t id;
2865
  };
2866
  int8_t metaOnly;
2867
  union {
2868
    uint16_t flags;
2869
    struct {
2870
      uint16_t optrType : 3;     // ETsdbOpType
2871
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2872
      uint16_t reserved : 12;
2873
    };
2874
  };
2875
  int8_t force;  // force compact
2876
} SCompactVnodeReq;
2877

2878
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2879
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2880

2881
typedef struct {
2882
  union {
2883
    int32_t compactId;
2884
    int32_t taskId;
2885
  };
2886
  int32_t vgId;
2887
  int32_t dnodeId;
2888
} SVKillCompactReq;
2889

2890
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2891
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2892

2893
typedef SVKillCompactReq SVKillRetentionReq;
2894

2895
typedef struct {
2896
  char        db[TSDB_DB_FNAME_LEN];
2897
  int32_t     maxSpeed;
2898
  int32_t     sqlLen;
2899
  char*       sql;
2900
  SArray*     vgroupIds;
2901
  STimeWindow tw;  // unit is second
2902
  union {
2903
    uint32_t flags;
2904
    struct {
2905
      uint32_t optrType : 3;     // ETsdbOpType
2906
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2907
      uint32_t reserved : 28;
2908
    };
2909
  };
2910
} STrimDbReq;
2911

2912
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2913
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2914
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2915

2916
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2917

2918
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2919
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2920

2921
typedef struct {
2922
  int32_t vgVersion;
2923
  int32_t buffer;
2924
  int32_t pageSize;
2925
  int32_t pages;
2926
  int32_t cacheLastSize;
2927
  int32_t daysPerFile;
2928
  int32_t daysToKeep0;
2929
  int32_t daysToKeep1;
2930
  int32_t daysToKeep2;
2931
  int32_t keepTimeOffset;
2932
  int32_t walFsyncPeriod;
2933
  int8_t  walLevel;
2934
  int8_t  strict;
2935
  int8_t  cacheLast;
2936
  int64_t reserved[7];
2937
  // 1st modification
2938
  int16_t sttTrigger;
2939
  int32_t minRows;
2940
  // 2nd modification
2941
  int32_t walRetentionPeriod;
2942
  int32_t walRetentionSize;
2943
  int32_t ssKeepLocal;
2944
  int8_t  ssCompact;
2945
} SAlterVnodeConfigReq;
2946

2947
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2948
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2949

2950
typedef struct {
2951
  int32_t  vgId;
2952
  int8_t   strict;
2953
  int8_t   selfIndex;
2954
  int8_t   replica;
2955
  SReplica replicas[TSDB_MAX_REPLICA];
2956
  int64_t  reserved[8];
2957
  int8_t   learnerSelfIndex;
2958
  int8_t   learnerReplica;
2959
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2960
  int32_t  changeVersion;
2961
  int32_t  electBaseLine;
2962
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2963

2964
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2965
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2966

2967
typedef struct {
2968
  int32_t vgId;
2969
  int8_t  disable;
2970
} SDisableVnodeWriteReq;
2971

2972
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2973
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2974

2975
typedef struct {
2976
  int32_t  srcVgId;
2977
  int32_t  dstVgId;
2978
  uint32_t hashBegin;
2979
  uint32_t hashEnd;
2980
  int32_t  changeVersion;
2981
  int32_t  reserved;
2982
} SAlterVnodeHashRangeReq;
2983

2984
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2985
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2986

2987
#define REQ_OPT_TBNAME 0x0
2988
#define REQ_OPT_TBUID  0x01
2989
typedef struct {
2990
  SMsgHead header;
2991
  char     dbFName[TSDB_DB_FNAME_LEN];
2992
  char     tbName[TSDB_TABLE_NAME_LEN];
2993
  uint8_t  option;
2994
  uint8_t  autoCreateCtb;
2995
} STableInfoReq;
2996

2997
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2998
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2999

3000
typedef struct {
3001
  int8_t  metaClone;  // create local clone of the cached table meta
3002
  int32_t numOfVgroups;
3003
  int32_t numOfTables;
3004
  int32_t numOfUdfs;
3005
  char    tableNames[];
3006
} SMultiTableInfoReq;
3007

3008
// todo refactor
3009
typedef struct SVgroupInfo {
3010
  int32_t  vgId;
3011
  uint32_t hashBegin;
3012
  uint32_t hashEnd;
3013
  SEpSet   epSet;
3014
  union {
3015
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3016
    int32_t taskId;      // used in stream
3017
  };
3018
} SVgroupInfo;
3019

3020
typedef struct {
3021
  int32_t     numOfVgroups;
3022
  SVgroupInfo vgroups[];
3023
} SVgroupsInfo;
3024

3025
typedef struct {
3026
  STableMetaRsp* pMeta;
3027
} SMAlterStbRsp;
3028

3029
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3030
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3031
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3032

3033
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3034
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3035
void    tFreeSTableMetaRsp(void* pRsp);
3036
void    tFreeSTableIndexRsp(void* info);
3037

3038
typedef struct {
3039
  SArray* pMetaRsp;   // Array of STableMetaRsp
3040
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3041
} SSTbHbRsp;
3042

3043
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3044
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3045
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3046

3047
typedef struct {
3048
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3049
} SViewHbRsp;
3050

3051
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3052
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3053
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3054

3055
typedef struct {
3056
  int32_t numOfTables;
3057
  int32_t numOfVgroup;
3058
  int32_t numOfUdf;
3059
  int32_t contLen;
3060
  int8_t  compressed;  // denote if compressed or not
3061
  int32_t rawLen;      // size before compress
3062
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3063
  char    meta[];
3064
} SMultiTableMeta;
3065

3066
typedef struct {
3067
  int32_t dataLen;
3068
  char    name[TSDB_TABLE_FNAME_LEN];
3069
  char*   data;
3070
} STagData;
3071

3072
typedef struct {
3073
  int32_t  opType;
3074
  uint32_t valLen;
3075
  char*    val;
3076
} SShowVariablesReq;
3077

3078
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3079
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3080
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3081

3082
typedef struct {
3083
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3084
  char value[TSDB_CONFIG_PATH_LEN + 1];
3085
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3086
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3087
  char info[TSDB_CONFIG_INFO_LEN + 1];
3088
} SVariablesInfo;
3089

3090
typedef struct {
3091
  SArray* variables;  // SArray<SVariablesInfo>
3092
} SShowVariablesRsp;
3093

3094
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3095
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3096

3097
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3098

3099
/*
3100
 * sql: show tables like '%a_%'
3101
 * payload is the query condition, e.g., '%a_%'
3102
 * payloadLen is the length of payload
3103
 */
3104
typedef struct {
3105
  int32_t type;
3106
  char    db[TSDB_DB_FNAME_LEN];
3107
  int32_t payloadLen;
3108
  char*   payload;
3109
} SShowReq;
3110

3111
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3112
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3113
void tFreeSShowReq(SShowReq* pReq);
3114

3115
typedef struct {
3116
  int64_t       showId;
3117
  STableMetaRsp tableMeta;
3118
} SShowRsp, SVShowTablesRsp;
3119

3120
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3121
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3122
// void    tFreeSShowRsp(SShowRsp* pRsp);
3123

3124
typedef struct {
3125
  char    db[TSDB_DB_FNAME_LEN];
3126
  char    tb[TSDB_TABLE_NAME_LEN];
3127
  char    user[TSDB_USER_LEN];
3128
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3129
  int64_t showId;
3130
  int64_t compactId;  // for compact
3131
  bool    withFull;   // for show users full
3132
} SRetrieveTableReq;
3133

3134
typedef struct SSysTableSchema {
3135
  int8_t   type;
3136
  col_id_t colId;
3137
  int32_t  bytes;
3138
} SSysTableSchema;
3139

3140
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3141
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3142

3143
#define RETRIEVE_TABLE_RSP_VERSION         0
3144
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3145
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3146

3147
typedef struct {
3148
  int64_t useconds;
3149
  int8_t  completed;  // all results are returned to client
3150
  int8_t  precision;
3151
  int8_t  compressed;
3152
  int8_t  streamBlockType;
3153
  int32_t payloadLen;
3154
  int32_t compLen;
3155
  int32_t numOfBlocks;
3156
  int64_t numOfRows;  // from int32_t change to int64_t
3157
  int64_t numOfCols;
3158
  int64_t skey;
3159
  int64_t ekey;
3160
  int64_t version;                         // for stream
3161
  TSKEY   watermark;                       // for stream
3162
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3163
  char    data[];
3164
} SRetrieveTableRsp;
3165

3166
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3167

3168
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3169
  do {                                          \
3170
    ((int32_t*)(_p))[0] = (_compLen);           \
3171
    ((int32_t*)(_p))[1] = (_fullLen);           \
3172
  } while (0);
3173

3174
typedef struct {
3175
  int64_t version;
3176
  int64_t numOfRows;
3177
  int8_t  compressed;
3178
  int8_t  precision;
3179
  char    data[];
3180
} SRetrieveTableRspForTmq;
3181

3182
typedef struct {
3183
  int64_t handle;
3184
  int64_t useconds;
3185
  int8_t  completed;  // all results are returned to client
3186
  int8_t  precision;
3187
  int8_t  compressed;
3188
  int32_t compLen;
3189
  int32_t numOfRows;
3190
  int32_t fullLen;
3191
  char    data[];
3192
} SRetrieveMetaTableRsp;
3193

3194
typedef struct SExplainExecInfo {
3195
  double   startupCost;
3196
  double   totalCost;
3197
  uint64_t numOfRows;
3198
  uint32_t verboseLen;
3199
  void*    verboseInfo;
3200
} SExplainExecInfo;
3201

3202
typedef struct {
3203
  int32_t           numOfPlans;
3204
  SExplainExecInfo* subplanInfo;
3205
} SExplainRsp;
3206

3207
typedef struct {
3208
  SExplainRsp rsp;
3209
  uint64_t    qId;
3210
  uint64_t    cId;
3211
  uint64_t    tId;
3212
  int64_t     rId;
3213
  int32_t     eId;
3214
} SExplainLocalRsp;
3215

3216
typedef struct STableScanAnalyzeInfo {
3217
  uint64_t totalRows;
3218
  uint64_t totalCheckedRows;
3219
  uint32_t totalBlocks;
3220
  uint32_t loadBlocks;
3221
  uint32_t loadBlockStatis;
3222
  uint32_t skipBlocks;
3223
  uint32_t filterOutBlocks;
3224
  double   elapsedTime;
3225
  double   filterTime;
3226
} STableScanAnalyzeInfo;
3227

3228
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3229
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3230
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3231

3232
typedef struct {
3233
  char    config[TSDB_DNODE_CONFIG_LEN];
3234
  char    value[TSDB_CLUSTER_VALUE_LEN];
3235
  int32_t sqlLen;
3236
  char*   sql;
3237
} SMCfgClusterReq;
3238

3239
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3240
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3241
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3242

3243
typedef struct {
3244
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3245
  int32_t port;
3246
  int32_t sqlLen;
3247
  char*   sql;
3248
} SCreateDnodeReq;
3249

3250
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3251
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3252
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3253

3254
typedef struct {
3255
  int32_t dnodeId;
3256
  char    fqdn[TSDB_FQDN_LEN];
3257
  int32_t port;
3258
  int8_t  force;
3259
  int8_t  unsafe;
3260
  int32_t sqlLen;
3261
  char*   sql;
3262
} SDropDnodeReq;
3263

3264
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3265
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3266
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3267

3268
enum {
3269
  RESTORE_TYPE__ALL = 1,
3270
  RESTORE_TYPE__MNODE,
3271
  RESTORE_TYPE__VNODE,
3272
  RESTORE_TYPE__QNODE,
3273
};
3274

3275
typedef struct {
3276
  int32_t dnodeId;
3277
  int8_t  restoreType;
3278
  int32_t sqlLen;
3279
  char*   sql;
3280
} SRestoreDnodeReq;
3281

3282
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3283
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3284
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3285

3286
typedef struct {
3287
  int32_t dnodeId;
3288
  char    config[TSDB_DNODE_CONFIG_LEN];
3289
  char    value[TSDB_DNODE_VALUE_LEN];
3290
  int32_t sqlLen;
3291
  char*   sql;
3292
} SMCfgDnodeReq;
3293

3294
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3295
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3296
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3297

3298
typedef struct {
3299
  char    config[TSDB_DNODE_CONFIG_LEN];
3300
  char    value[TSDB_DNODE_VALUE_LEN];
3301
  int32_t version;
3302
} SDCfgDnodeReq;
3303

3304
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3305
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3306

3307
typedef struct {
3308
  int32_t dnodeId;
3309
  int32_t sqlLen;
3310
  char*   sql;
3311
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3312
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3313

3314
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3315
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3316

3317
typedef struct {
3318
  int32_t nodeId;
3319
  SEpSet  epSet;
3320
} SNodeEpSet;
3321

3322
typedef struct {
3323
  int32_t    snodeId;
3324
  SNodeEpSet leaders[2];
3325
  SNodeEpSet replica;
3326
  int32_t    sqlLen;
3327
  char*      sql;
3328
} SDCreateSnodeReq;
3329

3330
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3331
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3332
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3333

3334
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3335
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3336
typedef struct {
3337
  int8_t   replica;
3338
  SReplica replicas[TSDB_MAX_REPLICA];
3339
  int8_t   learnerReplica;
3340
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3341
  int64_t  lastIndex;
3342
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3343

3344
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3345
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3346

3347
typedef struct {
3348
  int32_t urlLen;
3349
  int32_t sqlLen;
3350
  char*   url;
3351
  char*   sql;
3352
} SMCreateAnodeReq;
3353

3354
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3355
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3356
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3357

3358
typedef struct {
3359
  int32_t anodeId;
3360
  int32_t sqlLen;
3361
  char*   sql;
3362
} SMDropAnodeReq, SMUpdateAnodeReq;
3363

3364
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3365
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3366
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3367
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3368
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3369
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3370

3371
typedef struct {
3372
  int32_t dnodeId;
3373
  int32_t bnodeProto;
3374
  int32_t sqlLen;
3375
  char*   sql;
3376
} SMCreateBnodeReq, SDCreateBnodeReq;
3377

3378
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3379
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3380
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3381

3382
typedef struct {
3383
  int32_t dnodeId;
3384
  int32_t sqlLen;
3385
  char*   sql;
3386
} SMDropBnodeReq, SDDropBnodeReq;
3387

3388
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3389
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3390
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3391

3392
typedef struct {
3393
  int32_t vgId;
3394
  int32_t hbSeq;
3395
} SVArbHbReqMember;
3396

3397
typedef struct {
3398
  int32_t dnodeId;
3399
  char*   arbToken;
3400
  int64_t arbTerm;
3401
  SArray* hbMembers;  // SVArbHbReqMember
3402
} SVArbHeartBeatReq;
3403

3404
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3405
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3406
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3407

3408
typedef struct {
3409
  int32_t vgId;
3410
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3411
  int32_t hbSeq;
3412
} SVArbHbRspMember;
3413

3414
typedef struct {
3415
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3416
  int32_t dnodeId;
3417
  SArray* hbMembers;  // SVArbHbRspMember
3418
} SVArbHeartBeatRsp;
3419

3420
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3421
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3422
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3423

3424
typedef struct {
3425
  char*   arbToken;
3426
  int64_t arbTerm;
3427
  char*   member0Token;
3428
  char*   member1Token;
3429
} SVArbCheckSyncReq;
3430

3431
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3432
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3433
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3434

3435
typedef struct {
3436
  char*   arbToken;
3437
  char*   member0Token;
3438
  char*   member1Token;
3439
  int32_t vgId;
3440
  int32_t errCode;
3441
} SVArbCheckSyncRsp;
3442

3443
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3444
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3445
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3446

3447
typedef struct {
3448
  char*   arbToken;
3449
  int64_t arbTerm;
3450
  char*   memberToken;
3451
  int8_t  force;
3452
} SVArbSetAssignedLeaderReq;
3453

3454
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3455
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3456
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3457

3458
typedef struct {
3459
  char*   arbToken;
3460
  char*   memberToken;
3461
  int32_t vgId;
3462
} SVArbSetAssignedLeaderRsp;
3463

3464
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3465
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3466
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3467

3468
typedef struct {
3469
  int32_t dnodeId;
3470
  char*   token;
3471
} SMArbUpdateGroupMember;
3472

3473
typedef struct {
3474
  int32_t dnodeId;
3475
  char*   token;
3476
  int8_t  acked;
3477
} SMArbUpdateGroupAssigned;
3478

3479
typedef struct {
3480
  int32_t                  vgId;
3481
  int64_t                  dbUid;
3482
  SMArbUpdateGroupMember   members[2];
3483
  int8_t                   isSync;
3484
  int8_t                   assignedAcked;
3485
  SMArbUpdateGroupAssigned assignedLeader;
3486
  int64_t                  version;
3487
  int32_t                  code;
3488
  int64_t                  updateTimeMs;
3489
} SMArbUpdateGroup;
3490

3491
typedef struct {
3492
  SArray* updateArray;  // SMArbUpdateGroup
3493
} SMArbUpdateGroupBatchReq;
3494

3495
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3496
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3497
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3498

3499
typedef struct {
3500
  char queryStrId[TSDB_QUERY_ID_LEN];
3501
} SKillQueryReq;
3502

3503
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3504
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3505

3506
typedef struct {
3507
  uint32_t connId;
3508
} SKillConnReq;
3509

3510
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3511
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3512

3513
typedef struct {
3514
  int32_t transId;
3515
} SKillTransReq;
3516

3517
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3518
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3519

3520
typedef struct {
3521
  int32_t useless;  // useless
3522
  int32_t sqlLen;
3523
  char*   sql;
3524
} SBalanceVgroupReq;
3525

3526
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3527
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3528
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3529

3530
typedef struct {
3531
  int32_t useless;  // useless
3532
  int32_t sqlLen;
3533
  char*   sql;
3534
} SAssignLeaderReq;
3535

3536
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3537
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3538
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3539
typedef struct {
3540
  int32_t vgId1;
3541
  int32_t vgId2;
3542
} SMergeVgroupReq;
3543

3544
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3545
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3546

3547
typedef struct {
3548
  int32_t vgId;
3549
  int32_t dnodeId1;
3550
  int32_t dnodeId2;
3551
  int32_t dnodeId3;
3552
  int32_t sqlLen;
3553
  char*   sql;
3554
} SRedistributeVgroupReq;
3555

3556
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3557
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3558
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3559

3560
typedef struct {
3561
  int32_t reserved;
3562
  int32_t vgId;
3563
  int32_t sqlLen;
3564
  char*   sql;
3565
  char    db[TSDB_DB_FNAME_LEN];
3566
} SBalanceVgroupLeaderReq;
3567

3568
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3569
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3570
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3571

3572
typedef struct {
3573
  int32_t vgId;
3574
} SForceBecomeFollowerReq;
3575

3576
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3577
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3578

3579
typedef struct {
3580
  int32_t vgId;
3581
  bool    force;
3582
} SSplitVgroupReq;
3583

3584
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3585
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3586

3587
typedef struct {
3588
  char user[TSDB_USER_LEN];
3589
  char spi;
3590
  char encrypt;
3591
  char secret[TSDB_PASSWORD_LEN];
3592
  char ckey[TSDB_PASSWORD_LEN];
3593
} SAuthReq, SAuthRsp;
3594

3595
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3596
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3597

3598
typedef struct {
3599
  int32_t statusCode;
3600
  char    details[1024];
3601
} SServerStatusRsp;
3602

3603
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3604
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3605

3606
/**
3607
 * The layout of the query message payload is as following:
3608
 * +--------------------+---------------------------------+
3609
 * |Sql statement       | Physical plan                   |
3610
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3611
 * +--------------------+---------------------------------+
3612
 */
3613
typedef struct SSubQueryMsg {
3614
  SMsgHead header;
3615
  uint64_t sId;
3616
  uint64_t queryId;
3617
  uint64_t clientId;
3618
  uint64_t taskId;
3619
  int64_t  refId;
3620
  int32_t  execId;
3621
  int32_t  msgMask;
3622
  int8_t   taskType;
3623
  int8_t   explain;
3624
  int8_t   needFetch;
3625
  int8_t   compress;
3626
  uint32_t sqlLen;
3627
  char*    sql;
3628
  uint32_t msgLen;
3629
  char*    msg;
3630
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
3631
} SSubQueryMsg;
3632

3633
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3634
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3635
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3636

3637
typedef struct {
3638
  SMsgHead header;
3639
  uint64_t sId;
3640
  uint64_t queryId;
3641
  uint64_t taskId;
3642
} SSinkDataReq;
3643

3644
typedef struct {
3645
  SMsgHead header;
3646
  uint64_t sId;
3647
  uint64_t queryId;
3648
  uint64_t clientId;
3649
  uint64_t taskId;
3650
  int32_t  execId;
3651
} SQueryContinueReq;
3652

3653
typedef struct {
3654
  SMsgHead header;
3655
  uint64_t sId;
3656
  uint64_t queryId;
3657
  uint64_t taskId;
3658
} SResReadyReq;
3659

3660
typedef struct {
3661
  int32_t code;
3662
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3663
  int32_t sversion;
3664
  int32_t tversion;
3665
} SResReadyRsp;
3666

3667
typedef struct SOperatorParam {
3668
  int32_t opType;
3669
  int32_t downstreamIdx;
3670
  void*   value;
3671
  SArray* pChildren;  // SArray<SOperatorParam*>
3672
  bool    reUse;
3673
} SOperatorParam;
3674

3675
typedef struct SColIdNameKV {
3676
  col_id_t colId;
3677
  char     colName[TSDB_COL_NAME_LEN];
3678
} SColIdNameKV;
3679

3680
typedef struct SColIdPair {
3681
  col_id_t  vtbColId;
3682
  col_id_t  orgColId;
3683
  SDataType type;
3684
} SColIdPair;
3685

3686
typedef struct SColIdSlotIdPair {
3687
  int32_t  vtbSlotId;
3688
  col_id_t orgColId;
3689
} SColIdSlotIdPair;
3690

3691
typedef struct SOrgTbInfo {
3692
  int32_t vgId;
3693
  char    tbName[TSDB_TABLE_FNAME_LEN];
3694
  SArray* colMap;  // SArray<SColIdNameKV>
3695
} SOrgTbInfo;
3696

3697
void destroySOrgTbInfo(void *info);
3698

3699
typedef enum {
3700
  DYN_TYPE_STB_JOIN = 1,
3701
  DYN_TYPE_VSTB_SINGLE_SCAN,
3702
  DYN_TYPE_VSTB_BATCH_SCAN,
3703
} ETableScanDynType;
3704

3705
typedef struct STableScanOperatorParam {
3706
  bool              tableSeq;
3707
  bool              isNewParam;
3708
  uint64_t          groupid;
3709
  SArray*           pUidList;
3710
  SOrgTbInfo*       pOrgTbInfo;
3711
  SArray*           pBatchTbInfo;  // SArray<SOrgTbInfo>
3712
  SArray*           pTagList;
3713
  STimeWindow       window;
3714
  ETableScanDynType type;
3715
} STableScanOperatorParam;
3716

3717
typedef struct STagScanOperatorParam {
3718
  tb_uid_t vcUid;
3719
} STagScanOperatorParam;
3720

3721
typedef struct SVTableScanOperatorParam {
3722
  uint64_t        uid;
3723
  STimeWindow     window;
3724
  SOperatorParam* pTagScanOp;
3725
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3726
} SVTableScanOperatorParam;
3727

3728
typedef struct SMergeOperatorParam {
3729
  int32_t         winNum;
3730
} SMergeOperatorParam;
3731

3732
typedef struct SAggOperatorParam {
3733
  bool            needCleanRes;
3734
} SAggOperatorParam;
3735

3736
typedef struct SExternalWindowOperatorParam {
3737
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3738
} SExternalWindowOperatorParam;
3739

3740
typedef struct SDynQueryCtrlOperatorParam {
3741
  STimeWindow    window;
3742
} SDynQueryCtrlOperatorParam;
3743

3744
struct SStreamRuntimeFuncInfo;
3745
typedef struct {
3746
  SMsgHead        header;
3747
  uint64_t        sId;
3748
  uint64_t        queryId;
3749
  uint64_t        clientId;
3750
  uint64_t        taskId;
3751
  int32_t         execId;
3752
  SOperatorParam* pOpParam;
3753

3754
  // used for new-stream
3755
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3756
  bool                           reset;
3757
  bool                           dynTbname;
3758
  // used for new-stream
3759
} SResFetchReq;
3760

3761
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3762
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3763
void    tDestroySResFetchReq(SResFetchReq* pReq);
3764
typedef struct {
3765
  SMsgHead header;
3766
  uint64_t clientId;
3767
} SSchTasksStatusReq;
3768

3769
typedef struct {
3770
  uint64_t queryId;
3771
  uint64_t clientId;
3772
  uint64_t taskId;
3773
  int64_t  refId;
3774
  int32_t  subJobId;
3775
  int32_t  execId;
3776
  int8_t   status;
3777
} STaskStatus;
3778

3779
typedef struct {
3780
  int64_t refId;
3781
  SArray* taskStatus;  // SArray<STaskStatus>
3782
} SSchedulerStatusRsp;
3783

3784
typedef struct {
3785
  uint64_t queryId;
3786
  uint64_t taskId;
3787
  int8_t   action;
3788
} STaskAction;
3789

3790
typedef struct SQueryNodeEpId {
3791
  int32_t nodeId;  // vgId or qnodeId
3792
  SEp     ep;
3793
} SQueryNodeEpId;
3794

3795
typedef struct {
3796
  SMsgHead       header;
3797
  uint64_t       clientId;
3798
  SQueryNodeEpId epId;
3799
  SArray*        taskAction;  // SArray<STaskAction>
3800
} SSchedulerHbReq;
3801

3802
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3803
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3804
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3805

3806
typedef struct {
3807
  SQueryNodeEpId epId;
3808
  SArray*        taskStatus;  // SArray<STaskStatus>
3809
} SSchedulerHbRsp;
3810

3811
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3812
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3813
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3814

3815
typedef struct {
3816
  SMsgHead header;
3817
  uint64_t sId;
3818
  uint64_t queryId;
3819
  uint64_t clientId;
3820
  uint64_t taskId;
3821
  int64_t  refId;
3822
  int32_t  execId;
3823
} STaskCancelReq;
3824

3825
typedef struct {
3826
  int32_t code;
3827
} STaskCancelRsp;
3828

3829
typedef struct {
3830
  SMsgHead header;
3831
  uint64_t sId;
3832
  uint64_t queryId;
3833
  uint64_t clientId;
3834
  uint64_t taskId;
3835
  int64_t  refId;
3836
  int32_t  execId;
3837
} STaskDropReq;
3838

3839
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3840
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3841

3842
typedef enum {
3843
  TASK_NOTIFY_FINISHED = 1,
3844
} ETaskNotifyType;
3845

3846
typedef struct {
3847
  SMsgHead        header;
3848
  uint64_t        sId;
3849
  uint64_t        queryId;
3850
  uint64_t        clientId;
3851
  uint64_t        taskId;
3852
  int64_t         refId;
3853
  int32_t         execId;
3854
  ETaskNotifyType type;
3855
} STaskNotifyReq;
3856

3857
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3858
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3859

3860
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3861
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3862

3863
typedef struct {
3864
  int32_t code;
3865
} STaskDropRsp;
3866

3867
#define STREAM_TRIGGER_AT_ONCE                 1
3868
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3869
#define STREAM_TRIGGER_MAX_DELAY               3
3870
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3871
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3872

3873
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3874
#define STREAM_FILL_HISTORY_ON        1
3875
#define STREAM_FILL_HISTORY_OFF       0
3876
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3877
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3878
#define STREAM_CREATE_STABLE_TRUE     1
3879
#define STREAM_CREATE_STABLE_FALSE    0
3880

3881
typedef struct SVgroupVer {
3882
  int32_t vgId;
3883
  int64_t ver;
3884
} SVgroupVer;
3885

3886
typedef struct STaskNotifyEventStat {
3887
  int64_t notifyEventAddTimes;     // call times of add function
3888
  int64_t notifyEventAddElems;     // elements added by add function
3889
  double  notifyEventAddCostSec;   // time cost of add function
3890
  int64_t notifyEventPushTimes;    // call times of push function
3891
  int64_t notifyEventPushElems;    // elements pushed by push function
3892
  double  notifyEventPushCostSec;  // time cost of push function
3893
  int64_t notifyEventPackTimes;    // call times of pack function
3894
  int64_t notifyEventPackElems;    // elements packed by pack function
3895
  double  notifyEventPackCostSec;  // time cost of pack function
3896
  int64_t notifyEventSendTimes;    // call times of send function
3897
  int64_t notifyEventSendElems;    // elements sent by send function
3898
  double  notifyEventSendCostSec;  // time cost of send function
3899
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3900
} STaskNotifyEventStat;
3901

3902
enum {
3903
  TOPIC_SUB_TYPE__DB = 1,
3904
  TOPIC_SUB_TYPE__TABLE,
3905
  TOPIC_SUB_TYPE__COLUMN,
3906
};
3907

3908
#define DEFAULT_MAX_POLL_INTERVAL  300000
3909
#define DEFAULT_SESSION_TIMEOUT    12000
3910
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3911
#define DEFAULT_MIN_POLL_ROWS      4096
3912

3913
typedef struct {
3914
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3915
  int8_t igExists;
3916
  int8_t subType;
3917
  int8_t withMeta;
3918
  char*  sql;
3919
  char   subDbName[TSDB_DB_FNAME_LEN];
3920
  char*  ast;
3921
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3922
  int8_t reload;
3923
} SCMCreateTopicReq;
3924

3925
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3926
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3927
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3928

3929
typedef struct {
3930
  int64_t consumerId;
3931
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3932

3933
typedef struct {
3934
  int64_t consumerId;
3935
  char    cgroup[TSDB_CGROUP_LEN];
3936
  char    clientId[TSDB_CLIENT_ID_LEN];
3937
  char    user[TSDB_USER_LEN];
3938
  char    fqdn[TSDB_FQDN_LEN];
3939
  SArray* topicNames;  // SArray<char**>
3940

3941
  int8_t  withTbName;
3942
  int8_t  autoCommit;
3943
  int32_t autoCommitInterval;
3944
  int8_t  resetOffsetCfg;
3945
  int8_t  enableReplay;
3946
  int8_t  enableBatchMeta;
3947
  int32_t sessionTimeoutMs;
3948
  int32_t maxPollIntervalMs;
3949
} SCMSubscribeReq;
3950

3951
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3952
  int32_t tlen = 0;
283,956✔
3953
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
283,956✔
3954
  tlen += taosEncodeString(buf, pReq->cgroup);
283,956✔
3955
  tlen += taosEncodeString(buf, pReq->clientId);
283,956✔
3956

3957
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
283,956✔
3958
  tlen += taosEncodeFixedI32(buf, topicNum);
283,956✔
3959

3960
  for (int32_t i = 0; i < topicNum; i++) {
393,204✔
3961
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
218,230✔
3962
  }
3963

3964
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
284,222✔
3965
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
284,222✔
3966
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
284,222✔
3967
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
284,222✔
3968
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
284,222✔
3969
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
284,222✔
3970
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
284,222✔
3971
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
284,222✔
3972
  tlen += taosEncodeString(buf, pReq->user);
284,222✔
3973
  tlen += taosEncodeString(buf, pReq->fqdn);
284,222✔
3974

3975
  return tlen;
284,222✔
3976
}
3977

3978
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3979
  void* start = buf;
128,570✔
3980
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
128,570✔
3981
  buf = taosDecodeStringTo(buf, pReq->cgroup);
128,570✔
3982
  buf = taosDecodeStringTo(buf, pReq->clientId);
128,570✔
3983

3984
  int32_t topicNum = 0;
128,570✔
3985
  buf = taosDecodeFixedI32(buf, &topicNum);
128,570✔
3986

3987
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
128,570✔
3988
  if (pReq->topicNames == NULL) {
128,570✔
3989
    return terrno;
×
3990
  }
3991
  for (int32_t i = 0; i < topicNum; i++) {
182,650✔
3992
    char* name = NULL;
54,080✔
3993
    buf = taosDecodeString(buf, &name);
54,080✔
3994
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
108,160✔
3995
      return terrno;
×
3996
    }
3997
  }
3998

3999
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
128,570✔
4000
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
128,570✔
4001
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
128,570✔
4002
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
128,570✔
4003
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
128,570✔
4004
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
128,570✔
4005
  if ((char*)buf - (char*)start < len) {
128,570✔
4006
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
128,570✔
4007
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
128,570✔
4008
    buf = taosDecodeStringTo(buf, pReq->user);
128,570✔
4009
    buf = taosDecodeStringTo(buf, pReq->fqdn);
257,140✔
4010
  } else {
4011
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4012
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4013
  }
4014

4015
  return 0;
128,570✔
4016
}
4017

4018
typedef struct {
4019
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4020
  SArray* removedConsumers;  // SArray<int64_t>
4021
  SArray* newConsumers;      // SArray<int64_t>
4022
} SMqRebInfo;
4023

4024
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4025
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
97,472✔
4026
  if (pRebInfo == NULL) {
97,472✔
4027
    return NULL;
×
4028
  }
4029
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
97,472✔
4030
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
97,472✔
4031
  if (pRebInfo->removedConsumers == NULL) {
97,472✔
4032
    goto _err;
×
4033
  }
4034
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
97,472✔
4035
  if (pRebInfo->newConsumers == NULL) {
97,472✔
4036
    goto _err;
×
4037
  }
4038
  return pRebInfo;
97,472✔
4039
_err:
×
4040
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4041
  taosArrayDestroy(pRebInfo->newConsumers);
×
4042
  taosMemoryFreeClear(pRebInfo);
×
4043
  return NULL;
×
4044
}
4045

4046
typedef struct {
4047
  int64_t streamId;
4048
  int64_t checkpointId;
4049
  char    streamName[TSDB_STREAM_FNAME_LEN];
4050
} SMStreamDoCheckpointMsg;
4051

4052
typedef struct {
4053
  int64_t status;
4054
} SMVSubscribeRsp;
4055

4056
typedef struct {
4057
  char    name[TSDB_TOPIC_FNAME_LEN];
4058
  int8_t  igNotExists;
4059
  int32_t sqlLen;
4060
  char*   sql;
4061
  int8_t  force;
4062
} SMDropTopicReq;
4063

4064
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4065
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4066
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4067

4068
typedef struct {
4069
  char    name[TSDB_TOPIC_FNAME_LEN];
4070
  int8_t  igNotExists;
4071
  int32_t sqlLen;
4072
  char*   sql;
4073
} SMReloadTopicReq;
4074

4075
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4076
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4077
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4078

4079
typedef struct {
4080
  char   topic[TSDB_TOPIC_FNAME_LEN];
4081
  char   cgroup[TSDB_CGROUP_LEN];
4082
  int8_t igNotExists;
4083
  int8_t force;
4084
} SMDropCgroupReq;
4085

4086
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4087
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4088

4089
typedef struct {
4090
  int8_t reserved;
4091
} SMDropCgroupRsp;
4092

4093
typedef struct {
4094
  char    name[TSDB_TABLE_FNAME_LEN];
4095
  int8_t  alterType;
4096
  SSchema schema;
4097
} SAlterTopicReq;
4098

4099
typedef struct {
4100
  SMsgHead head;
4101
  char     name[TSDB_TABLE_FNAME_LEN];
4102
  int64_t  tuid;
4103
  int32_t  sverson;
4104
  int32_t  execLen;
4105
  char*    executor;
4106
  int32_t  sqlLen;
4107
  char*    sql;
4108
} SDCreateTopicReq;
4109

4110
typedef struct {
4111
  SMsgHead head;
4112
  char     name[TSDB_TABLE_FNAME_LEN];
4113
  int64_t  tuid;
4114
} SDDropTopicReq;
4115

4116
typedef struct {
4117
  char*      name;
4118
  int64_t    uid;
4119
  int64_t    interval[2];
4120
  int8_t     intervalUnit;
4121
  int16_t    nFuncs;
4122
  col_id_t*  funcColIds;  // column ids specified by user
4123
  func_id_t* funcIds;     // function ids specified by user
4124
} SRSmaParam;
4125

4126
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4127
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4128

4129
// TDMT_VND_CREATE_STB ==============
4130
typedef struct SVCreateStbReq {
4131
  char*           name;
4132
  tb_uid_t        suid;
4133
  int8_t          rollup;
4134
  SSchemaWrapper  schemaRow;
4135
  SSchemaWrapper  schemaTag;
4136
  SRSmaParam      rsmaParam;
4137
  int32_t         alterOriDataLen;
4138
  void*           alterOriData;
4139
  int8_t          source;
4140
  int8_t          colCmpred;
4141
  SColCmprWrapper colCmpr;
4142
  int64_t         keep;
4143
  SExtSchema*     pExtSchemas;
4144
  int8_t          virtualStb;
4145
} SVCreateStbReq;
4146

4147
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4148
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4149

4150
// TDMT_VND_DROP_STB ==============
4151
typedef struct SVDropStbReq {
4152
  char*    name;
4153
  tb_uid_t suid;
4154
} SVDropStbReq;
4155

4156
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4157
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4158

4159
// TDMT_VND_CREATE_TABLE ==============
4160
#define TD_CREATE_IF_NOT_EXISTS       0x1
4161
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4162
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4163
typedef struct SVCreateTbReq {
4164
  int32_t  flags;
4165
  char*    name;
4166
  tb_uid_t uid;
4167
  int64_t  btime;
4168
  int32_t  ttl;
4169
  int32_t  commentLen;
4170
  char*    comment;
4171
  int8_t   type;
4172
  union {
4173
    struct {
4174
      char*    stbName;  // super table name
4175
      uint8_t  tagNum;
4176
      tb_uid_t suid;
4177
      SArray*  tagName;
4178
      uint8_t* pTag;
4179
    } ctb;
4180
    struct {
4181
      SSchemaWrapper schemaRow;
4182
    } ntb;
4183
  };
4184
  int32_t         sqlLen;
4185
  char*           sql;
4186
  SColCmprWrapper colCmpr;
4187
  SExtSchema*     pExtSchemas;
4188
  SColRefWrapper  colRef;  // col reference for virtual table
4189
} SVCreateTbReq;
4190

4191
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4192
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4193
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4194
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4195

4196
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4197
  if (NULL == req) {
2,147,483,647✔
4198
    return;
2,147,483,647✔
4199
  }
4200

4201
  taosMemoryFreeClear(req->sql);
76,421,904✔
4202
  taosMemoryFreeClear(req->name);
76,422,618✔
4203
  taosMemoryFreeClear(req->comment);
76,443,159✔
4204
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
76,411,140✔
4205
    taosMemoryFreeClear(req->ctb.pTag);
56,486,510✔
4206
    taosMemoryFreeClear(req->ctb.stbName);
56,441,335✔
4207
    taosArrayDestroy(req->ctb.tagName);
56,508,388✔
4208
    req->ctb.tagName = NULL;
56,434,982✔
4209
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
19,946,647✔
4210
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
19,946,647✔
4211
  }
4212
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
76,390,701✔
4213
  taosMemoryFreeClear(req->pExtSchemas);
76,425,829✔
4214
  taosMemoryFreeClear(req->colRef.pColRef);
76,420,102✔
4215
}
4216

4217
typedef struct {
4218
  int32_t nReqs;
4219
  union {
4220
    SVCreateTbReq* pReqs;
4221
    SArray*        pArray;
4222
  };
4223
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4224
} SVCreateTbBatchReq;
4225

4226
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4227
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4228
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4229

4230
typedef struct {
4231
  int32_t        code;
4232
  STableMetaRsp* pMeta;
4233
} SVCreateTbRsp, SVUpdateTbRsp;
4234

4235
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4236
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4237
void tFreeSVCreateTbRsp(void* param);
4238

4239
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4240
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4241

4242
typedef struct {
4243
  int32_t nRsps;
4244
  union {
4245
    SVCreateTbRsp* pRsps;
4246
    SArray*        pArray;
4247
  };
4248
} SVCreateTbBatchRsp;
4249

4250
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4251
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4252

4253
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4254
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4255

4256
// TDMT_VND_DROP_TABLE =================
4257
typedef struct {
4258
  char*    name;
4259
  uint64_t suid;  // for tmq in wal format
4260
  int64_t  uid;
4261
  int8_t   igNotExists;
4262
  int8_t   isVirtual;
4263
} SVDropTbReq;
4264

4265
typedef struct {
4266
  int32_t code;
4267
} SVDropTbRsp;
4268

4269
typedef struct {
4270
  int32_t nReqs;
4271
  union {
4272
    SVDropTbReq* pReqs;
4273
    SArray*      pArray;
4274
  };
4275
} SVDropTbBatchReq;
4276

4277
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4278
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4279

4280
typedef struct {
4281
  int32_t nRsps;
4282
  union {
4283
    SVDropTbRsp* pRsps;
4284
    SArray*      pArray;
4285
  };
4286
} SVDropTbBatchRsp;
4287

4288
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4289
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4290

4291
// TDMT_VND_ALTER_TABLE =====================
4292
typedef struct SMultiTagUpateVal {
4293
  char*    tagName;
4294
  int32_t  colId;
4295
  int8_t   tagType;
4296
  int8_t   tagFree;
4297
  uint32_t nTagVal;
4298
  uint8_t* pTagVal;
4299
  int8_t   isNull;
4300
  SArray*  pTagArray;
4301
} SMultiTagUpateVal;
4302
typedef struct SVAlterTbReq {
4303
  char*   tbName;
4304
  int8_t  action;
4305
  char*   colName;
4306
  int32_t colId;
4307
  // TSDB_ALTER_TABLE_ADD_COLUMN
4308
  int8_t  type;
4309
  int8_t  flags;
4310
  int32_t bytes;
4311
  // TSDB_ALTER_TABLE_DROP_COLUMN
4312
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4313
  int8_t   colModType;
4314
  int32_t  colModBytes;
4315
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4316
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4317
  int8_t   isNull;
4318
  int8_t   tagType;
4319
  int8_t   tagFree;
4320
  uint32_t nTagVal;
4321
  uint8_t* pTagVal;
4322
  SArray*  pTagArray;
4323
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4324
  int8_t   updateTTL;
4325
  int32_t  newTTL;
4326
  int32_t  newCommentLen;
4327
  char*    newComment;
4328
  int64_t  ctimeMs;    // fill by vnode
4329
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4330
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4331
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4332
  // for Add column
4333
  STypeMod typeMod;
4334
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4335
  char* refDbName;
4336
  char* refTbName;
4337
  char* refColName;
4338
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4339
} SVAlterTbReq;
4340

4341
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4342
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4343
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4344
void    tfreeMultiTagUpateVal(void* pMultiTag);
4345

4346
typedef struct {
4347
  int32_t        code;
4348
  STableMetaRsp* pMeta;
4349
} SVAlterTbRsp;
4350

4351
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4352
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4353
// ======================
4354

4355
typedef struct {
4356
  SMsgHead head;
4357
  int64_t  uid;
4358
  int32_t  tid;
4359
  int16_t  tversion;
4360
  int16_t  colId;
4361
  int8_t   type;
4362
  int16_t  bytes;
4363
  int32_t  tagValLen;
4364
  int16_t  numOfTags;
4365
  int32_t  schemaLen;
4366
  char     data[];
4367
} SUpdateTagValReq;
4368

4369
typedef struct {
4370
  SMsgHead head;
4371
} SUpdateTagValRsp;
4372

4373
typedef struct {
4374
  SMsgHead head;
4375
} SVShowTablesReq;
4376

4377
typedef struct {
4378
  SMsgHead head;
4379
  int32_t  id;
4380
} SVShowTablesFetchReq;
4381

4382
typedef struct {
4383
  int64_t useconds;
4384
  int8_t  completed;  // all results are returned to client
4385
  int8_t  precision;
4386
  int8_t  compressed;
4387
  int32_t compLen;
4388
  int32_t numOfRows;
4389
  char    data[];
4390
} SVShowTablesFetchRsp;
4391

4392
typedef struct {
4393
  int64_t consumerId;
4394
  int32_t epoch;
4395
  char    cgroup[TSDB_CGROUP_LEN];
4396
} SMqAskEpReq;
4397

4398
typedef struct {
4399
  int32_t key;
4400
  int32_t valueLen;
4401
  void*   value;
4402
} SKv;
4403

4404
typedef struct {
4405
  int64_t tscRid;
4406
  int8_t  connType;
4407
} SClientHbKey;
4408

4409
typedef struct {
4410
  int64_t tid;
4411
  char    status[TSDB_JOB_STATUS_LEN];
4412
} SQuerySubDesc;
4413

4414
typedef struct {
4415
  char     sql[TSDB_SHOW_SQL_LEN];
4416
  uint64_t queryId;
4417
  int64_t  useconds;
4418
  int64_t  stime;  // timestamp precision ms
4419
  int64_t  reqRid;
4420
  bool     stableQuery;
4421
  bool     isSubQuery;
4422
  char     fqdn[TSDB_FQDN_LEN];
4423
  int32_t  subPlanNum;
4424
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4425
} SQueryDesc;
4426

4427
typedef struct {
4428
  uint32_t connId;
4429
  SArray*  queryDesc;  // SArray<SQueryDesc>
4430
} SQueryHbReqBasic;
4431

4432
typedef struct {
4433
  uint32_t connId;
4434
  uint64_t killRid;
4435
  int32_t  totalDnodes;
4436
  int32_t  onlineDnodes;
4437
  int8_t   killConnection;
4438
  int8_t   align[3];
4439
  SEpSet   epSet;
4440
  SArray*  pQnodeList;
4441
} SQueryHbRspBasic;
4442

4443
typedef struct SAppClusterSummary {
4444
  uint64_t numOfInsertsReq;
4445
  uint64_t numOfInsertRows;
4446
  uint64_t insertElapsedTime;
4447
  uint64_t insertBytes;  // submit to tsdb since launched.
4448

4449
  uint64_t fetchBytes;
4450
  uint64_t numOfQueryReq;
4451
  uint64_t queryElapsedTime;
4452
  uint64_t numOfSlowQueries;
4453
  uint64_t totalRequests;
4454
  uint64_t currentRequests;  // the number of SRequestObj
4455
} SAppClusterSummary;
4456

4457
typedef struct {
4458
  int64_t            appId;
4459
  int32_t            pid;
4460
  char               name[TSDB_APP_NAME_LEN];
4461
  int64_t            startTime;
4462
  SAppClusterSummary summary;
4463
} SAppHbReq;
4464

4465
typedef struct {
4466
  SClientHbKey      connKey;
4467
  int64_t           clusterId;
4468
  SAppHbReq         app;
4469
  SQueryHbReqBasic* query;
4470
  SHashObj*         info;  // hash<Skv.key, Skv>
4471
  char              user[TSDB_USER_LEN];
4472
  char              tokenName[TSDB_TOKEN_NAME_LEN];
4473
  char              userApp[TSDB_APP_NAME_LEN];
4474
  uint32_t          userIp;
4475
  SIpRange          userDualIp;
4476
  char              sVer[TSDB_VERSION_LEN];
4477
  char              cInfo[CONNECTOR_INFO_LEN];
4478
} SClientHbReq;
4479

4480
typedef struct {
4481
  int64_t reqId;
4482
  SArray* reqs;  // SArray<SClientHbReq>
4483
  int64_t ipWhiteListVer;
4484
} SClientHbBatchReq;
4485

4486
typedef struct {
4487
  SClientHbKey      connKey;
4488
  int32_t           status;
4489
  SQueryHbRspBasic* query;
4490
  SArray*           info;  // Array<Skv>
4491
} SClientHbRsp;
4492

4493
typedef struct {
4494
  int64_t       reqId;
4495
  int64_t       rspId;
4496
  int32_t       svrTimestamp;
4497
  SArray*       rsps;  // SArray<SClientHbRsp>
4498
  SMonitorParas monitorParas;
4499
  int8_t        enableAuditDelete;
4500
  int8_t        enableStrongPass;
4501
  int8_t        enableAuditSelect;
4502
  int8_t        enableAuditInsert;
4503
  int8_t        auditLevel;
4504
} SClientHbBatchRsp;
4505

4506
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
61,781,063✔
4507

4508
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4509
  void* pIter = taosHashIterate(info, NULL);
42,163,786✔
4510
  while (pIter != NULL) {
96,107,827✔
4511
    SKv* kv = (SKv*)pIter;
53,943,067✔
4512
    taosMemoryFreeClear(kv->value);
53,943,067✔
4513
    pIter = taosHashIterate(info, pIter);
53,941,938✔
4514
  }
4515
}
42,164,760✔
4516

4517
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
25,693,958✔
4518
  SQueryDesc* desc = (SQueryDesc*)pDesc;
25,693,958✔
4519
  if (desc->subDesc) {
25,693,958✔
4520
    taosArrayDestroy(desc->subDesc);
19,494,051✔
4521
    desc->subDesc = NULL;
19,494,169✔
4522
  }
4523
}
25,694,454✔
4524

4525
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
48,333,297✔
4526
  SClientHbReq* req = (SClientHbReq*)pReq;
50,980,688✔
4527
  if (req->query) {
50,980,688✔
4528
    if (req->query->queryDesc) {
48,333,297✔
4529
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
23,110,536✔
4530
    }
4531
    taosMemoryFreeClear(req->query);
48,333,297✔
4532
  }
4533

4534
  if (req->info) {
50,980,688✔
4535
    tFreeReqKvHash(req->info);
42,164,244✔
4536
    taosHashCleanup(req->info);
42,164,760✔
4537
    req->info = NULL;
42,164,387✔
4538
  }
4539
}
26,049,318✔
4540

4541
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4542
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4543

4544
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4545
  if (pReq == NULL) return;
20,552,025✔
4546
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
20,552,025✔
4547
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
20,552,025✔
4548
  taosMemoryFree(pReq);
20,552,025✔
4549
}
4550

4551
static FORCE_INLINE void tFreeClientKv(void* pKv) {
19,408,628✔
4552
  SKv* kv = (SKv*)pKv;
19,408,628✔
4553
  if (kv) {
19,408,628✔
4554
    taosMemoryFreeClear(kv->value);
19,408,628✔
4555
  }
4556
}
19,409,030✔
4557

4558
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
47,968,985✔
4559
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
47,968,985✔
4560
  if (rsp->query) {
47,968,985✔
4561
    taosArrayDestroy(rsp->query->pQnodeList);
47,966,264✔
4562
    taosMemoryFreeClear(rsp->query);
47,962,283✔
4563
  }
4564
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
47,970,240✔
4565
}
24,568,076✔
4566

4567
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4568
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
39,453,860✔
4569
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
39,453,860✔
4570
}
39,454,681✔
4571

4572
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4573
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4574
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4575

4576
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4577
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
156,075,073✔
4578
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
156,075,190✔
4579
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
156,075,307✔
4580
  return 0;
78,037,471✔
4581
}
4582

4583
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4584
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
74,522,294✔
4585
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
74,522,294✔
4586
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
37,261,147✔
4587
  if (pKv->value == NULL) {
37,261,147✔
4588
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4589
  }
4590
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
37,261,147✔
4591
  return 0;
37,261,147✔
4592
}
4593

4594
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4595
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
201,292,565✔
4596
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
201,288,341✔
4597
  return 0;
100,643,245✔
4598
}
4599

4600
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4601
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
99,897,830✔
4602
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
99,895,369✔
4603
  return 0;
49,946,718✔
4604
}
4605

4606
typedef struct {
4607
  int32_t vgId;
4608
  // TODO stas
4609
} SMqReportVgInfo;
4610

4611
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4612
  int32_t tlen = 0;
4613
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4614
  return tlen;
4615
}
4616

4617
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4618
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4619
  return buf;
4620
}
4621

4622
typedef struct {
4623
  int32_t epoch;
4624
  int64_t topicUid;
4625
  char    name[TSDB_TOPIC_FNAME_LEN];
4626
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4627
} SMqTopicInfo;
4628

4629
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4630
  int32_t tlen = 0;
4631
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4632
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4633
  tlen += taosEncodeString(buf, pTopicInfo->name);
4634
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4635
  tlen += taosEncodeFixedI32(buf, sz);
4636
  for (int32_t i = 0; i < sz; i++) {
4637
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4638
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4639
  }
4640
  return tlen;
4641
}
4642

4643
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4644
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4645
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4646
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4647
  int32_t sz;
4648
  buf = taosDecodeFixedI32(buf, &sz);
4649
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4650
    return NULL;
4651
  }
4652
  for (int32_t i = 0; i < sz; i++) {
4653
    SMqReportVgInfo vgInfo;
4654
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4655
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4656
      return NULL;
4657
    }
4658
  }
4659
  return buf;
4660
}
4661

4662
typedef struct {
4663
  int32_t status;  // ask hb endpoint
4664
  int32_t epoch;
4665
  int64_t consumerId;
4666
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4667
} SMqReportReq;
4668

4669
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4670
  int32_t tlen = 0;
4671
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4672
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4673
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4674
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4675
  tlen += taosEncodeFixedI32(buf, sz);
4676
  for (int32_t i = 0; i < sz; i++) {
4677
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4678
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4679
  }
4680
  return tlen;
4681
}
4682

4683
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4684
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4685
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4686
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4687
  int32_t sz;
4688
  buf = taosDecodeFixedI32(buf, &sz);
4689
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4690
    return NULL;
4691
  }
4692
  for (int32_t i = 0; i < sz; i++) {
4693
    SMqTopicInfo topicInfo;
4694
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4695
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4696
      return NULL;
4697
    }
4698
  }
4699
  return buf;
4700
}
4701

4702
typedef struct {
4703
  SMsgHead head;
4704
  int64_t  leftForVer;
4705
  int32_t  vgId;
4706
  int64_t  consumerId;
4707
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4708
} SMqVDeleteReq;
4709

4710
typedef struct {
4711
  int8_t reserved;
4712
} SMqVDeleteRsp;
4713

4714
typedef struct {
4715
  char*  name;
4716
  int8_t igNotExists;
4717
} SMDropStreamReq;
4718

4719
typedef struct {
4720
  int8_t reserved;
4721
} SMDropStreamRsp;
4722

4723
typedef struct {
4724
  SMsgHead head;
4725
  int64_t  resetRelHalt;  // reset related stream task halt status
4726
  int64_t  streamId;
4727
  int32_t  taskId;
4728
} SVDropStreamTaskReq;
4729

4730
typedef struct {
4731
  int8_t reserved;
4732
} SVDropStreamTaskRsp;
4733

4734
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4735
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4736
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4737

4738
typedef struct {
4739
  char*  name;
4740
  int8_t igNotExists;
4741
} SMPauseStreamReq;
4742

4743
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4744
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4745
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4746

4747
typedef struct {
4748
  char*  name;
4749
  int8_t igNotExists;
4750
  int8_t igUntreated;
4751
} SMResumeStreamReq;
4752

4753
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4754
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4755
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4756

4757
typedef struct {
4758
  char*       name;
4759
  int8_t      calcAll;
4760
  STimeWindow timeRange;
4761
} SMRecalcStreamReq;
4762

4763
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4764
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4765
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4766

4767
typedef struct SVndSetKeepVersionReq {
4768
  int64_t keepVersion;
4769
} SVndSetKeepVersionReq;
4770

4771
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4772
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4773

4774
typedef struct SVUpdateCheckpointInfoReq {
4775
  SMsgHead head;
4776
  int64_t  streamId;
4777
  int32_t  taskId;
4778
  int64_t  checkpointId;
4779
  int64_t  checkpointVer;
4780
  int64_t  checkpointTs;
4781
  int32_t  transId;
4782
  int64_t  hStreamId;  // add encode/decode
4783
  int64_t  hTaskId;
4784
  int8_t   dropRelHTask;
4785
} SVUpdateCheckpointInfoReq;
4786

4787
typedef struct {
4788
  int64_t leftForVer;
4789
  int32_t vgId;
4790
  int64_t oldConsumerId;
4791
  int64_t newConsumerId;
4792
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4793
  int8_t  subType;
4794
  int8_t  withMeta;
4795
  char*   qmsg;  // SubPlanToString
4796
  SSchemaWrapper schema;
4797
  int64_t suid;
4798
} SMqRebVgReq;
4799

4800
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4801
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4802

4803
// tqOffset
4804
enum {
4805
  TMQ_OFFSET__RESET_NONE = -3,
4806
  TMQ_OFFSET__RESET_EARLIEST = -2,
4807
  TMQ_OFFSET__RESET_LATEST = -1,
4808
  TMQ_OFFSET__LOG = 1,
4809
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4810
  TMQ_OFFSET__SNAPSHOT_META = 3,
4811
};
4812

4813
enum {
4814
  WITH_DATA = 0,
4815
  WITH_META = 1,
4816
  ONLY_META = 2,
4817
};
4818

4819
#define TQ_OFFSET_VERSION 1
4820

4821
typedef struct {
4822
  int8_t type;
4823
  union {
4824
    // snapshot
4825
    struct {
4826
      int64_t uid;
4827
      int64_t ts;
4828
      SValue  primaryKey;
4829
    };
4830
    // log
4831
    struct {
4832
      int64_t version;
4833
    };
4834
  };
4835
} STqOffsetVal;
4836

4837
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4838
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,678,049✔
4839
  pOffsetVal->uid = uid;
1,677,590✔
4840
  pOffsetVal->ts = ts;
1,678,016✔
4841
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,677,641✔
4842
    taosMemoryFree(pOffsetVal->primaryKey.pData);
60✔
4843
  }
4844
  pOffsetVal->primaryKey = primaryKey;
1,677,499✔
4845
}
1,677,101✔
4846

4847
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4848
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
6,731✔
4849
  pOffsetVal->uid = uid;
6,731✔
4850
}
6,731✔
4851

4852
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4853
  pOffsetVal->type = TMQ_OFFSET__LOG;
47,052,604✔
4854
  pOffsetVal->version = ver;
47,052,499✔
4855
}
47,050,594✔
4856

4857
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4858
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4859
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4860
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4861
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4862
void    tOffsetDestroy(void* pVal);
4863

4864
typedef struct {
4865
  STqOffsetVal val;
4866
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4867
} STqOffset;
4868

4869
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4870
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4871
void    tDeleteSTqOffset(void* val);
4872

4873
typedef struct SMqVgOffset {
4874
  int64_t   consumerId;
4875
  STqOffset offset;
4876
} SMqVgOffset;
4877

4878
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4879
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4880

4881
typedef struct {
4882
  char    name[TSDB_TABLE_FNAME_LEN];
4883
  char    stb[TSDB_TABLE_FNAME_LEN];
4884
  int8_t  igExists;
4885
  int8_t  intervalUnit;
4886
  int8_t  slidingUnit;
4887
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4888
  int32_t dstVgId;   // for stream
4889
  int64_t interval;
4890
  int64_t offset;
4891
  int64_t sliding;
4892
  int64_t maxDelay;
4893
  int64_t watermark;
4894
  int32_t exprLen;        // strlen + 1
4895
  int32_t tagsFilterLen;  // strlen + 1
4896
  int32_t sqlLen;         // strlen + 1
4897
  int32_t astLen;         // strlen + 1
4898
  char*   expr;
4899
  char*   tagsFilter;
4900
  char*   sql;
4901
  char*   ast;
4902
  int64_t deleteMark;
4903
  int64_t lastTs;
4904
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4905
  SArray* pVgroupVerList;
4906
  int8_t  recursiveTsma;
4907
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4908
  char*   createStreamReq;
4909
  int32_t streamReqLen;
4910
  char*   dropStreamReq;
4911
  int32_t dropStreamReqLen;
4912
  int64_t uid;
4913
} SMCreateSmaReq;
4914

4915
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4916
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4917
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4918

4919
typedef struct {
4920
  char    name[TSDB_TABLE_FNAME_LEN];
4921
  int8_t  igNotExists;
4922
  char*   dropStreamReq;
4923
  int32_t dropStreamReqLen;
4924
} SMDropSmaReq;
4925

4926
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4927
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4928
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
4929

4930
typedef struct {
4931
  char name[TSDB_TABLE_NAME_LEN];
4932
  union {
4933
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4934
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4935
  };
4936
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4937
  union {
4938
    int8_t igExists;   // used by mnode
4939
    int8_t alterType;  // used by vnode
4940
  };
4941
  int8_t     intervalUnit;
4942
  int16_t    nFuncs;       // number of functions specified by user
4943
  col_id_t*  funcColIds;   // column ids specified by user
4944
  func_id_t* funcIds;      // function ids specified by user
4945
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4946
  int64_t    tbUid;
4947
  int64_t    uid;     // rsma uid
4948
  int32_t    sqlLen;  // strlen + 1
4949
  char*      sql;
4950
} SMCreateRsmaReq;
4951

4952
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4953
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4954
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4955

4956
typedef SMCreateRsmaReq SVCreateRsmaReq;
4957

4958
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4959
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4960
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4961

4962
typedef SMCreateRsmaReq SVAlterRsmaReq;
4963

4964
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4965
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4966
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4967

4968
typedef struct {
4969
  char       name[TSDB_TABLE_NAME_LEN];
4970
  int8_t     alterType;
4971
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4972
  int8_t     igNotExists;
4973
  int16_t    nFuncs;      // number of functions specified by user
4974
  col_id_t*  funcColIds;  // column ids specified by user
4975
  func_id_t* funcIds;     // function ids specified by user
4976
  int32_t    sqlLen;      // strlen + 1
4977
  char*      sql;
4978
} SMAlterRsmaReq;
4979

4980
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4981
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4982
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4983

4984
typedef struct {
4985
  int64_t    id;
4986
  char       name[TSDB_TABLE_NAME_LEN];
4987
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4988
  int32_t    code;
4989
  int32_t    version;
4990
  int8_t     tbType;
4991
  int8_t     intervalUnit;
4992
  col_id_t   nFuncs;
4993
  col_id_t   nColNames;
4994
  int64_t    interval[2];
4995
  col_id_t*  funcColIds;
4996
  func_id_t* funcIds;
4997
  SArray*    colNames;
4998
} SRsmaInfoRsp;
4999

5000
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5001
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5002
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5003

5004
typedef struct {
5005
  char   name[TSDB_TABLE_FNAME_LEN];
5006
  int8_t igNotExists;
5007
} SMDropRsmaReq;
5008

5009
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5010
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5011

5012
typedef struct {
5013
  char    name[TSDB_TABLE_NAME_LEN];
5014
  char    tbName[TSDB_TABLE_NAME_LEN];
5015
  int64_t uid;
5016
  int64_t tbUid;
5017
  int8_t  tbType;
5018
} SVDropRsmaReq;
5019

5020
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5021
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5022

5023
typedef struct {
5024
  char   dbFName[TSDB_DB_FNAME_LEN];
5025
  char   stbName[TSDB_TABLE_NAME_LEN];
5026
  char   colName[TSDB_COL_NAME_LEN];
5027
  char   idxName[TSDB_INDEX_FNAME_LEN];
5028
  int8_t idxType;
5029
} SCreateTagIndexReq;
5030

5031
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5032
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5033

5034
typedef SMDropSmaReq SDropTagIndexReq;
5035

5036
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5037
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5038

5039
typedef struct {
5040
  int8_t         version;       // for compatibility(default 0)
5041
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5042
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5043
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5044
  int32_t        dstVgId;
5045
  char           indexName[TSDB_INDEX_NAME_LEN];
5046
  int32_t        exprLen;
5047
  int32_t        tagsFilterLen;
5048
  int64_t        indexUid;
5049
  tb_uid_t       tableUid;  // super/child/common table uid
5050
  tb_uid_t       dstTbUid;  // for dstVgroup
5051
  int64_t        interval;
5052
  int64_t        offset;  // use unit by precision of DB
5053
  int64_t        sliding;
5054
  char*          dstTbName;  // for dstVgroup
5055
  char*          expr;       // sma expression
5056
  char*          tagsFilter;
5057
  SSchemaWrapper schemaRow;  // for dstVgroup
5058
  SSchemaWrapper schemaTag;  // for dstVgroup
5059
} STSma;                     // Time-range-wise SMA
5060

5061
typedef STSma SVCreateTSmaReq;
5062

5063
typedef struct {
5064
  int8_t  type;  // 0 status report, 1 update data
5065
  int64_t indexUid;
5066
  int64_t skey;  // start TS key of interval/sliding window
5067
} STSmaMsg;
5068

5069
typedef struct {
5070
  int64_t indexUid;
5071
  char    indexName[TSDB_INDEX_NAME_LEN];
5072
} SVDropTSmaReq;
5073

5074
typedef struct {
5075
  int tmp;  // TODO: to avoid compile error
5076
} SVCreateTSmaRsp, SVDropTSmaRsp;
5077

5078
#if 0
5079
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5080
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5081
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5082
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5083
#endif
5084

5085
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5086
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5087
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5088
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5089

5090
typedef struct {
5091
  int32_t number;
5092
  STSma*  tSma;
5093
} STSmaWrapper;
5094

5095
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5096
  if (pSma) {
×
5097
    taosMemoryFreeClear(pSma->dstTbName);
×
5098
    taosMemoryFreeClear(pSma->expr);
×
5099
    taosMemoryFreeClear(pSma->tagsFilter);
×
5100
  }
5101
}
×
5102

5103
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5104
  if (pSW) {
×
5105
    if (pSW->tSma) {
×
5106
      if (deepCopy) {
×
5107
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5108
          tDestroyTSma(pSW->tSma + i);
×
5109
        }
5110
      }
5111
      taosMemoryFreeClear(pSW->tSma);
×
5112
    }
5113
  }
5114
}
×
5115

5116
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5117
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5118
  taosMemoryFreeClear(pSW);
×
5119
  return NULL;
×
5120
}
5121

5122
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5123
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5124

5125
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5126
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5127

5128
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5129
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5130
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5131
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5132
  }
5133
  return 0;
×
5134
}
5135

5136
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5137
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5138
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5139
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5140
  }
5141
  return 0;
×
5142
}
5143

5144
typedef struct {
5145
  int idx;
5146
} SMCreateFullTextReq;
5147

5148
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5149
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5150
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5151

5152
typedef struct {
5153
  char   name[TSDB_TABLE_FNAME_LEN];
5154
  int8_t igNotExists;
5155
} SMDropFullTextReq;
5156

5157
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5158
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5159

5160
typedef struct {
5161
  char indexFName[TSDB_INDEX_FNAME_LEN];
5162
} SUserIndexReq;
5163

5164
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5165
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5166

5167
typedef struct {
5168
  char dbFName[TSDB_DB_FNAME_LEN];
5169
  char tblFName[TSDB_TABLE_FNAME_LEN];
5170
  char colName[TSDB_COL_NAME_LEN];
5171
  char indexType[TSDB_INDEX_TYPE_LEN];
5172
  char indexExts[TSDB_INDEX_EXTS_LEN];
5173
} SUserIndexRsp;
5174

5175
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5176
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5177

5178
typedef struct {
5179
  char tbFName[TSDB_TABLE_FNAME_LEN];
5180
} STableIndexReq;
5181

5182
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5183
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5184

5185
typedef struct {
5186
  int8_t  intervalUnit;
5187
  int8_t  slidingUnit;
5188
  int64_t interval;
5189
  int64_t offset;
5190
  int64_t sliding;
5191
  int64_t dstTbUid;
5192
  int32_t dstVgId;
5193
  SEpSet  epSet;
5194
  char*   expr;
5195
} STableIndexInfo;
5196

5197
typedef struct {
5198
  char     tbName[TSDB_TABLE_NAME_LEN];
5199
  char     dbFName[TSDB_DB_FNAME_LEN];
5200
  uint64_t suid;
5201
  int32_t  version;
5202
  int32_t  indexSize;
5203
  SArray*  pIndex;  // STableIndexInfo
5204
} STableIndexRsp;
5205

5206
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5207
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5208
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5209

5210
void tFreeSTableIndexInfo(void* pInfo);
5211

5212
typedef struct {
5213
  int8_t  mqMsgType;
5214
  int32_t code;
5215
  int32_t epoch;
5216
  int64_t consumerId;
5217
  int64_t walsver;
5218
  int64_t walever;
5219
} SMqRspHead;
5220

5221
typedef struct {
5222
  SMsgHead     head;
5223
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5224
  int8_t       withTbName;
5225
  int8_t       useSnapshot;
5226
  int32_t      epoch;
5227
  uint64_t     reqId;
5228
  int64_t      consumerId;
5229
  int64_t      timeout;
5230
  STqOffsetVal reqOffset;
5231
  int8_t       enableReplay;
5232
  int8_t       sourceExcluded;
5233
  int8_t       rawData;
5234
  int32_t      minPollRows;
5235
  int8_t       enableBatchMeta;
5236
  SHashObj*    uidHash;  // to find if uid is duplicated
5237
} SMqPollReq;
5238

5239
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5240
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5241
void    tDestroySMqPollReq(SMqPollReq* pReq);
5242

5243
typedef struct {
5244
  int32_t vgId;
5245
  int64_t offset;
5246
  SEpSet  epSet;
5247
} SMqSubVgEp;
5248

5249
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5250
  int32_t tlen = 0;
519,508✔
5251
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
519,508✔
5252
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
519,508✔
5253
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
519,508✔
5254
  return tlen;
519,508✔
5255
}
5256

5257
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5258
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
281,334✔
5259
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
281,334✔
5260
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
281,334✔
5261
  return buf;
281,334✔
5262
}
5263

5264
typedef struct {
5265
  char           topic[TSDB_TOPIC_FNAME_LEN];
5266
  char           db[TSDB_DB_FNAME_LEN];
5267
  SArray*        vgs;  // SArray<SMqSubVgEp>
5268
} SMqSubTopicEp;
5269

5270
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5271
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5272
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5273

5274
typedef struct {
5275
  SMqRspHead   head;
5276
  STqOffsetVal rspOffset;
5277
  int16_t      resMsgType;
5278
  int32_t      metaRspLen;
5279
  void*        metaRsp;
5280
} SMqMetaRsp;
5281

5282
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5283
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5284
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5285

5286
#define MQ_DATA_RSP_VERSION 100
5287

5288
typedef struct {
5289
  SMqRspHead   head;
5290
  STqOffsetVal rspOffset;
5291
  STqOffsetVal reqOffset;
5292
  int32_t      blockNum;
5293
  int8_t       withTbName;
5294
  int8_t       withSchema;
5295
  SArray*      blockDataLen;
5296
  SArray*      blockData;
5297
  SArray*      blockTbName;
5298
  SArray*      blockSchema;
5299

5300
  union {
5301
    struct {
5302
      int64_t sleepTime;
5303
    };
5304
    struct {
5305
      int32_t createTableNum;
5306
      SArray* createTableLen;
5307
      SArray* createTableReq;
5308
    };
5309
    struct {
5310
      int32_t len;
5311
      void*   rawData;
5312
    };
5313
  };
5314
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5315
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5316
} SMqDataRsp;
5317

5318
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5319
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5320
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5321
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5322
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5323

5324
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5325
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5326
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5327

5328
typedef struct SMqBatchMetaRsp {
5329
  SMqRspHead   head;  // not serialize
5330
  STqOffsetVal rspOffset;
5331
  SArray*      batchMetaLen;
5332
  SArray*      batchMetaReq;
5333
  void*        pMetaBuff;    // not serialize
5334
  uint32_t     metaBuffLen;  // not serialize
5335
} SMqBatchMetaRsp;
5336

5337
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5338
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5339
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5340
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5341

5342
typedef struct {
5343
  int32_t    code;
5344
  SArray*    topics;  // SArray<SMqSubTopicEp>
5345
} SMqAskEpRsp;
5346

5347
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5348
  int32_t tlen = 0;
1,852,968✔
5349
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5350
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,852,968✔
5351
  tlen += taosEncodeFixedI32(buf, sz);
1,852,893✔
5352
  for (int32_t i = 0; i < sz; i++) {
2,026,567✔
5353
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
173,704✔
5354
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
173,704✔
5355
  }
5356
  tlen += taosEncodeFixedI32(buf, pRsp->code);
1,852,863✔
5357

5358
  return tlen;
1,852,968✔
5359
}
5360

5361
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5362
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5363
  int32_t sz;
745,117✔
5364
  buf = taosDecodeFixedI32(buf, &sz);
829,417✔
5365
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
829,417✔
5366
  if (pRsp->topics == NULL) {
829,417✔
5367
    return NULL;
×
5368
  }
5369
  for (int32_t i = 0; i < sz; i++) {
919,469✔
5370
    SMqSubTopicEp topicEp;
74,367✔
5371
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
90,052✔
5372
    if (buf == NULL) {
90,052✔
5373
      return NULL;
×
5374
    }
5375
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
180,104✔
5376
      return NULL;
×
5377
    }
5378
  }
5379
  buf = taosDecodeFixedI32(buf, &pRsp->code);
829,417✔
5380

5381
  return buf;
829,417✔
5382
}
5383

5384
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5385
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
2,165,087✔
5386
}
2,165,192✔
5387

5388
typedef struct {
5389
  int32_t      vgId;
5390
  STqOffsetVal offset;
5391
  int64_t      rows;
5392
  int64_t      ever;
5393
} OffsetRows;
5394

5395
typedef struct {
5396
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5397
  SArray* offsetRows;
5398
} TopicOffsetRows;
5399

5400
typedef struct {
5401
  int64_t consumerId;
5402
  int32_t epoch;
5403
  SArray* topics;
5404
  int8_t  pollFlag;
5405
} SMqHbReq;
5406

5407
typedef struct {
5408
  char   topic[TSDB_TOPIC_FNAME_LEN];
5409
  int8_t noPrivilege;
5410
} STopicPrivilege;
5411

5412
typedef struct {
5413
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5414
  int32_t debugFlag;
5415
} SMqHbRsp;
5416

5417
typedef struct {
5418
  SMsgHead head;
5419
  int64_t  consumerId;
5420
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5421
} SMqSeekReq;
5422

5423
#define TD_AUTO_CREATE_TABLE 0x1
5424
typedef struct {
5425
  int64_t       suid;
5426
  int64_t       uid;
5427
  int32_t       sver;
5428
  uint32_t      nData;
5429
  uint8_t*      pData;
5430
  SVCreateTbReq cTbReq;
5431
} SVSubmitBlk;
5432

5433
typedef struct {
5434
  SMsgHead header;
5435
  uint64_t sId;
5436
  uint64_t queryId;
5437
  uint64_t clientId;
5438
  uint64_t taskId;
5439
  uint32_t sqlLen;
5440
  uint32_t phyLen;
5441
  char*    sql;
5442
  char*    msg;
5443
  int8_t   source;
5444
} SVDeleteReq;
5445

5446
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5447
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5448

5449
typedef struct {
5450
  int64_t affectedRows;
5451
} SVDeleteRsp;
5452

5453
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5454
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5455

5456
typedef struct SDeleteRes {
5457
  uint64_t suid;
5458
  SArray*  uidList;
5459
  int64_t  skey;
5460
  int64_t  ekey;
5461
  int64_t  affectedRows;
5462
  char     tableFName[TSDB_TABLE_NAME_LEN];
5463
  char     tsColName[TSDB_COL_NAME_LEN];
5464
  int64_t  ctimeMs;  // fill by vnode
5465
  int8_t   source;
5466
} SDeleteRes;
5467

5468
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5469
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5470

5471
typedef struct {
5472
  // int64_t uid;
5473
  char    tbname[TSDB_TABLE_NAME_LEN];
5474
  int64_t startTs;
5475
  int64_t endTs;
5476
} SSingleDeleteReq;
5477

5478
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5479
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5480

5481
typedef struct {
5482
  int64_t suid;
5483
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5484
  int64_t ctimeMs;     // fill by vnode
5485
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5486
} SBatchDeleteReq;
5487

5488
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5489
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5490
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5491

5492
typedef struct {
5493
  int32_t msgIdx;
5494
  int32_t msgType;
5495
  int32_t msgLen;
5496
  void*   msg;
5497
} SBatchMsg;
5498

5499
typedef struct {
5500
  SMsgHead header;
5501
  SArray*  pMsgs;  // SArray<SBatchMsg>
5502
} SBatchReq;
5503

5504
typedef struct {
5505
  int32_t reqType;
5506
  int32_t msgIdx;
5507
  int32_t msgLen;
5508
  int32_t rspCode;
5509
  void*   msg;
5510
} SBatchRspMsg;
5511

5512
typedef struct {
5513
  SArray* pRsps;  // SArray<SBatchRspMsg>
5514
} SBatchRsp;
5515

5516
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5517
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5518
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
91,964,136✔
5519
  if (NULL == msg) {
91,964,136✔
5520
    return;
×
5521
  }
5522
  SBatchMsg* pMsg = (SBatchMsg*)msg;
91,964,136✔
5523
  taosMemoryFree(pMsg->msg);
91,964,136✔
5524
}
5525

5526
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5527
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5528

5529
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
129,834,400✔
5530
  if (NULL == p) {
129,834,400✔
5531
    return;
×
5532
  }
5533

5534
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
129,834,400✔
5535
  taosMemoryFree(pRsp->msg);
129,834,400✔
5536
}
5537

5538
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5539
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5540
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5541
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5542
void    tDestroySMqHbReq(SMqHbReq* pReq);
5543

5544
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5545
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5546
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5547

5548
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5549
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5550

5551
#define TD_REQ_FROM_APP               0x0
5552
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5553
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5554
#define SUBMIT_REQ_FROM_FILE          0x4
5555
#define TD_REQ_FROM_TAOX              0x8
5556
#define TD_REQ_FROM_SML               0x10
5557
#define SUBMIT_REQUEST_VERSION        (2)
5558
#define SUBMIT_REQ_WITH_BLOB          0x10
5559
#define SUBMIT_REQ_SCHEMA_RES         0x20
5560
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5561

5562
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5563

5564
typedef struct {
5565
  int32_t        flags;
5566
  SVCreateTbReq* pCreateTbReq;
5567
  int64_t        suid;
5568
  int64_t        uid;
5569
  int32_t        sver;
5570
  union {
5571
    SArray* aRowP;
5572
    SArray* aCol;
5573
  };
5574
  int64_t   ctimeMs;
5575
  SBlobSet* pBlobSet;
5576
} SSubmitTbData;
5577

5578
typedef struct {
5579
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5580
  SArray* aSubmitBlobData;
5581
  bool    raw;
5582
} SSubmitReq2;
5583

5584
typedef struct {
5585
  SMsgHead header;
5586
  int64_t  version;
5587
  char     data[];  // SSubmitReq2
5588
} SSubmitReq2Msg;
5589

5590
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5591
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5592
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5593
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5594
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5595

5596
typedef struct {
5597
  int32_t affectedRows;
5598
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5599
} SSubmitRsp2;
5600

5601
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5602
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5603
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5604

5605
#define TSDB_MSG_FLG_ENCODE 0x1
5606
#define TSDB_MSG_FLG_DECODE 0x2
5607
#define TSDB_MSG_FLG_CMPT   0x3
5608

5609
typedef struct {
5610
  union {
5611
    struct {
5612
      void*   msgStr;
5613
      int32_t msgLen;
5614
      int64_t ver;
5615
    };
5616
    void* pDataBlock;
5617
  };
5618
} SPackedData;
5619

5620
typedef struct {
5621
  char     fullname[TSDB_VIEW_FNAME_LEN];
5622
  char     name[TSDB_VIEW_NAME_LEN];
5623
  char     dbFName[TSDB_DB_FNAME_LEN];
5624
  char*    querySql;
5625
  char*    sql;
5626
  int8_t   orReplace;
5627
  int8_t   precision;
5628
  int32_t  numOfCols;
5629
  SSchema* pSchema;
5630
} SCMCreateViewReq;
5631

5632
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5633
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5634
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5635

5636
typedef struct {
5637
  char   fullname[TSDB_VIEW_FNAME_LEN];
5638
  char   name[TSDB_VIEW_NAME_LEN];
5639
  char   dbFName[TSDB_DB_FNAME_LEN];
5640
  char*  sql;
5641
  int8_t igNotExists;
5642
} SCMDropViewReq;
5643

5644
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5645
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5646
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5647

5648
typedef struct {
5649
  char fullname[TSDB_VIEW_FNAME_LEN];
5650
} SViewMetaReq;
5651
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5652
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5653

5654
typedef struct {
5655
  char     name[TSDB_VIEW_NAME_LEN];
5656
  char     dbFName[TSDB_DB_FNAME_LEN];
5657
  char*    user;
5658
  uint64_t dbId;
5659
  uint64_t viewId;
5660
  char*    querySql;
5661
  int8_t   precision;
5662
  int8_t   type;
5663
  int32_t  version;
5664
  int32_t  numOfCols;
5665
  SSchema* pSchema;
5666
} SViewMetaRsp;
5667
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5668
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5669
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5670
typedef struct {
5671
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5672
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5673
} STableTSMAInfoReq;
5674

5675
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5676
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5677

5678
typedef struct {
5679
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5680
  union {
5681
    uint8_t flags;
5682
    struct {
5683
      uint8_t withColName : 1;
5684
      uint8_t reserved : 7;
5685
    };
5686
  };
5687

5688
} SRsmaInfoReq;
5689

5690
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5691
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5692

5693
typedef struct {
5694
  int32_t  funcId;
5695
  col_id_t colId;
5696
} STableTSMAFuncInfo;
5697

5698
typedef struct {
5699
  char     name[TSDB_TABLE_NAME_LEN];
5700
  uint64_t tsmaId;
5701
  char     targetTb[TSDB_TABLE_NAME_LEN];
5702
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5703
  char     tb[TSDB_TABLE_NAME_LEN];
5704
  char     dbFName[TSDB_DB_FNAME_LEN];
5705
  uint64_t suid;
5706
  uint64_t destTbUid;
5707
  uint64_t dbId;
5708
  int32_t  version;
5709
  int64_t  interval;
5710
  int8_t   unit;
5711
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5712
  SArray*  pTags;      // SArray<SSchema>
5713
  SArray*  pUsedCols;  // SArray<SSchema>
5714
  char*    ast;
5715

5716
  int64_t streamUid;
5717
  int64_t reqTs;
5718
  int64_t rspTs;
5719
  int64_t delayDuration;  // ms
5720
  bool    fillHistoryFinished;
5721

5722
  void* streamAddr;  // for stream task, the address of the stream task
5723
} STableTSMAInfo;
5724

5725
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5726
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5727
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5728
void    tFreeTableTSMAInfo(void* p);
5729
void    tFreeAndClearTableTSMAInfo(void* p);
5730
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5731

5732
#define STSMAHbRsp            STableTSMAInfoRsp
5733
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5734
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5735
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5736

5737
typedef struct SDropCtbWithTsmaSingleVgReq {
5738
  SVgroupInfo vgInfo;
5739
  SArray*     pTbs;  // SVDropTbReq
5740
} SMDropTbReqsOnSingleVg;
5741

5742
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5743
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5744
void    tFreeSMDropTbReqOnSingleVg(void* p);
5745

5746
typedef struct SDropTbsReq {
5747
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5748
} SMDropTbsReq;
5749

5750
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5751
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5752
void    tFreeSMDropTbsReq(void*);
5753

5754
typedef struct SVFetchTtlExpiredTbsRsp {
5755
  SArray* pExpiredTbs;  // SVDropTbReq
5756
  int32_t vgId;
5757
} SVFetchTtlExpiredTbsRsp;
5758

5759
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5760
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5761

5762
void tFreeFetchTtlExpiredTbsRsp(void* p);
5763

5764
void setDefaultOptionsForField(SFieldWithOptions* field);
5765
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5766

5767
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5768
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5769

5770
typedef struct {
5771
  char    id[TSDB_INSTANCE_ID_LEN];
5772
  char    type[TSDB_INSTANCE_TYPE_LEN];
5773
  char    desc[TSDB_INSTANCE_DESC_LEN];
5774
  int32_t expire;
5775
} SInstanceRegisterReq;
5776

5777
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5778
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5779

5780
typedef struct {
5781
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5782
} SInstanceListReq;
5783

5784
typedef struct {
5785
  int32_t count;
5786
  char**  ids;  // Array of instance IDs
5787
} SInstanceListRsp;
5788

5789
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5790
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5791
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5792
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5793

5794
#ifdef USE_MOUNT
5795
typedef struct {
5796
  char     mountName[TSDB_MOUNT_NAME_LEN];
5797
  int8_t   ignoreExist;
5798
  int16_t  nMounts;
5799
  int32_t* dnodeIds;
5800
  char**   mountPaths;
5801
  int32_t  sqlLen;
5802
  char*    sql;
5803
} SCreateMountReq;
5804

5805
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5806
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5807
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5808

5809
typedef struct {
5810
  char    mountName[TSDB_MOUNT_NAME_LEN];
5811
  int8_t  ignoreNotExists;
5812
  int32_t sqlLen;
5813
  char*   sql;
5814
} SDropMountReq;
5815

5816
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5817
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5818
void    tFreeSDropMountReq(SDropMountReq* pReq);
5819

5820
typedef struct {
5821
  char     mountName[TSDB_MOUNT_NAME_LEN];
5822
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5823
  int64_t  mountUid;
5824
  int32_t  dnodeId;
5825
  uint32_t valLen;
5826
  int8_t   ignoreExist;
5827
  void*    pVal;
5828
} SRetrieveMountPathReq;
5829

5830
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5831
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5832

5833
typedef struct {
5834
  // path
5835
  int32_t diskPrimary;
5836
  // vgInfo
5837
  int32_t  vgId;
5838
  int32_t  cacheLastSize;
5839
  int32_t  szPage;
5840
  int32_t  szCache;
5841
  uint64_t szBuf;
5842
  int8_t   cacheLast;
5843
  int8_t   standby;
5844
  int8_t   hashMethod;
5845
  uint32_t hashBegin;
5846
  uint32_t hashEnd;
5847
  int16_t  hashPrefix;
5848
  int16_t  hashSuffix;
5849
  int16_t  sttTrigger;
5850
  // syncInfo
5851
  int32_t replications;
5852
  // tsdbInfo
5853
  int8_t  precision;
5854
  int8_t  compression;
5855
  int8_t  slLevel;
5856
  int32_t daysPerFile;
5857
  int32_t keep0;
5858
  int32_t keep1;
5859
  int32_t keep2;
5860
  int32_t keepTimeOffset;
5861
  int32_t minRows;
5862
  int32_t maxRows;
5863
  int32_t tsdbPageSize;
5864
  int32_t ssChunkSize;
5865
  int32_t ssKeepLocal;
5866
  int8_t  ssCompact;
5867
  // walInfo
5868
  int32_t walFsyncPeriod;      // millisecond
5869
  int32_t walRetentionPeriod;  // secs
5870
  int32_t walRollPeriod;       // secs
5871
  int64_t walRetentionSize;
5872
  int64_t walSegSize;
5873
  int32_t walLevel;
5874
  // encryptInfo
5875
  int32_t encryptAlgorithm;
5876
  // SVState
5877
  int64_t committed;
5878
  int64_t commitID;
5879
  int64_t commitTerm;
5880
  // stats
5881
  int64_t numOfSTables;
5882
  int64_t numOfCTables;
5883
  int64_t numOfNTables;
5884
  // dbInfo
5885
  uint64_t dbId;
5886
} SMountVgInfo;
5887

5888
typedef struct {
5889
  SMCreateStbReq req;
5890
  SArray*        pColExts;  // element: column id
5891
  SArray*        pTagExts;  // element: tag id
5892
} SMountStbInfo;
5893

5894
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5895
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5896

5897
typedef struct {
5898
  char     dbName[TSDB_DB_FNAME_LEN];
5899
  uint64_t dbId;
5900
  SArray*  pVgs;   // SMountVgInfo
5901
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5902
} SMountDbInfo;
5903

5904
typedef struct {
5905
  // common fields
5906
  char     mountName[TSDB_MOUNT_NAME_LEN];
5907
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5908
  int8_t   ignoreExist;
5909
  int64_t  mountUid;
5910
  int64_t  clusterId;
5911
  int32_t  dnodeId;
5912
  uint32_t valLen;
5913
  void*    pVal;
5914

5915
  // response fields
5916
  SArray* pDbs;  // SMountDbInfo
5917

5918
  // memory fields, no serialized
5919
  SArray*   pDisks[TFS_MAX_TIERS];
5920
  TdFilePtr pFile;
5921
} SMountInfo;
5922

5923
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5924
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5925
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5926

5927
typedef struct {
5928
  SCreateVnodeReq createReq;
5929
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5930
  char            mountName[TSDB_MOUNT_NAME_LEN];
5931
  int64_t         mountId;
5932
  int32_t         diskPrimary;
5933
  int32_t         mountVgId;
5934
  int64_t         committed;
5935
  int64_t         commitID;
5936
  int64_t         commitTerm;
5937
  int64_t         numOfSTables;
5938
  int64_t         numOfCTables;
5939
  int64_t         numOfNTables;
5940
} SMountVnodeReq;
5941

5942
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
5943
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5944
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5945

5946
#endif  // USE_MOUNT
5947

5948
#pragma pack(pop)
5949

5950
typedef struct {
5951
  char        db[TSDB_DB_FNAME_LEN];
5952
  STimeWindow timeRange;
5953
  int32_t     sqlLen;
5954
  char*       sql;
5955
  SArray*     vgroupIds;
5956
} SScanDbReq;
5957

5958
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5959
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5960
void    tFreeSScanDbReq(SScanDbReq* pReq);
5961

5962
typedef struct {
5963
  int32_t scanId;
5964
  int8_t  bAccepted;
5965
} SScanDbRsp;
5966

5967
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5968
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5969

5970
typedef struct {
5971
  int32_t scanId;
5972
  int32_t sqlLen;
5973
  char*   sql;
5974
} SKillScanReq;
5975

5976
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5977
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5978
void    tFreeSKillScanReq(SKillScanReq* pReq);
5979

5980
typedef struct {
5981
  int32_t scanId;
5982
  int32_t vgId;
5983
  int32_t dnodeId;
5984
} SVKillScanReq;
5985

5986
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5987
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5988

5989
typedef struct {
5990
  int32_t scanId;
5991
  int32_t vgId;
5992
  int32_t dnodeId;
5993
  int32_t numberFileset;
5994
  int32_t finished;
5995
  int32_t progress;
5996
  int64_t remainingTime;
5997
} SQueryScanProgressRsp;
5998

5999
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6000
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6001

6002
typedef struct {
6003
  int32_t scanId;
6004
  int32_t vgId;
6005
  int32_t dnodeId;
6006
} SQueryScanProgressReq;
6007

6008
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6009
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6010

6011
typedef struct {
6012
  int64_t     dbUid;
6013
  char        db[TSDB_DB_FNAME_LEN];
6014
  int64_t     scanStartTime;
6015
  STimeWindow tw;
6016
  int32_t     scanId;
6017
} SScanVnodeReq;
6018

6019
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6020
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6021

6022
#ifdef __cplusplus
6023
}
6024
#endif
6025

6026
#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