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

taosdata / TDengine / #4894

22 Dec 2025 09:33AM UTC coverage: 65.72% (+0.2%) from 65.57%
#4894

push

travis-ci

web-flow
Update README.md (#34007)

* Update README.md

* docs: update table of contents and improve installation instructions in README

* docs: adjust words

---------

Signed-off-by: WANG Xu <feici02@outlook.com>
Co-authored-by: WANG Xu <feici02@outlook.com>

184394 of 280577 relevant lines covered (65.72%)

111859687.16 hits per line

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

84.12
/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;
×
105
}
106

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

109
static inline bool vnodeIsMsgBlock(tmsg_t type) {
722,686,133✔
110
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
684,420,091✔
111
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,407,106,224✔
112
         (type == TDMT_SYNC_CONFIG_CHANGE);
113
}
114

115
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,922,673,110✔
116
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,922,673,110✔
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_MAX,
207
} EShowType;
208

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

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

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

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

249

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

255

256
#define TSDB_ALTER_RSMA_FUNCTION 0x1
257

258
#define TSDB_KILL_MSG_LEN 30
259

260
#define TSDB_TABLE_NUM_UNIT 100000
261

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

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

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

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

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

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

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

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

522
  // logic plan node
523
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
524
  QUERY_NODE_LOGIC_PLAN_JOIN,
525
  QUERY_NODE_LOGIC_PLAN_AGG,
526
  QUERY_NODE_LOGIC_PLAN_PROJECT,
527
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
528
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
529
  QUERY_NODE_LOGIC_PLAN_MERGE,
530
  QUERY_NODE_LOGIC_PLAN_WINDOW,
531
  QUERY_NODE_LOGIC_PLAN_FILL,
532
  QUERY_NODE_LOGIC_PLAN_SORT,
533
  QUERY_NODE_LOGIC_PLAN_PARTITION,
534
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
535
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
536
  QUERY_NODE_LOGIC_SUBPLAN,
537
  QUERY_NODE_LOGIC_PLAN,
538
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
539
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
540
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
541
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
542
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
543

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

615
typedef struct {
616
  int32_t     vgId;
617
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
618
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
619
  const char* dbFName;
620
  const char* tbName;
621
} SBuildTableInput;
622

623
typedef struct {
624
  char    db[TSDB_DB_FNAME_LEN];
625
  int64_t dbId;
626
  int32_t vgVersion;
627
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
628
  int64_t stateTs;
629
} SBuildUseDBInput;
630

631
typedef struct SField {
632
  char    name[TSDB_COL_NAME_LEN];
633
  uint8_t type;
634
  int8_t  flags;
635
  int32_t bytes;
636
} SField;
637

638
typedef struct SFieldWithOptions {
639
  char     name[TSDB_COL_NAME_LEN];
640
  uint8_t  type;
641
  int8_t   flags;
642
  int32_t  bytes;
643
  uint32_t compress;
644
  STypeMod typeMod;
645
} SFieldWithOptions;
646

647
typedef struct SRetention {
648
  int64_t freq;
649
  int64_t keep;
650
  int8_t  freqUnit;
651
  int8_t  keepUnit;
652
} SRetention;
653

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

656
#pragma pack(push, 1)
657
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
658
typedef struct SEp {
659
  char     fqdn[TSDB_FQDN_LEN];
660
  uint16_t port;
661
} SEp;
662

663
typedef struct {
664
  int32_t contLen;
665
  int32_t vgId;
666
} SMsgHead;
667

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

679
// Submit message for this TSDB
680
typedef struct {
681
  SMsgHead header;
682
  int64_t  version;
683
  int32_t  length;
684
  int32_t  numOfBlocks;
685
  char     blocks[];
686
} SSubmitReq;
687

688
typedef struct {
689
  int32_t totalLen;
690
  int32_t len;
691
  STSRow* row;
692
} SSubmitBlkIter;
693

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

709
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
710
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
711
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
712
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
713
// for debug
714
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
715

716
typedef struct {
717
  bool     hasRef;
718
  col_id_t id;
719
  char     refDbName[TSDB_DB_NAME_LEN];
720
  char     refTableName[TSDB_TABLE_NAME_LEN];
721
  char     refColName[TSDB_COL_NAME_LEN];
722
} SColRef;
723

724
typedef struct {
725
  int32_t  nCols;
726
  int32_t  version;
727
  SColRef* pColRef;
728
} SColRefWrapper;
729

730
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
731
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
732
typedef struct {
733
  int32_t vgId;
734
  SColRef colRef;
735
} SColRefEx;
736

737
typedef struct {
738
  int16_t colId;
739
  char    refDbName[TSDB_DB_NAME_LEN];
740
  char    refTableName[TSDB_TABLE_NAME_LEN];
741
  char    refColName[TSDB_COL_NAME_LEN];
742
} SRefColInfo;
743

744
typedef struct SVCTableRefCols {
745
  uint64_t     uid;
746
  int32_t      numOfSrcTbls;
747
  int32_t      numOfColRefs;
748
  SRefColInfo* refCols;
749
} SVCTableRefCols;
750

751
typedef struct SVCTableMergeInfo {
752
  uint64_t uid;
753
  int32_t  numOfSrcTbls;
754
} SVCTableMergeInfo;
755

756
typedef struct {
757
  int32_t    nCols;
758
  SColRefEx* pColRefEx;
759
} SColRefExWrapper;
760

761
struct SSchema {
762
  int8_t   type;
763
  int8_t   flags;
764
  col_id_t colId;
765
  int32_t  bytes;
766
  char     name[TSDB_COL_NAME_LEN];
767
};
768
struct SSchemaExt {
769
  col_id_t colId;
770
  uint32_t compress;
771
  STypeMod typeMod;
772
};
773

774
struct SSchemaRsma {
775
  int64_t    interval[2];
776
  int32_t    nFuncs;
777
  int8_t     tbType;
778
  tb_uid_t   tbUid;
779
  func_id_t* funcIds;
780
  char       tbName[TSDB_TABLE_NAME_LEN];
781
};
782

783
struct SSchema2 {
784
  int8_t   type;
785
  int8_t   flags;
786
  col_id_t colId;
787
  int32_t  bytes;
788
  char     name[TSDB_COL_NAME_LEN];
789
  uint32_t compress;
790
};
791

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

815
typedef struct {
816
  int32_t        code;
817
  int64_t        uid;
818
  char*          tblFName;
819
  int32_t        numOfRows;
820
  int32_t        affectedRows;
821
  int64_t        sver;
822
  STableMetaRsp* pMeta;
823
} SSubmitBlkRsp;
824

825
typedef struct {
826
  int32_t numOfRows;
827
  int32_t affectedRows;
828
  int32_t nBlocks;
829
  union {
830
    SArray*        pArray;
831
    SSubmitBlkRsp* pBlocks;
832
  };
833
} SSubmitRsp;
834

835
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
836
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
837
// void    tFreeSSubmitBlkRsp(void* param);
838
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
839

840
#define COL_SMA_ON       ((int8_t)0x1)
841
#define COL_IDX_ON       ((int8_t)0x2)
842
#define COL_IS_KEY       ((int8_t)0x4)
843
#define COL_SET_NULL     ((int8_t)0x10)
844
#define COL_SET_VAL      ((int8_t)0x20)
845
#define COL_IS_SYSINFO   ((int8_t)0x40)
846
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
847
#define COL_REF_BY_STM   ((int8_t)0x08)
848

849
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
850
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
851

852
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
853
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
854
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
855

856
#define SSCHMEA_SET_IDX_ON(s) \
857
  do {                        \
858
    (s)->flags |= COL_IDX_ON; \
859
  } while (0)
860

861
#define SSCHMEA_SET_IDX_OFF(s)   \
862
  do {                           \
863
    (s)->flags &= (~COL_IDX_ON); \
864
  } while (0)
865

866
#define SSCHEMA_SET_TYPE_MOD(s)     \
867
  do {                              \
868
    (s)->flags |= COL_HAS_TYPE_MOD; \
869
  } while (0)
870

871
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
872

873
#define SSCHMEA_TYPE(s)  ((s)->type)
874
#define SSCHMEA_FLAGS(s) ((s)->flags)
875
#define SSCHMEA_COLID(s) ((s)->colId)
876
#define SSCHMEA_BYTES(s) ((s)->bytes)
877
#define SSCHMEA_NAME(s)  ((s)->name)
878

879
typedef struct {
880
  bool    tsEnableMonitor;
881
  int32_t tsMonitorInterval;
882
  int32_t tsSlowLogThreshold;
883
  int32_t tsSlowLogMaxLen;
884
  int32_t tsSlowLogScope;
885
  int32_t tsSlowLogThresholdTest;  // Obsolete
886
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
887
} SMonitorParas;
888

889
typedef struct {
890
  STypeMod typeMod;
891
} SExtSchema;
892

893
bool hasExtSchema(const SExtSchema* pExtSchema);
894

895
typedef struct {
896
  int32_t      nCols;
897
  int32_t      version;
898
  SSchema*     pSchema;
899
  SSchemaRsma* pRsma;
900
} SSchemaWrapper;
901

902
typedef struct {
903
  col_id_t id;
904
  uint32_t alg;
905
} SColCmpr;
906

907
typedef struct {
908
  int32_t   nCols;
909
  int32_t   version;
910
  SColCmpr* pColCmpr;
911
} SColCmprWrapper;
912

913
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
914
  if (pRef->pColRef) {
390,299✔
915
    return TSDB_CODE_INVALID_PARA;
×
916
  }
917
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
390,299✔
918
  if (pRef->pColRef == NULL) {
390,299✔
919
    return terrno;
×
920
  }
921
  pRef->nCols = nCols;
390,299✔
922
  for (int32_t i = 0; i < nCols; i++) {
4,837,536✔
923
    pRef->pColRef[i].hasRef = false;
4,447,237✔
924
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4,447,237✔
925
  }
926
  return 0;
390,299✔
927
}
928

929
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
930
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
931
    terrno = TSDB_CODE_INVALID_PARA;
932
    return NULL;
933
  }
934

935
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
936
  if (pDstWrapper == NULL) {
937
    return NULL;
938
  }
939
  pDstWrapper->nCols = pSrcWrapper->nCols;
940
  pDstWrapper->version = pSrcWrapper->version;
941

942
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
943
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
944
  if (pDstWrapper->pColCmpr == NULL) {
945
    taosMemoryFree(pDstWrapper);
946
    return NULL;
947
  }
948
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
949

950
  return pDstWrapper;
951
}
952

953
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
954
  if (!(!pCmpr->pColCmpr)) {
2,351,193✔
955
    return TSDB_CODE_INVALID_PARA;
×
956
  }
957
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
2,351,193✔
958
  if (pCmpr->pColCmpr == NULL) {
2,351,193✔
959
    return terrno;
×
960
  }
961
  pCmpr->nCols = nCols;
2,351,193✔
962
  return 0;
2,351,193✔
963
}
964

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

983
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
984
  if (pWrapper == NULL) return;
985

986
  taosMemoryFreeClear(pWrapper->pColCmpr);
987
  taosMemoryFreeClear(pWrapper);
988
}
989
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
990
  if (pSchemaWrapper->pSchema == NULL) return NULL;
503,649,366✔
991

992
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
503,562,305✔
993
  if (pSW == NULL) {
503,614,318✔
994
    return NULL;
×
995
  }
996
  pSW->nCols = pSchemaWrapper->nCols;
503,614,318✔
997
  pSW->version = pSchemaWrapper->version;
503,529,168✔
998
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
503,549,627✔
999
  if (pSW->pSchema == NULL) {
503,416,835✔
1000
    taosMemoryFree(pSW);
×
1001
    return NULL;
×
1002
  }
1003

1004
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
503,498,671✔
1005
  return pSW;
503,623,609✔
1006
}
1007

1008
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
96,846,086✔
1009
  if (pSchemaWrapper) {
1,354,417,644✔
1010
    taosMemoryFree(pSchemaWrapper->pSchema);
759,927,500✔
1011
    if (pSchemaWrapper->pRsma) {
759,938,611✔
1012
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
29,088✔
1013
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
29,088✔
1014
    }
1015
    taosMemoryFree(pSchemaWrapper);
759,853,480✔
1016
  }
1017
}
1,341,183,493✔
1018

1019
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1020
  if (pSchemaWrapper) {
1021
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1022
    if (pSchemaWrapper->pRsma) {
1023
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1024
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1025
    }
1026
  }
1027
}
1028

1029
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,412,076✔
1030
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,412,076✔
1031
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
1,412,715✔
1032
  }
1033
}
1,412,076✔
1034

1035
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1036
  int32_t tlen = 0;
1,384,836✔
1037
  tlen += taosEncodeFixedI8(buf, pSchema->type);
1,384,908✔
1038
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
1,384,836✔
1039
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
1,384,836✔
1040
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
1,384,836✔
1041
  tlen += taosEncodeString(buf, pSchema->name);
1,384,836✔
1042
  return tlen;
1,384,836✔
1043
}
1044

1045
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1046
  buf = taosDecodeFixedI8(buf, &pSchema->type);
610,719✔
1047
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
610,701✔
1048
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
610,701✔
1049
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
610,701✔
1050
  buf = taosDecodeStringTo(buf, pSchema->name);
610,701✔
1051
  return (void*)buf;
610,701✔
1052
}
1053

1054
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1055
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1056
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1057
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1058
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1059
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1060
  return 0;
2,147,483,647✔
1061
}
1062

1063
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1064
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1065
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1066
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1067
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1068
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1069
  return 0;
2,147,483,647✔
1070
}
1071

1072
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1073
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1074
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1075
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1076
  return 0;
2,147,483,647✔
1077
}
1078

1079
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1080
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1081
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1082
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1083
  return 0;
2,147,483,647✔
1084
}
1085

1086
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1087
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
24,135,028✔
1088
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
24,135,028✔
1089
  if (pColRef->hasRef) {
12,067,514✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
13,411,468✔
1091
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
13,411,468✔
1092
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
13,411,468✔
1093
  }
1094
  return 0;
12,067,514✔
1095
}
1096

1097
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1098
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
15,050,098✔
1099
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
15,050,098✔
1100
  if (pColRef->hasRef) {
7,525,049✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
4,358,886✔
1102
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
4,358,886✔
1103
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
4,358,886✔
1104
  }
1105

1106
  return 0;
7,525,049✔
1107
}
1108

1109
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1110
  int32_t tlen = 0;
180,944✔
1111
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
180,944✔
1112
  tlen += taosEncodeVariantI32(buf, pSW->version);
180,944✔
1113
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,565,780✔
1114
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
2,769,672✔
1115
  }
1116
  return tlen;
180,944✔
1117
}
1118

1119
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1120
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
76,855✔
1121
  buf = taosDecodeVariantI32(buf, &pSW->version);
76,855✔
1122
  if (pSW->nCols > 0) {
76,855✔
1123
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
76,855✔
1124
    if (pSW->pSchema == NULL) {
76,855✔
1125
      return NULL;
×
1126
    }
1127

1128
    for (int32_t i = 0; i < pSW->nCols; i++) {
687,556✔
1129
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
1,221,402✔
1130
    }
1131
  } else {
1132
    pSW->pSchema = NULL;
×
1133
  }
1134
  return (void*)buf;
76,855✔
1135
}
1136

1137
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1138
  if (pSW == NULL) {
275,608,659✔
1139
    return TSDB_CODE_INVALID_PARA;
×
1140
  }
1141
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
551,242,160✔
1142
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
551,227,604✔
1143
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1144
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1145
  }
1146
  return 0;
275,730,453✔
1147
}
1148

1149
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1150
  if (pSW == NULL) {
76,224,997✔
1151
    return TSDB_CODE_INVALID_PARA;
×
1152
  }
1153
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
152,431,888✔
1154
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
152,416,810✔
1155

1156
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
76,209,919✔
1157
  if (pSW->pSchema == NULL) {
76,188,148✔
1158
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1159
  }
1160
  for (int32_t i = 0; i < pSW->nCols; i++) {
737,706,283✔
1161
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,322,928,155✔
1162
  }
1163

1164
  return 0;
76,239,147✔
1165
}
1166

1167
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1168
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1169
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1170

1171
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1172
  if (pSW->pSchema == NULL) {
1,693,255,246✔
1173
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1174
  }
1175
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1176
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1177
  }
1178

1179
  return 0;
1,693,649,906✔
1180
}
1181

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

1215
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1216
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1217
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1218

1219
typedef struct {
1220
  STableMetaRsp* pMeta;
1221
} SMCreateStbRsp;
1222

1223
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1224
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1225
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1226

1227
typedef struct {
1228
  char     name[TSDB_TABLE_FNAME_LEN];
1229
  int8_t   igNotExists;
1230
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1231
  int8_t   reserved[6];
1232
  tb_uid_t suid;
1233
  int32_t  sqlLen;
1234
  char*    sql;
1235
} SMDropStbReq;
1236

1237
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1238
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1239
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1240

1241
typedef struct {
1242
  char    name[TSDB_TABLE_FNAME_LEN];
1243
  int8_t  alterType;
1244
  int32_t numOfFields;
1245
  SArray* pFields;
1246
  int32_t ttl;
1247
  int32_t commentLen;
1248
  char*   comment;
1249
  int32_t sqlLen;
1250
  char*   sql;
1251
  int64_t keep;
1252
  SArray* pTypeMods;
1253
} SMAlterStbReq;
1254

1255
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1256
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1257
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1258

1259
typedef struct SEpSet {
1260
  int8_t inUse;
1261
  int8_t numOfEps;
1262
  SEp    eps[TSDB_MAX_REPLICA];
1263
} SEpSet;
1264

1265
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1266
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1267
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1268
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1269

1270
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1271
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1272

1273
typedef struct {
1274
  int8_t  connType;
1275
  int32_t pid;
1276
  char    app[TSDB_APP_NAME_LEN];
1277
  char    db[TSDB_DB_NAME_LEN];
1278
  char    user[TSDB_USER_LEN];
1279
  char    passwd[TSDB_PASSWORD_LEN];
1280
  int64_t startTime;
1281
  char    sVer[TSDB_VERSION_LEN];
1282
  int32_t totpCode;
1283
} SConnectReq;
1284

1285
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1286
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1287

1288
typedef struct {
1289
  int64_t       clusterId;
1290
  int32_t       acctId;
1291
  uint32_t      connId;
1292
  int32_t       dnodeNum;
1293
  int8_t        superUser;
1294
  int8_t        sysInfo;
1295
  int8_t        connType;
1296
  SEpSet        epSet;
1297
  int32_t       svrTimestamp;
1298
  int32_t       passVer;
1299
  int32_t       authVer;
1300
  char          sVer[TSDB_VERSION_LEN];
1301
  char          sDetailVer[128];
1302
  int64_t       whiteListVer;
1303
  int64_t       timeWhiteListVer;
1304
  SMonitorParas monitorParas;
1305
  int8_t        enableAuditDelete;
1306
  int8_t        enableAuditSelect;
1307
  int8_t        enableAuditInsert;
1308
  int8_t        auditLevel;
1309
} SConnectRsp;
1310

1311
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1312
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1313

1314
typedef struct {
1315
  char    user[TSDB_USER_LEN];
1316
  char    pass[TSDB_PASSWORD_LEN];
1317
  int32_t maxUsers;
1318
  int32_t maxDbs;
1319
  int32_t maxTimeSeries;
1320
  int32_t maxStreams;
1321
  int32_t accessState;  // Configured only by command
1322
  int64_t maxStorage;
1323
} SCreateAcctReq, SAlterAcctReq;
1324

1325
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1326
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1327

1328
typedef struct {
1329
  char    user[TSDB_USER_LEN];
1330
  int32_t sqlLen;
1331
  char*   sql;
1332
} SDropUserReq, SDropAcctReq;
1333

1334
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1335
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1336
void    tFreeSDropUserReq(SDropUserReq* pReq);
1337

1338
typedef struct {
1339
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1340
  int32_t sqlLen;
1341
  char*   sql;
1342
} SDropEncryptAlgrReq;
1343

1344
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1345
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1346
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1347

1348
typedef struct SIpV4Range {
1349
  uint32_t ip;
1350
  uint32_t mask;
1351
} SIpV4Range;
1352

1353
typedef struct SIpv6Range {
1354
  uint64_t addr[2];
1355
  uint32_t mask;
1356
} SIpV6Range;
1357

1358
typedef struct {
1359
  int8_t type;   // 0: IPv4, 1: IPv6
1360
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1361
  union {
1362
    SIpV4Range ipV4;
1363
    SIpV6Range ipV6;
1364
  };
1365
} SIpRange;
1366

1367
typedef struct {
1368
  int32_t    num;
1369
  SIpV4Range pIpRange[];
1370
} SIpWhiteList;
1371

1372
typedef struct {
1373
  int32_t  num;
1374
  SIpRange pIpRanges[];
1375
} SIpWhiteListDual;
1376

1377
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1378
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1379
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1380
int32_t           createDefaultIp6Range(SIpRange* pRange);
1381
int32_t           createDefaultIp4Range(SIpRange* pRange);
1382

1383
typedef struct {
1384
  int32_t sessPerUser;
1385
  int32_t sessConnTime;
1386
  int32_t sessConnIdleTime;
1387
  int32_t sessMaxConcurrency;
1388
  int32_t sessMaxCallVnodeNum;
1389
} SUserSessCfg;
1390

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

1395
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1396
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1397
typedef struct {
1398
  int16_t year;
1399
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1400
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1401
  int8_t hour;
1402
  int8_t minute;
1403
  int8_t neg;   // this is a negative entry
1404
  int32_t duration; // duration in minute
1405
} SDateTimeRange;
1406

1407
bool isValidDateTimeRange(SDateTimeRange* pRange);
1408
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1409
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1410

1411

1412
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1413
typedef struct {
1414
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1415
  bool neg;         // this is a negative entry
1416
  int32_t duration; // duration in seconds
1417
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1418
} SDateTimeWhiteListItem;
1419

1420
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1421
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1422

1423
typedef struct {
1424
  int32_t num;
1425
  SDateTimeWhiteListItem ranges[];
1426
} SDateTimeWhiteList;
1427

1428
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1429
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1430

1431

1432
typedef struct {
1433
  int8_t createType;
1434
  int8_t superUser;  // denote if it is a super user or not
1435
  int8_t ignoreExisting;
1436

1437
  char   user[TSDB_USER_LEN];
1438
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1439
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1440

1441
  int8_t sysInfo;
1442
  int8_t createDb;
1443
  int8_t isImport;
1444
  int8_t changepass;
1445
  int8_t enable;
1446

1447
  int8_t negIpRanges;
1448
  int8_t negTimeRanges;
1449

1450
  int32_t sessionPerUser;
1451
  int32_t connectTime;
1452
  int32_t connectIdleTime;
1453
  int32_t callPerSession;
1454
  int32_t vnodePerCall;
1455
  int32_t failedLoginAttempts;
1456
  int32_t passwordLifeTime;
1457
  int32_t passwordReuseTime;
1458
  int32_t passwordReuseMax;
1459
  int32_t passwordLockTime;
1460
  int32_t passwordGraceTime;
1461
  int32_t inactiveAccountTime;
1462
  int32_t allowTokenNum;
1463

1464
  int32_t         numIpRanges;
1465
  SIpRange*       pIpDualRanges;
1466
  int32_t         numTimeRanges;
1467
  SDateTimeRange* pTimeRanges;
1468

1469
  int32_t sqlLen;
1470
  char*   sql;
1471
} SCreateUserReq;
1472

1473
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1474
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1475
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1476

1477
typedef struct {
1478
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1479
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1480
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1481
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1482
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1483
  int32_t sqlLen;
1484
  char*   sql;
1485
} SCreateEncryptAlgrReq;
1486

1487
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1488
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1489
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1490

1491
typedef struct {
1492
  int32_t dnodeId;
1493
  int64_t analVer;
1494
} SRetrieveAnalyticsAlgoReq;
1495

1496
typedef struct {
1497
  int64_t   ver;
1498
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1499
} SRetrieveAnalyticAlgoRsp;
1500

1501
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1502
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1503
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1504
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1505
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1506

1507
typedef struct {
1508
  int8_t alterType;
1509

1510
  int8_t isView;
1511
  
1512
  int8_t hasPassword;
1513
  int8_t hasTotpseed;
1514
  int8_t hasEnable;
1515
  int8_t hasSysinfo;
1516
  int8_t hasCreatedb;
1517
  int8_t hasChangepass;
1518
  int8_t hasSessionPerUser;
1519
  int8_t hasConnectTime;
1520
  int8_t hasConnectIdleTime;
1521
  int8_t hasCallPerSession;
1522
  int8_t hasVnodePerCall;
1523
  int8_t hasFailedLoginAttempts;
1524
  int8_t hasPasswordLifeTime;
1525
  int8_t hasPasswordReuseTime;
1526
  int8_t hasPasswordReuseMax;
1527
  int8_t hasPasswordLockTime;
1528
  int8_t hasPasswordGraceTime;
1529
  int8_t hasInactiveAccountTime;
1530
  int8_t hasAllowTokenNum;
1531

1532
  int8_t enable;
1533
  int8_t sysinfo;
1534
  int8_t createdb;
1535
  int8_t changepass;
1536

1537
  char   user[TSDB_USER_LEN];
1538
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1539
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1540
  int32_t sessionPerUser;
1541
  int32_t connectTime;
1542
  int32_t connectIdleTime;
1543
  int32_t callPerSession;
1544
  int32_t vnodePerCall;
1545
  int32_t failedLoginAttempts;
1546
  int32_t passwordLifeTime;
1547
  int32_t passwordReuseTime;
1548
  int32_t passwordReuseMax;
1549
  int32_t passwordLockTime;
1550
  int32_t passwordGraceTime;
1551
  int32_t inactiveAccountTime;
1552
  int32_t allowTokenNum;
1553

1554
  int32_t         numIpRanges;
1555
  int32_t         numTimeRanges;
1556
  int32_t         numDropIpRanges;
1557
  int32_t         numDropTimeRanges;
1558
  SIpRange*       pIpRanges;
1559
  SDateTimeRange* pTimeRanges;
1560
  SIpRange*       pDropIpRanges;
1561
  SDateTimeRange* pDropTimeRanges;
1562

1563
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1564
  char        tabName[TSDB_TABLE_NAME_LEN];
1565
  char*       tagCond;
1566
  int32_t     tagCondLen;
1567
  int32_t     sqlLen;
1568
  char*       sql;
1569
  int64_t     privileges;
1570
} SAlterUserReq;
1571

1572
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1573
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1574
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1575

1576
typedef struct {
1577
  char user[TSDB_USER_LEN];
1578
} SGetUserAuthReq;
1579

1580
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1581
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1582

1583
typedef struct {
1584
  char      user[TSDB_USER_LEN];
1585
  int32_t   version;
1586
  int32_t   passVer;
1587
  int8_t    superAuth;
1588
  int8_t    sysInfo;
1589
  int8_t    enable;
1590
  int8_t    dropped;
1591
  SHashObj* createdDbs;
1592
  SHashObj* readDbs;
1593
  SHashObj* writeDbs;
1594
  SHashObj* readTbs;
1595
  SHashObj* writeTbs;
1596
  SHashObj* alterTbs;
1597
  SHashObj* readViews;
1598
  SHashObj* writeViews;
1599
  SHashObj* alterViews;
1600
  SHashObj* useDbs;
1601
  int64_t   whiteListVer;
1602

1603
  SUserSessCfg sessCfg;
1604
  int64_t      timeWhiteListVer;
1605
} SGetUserAuthRsp;
1606

1607
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1608
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1609
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1610

1611
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1612
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1613
typedef struct {
1614
  int64_t ver;
1615
  char    user[TSDB_USER_LEN];
1616
  int32_t numOfRange;
1617
  union {
1618
    SIpV4Range* pIpRanges;
1619
    SIpRange*   pIpDualRanges;
1620
  };
1621
} SUpdateUserIpWhite;
1622

1623
typedef struct {
1624
  int64_t             ver;
1625
  int                 numOfUser;
1626
  SUpdateUserIpWhite* pUserIpWhite;
1627
} SUpdateIpWhite;
1628

1629
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1630
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1631
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1632
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1633

1634
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1635
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1636
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1637

1638

1639
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1640
// corresponding response struct is different.
1641
typedef struct {
1642
  int64_t ver;
1643
} SRetrieveWhiteListReq;
1644

1645
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1646
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1647

1648

1649
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1650
// corresponding response struct is different.
1651
typedef struct {
1652
  char user[TSDB_USER_LEN];
1653
} SGetUserWhiteListReq;
1654

1655
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1656
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1657

1658
typedef struct {
1659
  char    user[TSDB_USER_LEN];
1660
  int32_t numWhiteLists;
1661
  union {
1662
    SIpV4Range* pWhiteLists;
1663
    SIpRange*   pWhiteListsDual;
1664
  };
1665
} SGetUserIpWhiteListRsp;
1666

1667
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1668
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1669
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1670
void    tIpRangeSetDefaultMask(SIpRange* range);
1671

1672
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1673
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1674
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1675

1676
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1677
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1678
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1679

1680
typedef struct {
1681
  int64_t ver;
1682
  char    user[TSDB_USER_LEN];
1683
  int32_t numWhiteLists;
1684
  SDateTimeWhiteListItem* pWhiteLists;
1685
} SUserDateTimeWhiteList;
1686

1687

1688
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1689
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1690
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1691
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1692

1693
typedef struct {
1694
  int64_t             ver;
1695
  int                 numOfUser;
1696
  SUserDateTimeWhiteList *pUsers;
1697
} SRetrieveDateTimeWhiteListRsp;
1698

1699
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1700
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1701
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1702
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1703

1704
/*
1705
 * for client side struct, only column id, type, bytes are necessary
1706
 * But for data in vnode side, we need all the following information.
1707
 */
1708
typedef struct {
1709
  union {
1710
    col_id_t colId;
1711
    int16_t  slotId;
1712
  };
1713

1714
  uint8_t precision;
1715
  uint8_t scale;
1716
  int32_t bytes;
1717
  int8_t  type;
1718
  uint8_t pk;
1719
  bool    noData;
1720
} SColumnInfo;
1721

1722
typedef struct STimeWindow {
1723
  TSKEY skey;
1724
  TSKEY ekey;
1725
} STimeWindow;
1726

1727
typedef struct SQueryHint {
1728
  bool batchScan;
1729
} SQueryHint;
1730

1731
typedef struct {
1732
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1733
  int32_t tsLen;          // total length of ts comp block
1734
  int32_t tsNumOfBlocks;  // ts comp block numbers
1735
  int32_t tsOrder;        // ts comp block order
1736
} STsBufInfo;
1737

1738
typedef struct {
1739
  void*       timezone;
1740
  char        intervalUnit;
1741
  char        slidingUnit;
1742
  char        offsetUnit;
1743
  int8_t      precision;
1744
  int64_t     interval;
1745
  int64_t     sliding;
1746
  int64_t     offset;
1747
  STimeWindow timeRange;
1748
} SInterval;
1749

1750
typedef struct STbVerInfo {
1751
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1752
  int32_t sversion;
1753
  int32_t tversion;
1754
  int32_t rversion;  // virtual table's column ref's version
1755
} STbVerInfo;
1756

1757
typedef struct {
1758
  int32_t code;
1759
  int64_t affectedRows;
1760
  SArray* tbVerInfo;  // STbVerInfo
1761
} SQueryTableRsp;
1762

1763
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1764

1765
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1766

1767
typedef struct {
1768
  SMsgHead header;
1769
  char     dbFName[TSDB_DB_FNAME_LEN];
1770
  char     tbName[TSDB_TABLE_NAME_LEN];
1771
} STableCfgReq;
1772

1773
typedef struct {
1774
  char        tbName[TSDB_TABLE_NAME_LEN];
1775
  char        stbName[TSDB_TABLE_NAME_LEN];
1776
  char        dbFName[TSDB_DB_FNAME_LEN];
1777
  int32_t     numOfTags;
1778
  int32_t     numOfColumns;
1779
  int8_t      tableType;
1780
  int64_t     delay1;
1781
  int64_t     delay2;
1782
  int64_t     watermark1;
1783
  int64_t     watermark2;
1784
  int32_t     ttl;
1785
  int32_t     keep;
1786
  SArray*     pFuncs;
1787
  int32_t     commentLen;
1788
  char*       pComment;
1789
  SSchema*    pSchemas;
1790
  int32_t     tagsLen;
1791
  char*       pTags;
1792
  SSchemaExt* pSchemaExt;
1793
  int8_t      virtualStb;
1794
  SColRef*    pColRefs;
1795
} STableCfg;
1796

1797
typedef STableCfg STableCfgRsp;
1798

1799
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1800
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1801

1802
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1803
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1804
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1805

1806
typedef struct {
1807
  SMsgHead header;
1808
  tb_uid_t suid;
1809
} SVSubTablesReq;
1810

1811
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1812
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1813

1814
typedef struct {
1815
  int32_t vgId;
1816
  SArray* pTables;  // SArray<SVCTableRefCols*>
1817
} SVSubTablesRsp;
1818

1819
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1820
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1821
void    tDestroySVSubTablesRsp(void* rsp);
1822

1823
typedef struct {
1824
  SMsgHead header;
1825
  tb_uid_t suid;
1826
} SVStbRefDbsReq;
1827

1828
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1829
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1830

1831
typedef struct {
1832
  int32_t vgId;
1833
  SArray* pDbs;  // SArray<char* (db name)>
1834
} SVStbRefDbsRsp;
1835

1836
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1837
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1838
void    tDestroySVStbRefDbsRsp(void* rsp);
1839

1840
typedef struct {
1841
  char    db[TSDB_DB_FNAME_LEN];
1842
  int32_t numOfVgroups;
1843
  int32_t numOfStables;  // single_stable
1844
  int32_t buffer;        // MB
1845
  int32_t pageSize;
1846
  int32_t pages;
1847
  int32_t cacheLastSize;
1848
  int32_t daysPerFile;
1849
  int32_t daysToKeep0;
1850
  int32_t daysToKeep1;
1851
  int32_t daysToKeep2;
1852
  int32_t keepTimeOffset;
1853
  int32_t minRows;
1854
  int32_t maxRows;
1855
  int32_t walFsyncPeriod;
1856
  int8_t  walLevel;
1857
  int8_t  precision;  // time resolution
1858
  int8_t  compression;
1859
  int8_t  replications;
1860
  int8_t  strict;
1861
  int8_t  cacheLast;
1862
  int8_t  schemaless;
1863
  int8_t  ignoreExist;
1864
  int32_t numOfRetensions;
1865
  SArray* pRetensions;  // SRetention
1866
  int32_t walRetentionPeriod;
1867
  int64_t walRetentionSize;
1868
  int32_t walRollPeriod;
1869
  int64_t walSegmentSize;
1870
  int32_t sstTrigger;
1871
  int16_t hashPrefix;
1872
  int16_t hashSuffix;
1873
  int32_t ssChunkSize;
1874
  int32_t ssKeepLocal;
1875
  int8_t  ssCompact;
1876
  int32_t tsdbPageSize;
1877
  int32_t sqlLen;
1878
  char*   sql;
1879
  int8_t  withArbitrator;
1880
  int8_t  encryptAlgorithm;
1881
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1882
  // 1. add auto-compact parameters
1883
  int32_t compactInterval;    // minutes
1884
  int32_t compactStartTime;   // minutes
1885
  int32_t compactEndTime;     // minutes
1886
  int8_t  compactTimeOffset;  // hour
1887
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1888
  int8_t  isAudit;
1889
} SCreateDbReq;
1890

1891
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1892
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1893
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1894

1895
typedef struct {
1896
  char    db[TSDB_DB_FNAME_LEN];
1897
  int32_t buffer;
1898
  int32_t pageSize;
1899
  int32_t pages;
1900
  int32_t cacheLastSize;
1901
  int32_t daysPerFile;
1902
  int32_t daysToKeep0;
1903
  int32_t daysToKeep1;
1904
  int32_t daysToKeep2;
1905
  int32_t keepTimeOffset;
1906
  int32_t walFsyncPeriod;
1907
  int8_t  walLevel;
1908
  int8_t  strict;
1909
  int8_t  cacheLast;
1910
  int8_t  replications;
1911
  int32_t sstTrigger;
1912
  int32_t minRows;
1913
  int32_t walRetentionPeriod;
1914
  int32_t walRetentionSize;
1915
  int32_t ssKeepLocal;
1916
  int8_t  ssCompact;
1917
  int32_t sqlLen;
1918
  char*   sql;
1919
  int8_t  withArbitrator;
1920
  // 1. add auto-compact parameters
1921
  int32_t compactInterval;
1922
  int32_t compactStartTime;
1923
  int32_t compactEndTime;
1924
  int8_t  compactTimeOffset;
1925
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1926
  int8_t  isAudit;
1927
} SAlterDbReq;
1928

1929
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1930
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1931
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1932

1933
typedef struct {
1934
  char    db[TSDB_DB_FNAME_LEN];
1935
  int8_t  ignoreNotExists;
1936
  int8_t  force;
1937
  int32_t sqlLen;
1938
  char*   sql;
1939
} SDropDbReq;
1940

1941
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1942
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1943
void    tFreeSDropDbReq(SDropDbReq* pReq);
1944

1945
typedef struct {
1946
  char    db[TSDB_DB_FNAME_LEN];
1947
  int64_t uid;
1948
} SDropDbRsp;
1949

1950
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1951
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1952

1953
typedef struct {
1954
  char    name[TSDB_MOUNT_NAME_LEN];
1955
  int64_t uid;
1956
} SDropMountRsp;
1957

1958
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1959
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1960

1961
typedef struct {
1962
  char    db[TSDB_DB_FNAME_LEN];
1963
  int64_t dbId;
1964
  int32_t vgVersion;
1965
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1966
  int64_t stateTs;     // ms
1967
} SUseDbReq;
1968

1969
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1970
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1971

1972
typedef struct {
1973
  char    db[TSDB_DB_FNAME_LEN];
1974
  int64_t uid;
1975
  int32_t vgVersion;
1976
  int32_t vgNum;
1977
  int16_t hashPrefix;
1978
  int16_t hashSuffix;
1979
  int8_t  hashMethod;
1980
  union {
1981
    uint8_t flags;
1982
    struct {
1983
      uint8_t isMount : 1;  // TS-5868
1984
      uint8_t padding : 7;
1985
    };
1986
  };
1987
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1988
  int32_t errCode;
1989
  int64_t stateTs;  // ms
1990
} SUseDbRsp;
1991

1992
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1993
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1994
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1995
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1996
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1997

1998
typedef struct {
1999
  char db[TSDB_DB_FNAME_LEN];
2000
} SDbCfgReq;
2001

2002
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2003
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2004

2005
typedef struct {
2006
  char db[TSDB_DB_FNAME_LEN];
2007
} SSsMigrateDbReq;
2008

2009
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2010
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2011

2012
typedef struct {
2013
  int32_t ssMigrateId;
2014
  bool    bAccepted;
2015
} SSsMigrateDbRsp;
2016

2017
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2018
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2019

2020
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2021
typedef struct {
2022
  int32_t ssMigrateId;
2023
} SListSsMigrateFileSetsReq;
2024

2025
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2026
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2027

2028
typedef struct {
2029
  int32_t ssMigrateId;
2030
  int32_t vgId;       // vgroup id
2031
  SArray* pFileSets;  // SArray<int32_t>
2032
} SListSsMigrateFileSetsRsp;
2033

2034
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2035
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2036
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2037

2038
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2039
typedef struct {
2040
  int32_t ssMigrateId;
2041
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2042
  int32_t fid;
2043
  int64_t startTimeSec;
2044
} SSsMigrateFileSetReq;
2045

2046
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2047
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2048

2049
typedef struct {
2050
  int32_t ssMigrateId;
2051
  int32_t nodeId;  // node id of the leader vnode
2052
  int32_t vgId;
2053
  int32_t fid;
2054
} SSsMigrateFileSetRsp;
2055

2056
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2057
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2058

2059
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2060
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2061
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2062
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2063
#define SSMIGRATE_FILESET_STATE_FAILED      4
2064

2065
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2066
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2067
// while as a request, the 'state' field is not used.
2068
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2069
typedef struct {
2070
  int32_t ssMigrateId;  // ss migrate id
2071
  int32_t nodeId;       // node id of the leader vnode
2072
  int32_t vgId;         // vgroup id
2073
  int32_t fid;          // file set id
2074
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2075
} SSsMigrateProgress;
2076

2077
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2078
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2079

2080
// Request for TDMT_MND_KILL_SSMIGRATE
2081
typedef struct {
2082
  int32_t ssMigrateId;
2083
  int32_t sqlLen;
2084
  char*   sql;
2085
} SKillSsMigrateReq;
2086

2087
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2088
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2089
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2090

2091
// Request for TDMT_VND_KILL_SSMIGRATE
2092
typedef struct {
2093
  int32_t ssMigrateId;
2094
} SVnodeKillSsMigrateReq;
2095

2096
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2097
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2098

2099
typedef struct {
2100
  int32_t vgId;
2101
  int64_t keepVersion;
2102
} SMndSetVgroupKeepVersionReq;
2103

2104
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2105
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2106

2107
typedef struct {
2108
  int32_t timestampSec;
2109
  int32_t ttlDropMaxCount;
2110
  int32_t nUids;
2111
  SArray* pTbUids;
2112
} SVDropTtlTableReq;
2113

2114
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2115
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2116

2117
typedef struct {
2118
  char    db[TSDB_DB_FNAME_LEN];
2119
  int64_t dbId;
2120
  int32_t cfgVersion;
2121
  int32_t numOfVgroups;
2122
  int32_t numOfStables;
2123
  int32_t buffer;
2124
  int32_t cacheSize;
2125
  int32_t pageSize;
2126
  int32_t pages;
2127
  int32_t daysPerFile;
2128
  int32_t daysToKeep0;
2129
  int32_t daysToKeep1;
2130
  int32_t daysToKeep2;
2131
  int32_t keepTimeOffset;
2132
  int32_t minRows;
2133
  int32_t maxRows;
2134
  int32_t walFsyncPeriod;
2135
  int16_t hashPrefix;
2136
  int16_t hashSuffix;
2137
  int8_t  hashMethod;
2138
  int8_t  walLevel;
2139
  int8_t  precision;
2140
  int8_t  compression;
2141
  int8_t  replications;
2142
  int8_t  strict;
2143
  int8_t  cacheLast;
2144
  int8_t  encryptAlgr;
2145
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2146
  int32_t ssChunkSize;
2147
  int32_t ssKeepLocal;
2148
  int8_t  ssCompact;
2149
  union {
2150
    uint8_t flags;
2151
    struct {
2152
      uint8_t isMount : 1;  // TS-5868
2153
      uint8_t padding : 7;
2154
    };
2155
  };
2156
  int8_t  compactTimeOffset;
2157
  int32_t compactInterval;
2158
  int32_t compactStartTime;
2159
  int32_t compactEndTime;
2160
  int32_t tsdbPageSize;
2161
  int32_t walRetentionPeriod;
2162
  int32_t walRollPeriod;
2163
  int64_t walRetentionSize;
2164
  int64_t walSegmentSize;
2165
  int32_t numOfRetensions;
2166
  SArray* pRetensions;
2167
  int8_t  schemaless;
2168
  int16_t sstTrigger;
2169
  int8_t  withArbitrator;
2170
  int8_t  isAudit;
2171
} SDbCfgRsp;
2172

2173
typedef SDbCfgRsp SDbCfgInfo;
2174

2175
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2176
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2177
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2178
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2179
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2180

2181
typedef struct {
2182
  int32_t rowNum;
2183
} SQnodeListReq;
2184

2185
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2186
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2187

2188
typedef struct {
2189
  int32_t rowNum;
2190
} SDnodeListReq;
2191

2192
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2193

2194
typedef struct {
2195
  int32_t useless;  // useless
2196
} SServerVerReq;
2197

2198
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2199
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2200

2201
typedef struct {
2202
  char ver[TSDB_VERSION_LEN];
2203
} SServerVerRsp;
2204

2205
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2206
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2207

2208
typedef struct SQueryNodeAddr {
2209
  int32_t nodeId;  // vgId or qnodeId
2210
  SEpSet  epSet;
2211
} SQueryNodeAddr;
2212

2213
typedef struct {
2214
  SQueryNodeAddr addr;
2215
  uint64_t       load;
2216
} SQueryNodeLoad;
2217

2218
typedef struct {
2219
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2220
} SQnodeListRsp;
2221

2222
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2223
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2224
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2225

2226

2227
typedef struct SDownstreamSourceNode {
2228
  ENodeType      type;
2229
  SQueryNodeAddr addr;
2230
  uint64_t       clientId;
2231
  uint64_t       taskId;
2232
  uint64_t       sId;
2233
  int32_t        execId;
2234
  int32_t        fetchMsgType;
2235
  bool           localExec;
2236
} SDownstreamSourceNode;
2237

2238

2239

2240
typedef struct SDNodeAddr {
2241
  int32_t nodeId;  // dnodeId
2242
  SEpSet  epSet;
2243
} SDNodeAddr;
2244

2245
typedef struct {
2246
  SArray* dnodeList;  // SArray<SDNodeAddr>
2247
} SDnodeListRsp;
2248

2249
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2250
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2251
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2252

2253
typedef struct {
2254
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2255
} STableTSMAInfoRsp;
2256

2257
typedef struct {
2258
  SUseDbRsp*         useDbRsp;
2259
  SDbCfgRsp*         cfgRsp;
2260
  STableTSMAInfoRsp* pTsmaRsp;
2261
  int32_t            dbTsmaVersion;
2262
  char               db[TSDB_DB_FNAME_LEN];
2263
  int64_t            dbId;
2264
} SDbHbRsp;
2265

2266
typedef struct {
2267
  SArray* pArray;  // Array of SDbHbRsp
2268
} SDbHbBatchRsp;
2269

2270
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2271
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2272
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2273

2274
typedef struct {
2275
  SArray* pArray;  // Array of SGetUserAuthRsp
2276
} SUserAuthBatchRsp;
2277

2278
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2279
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2280
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2281

2282
typedef struct {
2283
  char        db[TSDB_DB_FNAME_LEN];
2284
  STimeWindow timeRange;
2285
  int32_t     sqlLen;
2286
  char*       sql;
2287
  SArray*     vgroupIds;
2288
  int32_t     compactId;
2289
  int8_t      metaOnly;
2290
  int8_t      force;
2291
} SCompactDbReq;
2292

2293
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2294
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2295
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2296

2297
typedef struct {
2298
  union {
2299
    int32_t compactId;
2300
    int32_t id;
2301
  };
2302
  int8_t bAccepted;
2303
} SCompactDbRsp;
2304

2305
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2306
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2307

2308
typedef struct {
2309
  union {
2310
    int32_t compactId;
2311
    int32_t id;
2312
  };
2313
  int32_t sqlLen;
2314
  char*   sql;
2315
} SKillCompactReq;
2316

2317
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2318
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2319
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2320

2321
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2322
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2323

2324
typedef struct {
2325
  char    name[TSDB_FUNC_NAME_LEN];
2326
  int8_t  igExists;
2327
  int8_t  funcType;
2328
  int8_t  scriptType;
2329
  int8_t  outputType;
2330
  int32_t outputLen;
2331
  int32_t bufSize;
2332
  int32_t codeLen;
2333
  int64_t signature;
2334
  char*   pComment;
2335
  char*   pCode;
2336
  int8_t  orReplace;
2337
} SCreateFuncReq;
2338

2339
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2340
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2341
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2342

2343
typedef struct {
2344
  char   name[TSDB_FUNC_NAME_LEN];
2345
  int8_t igNotExists;
2346
} SDropFuncReq;
2347

2348
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2349
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2350

2351
typedef struct {
2352
  int32_t numOfFuncs;
2353
  bool    ignoreCodeComment;
2354
  SArray* pFuncNames;
2355
} SRetrieveFuncReq;
2356

2357
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2358
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2359
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2360

2361
typedef struct {
2362
  char    name[TSDB_FUNC_NAME_LEN];
2363
  int8_t  funcType;
2364
  int8_t  scriptType;
2365
  int8_t  outputType;
2366
  int32_t outputLen;
2367
  int32_t bufSize;
2368
  int64_t signature;
2369
  int32_t commentSize;
2370
  int32_t codeSize;
2371
  char*   pComment;
2372
  char*   pCode;
2373
} SFuncInfo;
2374

2375
typedef struct {
2376
  int32_t funcVersion;
2377
  int64_t funcCreatedTime;
2378
} SFuncExtraInfo;
2379

2380
typedef struct {
2381
  int32_t numOfFuncs;
2382
  SArray* pFuncInfos;
2383
  SArray* pFuncExtraInfos;
2384
} SRetrieveFuncRsp;
2385

2386
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2387
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2388
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2389
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2390

2391
typedef struct {
2392
  int32_t       statusInterval;
2393
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2394
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2395
  char          locale[TD_LOCALE_LEN];      // tsLocale
2396
  char          charset[TD_LOCALE_LEN];     // tsCharset
2397
  int8_t        ttlChangeOnWrite;
2398
  int8_t        enableWhiteList;
2399
  int8_t        encryptionKeyStat;
2400
  uint32_t      encryptionKeyChksum;
2401
  SMonitorParas monitorParas;
2402
  int32_t       statusIntervalMs;
2403
} SClusterCfg;
2404

2405
typedef struct {
2406
  int32_t openVnodes;
2407
  int32_t dropVnodes;
2408
  int32_t totalVnodes;
2409
  int32_t masterNum;
2410
  int64_t numOfSelectReqs;
2411
  int64_t numOfInsertReqs;
2412
  int64_t numOfInsertSuccessReqs;
2413
  int64_t numOfBatchInsertReqs;
2414
  int64_t numOfBatchInsertSuccessReqs;
2415
  int64_t errors;
2416
} SVnodesStat;
2417

2418
typedef struct {
2419
  int32_t vgId;
2420
  int8_t  syncState;
2421
  int8_t  syncRestore;
2422
  int64_t syncTerm;
2423
  int64_t roleTimeMs;
2424
  int64_t startTimeMs;
2425
  int8_t  syncCanRead;
2426
  int64_t cacheUsage;
2427
  int64_t numOfTables;
2428
  int64_t numOfTimeSeries;
2429
  int64_t totalStorage;
2430
  int64_t compStorage;
2431
  int64_t pointsWritten;
2432
  int64_t numOfSelectReqs;
2433
  int64_t numOfInsertReqs;
2434
  int64_t numOfInsertSuccessReqs;
2435
  int64_t numOfBatchInsertReqs;
2436
  int64_t numOfBatchInsertSuccessReqs;
2437
  int32_t numOfCachedTables;
2438
  int32_t learnerProgress;  // use one reservered
2439
  int64_t syncAppliedIndex;
2440
  int64_t syncCommitIndex;
2441
  int64_t bufferSegmentUsed;
2442
  int64_t bufferSegmentSize;
2443
} SVnodeLoad;
2444

2445
typedef struct {
2446
  int64_t total_requests;
2447
  int64_t total_rows;
2448
  int64_t total_bytes;
2449
  double  write_size;
2450
  double  cache_hit_ratio;
2451
  int64_t rpc_queue_wait;
2452
  int64_t preprocess_time;
2453

2454
  int64_t memory_table_size;
2455
  int64_t commit_count;
2456
  int64_t merge_count;
2457
  double  commit_time;
2458
  double  merge_time;
2459
  int64_t block_commit_time;
2460
  int64_t memtable_wait_time;
2461
} SVnodeMetrics;
2462

2463
typedef struct {
2464
  int32_t     vgId;
2465
  int64_t     numOfTables;
2466
  int64_t     memSize;
2467
  int64_t     l1Size;
2468
  int64_t     l2Size;
2469
  int64_t     l3Size;
2470
  int64_t     cacheSize;
2471
  int64_t     walSize;
2472
  int64_t     metaSize;
2473
  int64_t     rawDataSize;
2474
  int64_t     ssSize;
2475
  const char* dbname;
2476
  int8_t      estimateRawData;
2477
} SDbSizeStatisInfo;
2478

2479
typedef struct {
2480
  int32_t vgId;
2481
  int64_t nTimeSeries;
2482
} SVnodeLoadLite;
2483

2484
typedef struct {
2485
  int8_t  syncState;
2486
  int64_t syncTerm;
2487
  int8_t  syncRestore;
2488
  int64_t roleTimeMs;
2489
} SMnodeLoad;
2490

2491
typedef struct {
2492
  int32_t dnodeId;
2493
  int64_t numOfProcessedQuery;
2494
  int64_t numOfProcessedCQuery;
2495
  int64_t numOfProcessedFetch;
2496
  int64_t numOfProcessedDrop;
2497
  int64_t numOfProcessedNotify;
2498
  int64_t numOfProcessedHb;
2499
  int64_t numOfProcessedDelete;
2500
  int64_t cacheDataSize;
2501
  int64_t numOfQueryInQueue;
2502
  int64_t numOfFetchInQueue;
2503
  int64_t timeInQueryQueue;
2504
  int64_t timeInFetchQueue;
2505
} SQnodeLoad;
2506

2507
typedef struct {
2508
  int32_t     sver;      // software version
2509
  int64_t     dnodeVer;  // dnode table version in sdb
2510
  int32_t     dnodeId;
2511
  int64_t     clusterId;
2512
  int64_t     rebootTime;
2513
  int64_t     updateTime;
2514
  float       numOfCores;
2515
  int32_t     numOfSupportVnodes;
2516
  int32_t     numOfDiskCfg;
2517
  int64_t     memTotal;
2518
  int64_t     memAvail;
2519
  char        dnodeEp[TSDB_EP_LEN];
2520
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2521
  SMnodeLoad  mload;
2522
  SQnodeLoad  qload;
2523
  SClusterCfg clusterCfg;
2524
  SArray*     pVloads;  // array of SVnodeLoad
2525
  int32_t     statusSeq;
2526
  int64_t     ipWhiteVer;
2527
  int64_t     timeWhiteVer;
2528
  int64_t     analVer;
2529
  int64_t     timestamp;
2530
  char        auditDB[TSDB_DB_FNAME_LEN];
2531
  char        auditToken[AUDIT_TOKEN_LEN];
2532
} SStatusReq;
2533

2534
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2535
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2536
void    tFreeSStatusReq(SStatusReq* pReq);
2537

2538
typedef struct {
2539
  int32_t forceReadConfig;
2540
  int32_t cver;
2541
  SArray* array;
2542
} SConfigReq;
2543

2544
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2545
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2546
void    tFreeSConfigReq(SConfigReq* pReq);
2547

2548
typedef struct {
2549
  int32_t dnodeId;
2550
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2551
} SDnodeInfoReq;
2552

2553
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2554
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2555

2556
typedef enum {
2557
  MONITOR_TYPE_COUNTER = 0,
2558
  MONITOR_TYPE_SLOW_LOG = 1,
2559
} MONITOR_TYPE;
2560

2561
typedef struct {
2562
  int32_t      contLen;
2563
  char*        pCont;
2564
  MONITOR_TYPE type;
2565
} SStatisReq;
2566

2567
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2568
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2569
void    tFreeSStatisReq(SStatisReq* pReq);
2570

2571
typedef struct {
2572
  char    db[TSDB_DB_FNAME_LEN];
2573
  char    table[TSDB_TABLE_NAME_LEN];
2574
  char    operation[AUDIT_OPERATION_LEN];
2575
  int32_t sqlLen;
2576
  char*   pSql;
2577
  double  duration;
2578
  int64_t affectedRows;
2579
} SAuditReq;
2580
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2581
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2582
void    tFreeSAuditReq(SAuditReq* pReq);
2583

2584
typedef struct {
2585
  SArray* auditArr;
2586
} SBatchAuditReq;
2587
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2588
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2589
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2590

2591
typedef struct {
2592
  int32_t dnodeId;
2593
  int64_t clusterId;
2594
  SArray* pVloads;
2595
} SNotifyReq;
2596

2597
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2598
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2599
void    tFreeSNotifyReq(SNotifyReq* pReq);
2600

2601
typedef struct {
2602
  int32_t dnodeId;
2603
  int64_t clusterId;
2604
} SDnodeCfg;
2605

2606
typedef struct {
2607
  int32_t id;
2608
  int8_t  isMnode;
2609
  SEp     ep;
2610
} SDnodeEp;
2611

2612
typedef struct {
2613
  int32_t id;
2614
  int8_t  isMnode;
2615
  int8_t  offlineReason;
2616
  SEp     ep;
2617
  char    active[TSDB_ACTIVE_KEY_LEN];
2618
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2619
} SDnodeInfo;
2620

2621
typedef struct {
2622
  int64_t   dnodeVer;
2623
  SDnodeCfg dnodeCfg;
2624
  SArray*   pDnodeEps;  // Array of SDnodeEp
2625
  int32_t   statusSeq;
2626
  int64_t   ipWhiteVer;
2627
  int64_t   analVer;
2628
  int64_t   timeWhiteVer;
2629
  char      auditDB[TSDB_DB_FNAME_LEN];
2630
  char      auditToken[AUDIT_TOKEN_LEN];
2631
} SStatusRsp;
2632

2633
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2634
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2635
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2636

2637
typedef struct {
2638
  int32_t forceReadConfig;
2639
  int32_t isConifgVerified;
2640
  int32_t isVersionVerified;
2641
  int32_t cver;
2642
  SArray* array;
2643
} SConfigRsp;
2644

2645
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2646
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2647
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2648

2649
typedef struct {
2650
  int32_t reserved;
2651
} SMTimerReq;
2652

2653
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2654
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2655

2656
typedef struct SOrphanTask {
2657
  int64_t streamId;
2658
  int32_t taskId;
2659
  int32_t nodeId;
2660
} SOrphanTask;
2661

2662
typedef struct SMStreamDropOrphanMsg {
2663
  SArray* pList;  // SArray<SOrphanTask>
2664
} SMStreamDropOrphanMsg;
2665

2666
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2667
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2668
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2669

2670
typedef struct {
2671
  int32_t  id;
2672
  uint16_t port;                 // node sync Port
2673
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2674
} SReplica;
2675

2676
typedef struct {
2677
  int32_t  vgId;
2678
  char     db[TSDB_DB_FNAME_LEN];
2679
  int64_t  dbUid;
2680
  int32_t  vgVersion;
2681
  int32_t  numOfStables;
2682
  int32_t  buffer;
2683
  int32_t  pageSize;
2684
  int32_t  pages;
2685
  int32_t  cacheLastSize;
2686
  int32_t  daysPerFile;
2687
  int32_t  daysToKeep0;
2688
  int32_t  daysToKeep1;
2689
  int32_t  daysToKeep2;
2690
  int32_t  keepTimeOffset;
2691
  int32_t  minRows;
2692
  int32_t  maxRows;
2693
  int32_t  walFsyncPeriod;
2694
  uint32_t hashBegin;
2695
  uint32_t hashEnd;
2696
  int8_t   hashMethod;
2697
  int8_t   walLevel;
2698
  int8_t   precision;
2699
  int8_t   compression;
2700
  int8_t   strict;
2701
  int8_t   cacheLast;
2702
  int8_t   isTsma;
2703
  int8_t   replica;
2704
  int8_t   selfIndex;
2705
  SReplica replicas[TSDB_MAX_REPLICA];
2706
  int32_t  numOfRetensions;
2707
  SArray*  pRetensions;  // SRetention
2708
  void*    pTsma;
2709
  int32_t  walRetentionPeriod;
2710
  int64_t  walRetentionSize;
2711
  int32_t  walRollPeriod;
2712
  int64_t  walSegmentSize;
2713
  int16_t  sstTrigger;
2714
  int16_t  hashPrefix;
2715
  int16_t  hashSuffix;
2716
  int32_t  tsdbPageSize;
2717
  int32_t  ssChunkSize;
2718
  int32_t  ssKeepLocal;
2719
  int8_t   ssCompact;
2720
  int64_t  reserved[6];
2721
  int8_t   learnerReplica;
2722
  int8_t   learnerSelfIndex;
2723
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2724
  int32_t  changeVersion;
2725
  int8_t   encryptAlgorithm;
2726
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2727
} SCreateVnodeReq;
2728

2729
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2730
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2731
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2732

2733
typedef struct {
2734
  union {
2735
    int32_t compactId;
2736
    int32_t id;
2737
  };
2738
  int32_t vgId;
2739
  int32_t dnodeId;
2740
} SQueryCompactProgressReq;
2741

2742
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2743
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2744

2745
typedef struct {
2746
  union {
2747
    int32_t compactId;
2748
    int32_t id;
2749
  };
2750
  int32_t vgId;
2751
  int32_t dnodeId;
2752
  int32_t numberFileset;
2753
  int32_t finished;
2754
  int32_t progress;
2755
  int64_t remainingTime;
2756
} SQueryCompactProgressRsp;
2757

2758
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2759
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2760

2761
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2762
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2763

2764
typedef struct {
2765
  int32_t vgId;
2766
  int32_t dnodeId;
2767
  int64_t dbUid;
2768
  char    db[TSDB_DB_FNAME_LEN];
2769
  int64_t reserved[8];
2770
} SDropVnodeReq;
2771

2772
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2773
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2774

2775
typedef struct {
2776
  char    colName[TSDB_COL_NAME_LEN];
2777
  char    stb[TSDB_TABLE_FNAME_LEN];
2778
  int64_t stbUid;
2779
  int64_t dbUid;
2780
  int64_t reserved[8];
2781
} SDropIndexReq;
2782

2783
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2784
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2785

2786
typedef struct {
2787
  int64_t dbUid;
2788
  char    db[TSDB_DB_FNAME_LEN];
2789
  union {
2790
    int64_t compactStartTime;
2791
    int64_t startTime;
2792
  };
2793

2794
  STimeWindow tw;
2795
  union {
2796
    int32_t compactId;
2797
    int32_t id;
2798
  };
2799
  int8_t metaOnly;
2800
  union {
2801
    uint16_t flags;
2802
    struct {
2803
      uint16_t optrType : 3;     // ETsdbOpType
2804
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2805
      uint16_t reserved : 12;
2806
    };
2807
  };
2808
  int8_t force;  // force compact
2809
} SCompactVnodeReq;
2810

2811
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2812
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2813

2814
typedef struct {
2815
  union {
2816
    int32_t compactId;
2817
    int32_t taskId;
2818
  };
2819
  int32_t vgId;
2820
  int32_t dnodeId;
2821
} SVKillCompactReq;
2822

2823
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2824
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2825

2826
typedef SVKillCompactReq SVKillRetentionReq;
2827

2828
typedef struct {
2829
  char        db[TSDB_DB_FNAME_LEN];
2830
  int32_t     maxSpeed;
2831
  int32_t     sqlLen;
2832
  char*       sql;
2833
  SArray*     vgroupIds;
2834
  STimeWindow tw;  // unit is second
2835
  union {
2836
    uint32_t flags;
2837
    struct {
2838
      uint32_t optrType : 3;     // ETsdbOpType
2839
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2840
      uint32_t reserved : 28;
2841
    };
2842
  };
2843
} STrimDbReq;
2844

2845
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2846
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2847
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2848

2849
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2850

2851
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2852
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2853

2854
typedef struct {
2855
  int32_t vgVersion;
2856
  int32_t buffer;
2857
  int32_t pageSize;
2858
  int32_t pages;
2859
  int32_t cacheLastSize;
2860
  int32_t daysPerFile;
2861
  int32_t daysToKeep0;
2862
  int32_t daysToKeep1;
2863
  int32_t daysToKeep2;
2864
  int32_t keepTimeOffset;
2865
  int32_t walFsyncPeriod;
2866
  int8_t  walLevel;
2867
  int8_t  strict;
2868
  int8_t  cacheLast;
2869
  int64_t reserved[7];
2870
  // 1st modification
2871
  int16_t sttTrigger;
2872
  int32_t minRows;
2873
  // 2nd modification
2874
  int32_t walRetentionPeriod;
2875
  int32_t walRetentionSize;
2876
  int32_t ssKeepLocal;
2877
  int8_t  ssCompact;
2878
} SAlterVnodeConfigReq;
2879

2880
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2881
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2882

2883
typedef struct {
2884
  int32_t  vgId;
2885
  int8_t   strict;
2886
  int8_t   selfIndex;
2887
  int8_t   replica;
2888
  SReplica replicas[TSDB_MAX_REPLICA];
2889
  int64_t  reserved[8];
2890
  int8_t   learnerSelfIndex;
2891
  int8_t   learnerReplica;
2892
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2893
  int32_t  changeVersion;
2894
  int32_t  electBaseLine;
2895
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2896

2897
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2898
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2899

2900
typedef struct {
2901
  int32_t vgId;
2902
  int8_t  disable;
2903
} SDisableVnodeWriteReq;
2904

2905
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2906
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2907

2908
typedef struct {
2909
  int32_t  srcVgId;
2910
  int32_t  dstVgId;
2911
  uint32_t hashBegin;
2912
  uint32_t hashEnd;
2913
  int32_t  changeVersion;
2914
  int32_t  reserved;
2915
} SAlterVnodeHashRangeReq;
2916

2917
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2918
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2919

2920
#define REQ_OPT_TBNAME 0x0
2921
#define REQ_OPT_TBUID  0x01
2922
typedef struct {
2923
  SMsgHead header;
2924
  char     dbFName[TSDB_DB_FNAME_LEN];
2925
  char     tbName[TSDB_TABLE_NAME_LEN];
2926
  uint8_t  option;
2927
  uint8_t  autoCreateCtb;
2928
} STableInfoReq;
2929

2930
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2931
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2932

2933
typedef struct {
2934
  int8_t  metaClone;  // create local clone of the cached table meta
2935
  int32_t numOfVgroups;
2936
  int32_t numOfTables;
2937
  int32_t numOfUdfs;
2938
  char    tableNames[];
2939
} SMultiTableInfoReq;
2940

2941
// todo refactor
2942
typedef struct SVgroupInfo {
2943
  int32_t  vgId;
2944
  uint32_t hashBegin;
2945
  uint32_t hashEnd;
2946
  SEpSet   epSet;
2947
  union {
2948
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2949
    int32_t taskId;      // used in stream
2950
  };
2951
} SVgroupInfo;
2952

2953
typedef struct {
2954
  int32_t     numOfVgroups;
2955
  SVgroupInfo vgroups[];
2956
} SVgroupsInfo;
2957

2958
typedef struct {
2959
  STableMetaRsp* pMeta;
2960
} SMAlterStbRsp;
2961

2962
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2963
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2964
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2965

2966
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2967
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2968
void    tFreeSTableMetaRsp(void* pRsp);
2969
void    tFreeSTableIndexRsp(void* info);
2970

2971
typedef struct {
2972
  SArray* pMetaRsp;   // Array of STableMetaRsp
2973
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2974
} SSTbHbRsp;
2975

2976
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2977
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2978
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2979

2980
typedef struct {
2981
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2982
} SViewHbRsp;
2983

2984
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2985
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2986
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2987

2988
typedef struct {
2989
  int32_t numOfTables;
2990
  int32_t numOfVgroup;
2991
  int32_t numOfUdf;
2992
  int32_t contLen;
2993
  int8_t  compressed;  // denote if compressed or not
2994
  int32_t rawLen;      // size before compress
2995
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2996
  char    meta[];
2997
} SMultiTableMeta;
2998

2999
typedef struct {
3000
  int32_t dataLen;
3001
  char    name[TSDB_TABLE_FNAME_LEN];
3002
  char*   data;
3003
} STagData;
3004

3005
typedef struct {
3006
  int32_t  opType;
3007
  uint32_t valLen;
3008
  char*    val;
3009
} SShowVariablesReq;
3010

3011
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3012
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3013
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3014

3015
typedef struct {
3016
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3017
  char value[TSDB_CONFIG_PATH_LEN + 1];
3018
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3019
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3020
  char info[TSDB_CONFIG_INFO_LEN + 1];
3021
} SVariablesInfo;
3022

3023
typedef struct {
3024
  SArray* variables;  // SArray<SVariablesInfo>
3025
} SShowVariablesRsp;
3026

3027
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3028
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3029

3030
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3031

3032
/*
3033
 * sql: show tables like '%a_%'
3034
 * payload is the query condition, e.g., '%a_%'
3035
 * payloadLen is the length of payload
3036
 */
3037
typedef struct {
3038
  int32_t type;
3039
  char    db[TSDB_DB_FNAME_LEN];
3040
  int32_t payloadLen;
3041
  char*   payload;
3042
} SShowReq;
3043

3044
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3045
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3046
void tFreeSShowReq(SShowReq* pReq);
3047

3048
typedef struct {
3049
  int64_t       showId;
3050
  STableMetaRsp tableMeta;
3051
} SShowRsp, SVShowTablesRsp;
3052

3053
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3054
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3055
// void    tFreeSShowRsp(SShowRsp* pRsp);
3056

3057
typedef struct {
3058
  char    db[TSDB_DB_FNAME_LEN];
3059
  char    tb[TSDB_TABLE_NAME_LEN];
3060
  char    user[TSDB_USER_LEN];
3061
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3062
  int64_t showId;
3063
  int64_t compactId;  // for compact
3064
  bool    withFull;   // for show users full
3065
} SRetrieveTableReq;
3066

3067
typedef struct SSysTableSchema {
3068
  int8_t   type;
3069
  col_id_t colId;
3070
  int32_t  bytes;
3071
} SSysTableSchema;
3072

3073
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3074
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3075

3076
#define RETRIEVE_TABLE_RSP_VERSION         0
3077
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3078
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3079

3080
typedef struct {
3081
  int64_t useconds;
3082
  int8_t  completed;  // all results are returned to client
3083
  int8_t  precision;
3084
  int8_t  compressed;
3085
  int8_t  streamBlockType;
3086
  int32_t payloadLen;
3087
  int32_t compLen;
3088
  int32_t numOfBlocks;
3089
  int64_t numOfRows;  // from int32_t change to int64_t
3090
  int64_t numOfCols;
3091
  int64_t skey;
3092
  int64_t ekey;
3093
  int64_t version;                         // for stream
3094
  TSKEY   watermark;                       // for stream
3095
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3096
  char    data[];
3097
} SRetrieveTableRsp;
3098

3099
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3100

3101
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3102
  do {                                          \
3103
    ((int32_t*)(_p))[0] = (_compLen);           \
3104
    ((int32_t*)(_p))[1] = (_fullLen);           \
3105
  } while (0);
3106

3107
typedef struct {
3108
  int64_t version;
3109
  int64_t numOfRows;
3110
  int8_t  compressed;
3111
  int8_t  precision;
3112
  char    data[];
3113
} SRetrieveTableRspForTmq;
3114

3115
typedef struct {
3116
  int64_t handle;
3117
  int64_t useconds;
3118
  int8_t  completed;  // all results are returned to client
3119
  int8_t  precision;
3120
  int8_t  compressed;
3121
  int32_t compLen;
3122
  int32_t numOfRows;
3123
  int32_t fullLen;
3124
  char    data[];
3125
} SRetrieveMetaTableRsp;
3126

3127
typedef struct SExplainExecInfo {
3128
  double   startupCost;
3129
  double   totalCost;
3130
  uint64_t numOfRows;
3131
  uint32_t verboseLen;
3132
  void*    verboseInfo;
3133
} SExplainExecInfo;
3134

3135
typedef struct {
3136
  int32_t           numOfPlans;
3137
  SExplainExecInfo* subplanInfo;
3138
} SExplainRsp;
3139

3140
typedef struct {
3141
  SExplainRsp rsp;
3142
  uint64_t    qId;
3143
  uint64_t    cId;
3144
  uint64_t    tId;
3145
  int64_t     rId;
3146
  int32_t     eId;
3147
} SExplainLocalRsp;
3148

3149
typedef struct STableScanAnalyzeInfo {
3150
  uint64_t totalRows;
3151
  uint64_t totalCheckedRows;
3152
  uint32_t totalBlocks;
3153
  uint32_t loadBlocks;
3154
  uint32_t loadBlockStatis;
3155
  uint32_t skipBlocks;
3156
  uint32_t filterOutBlocks;
3157
  double   elapsedTime;
3158
  double   filterTime;
3159
} STableScanAnalyzeInfo;
3160

3161
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3162
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3163
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3164

3165
typedef struct {
3166
  char    config[TSDB_DNODE_CONFIG_LEN];
3167
  char    value[TSDB_CLUSTER_VALUE_LEN];
3168
  int32_t sqlLen;
3169
  char*   sql;
3170
} SMCfgClusterReq;
3171

3172
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3173
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3174
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3175

3176
typedef struct {
3177
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3178
  int32_t port;
3179
  int32_t sqlLen;
3180
  char*   sql;
3181
} SCreateDnodeReq;
3182

3183
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3184
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3185
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3186

3187
typedef struct {
3188
  int32_t dnodeId;
3189
  char    fqdn[TSDB_FQDN_LEN];
3190
  int32_t port;
3191
  int8_t  force;
3192
  int8_t  unsafe;
3193
  int32_t sqlLen;
3194
  char*   sql;
3195
} SDropDnodeReq;
3196

3197
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3198
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3199
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3200

3201
enum {
3202
  RESTORE_TYPE__ALL = 1,
3203
  RESTORE_TYPE__MNODE,
3204
  RESTORE_TYPE__VNODE,
3205
  RESTORE_TYPE__QNODE,
3206
};
3207

3208
typedef struct {
3209
  int32_t dnodeId;
3210
  int8_t  restoreType;
3211
  int32_t sqlLen;
3212
  char*   sql;
3213
} SRestoreDnodeReq;
3214

3215
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3216
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3217
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3218

3219
typedef struct {
3220
  int32_t dnodeId;
3221
  char    config[TSDB_DNODE_CONFIG_LEN];
3222
  char    value[TSDB_DNODE_VALUE_LEN];
3223
  int32_t sqlLen;
3224
  char*   sql;
3225
} SMCfgDnodeReq;
3226

3227
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3228
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3229
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3230

3231
typedef struct {
3232
  char    config[TSDB_DNODE_CONFIG_LEN];
3233
  char    value[TSDB_DNODE_VALUE_LEN];
3234
  int32_t version;
3235
} SDCfgDnodeReq;
3236

3237
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3238
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3239

3240
typedef struct {
3241
  int32_t dnodeId;
3242
  int32_t sqlLen;
3243
  char*   sql;
3244
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3245
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3246

3247
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3248
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3249

3250
typedef struct {
3251
  int32_t nodeId;
3252
  SEpSet  epSet;
3253
} SNodeEpSet;
3254

3255
typedef struct {
3256
  int32_t    snodeId;
3257
  SNodeEpSet leaders[2];
3258
  SNodeEpSet replica;
3259
  int32_t    sqlLen;
3260
  char*      sql;
3261
} SDCreateSnodeReq;
3262

3263
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3264
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3265
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3266

3267
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3268
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3269
typedef struct {
3270
  int8_t   replica;
3271
  SReplica replicas[TSDB_MAX_REPLICA];
3272
  int8_t   learnerReplica;
3273
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3274
  int64_t  lastIndex;
3275
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3276

3277
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3278
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3279

3280
typedef struct {
3281
  int32_t urlLen;
3282
  int32_t sqlLen;
3283
  char*   url;
3284
  char*   sql;
3285
} SMCreateAnodeReq;
3286

3287
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3288
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3289
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3290

3291
typedef struct {
3292
  int32_t anodeId;
3293
  int32_t sqlLen;
3294
  char*   sql;
3295
} SMDropAnodeReq, SMUpdateAnodeReq;
3296

3297
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3298
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3299
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3300
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3301
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3302
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3303

3304
typedef struct {
3305
  int32_t dnodeId;
3306
  int32_t bnodeProto;
3307
  int32_t sqlLen;
3308
  char*   sql;
3309
} SMCreateBnodeReq, SDCreateBnodeReq;
3310

3311
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3312
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3313
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3314

3315
typedef struct {
3316
  int32_t dnodeId;
3317
  int32_t sqlLen;
3318
  char*   sql;
3319
} SMDropBnodeReq, SDDropBnodeReq;
3320

3321
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3322
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3323
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3324

3325
typedef struct {
3326
  int32_t vgId;
3327
  int32_t hbSeq;
3328
} SVArbHbReqMember;
3329

3330
typedef struct {
3331
  int32_t dnodeId;
3332
  char*   arbToken;
3333
  int64_t arbTerm;
3334
  SArray* hbMembers;  // SVArbHbReqMember
3335
} SVArbHeartBeatReq;
3336

3337
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3338
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3339
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3340

3341
typedef struct {
3342
  int32_t vgId;
3343
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3344
  int32_t hbSeq;
3345
} SVArbHbRspMember;
3346

3347
typedef struct {
3348
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3349
  int32_t dnodeId;
3350
  SArray* hbMembers;  // SVArbHbRspMember
3351
} SVArbHeartBeatRsp;
3352

3353
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3354
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3355
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3356

3357
typedef struct {
3358
  char*   arbToken;
3359
  int64_t arbTerm;
3360
  char*   member0Token;
3361
  char*   member1Token;
3362
} SVArbCheckSyncReq;
3363

3364
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3365
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3366
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3367

3368
typedef struct {
3369
  char*   arbToken;
3370
  char*   member0Token;
3371
  char*   member1Token;
3372
  int32_t vgId;
3373
  int32_t errCode;
3374
} SVArbCheckSyncRsp;
3375

3376
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3377
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3378
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3379

3380
typedef struct {
3381
  char*   arbToken;
3382
  int64_t arbTerm;
3383
  char*   memberToken;
3384
  int8_t  force;
3385
} SVArbSetAssignedLeaderReq;
3386

3387
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3388
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3389
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3390

3391
typedef struct {
3392
  char*   arbToken;
3393
  char*   memberToken;
3394
  int32_t vgId;
3395
} SVArbSetAssignedLeaderRsp;
3396

3397
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3398
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3399
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3400

3401
typedef struct {
3402
  int32_t dnodeId;
3403
  char*   token;
3404
} SMArbUpdateGroupMember;
3405

3406
typedef struct {
3407
  int32_t dnodeId;
3408
  char*   token;
3409
  int8_t  acked;
3410
} SMArbUpdateGroupAssigned;
3411

3412
typedef struct {
3413
  int32_t                  vgId;
3414
  int64_t                  dbUid;
3415
  SMArbUpdateGroupMember   members[2];
3416
  int8_t                   isSync;
3417
  int8_t                   assignedAcked;
3418
  SMArbUpdateGroupAssigned assignedLeader;
3419
  int64_t                  version;
3420
  int32_t                  code;
3421
  int64_t                  updateTimeMs;
3422
} SMArbUpdateGroup;
3423

3424
typedef struct {
3425
  SArray* updateArray;  // SMArbUpdateGroup
3426
} SMArbUpdateGroupBatchReq;
3427

3428
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3429
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3430
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3431

3432
typedef struct {
3433
  char queryStrId[TSDB_QUERY_ID_LEN];
3434
} SKillQueryReq;
3435

3436
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3437
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3438

3439
typedef struct {
3440
  uint32_t connId;
3441
} SKillConnReq;
3442

3443
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3444
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3445

3446
typedef struct {
3447
  int32_t transId;
3448
} SKillTransReq;
3449

3450
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3451
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3452

3453
typedef struct {
3454
  int32_t useless;  // useless
3455
  int32_t sqlLen;
3456
  char*   sql;
3457
} SBalanceVgroupReq;
3458

3459
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3460
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3461
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3462

3463
typedef struct {
3464
  int32_t useless;  // useless
3465
  int32_t sqlLen;
3466
  char*   sql;
3467
} SAssignLeaderReq;
3468

3469
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3470
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3471
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3472
typedef struct {
3473
  int32_t vgId1;
3474
  int32_t vgId2;
3475
} SMergeVgroupReq;
3476

3477
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3478
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3479

3480
typedef struct {
3481
  int32_t vgId;
3482
  int32_t dnodeId1;
3483
  int32_t dnodeId2;
3484
  int32_t dnodeId3;
3485
  int32_t sqlLen;
3486
  char*   sql;
3487
} SRedistributeVgroupReq;
3488

3489
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3490
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3491
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3492

3493
typedef struct {
3494
  int32_t reserved;
3495
  int32_t vgId;
3496
  int32_t sqlLen;
3497
  char*   sql;
3498
  char    db[TSDB_DB_FNAME_LEN];
3499
} SBalanceVgroupLeaderReq;
3500

3501
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3502
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3503
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3504

3505
typedef struct {
3506
  int32_t vgId;
3507
} SForceBecomeFollowerReq;
3508

3509
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3510
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3511

3512
typedef struct {
3513
  int32_t vgId;
3514
  bool    force;
3515
} SSplitVgroupReq;
3516

3517
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3518
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3519

3520
typedef struct {
3521
  char user[TSDB_USER_LEN];
3522
  char spi;
3523
  char encrypt;
3524
  char secret[TSDB_PASSWORD_LEN];
3525
  char ckey[TSDB_PASSWORD_LEN];
3526
} SAuthReq, SAuthRsp;
3527

3528
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3529
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3530

3531
typedef struct {
3532
  int32_t statusCode;
3533
  char    details[1024];
3534
} SServerStatusRsp;
3535

3536
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3537
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3538

3539
/**
3540
 * The layout of the query message payload is as following:
3541
 * +--------------------+---------------------------------+
3542
 * |Sql statement       | Physical plan                   |
3543
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3544
 * +--------------------+---------------------------------+
3545
 */
3546
typedef struct SSubQueryMsg {
3547
  SMsgHead header;
3548
  uint64_t sId;
3549
  uint64_t queryId;
3550
  uint64_t clientId;
3551
  uint64_t taskId;
3552
  int64_t  refId;
3553
  int32_t  execId;
3554
  int32_t  msgMask;
3555
  int8_t   taskType;
3556
  int8_t   explain;
3557
  int8_t   needFetch;
3558
  int8_t   compress;
3559
  uint32_t sqlLen;
3560
  char*    sql;
3561
  uint32_t msgLen;
3562
  char*    msg;
3563
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
3564
} SSubQueryMsg;
3565

3566
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3567
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3568
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3569

3570
typedef struct {
3571
  SMsgHead header;
3572
  uint64_t sId;
3573
  uint64_t queryId;
3574
  uint64_t taskId;
3575
} SSinkDataReq;
3576

3577
typedef struct {
3578
  SMsgHead header;
3579
  uint64_t sId;
3580
  uint64_t queryId;
3581
  uint64_t clientId;
3582
  uint64_t taskId;
3583
  int32_t  execId;
3584
} SQueryContinueReq;
3585

3586
typedef struct {
3587
  SMsgHead header;
3588
  uint64_t sId;
3589
  uint64_t queryId;
3590
  uint64_t taskId;
3591
} SResReadyReq;
3592

3593
typedef struct {
3594
  int32_t code;
3595
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3596
  int32_t sversion;
3597
  int32_t tversion;
3598
} SResReadyRsp;
3599

3600
typedef struct SOperatorParam {
3601
  int32_t opType;
3602
  int32_t downstreamIdx;
3603
  void*   value;
3604
  SArray* pChildren;  // SArray<SOperatorParam*>
3605
  bool    reUse;
3606
} SOperatorParam;
3607

3608
typedef struct SColIdNameKV {
3609
  col_id_t colId;
3610
  char     colName[TSDB_COL_NAME_LEN];
3611
} SColIdNameKV;
3612

3613
typedef struct SColIdPair {
3614
  col_id_t  vtbColId;
3615
  col_id_t  orgColId;
3616
  SDataType type;
3617
} SColIdPair;
3618

3619
typedef struct SColIdSlotIdPair {
3620
  int32_t  vtbSlotId;
3621
  col_id_t orgColId;
3622
} SColIdSlotIdPair;
3623

3624
typedef struct SOrgTbInfo {
3625
  int32_t vgId;
3626
  char    tbName[TSDB_TABLE_FNAME_LEN];
3627
  SArray* colMap;  // SArray<SColIdNameKV>
3628
} SOrgTbInfo;
3629

3630
typedef struct STableScanOperatorParam {
3631
  bool        tableSeq;
3632
  bool        isNewParam;
3633
  SArray*     pUidList;
3634
  SOrgTbInfo* pOrgTbInfo;
3635
  STimeWindow window;
3636
} STableScanOperatorParam;
3637

3638
typedef struct STagScanOperatorParam {
3639
  tb_uid_t vcUid;
3640
} STagScanOperatorParam;
3641

3642
typedef struct SVTableScanOperatorParam {
3643
  uint64_t        uid;
3644
  STimeWindow     window;
3645
  SOperatorParam* pTagScanOp;
3646
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3647
} SVTableScanOperatorParam;
3648

3649
typedef struct SMergeOperatorParam {
3650
  int32_t         winNum;
3651
} SMergeOperatorParam;
3652

3653
typedef struct SExternalWindowOperatorParam {
3654
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3655
} SExternalWindowOperatorParam;
3656

3657
typedef struct SDynQueryCtrlOperatorParam {
3658
  STimeWindow    window;
3659
} SDynQueryCtrlOperatorParam;
3660

3661
struct SStreamRuntimeFuncInfo;
3662
typedef struct {
3663
  SMsgHead        header;
3664
  uint64_t        sId;
3665
  uint64_t        queryId;
3666
  uint64_t        clientId;
3667
  uint64_t        taskId;
3668
  int32_t         execId;
3669
  SOperatorParam* pOpParam;
3670

3671
  // used for new-stream
3672
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3673
  bool                           reset;
3674
  bool                           dynTbname;
3675
  // used for new-stream
3676
} SResFetchReq;
3677

3678
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3679
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3680
void    tDestroySResFetchReq(SResFetchReq* pReq);
3681
typedef struct {
3682
  SMsgHead header;
3683
  uint64_t clientId;
3684
} SSchTasksStatusReq;
3685

3686
typedef struct {
3687
  uint64_t queryId;
3688
  uint64_t clientId;
3689
  uint64_t taskId;
3690
  int64_t  refId;
3691
  int32_t  subJobId;
3692
  int32_t  execId;
3693
  int8_t   status;
3694
} STaskStatus;
3695

3696
typedef struct {
3697
  int64_t refId;
3698
  SArray* taskStatus;  // SArray<STaskStatus>
3699
} SSchedulerStatusRsp;
3700

3701
typedef struct {
3702
  uint64_t queryId;
3703
  uint64_t taskId;
3704
  int8_t   action;
3705
} STaskAction;
3706

3707
typedef struct SQueryNodeEpId {
3708
  int32_t nodeId;  // vgId or qnodeId
3709
  SEp     ep;
3710
} SQueryNodeEpId;
3711

3712
typedef struct {
3713
  SMsgHead       header;
3714
  uint64_t       clientId;
3715
  SQueryNodeEpId epId;
3716
  SArray*        taskAction;  // SArray<STaskAction>
3717
} SSchedulerHbReq;
3718

3719
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3720
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3721
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3722

3723
typedef struct {
3724
  SQueryNodeEpId epId;
3725
  SArray*        taskStatus;  // SArray<STaskStatus>
3726
} SSchedulerHbRsp;
3727

3728
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3729
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3730
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3731

3732
typedef struct {
3733
  SMsgHead header;
3734
  uint64_t sId;
3735
  uint64_t queryId;
3736
  uint64_t clientId;
3737
  uint64_t taskId;
3738
  int64_t  refId;
3739
  int32_t  execId;
3740
} STaskCancelReq;
3741

3742
typedef struct {
3743
  int32_t code;
3744
} STaskCancelRsp;
3745

3746
typedef struct {
3747
  SMsgHead header;
3748
  uint64_t sId;
3749
  uint64_t queryId;
3750
  uint64_t clientId;
3751
  uint64_t taskId;
3752
  int64_t  refId;
3753
  int32_t  execId;
3754
} STaskDropReq;
3755

3756
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3757
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3758

3759
typedef enum {
3760
  TASK_NOTIFY_FINISHED = 1,
3761
} ETaskNotifyType;
3762

3763
typedef struct {
3764
  SMsgHead        header;
3765
  uint64_t        sId;
3766
  uint64_t        queryId;
3767
  uint64_t        clientId;
3768
  uint64_t        taskId;
3769
  int64_t         refId;
3770
  int32_t         execId;
3771
  ETaskNotifyType type;
3772
} STaskNotifyReq;
3773

3774
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3775
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3776

3777
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3778
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3779

3780
typedef struct {
3781
  int32_t code;
3782
} STaskDropRsp;
3783

3784
#define STREAM_TRIGGER_AT_ONCE                 1
3785
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3786
#define STREAM_TRIGGER_MAX_DELAY               3
3787
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3788
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3789

3790
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3791
#define STREAM_FILL_HISTORY_ON        1
3792
#define STREAM_FILL_HISTORY_OFF       0
3793
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3794
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3795
#define STREAM_CREATE_STABLE_TRUE     1
3796
#define STREAM_CREATE_STABLE_FALSE    0
3797

3798
typedef struct SVgroupVer {
3799
  int32_t vgId;
3800
  int64_t ver;
3801
} SVgroupVer;
3802

3803
typedef struct STaskNotifyEventStat {
3804
  int64_t notifyEventAddTimes;     // call times of add function
3805
  int64_t notifyEventAddElems;     // elements added by add function
3806
  double  notifyEventAddCostSec;   // time cost of add function
3807
  int64_t notifyEventPushTimes;    // call times of push function
3808
  int64_t notifyEventPushElems;    // elements pushed by push function
3809
  double  notifyEventPushCostSec;  // time cost of push function
3810
  int64_t notifyEventPackTimes;    // call times of pack function
3811
  int64_t notifyEventPackElems;    // elements packed by pack function
3812
  double  notifyEventPackCostSec;  // time cost of pack function
3813
  int64_t notifyEventSendTimes;    // call times of send function
3814
  int64_t notifyEventSendElems;    // elements sent by send function
3815
  double  notifyEventSendCostSec;  // time cost of send function
3816
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3817
} STaskNotifyEventStat;
3818

3819
enum {
3820
  TOPIC_SUB_TYPE__DB = 1,
3821
  TOPIC_SUB_TYPE__TABLE,
3822
  TOPIC_SUB_TYPE__COLUMN,
3823
};
3824

3825
#define DEFAULT_MAX_POLL_INTERVAL  300000
3826
#define DEFAULT_SESSION_TIMEOUT    12000
3827
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3828
#define DEFAULT_MIN_POLL_ROWS      4096
3829

3830
typedef struct {
3831
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3832
  int8_t igExists;
3833
  int8_t subType;
3834
  int8_t withMeta;
3835
  char*  sql;
3836
  char   subDbName[TSDB_DB_FNAME_LEN];
3837
  char*  ast;
3838
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3839
  int8_t reload;
3840
} SCMCreateTopicReq;
3841

3842
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3843
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3844
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3845

3846
typedef struct {
3847
  int64_t consumerId;
3848
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3849

3850
typedef struct {
3851
  int64_t consumerId;
3852
  char    cgroup[TSDB_CGROUP_LEN];
3853
  char    clientId[TSDB_CLIENT_ID_LEN];
3854
  char    user[TSDB_USER_LEN];
3855
  char    fqdn[TSDB_FQDN_LEN];
3856
  SArray* topicNames;  // SArray<char**>
3857

3858
  int8_t  withTbName;
3859
  int8_t  autoCommit;
3860
  int32_t autoCommitInterval;
3861
  int8_t  resetOffsetCfg;
3862
  int8_t  enableReplay;
3863
  int8_t  enableBatchMeta;
3864
  int32_t sessionTimeoutMs;
3865
  int32_t maxPollIntervalMs;
3866
} SCMSubscribeReq;
3867

3868
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3869
  int32_t tlen = 0;
273,212✔
3870
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
273,212✔
3871
  tlen += taosEncodeString(buf, pReq->cgroup);
273,212✔
3872
  tlen += taosEncodeString(buf, pReq->clientId);
273,212✔
3873

3874
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
273,212✔
3875
  tlen += taosEncodeFixedI32(buf, topicNum);
273,212✔
3876

3877
  for (int32_t i = 0; i < topicNum; i++) {
382,114✔
3878
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
217,804✔
3879
  }
3880

3881
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
273,212✔
3882
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
273,212✔
3883
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
273,212✔
3884
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
273,212✔
3885
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
273,212✔
3886
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
273,212✔
3887
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
273,212✔
3888
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
273,212✔
3889
  tlen += taosEncodeString(buf, pReq->user);
273,212✔
3890
  tlen += taosEncodeString(buf, pReq->fqdn);
273,212✔
3891

3892
  return tlen;
273,212✔
3893
}
3894

3895
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3896
  void* start = buf;
110,867✔
3897
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
110,867✔
3898
  buf = taosDecodeStringTo(buf, pReq->cgroup);
110,867✔
3899
  buf = taosDecodeStringTo(buf, pReq->clientId);
110,867✔
3900

3901
  int32_t topicNum = 0;
110,867✔
3902
  buf = taosDecodeFixedI32(buf, &topicNum);
110,867✔
3903

3904
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
110,867✔
3905
  if (pReq->topicNames == NULL) {
110,867✔
3906
    return terrno;
×
3907
  }
3908
  for (int32_t i = 0; i < topicNum; i++) {
159,433✔
3909
    char* name = NULL;
48,566✔
3910
    buf = taosDecodeString(buf, &name);
48,566✔
3911
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
97,132✔
3912
      return terrno;
×
3913
    }
3914
  }
3915

3916
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
110,867✔
3917
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
110,867✔
3918
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
110,867✔
3919
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
110,867✔
3920
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
110,867✔
3921
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
110,867✔
3922
  if ((char*)buf - (char*)start < len) {
110,867✔
3923
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
110,867✔
3924
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
110,867✔
3925
    buf = taosDecodeStringTo(buf, pReq->user);
110,867✔
3926
    buf = taosDecodeStringTo(buf, pReq->fqdn);
221,734✔
3927
  } else {
3928
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3929
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3930
  }
3931

3932
  return 0;
110,867✔
3933
}
3934

3935
typedef struct {
3936
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3937
  SArray* removedConsumers;  // SArray<int64_t>
3938
  SArray* newConsumers;      // SArray<int64_t>
3939
} SMqRebInfo;
3940

3941
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3942
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
85,018✔
3943
  if (pRebInfo == NULL) {
85,018✔
3944
    return NULL;
×
3945
  }
3946
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
85,018✔
3947
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
85,018✔
3948
  if (pRebInfo->removedConsumers == NULL) {
85,018✔
3949
    goto _err;
×
3950
  }
3951
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
85,018✔
3952
  if (pRebInfo->newConsumers == NULL) {
85,018✔
3953
    goto _err;
×
3954
  }
3955
  return pRebInfo;
85,018✔
3956
_err:
×
3957
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3958
  taosArrayDestroy(pRebInfo->newConsumers);
×
3959
  taosMemoryFreeClear(pRebInfo);
×
3960
  return NULL;
×
3961
}
3962

3963
typedef struct {
3964
  int64_t streamId;
3965
  int64_t checkpointId;
3966
  char    streamName[TSDB_STREAM_FNAME_LEN];
3967
} SMStreamDoCheckpointMsg;
3968

3969
typedef struct {
3970
  int64_t status;
3971
} SMVSubscribeRsp;
3972

3973
typedef struct {
3974
  char    name[TSDB_TOPIC_FNAME_LEN];
3975
  int8_t  igNotExists;
3976
  int32_t sqlLen;
3977
  char*   sql;
3978
  int8_t  force;
3979
} SMDropTopicReq;
3980

3981
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3982
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3983
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3984

3985
typedef struct {
3986
  char    name[TSDB_TOPIC_FNAME_LEN];
3987
  int8_t  igNotExists;
3988
  int32_t sqlLen;
3989
  char*   sql;
3990
} SMReloadTopicReq;
3991

3992
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3993
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3994
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
3995

3996
typedef struct {
3997
  char   topic[TSDB_TOPIC_FNAME_LEN];
3998
  char   cgroup[TSDB_CGROUP_LEN];
3999
  int8_t igNotExists;
4000
  int8_t force;
4001
} SMDropCgroupReq;
4002

4003
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4004
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4005

4006
typedef struct {
4007
  int8_t reserved;
4008
} SMDropCgroupRsp;
4009

4010
typedef struct {
4011
  char    name[TSDB_TABLE_FNAME_LEN];
4012
  int8_t  alterType;
4013
  SSchema schema;
4014
} SAlterTopicReq;
4015

4016
typedef struct {
4017
  SMsgHead head;
4018
  char     name[TSDB_TABLE_FNAME_LEN];
4019
  int64_t  tuid;
4020
  int32_t  sverson;
4021
  int32_t  execLen;
4022
  char*    executor;
4023
  int32_t  sqlLen;
4024
  char*    sql;
4025
} SDCreateTopicReq;
4026

4027
typedef struct {
4028
  SMsgHead head;
4029
  char     name[TSDB_TABLE_FNAME_LEN];
4030
  int64_t  tuid;
4031
} SDDropTopicReq;
4032

4033
typedef struct {
4034
  char*      name;
4035
  int64_t    uid;
4036
  int64_t    interval[2];
4037
  int8_t     intervalUnit;
4038
  int16_t    nFuncs;
4039
  col_id_t*  funcColIds;  // column ids specified by user
4040
  func_id_t* funcIds;     // function ids specified by user
4041
} SRSmaParam;
4042

4043
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4044
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4045

4046
// TDMT_VND_CREATE_STB ==============
4047
typedef struct SVCreateStbReq {
4048
  char*           name;
4049
  tb_uid_t        suid;
4050
  int8_t          rollup;
4051
  SSchemaWrapper  schemaRow;
4052
  SSchemaWrapper  schemaTag;
4053
  SRSmaParam      rsmaParam;
4054
  int32_t         alterOriDataLen;
4055
  void*           alterOriData;
4056
  int8_t          source;
4057
  int8_t          colCmpred;
4058
  SColCmprWrapper colCmpr;
4059
  int64_t         keep;
4060
  SExtSchema*     pExtSchemas;
4061
  int8_t          virtualStb;
4062
} SVCreateStbReq;
4063

4064
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4065
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4066

4067
// TDMT_VND_DROP_STB ==============
4068
typedef struct SVDropStbReq {
4069
  char*    name;
4070
  tb_uid_t suid;
4071
} SVDropStbReq;
4072

4073
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4074
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4075

4076
// TDMT_VND_CREATE_TABLE ==============
4077
#define TD_CREATE_IF_NOT_EXISTS       0x1
4078
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4079
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4080
typedef struct SVCreateTbReq {
4081
  int32_t  flags;
4082
  char*    name;
4083
  tb_uid_t uid;
4084
  int64_t  btime;
4085
  int32_t  ttl;
4086
  int32_t  commentLen;
4087
  char*    comment;
4088
  int8_t   type;
4089
  union {
4090
    struct {
4091
      char*    stbName;  // super table name
4092
      uint8_t  tagNum;
4093
      tb_uid_t suid;
4094
      SArray*  tagName;
4095
      uint8_t* pTag;
4096
    } ctb;
4097
    struct {
4098
      SSchemaWrapper schemaRow;
4099
    } ntb;
4100
  };
4101
  int32_t         sqlLen;
4102
  char*           sql;
4103
  SColCmprWrapper colCmpr;
4104
  SExtSchema*     pExtSchemas;
4105
  SColRefWrapper  colRef;  // col reference for virtual table
4106
} SVCreateTbReq;
4107

4108
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4109
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4110
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4111
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4112

4113
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4114
  if (NULL == req) {
2,147,483,647✔
4115
    return;
2,147,483,647✔
4116
  }
4117

4118
  taosMemoryFreeClear(req->sql);
56,887,224✔
4119
  taosMemoryFreeClear(req->name);
56,887,542✔
4120
  taosMemoryFreeClear(req->comment);
56,886,997✔
4121
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
56,881,352✔
4122
    taosMemoryFreeClear(req->ctb.pTag);
54,256,148✔
4123
    taosMemoryFreeClear(req->ctb.stbName);
54,240,045✔
4124
    taosArrayDestroy(req->ctb.tagName);
54,255,941✔
4125
    req->ctb.tagName = NULL;
54,248,685✔
4126
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,628,884✔
4127
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,628,493✔
4128
  }
4129
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
56,878,953✔
4130
  taosMemoryFreeClear(req->pExtSchemas);
56,886,046✔
4131
  taosMemoryFreeClear(req->colRef.pColRef);
56,882,732✔
4132
}
4133

4134
typedef struct {
4135
  int32_t nReqs;
4136
  union {
4137
    SVCreateTbReq* pReqs;
4138
    SArray*        pArray;
4139
  };
4140
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4141
} SVCreateTbBatchReq;
4142

4143
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4144
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4145
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4146

4147
typedef struct {
4148
  int32_t        code;
4149
  STableMetaRsp* pMeta;
4150
} SVCreateTbRsp, SVUpdateTbRsp;
4151

4152
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4153
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4154
void tFreeSVCreateTbRsp(void* param);
4155

4156
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4157
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4158

4159
typedef struct {
4160
  int32_t nRsps;
4161
  union {
4162
    SVCreateTbRsp* pRsps;
4163
    SArray*        pArray;
4164
  };
4165
} SVCreateTbBatchRsp;
4166

4167
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4168
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4169

4170
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4171
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4172

4173
// TDMT_VND_DROP_TABLE =================
4174
typedef struct {
4175
  char*    name;
4176
  uint64_t suid;  // for tmq in wal format
4177
  int64_t  uid;
4178
  int8_t   igNotExists;
4179
  int8_t   isVirtual;
4180
} SVDropTbReq;
4181

4182
typedef struct {
4183
  int32_t code;
4184
} SVDropTbRsp;
4185

4186
typedef struct {
4187
  int32_t nReqs;
4188
  union {
4189
    SVDropTbReq* pReqs;
4190
    SArray*      pArray;
4191
  };
4192
} SVDropTbBatchReq;
4193

4194
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4195
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4196

4197
typedef struct {
4198
  int32_t nRsps;
4199
  union {
4200
    SVDropTbRsp* pRsps;
4201
    SArray*      pArray;
4202
  };
4203
} SVDropTbBatchRsp;
4204

4205
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4206
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4207

4208
// TDMT_VND_ALTER_TABLE =====================
4209
typedef struct SMultiTagUpateVal {
4210
  char*    tagName;
4211
  int32_t  colId;
4212
  int8_t   tagType;
4213
  int8_t   tagFree;
4214
  uint32_t nTagVal;
4215
  uint8_t* pTagVal;
4216
  int8_t   isNull;
4217
  SArray*  pTagArray;
4218
} SMultiTagUpateVal;
4219
typedef struct SVAlterTbReq {
4220
  char*   tbName;
4221
  int8_t  action;
4222
  char*   colName;
4223
  int32_t colId;
4224
  // TSDB_ALTER_TABLE_ADD_COLUMN
4225
  int8_t  type;
4226
  int8_t  flags;
4227
  int32_t bytes;
4228
  // TSDB_ALTER_TABLE_DROP_COLUMN
4229
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4230
  int8_t   colModType;
4231
  int32_t  colModBytes;
4232
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4233
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4234
  int8_t   isNull;
4235
  int8_t   tagType;
4236
  int8_t   tagFree;
4237
  uint32_t nTagVal;
4238
  uint8_t* pTagVal;
4239
  SArray*  pTagArray;
4240
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4241
  int8_t   updateTTL;
4242
  int32_t  newTTL;
4243
  int32_t  newCommentLen;
4244
  char*    newComment;
4245
  int64_t  ctimeMs;    // fill by vnode
4246
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4247
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4248
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4249
  // for Add column
4250
  STypeMod typeMod;
4251
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4252
  char* refDbName;
4253
  char* refTbName;
4254
  char* refColName;
4255
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4256
} SVAlterTbReq;
4257

4258
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4259
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4260
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4261
void    tfreeMultiTagUpateVal(void* pMultiTag);
4262

4263
typedef struct {
4264
  int32_t        code;
4265
  STableMetaRsp* pMeta;
4266
} SVAlterTbRsp;
4267

4268
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4269
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4270
// ======================
4271

4272
typedef struct {
4273
  SMsgHead head;
4274
  int64_t  uid;
4275
  int32_t  tid;
4276
  int16_t  tversion;
4277
  int16_t  colId;
4278
  int8_t   type;
4279
  int16_t  bytes;
4280
  int32_t  tagValLen;
4281
  int16_t  numOfTags;
4282
  int32_t  schemaLen;
4283
  char     data[];
4284
} SUpdateTagValReq;
4285

4286
typedef struct {
4287
  SMsgHead head;
4288
} SUpdateTagValRsp;
4289

4290
typedef struct {
4291
  SMsgHead head;
4292
} SVShowTablesReq;
4293

4294
typedef struct {
4295
  SMsgHead head;
4296
  int32_t  id;
4297
} SVShowTablesFetchReq;
4298

4299
typedef struct {
4300
  int64_t useconds;
4301
  int8_t  completed;  // all results are returned to client
4302
  int8_t  precision;
4303
  int8_t  compressed;
4304
  int32_t compLen;
4305
  int32_t numOfRows;
4306
  char    data[];
4307
} SVShowTablesFetchRsp;
4308

4309
typedef struct {
4310
  int64_t consumerId;
4311
  int32_t epoch;
4312
  char    cgroup[TSDB_CGROUP_LEN];
4313
} SMqAskEpReq;
4314

4315
typedef struct {
4316
  int32_t key;
4317
  int32_t valueLen;
4318
  void*   value;
4319
} SKv;
4320

4321
typedef struct {
4322
  int64_t tscRid;
4323
  int8_t  connType;
4324
} SClientHbKey;
4325

4326
typedef struct {
4327
  int64_t tid;
4328
  char    status[TSDB_JOB_STATUS_LEN];
4329
} SQuerySubDesc;
4330

4331
typedef struct {
4332
  char     sql[TSDB_SHOW_SQL_LEN];
4333
  uint64_t queryId;
4334
  int64_t  useconds;
4335
  int64_t  stime;  // timestamp precision ms
4336
  int64_t  reqRid;
4337
  bool     stableQuery;
4338
  bool     isSubQuery;
4339
  char     fqdn[TSDB_FQDN_LEN];
4340
  int32_t  subPlanNum;
4341
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4342
} SQueryDesc;
4343

4344
typedef struct {
4345
  uint32_t connId;
4346
  SArray*  queryDesc;  // SArray<SQueryDesc>
4347
} SQueryHbReqBasic;
4348

4349
typedef struct {
4350
  uint32_t connId;
4351
  uint64_t killRid;
4352
  int32_t  totalDnodes;
4353
  int32_t  onlineDnodes;
4354
  int8_t   killConnection;
4355
  int8_t   align[3];
4356
  SEpSet   epSet;
4357
  SArray*  pQnodeList;
4358
} SQueryHbRspBasic;
4359

4360
typedef struct SAppClusterSummary {
4361
  uint64_t numOfInsertsReq;
4362
  uint64_t numOfInsertRows;
4363
  uint64_t insertElapsedTime;
4364
  uint64_t insertBytes;  // submit to tsdb since launched.
4365

4366
  uint64_t fetchBytes;
4367
  uint64_t numOfQueryReq;
4368
  uint64_t queryElapsedTime;
4369
  uint64_t numOfSlowQueries;
4370
  uint64_t totalRequests;
4371
  uint64_t currentRequests;  // the number of SRequestObj
4372
} SAppClusterSummary;
4373

4374
typedef struct {
4375
  int64_t            appId;
4376
  int32_t            pid;
4377
  char               name[TSDB_APP_NAME_LEN];
4378
  int64_t            startTime;
4379
  SAppClusterSummary summary;
4380
} SAppHbReq;
4381

4382
typedef struct {
4383
  SClientHbKey      connKey;
4384
  int64_t           clusterId;
4385
  SAppHbReq         app;
4386
  SQueryHbReqBasic* query;
4387
  SHashObj*         info;  // hash<Skv.key, Skv>
4388
  char              userApp[TSDB_APP_NAME_LEN];
4389
  uint32_t          userIp;
4390
  SIpRange          userDualIp;
4391
  char              sVer[TSDB_VERSION_LEN];
4392
  char              cInfo[CONNECTOR_INFO_LEN];
4393
} SClientHbReq;
4394

4395
typedef struct {
4396
  int64_t reqId;
4397
  SArray* reqs;  // SArray<SClientHbReq>
4398
  int64_t ipWhiteListVer;
4399
} SClientHbBatchReq;
4400

4401
typedef struct {
4402
  SClientHbKey      connKey;
4403
  int32_t           status;
4404
  SQueryHbRspBasic* query;
4405
  SArray*           info;  // Array<Skv>
4406
} SClientHbRsp;
4407

4408
typedef struct {
4409
  int64_t       reqId;
4410
  int64_t       rspId;
4411
  int32_t       svrTimestamp;
4412
  SArray*       rsps;  // SArray<SClientHbRsp>
4413
  SMonitorParas monitorParas;
4414
  int8_t        enableAuditDelete;
4415
  int8_t        enableStrongPass;
4416
  int8_t        enableAuditSelect;
4417
  int8_t        enableAuditInsert;
4418
  int8_t        auditLevel;
4419
} SClientHbBatchRsp;
4420

4421
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
98,665,966✔
4422

4423
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4424
  void* pIter = taosHashIterate(info, NULL);
67,061,497✔
4425
  while (pIter != NULL) {
152,401,228✔
4426
    SKv* kv = (SKv*)pIter;
85,339,589✔
4427
    taosMemoryFreeClear(kv->value);
85,339,589✔
4428
    pIter = taosHashIterate(info, pIter);
85,339,802✔
4429
  }
4430
}
67,061,639✔
4431

4432
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
41,277,591✔
4433
  SQueryDesc* desc = (SQueryDesc*)pDesc;
41,277,591✔
4434
  if (desc->subDesc) {
41,277,591✔
4435
    taosArrayDestroy(desc->subDesc);
30,605,711✔
4436
    desc->subDesc = NULL;
30,605,110✔
4437
  }
4438
}
41,277,276✔
4439

4440
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
77,312,967✔
4441
  SClientHbReq* req = (SClientHbReq*)pReq;
80,598,381✔
4442
  if (req->query) {
80,598,381✔
4443
    if (req->query->queryDesc) {
77,312,949✔
4444
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
38,019,008✔
4445
    }
4446
    taosMemoryFreeClear(req->query);
77,312,967✔
4447
  }
4448

4449
  if (req->info) {
80,598,202✔
4450
    tFreeReqKvHash(req->info);
67,061,548✔
4451
    taosHashCleanup(req->info);
67,061,639✔
4452
    req->info = NULL;
67,061,627✔
4453
  }
4454
}
39,355,409✔
4455

4456
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4457
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4458

4459
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4460
  if (pReq == NULL) return;
34,328,827✔
4461
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
34,328,827✔
4462
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
34,328,827✔
4463
  taosMemoryFree(pReq);
34,328,827✔
4464
}
4465

4466
static FORCE_INLINE void tFreeClientKv(void* pKv) {
30,253,046✔
4467
  SKv* kv = (SKv*)pKv;
30,253,046✔
4468
  if (kv) {
30,253,046✔
4469
    taosMemoryFreeClear(kv->value);
30,253,046✔
4470
  }
4471
}
30,253,046✔
4472

4473
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
77,039,674✔
4474
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
77,039,674✔
4475
  if (rsp->query) {
77,039,674✔
4476
    taosArrayDestroy(rsp->query->pQnodeList);
77,037,424✔
4477
    taosMemoryFreeClear(rsp->query);
77,035,285✔
4478
  }
4479
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
77,043,398✔
4480
}
40,971,097✔
4481

4482
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4483
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
62,554,655✔
4484
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
62,554,655✔
4485
}
62,555,781✔
4486

4487
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4488
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4489
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4490

4491
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4492
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
233,375,256✔
4493
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
233,375,048✔
4494
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
233,375,256✔
4495
  return 0;
116,687,732✔
4496
}
4497

4498
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4499
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
108,095,280✔
4500
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
108,095,572✔
4501
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
54,047,786✔
4502
  if (pKv->value == NULL) {
54,047,786✔
4503
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4504
  }
4505
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
54,047,786✔
4506
  return 0;
54,047,786✔
4507
}
4508

4509
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4510
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
300,359,982✔
4511
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
300,357,715✔
4512
  return 0;
150,178,132✔
4513
}
4514

4515
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4516
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
149,652,241✔
4517
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
149,652,471✔
4518
  return 0;
74,826,870✔
4519
}
4520

4521
typedef struct {
4522
  int32_t vgId;
4523
  // TODO stas
4524
} SMqReportVgInfo;
4525

4526
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4527
  int32_t tlen = 0;
4528
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4529
  return tlen;
4530
}
4531

4532
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4533
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4534
  return buf;
4535
}
4536

4537
typedef struct {
4538
  int32_t epoch;
4539
  int64_t topicUid;
4540
  char    name[TSDB_TOPIC_FNAME_LEN];
4541
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4542
} SMqTopicInfo;
4543

4544
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4545
  int32_t tlen = 0;
4546
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4547
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4548
  tlen += taosEncodeString(buf, pTopicInfo->name);
4549
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4550
  tlen += taosEncodeFixedI32(buf, sz);
4551
  for (int32_t i = 0; i < sz; i++) {
4552
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4553
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4554
  }
4555
  return tlen;
4556
}
4557

4558
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4559
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4560
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4561
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4562
  int32_t sz;
4563
  buf = taosDecodeFixedI32(buf, &sz);
4564
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4565
    return NULL;
4566
  }
4567
  for (int32_t i = 0; i < sz; i++) {
4568
    SMqReportVgInfo vgInfo;
4569
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4570
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4571
      return NULL;
4572
    }
4573
  }
4574
  return buf;
4575
}
4576

4577
typedef struct {
4578
  int32_t status;  // ask hb endpoint
4579
  int32_t epoch;
4580
  int64_t consumerId;
4581
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4582
} SMqReportReq;
4583

4584
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4585
  int32_t tlen = 0;
4586
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4587
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4588
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4589
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4590
  tlen += taosEncodeFixedI32(buf, sz);
4591
  for (int32_t i = 0; i < sz; i++) {
4592
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4593
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4594
  }
4595
  return tlen;
4596
}
4597

4598
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4599
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4600
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4601
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4602
  int32_t sz;
4603
  buf = taosDecodeFixedI32(buf, &sz);
4604
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4605
    return NULL;
4606
  }
4607
  for (int32_t i = 0; i < sz; i++) {
4608
    SMqTopicInfo topicInfo;
4609
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4610
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4611
      return NULL;
4612
    }
4613
  }
4614
  return buf;
4615
}
4616

4617
typedef struct {
4618
  SMsgHead head;
4619
  int64_t  leftForVer;
4620
  int32_t  vgId;
4621
  int64_t  consumerId;
4622
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4623
} SMqVDeleteReq;
4624

4625
typedef struct {
4626
  int8_t reserved;
4627
} SMqVDeleteRsp;
4628

4629
typedef struct {
4630
  char*  name;
4631
  int8_t igNotExists;
4632
} SMDropStreamReq;
4633

4634
typedef struct {
4635
  int8_t reserved;
4636
} SMDropStreamRsp;
4637

4638
typedef struct {
4639
  SMsgHead head;
4640
  int64_t  resetRelHalt;  // reset related stream task halt status
4641
  int64_t  streamId;
4642
  int32_t  taskId;
4643
} SVDropStreamTaskReq;
4644

4645
typedef struct {
4646
  int8_t reserved;
4647
} SVDropStreamTaskRsp;
4648

4649
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4650
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4651
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4652

4653
typedef struct {
4654
  char*  name;
4655
  int8_t igNotExists;
4656
} SMPauseStreamReq;
4657

4658
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4659
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4660
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4661

4662
typedef struct {
4663
  char*  name;
4664
  int8_t igNotExists;
4665
  int8_t igUntreated;
4666
} SMResumeStreamReq;
4667

4668
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4669
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4670
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4671

4672
typedef struct {
4673
  char*       name;
4674
  int8_t      calcAll;
4675
  STimeWindow timeRange;
4676
} SMRecalcStreamReq;
4677

4678
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4679
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4680
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4681

4682
typedef struct SVndSetKeepVersionReq {
4683
  int64_t keepVersion;
4684
} SVndSetKeepVersionReq;
4685

4686
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4687
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4688

4689
typedef struct SVUpdateCheckpointInfoReq {
4690
  SMsgHead head;
4691
  int64_t  streamId;
4692
  int32_t  taskId;
4693
  int64_t  checkpointId;
4694
  int64_t  checkpointVer;
4695
  int64_t  checkpointTs;
4696
  int32_t  transId;
4697
  int64_t  hStreamId;  // add encode/decode
4698
  int64_t  hTaskId;
4699
  int8_t   dropRelHTask;
4700
} SVUpdateCheckpointInfoReq;
4701

4702
typedef struct {
4703
  int64_t leftForVer;
4704
  int32_t vgId;
4705
  int64_t oldConsumerId;
4706
  int64_t newConsumerId;
4707
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4708
  int8_t  subType;
4709
  int8_t  withMeta;
4710
  char*   qmsg;  // SubPlanToString
4711
  SSchemaWrapper schema;
4712
  int64_t suid;
4713
} SMqRebVgReq;
4714

4715
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4716
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4717

4718
// tqOffset
4719
enum {
4720
  TMQ_OFFSET__RESET_NONE = -3,
4721
  TMQ_OFFSET__RESET_EARLIEST = -2,
4722
  TMQ_OFFSET__RESET_LATEST = -1,
4723
  TMQ_OFFSET__LOG = 1,
4724
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4725
  TMQ_OFFSET__SNAPSHOT_META = 3,
4726
};
4727

4728
enum {
4729
  WITH_DATA = 0,
4730
  WITH_META = 1,
4731
  ONLY_META = 2,
4732
};
4733

4734
#define TQ_OFFSET_VERSION 1
4735

4736
typedef struct {
4737
  int8_t type;
4738
  union {
4739
    // snapshot
4740
    struct {
4741
      int64_t uid;
4742
      int64_t ts;
4743
      SValue  primaryKey;
4744
    };
4745
    // log
4746
    struct {
4747
      int64_t version;
4748
    };
4749
  };
4750
} STqOffsetVal;
4751

4752
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4753
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,693,673✔
4754
  pOffsetVal->uid = uid;
1,693,560✔
4755
  pOffsetVal->ts = ts;
1,693,106✔
4756
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,692,937✔
4757
    taosMemoryFree(pOffsetVal->primaryKey.pData);
68✔
4758
  }
4759
  pOffsetVal->primaryKey = primaryKey;
1,692,093✔
4760
}
1,692,464✔
4761

4762
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4763
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
8,111✔
4764
  pOffsetVal->uid = uid;
8,111✔
4765
}
8,111✔
4766

4767
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4768
  pOffsetVal->type = TMQ_OFFSET__LOG;
47,073,200✔
4769
  pOffsetVal->version = ver;
47,073,364✔
4770
}
47,068,087✔
4771

4772
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4773
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4774
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4775
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4776
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4777
void    tOffsetDestroy(void* pVal);
4778

4779
typedef struct {
4780
  STqOffsetVal val;
4781
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4782
} STqOffset;
4783

4784
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4785
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4786
void    tDeleteSTqOffset(void* val);
4787

4788
typedef struct SMqVgOffset {
4789
  int64_t   consumerId;
4790
  STqOffset offset;
4791
} SMqVgOffset;
4792

4793
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4794
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4795

4796
typedef struct {
4797
  char    name[TSDB_TABLE_FNAME_LEN];
4798
  char    stb[TSDB_TABLE_FNAME_LEN];
4799
  int8_t  igExists;
4800
  int8_t  intervalUnit;
4801
  int8_t  slidingUnit;
4802
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4803
  int32_t dstVgId;   // for stream
4804
  int64_t interval;
4805
  int64_t offset;
4806
  int64_t sliding;
4807
  int64_t maxDelay;
4808
  int64_t watermark;
4809
  int32_t exprLen;        // strlen + 1
4810
  int32_t tagsFilterLen;  // strlen + 1
4811
  int32_t sqlLen;         // strlen + 1
4812
  int32_t astLen;         // strlen + 1
4813
  char*   expr;
4814
  char*   tagsFilter;
4815
  char*   sql;
4816
  char*   ast;
4817
  int64_t deleteMark;
4818
  int64_t lastTs;
4819
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4820
  SArray* pVgroupVerList;
4821
  int8_t  recursiveTsma;
4822
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4823
  char*   createStreamReq;
4824
  int32_t streamReqLen;
4825
  char*   dropStreamReq;
4826
  int32_t dropStreamReqLen;
4827
  int64_t uid;
4828
} SMCreateSmaReq;
4829

4830
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4831
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4832
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4833

4834
typedef struct {
4835
  char    name[TSDB_TABLE_FNAME_LEN];
4836
  int8_t  igNotExists;
4837
  char*   dropStreamReq;
4838
  int32_t dropStreamReqLen;
4839
} SMDropSmaReq;
4840

4841
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4842
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4843
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
4844

4845
typedef struct {
4846
  char name[TSDB_TABLE_NAME_LEN];
4847
  union {
4848
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4849
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4850
  };
4851
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4852
  union {
4853
    int8_t igExists;   // used by mnode
4854
    int8_t alterType;  // used by vnode
4855
  };
4856
  int8_t     intervalUnit;
4857
  int16_t    nFuncs;       // number of functions specified by user
4858
  col_id_t*  funcColIds;   // column ids specified by user
4859
  func_id_t* funcIds;      // function ids specified by user
4860
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4861
  int64_t    tbUid;
4862
  int64_t    uid;     // rsma uid
4863
  int32_t    sqlLen;  // strlen + 1
4864
  char*      sql;
4865
} SMCreateRsmaReq;
4866

4867
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4868
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4869
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4870

4871
typedef SMCreateRsmaReq SVCreateRsmaReq;
4872

4873
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4874
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4875
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4876

4877
typedef SMCreateRsmaReq SVAlterRsmaReq;
4878

4879
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4880
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4881
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4882

4883
typedef struct {
4884
  char       name[TSDB_TABLE_NAME_LEN];
4885
  int8_t     alterType;
4886
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4887
  int8_t     igNotExists;
4888
  int16_t    nFuncs;      // number of functions specified by user
4889
  col_id_t*  funcColIds;  // column ids specified by user
4890
  func_id_t* funcIds;     // function ids specified by user
4891
  int32_t    sqlLen;      // strlen + 1
4892
  char*      sql;
4893
} SMAlterRsmaReq;
4894

4895
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4896
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4897
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4898

4899
typedef struct {
4900
  int64_t    id;
4901
  char       name[TSDB_TABLE_NAME_LEN];
4902
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4903
  int32_t    code;
4904
  int32_t    version;
4905
  int8_t     tbType;
4906
  int8_t     intervalUnit;
4907
  col_id_t   nFuncs;
4908
  col_id_t   nColNames;
4909
  int64_t    interval[2];
4910
  col_id_t*  funcColIds;
4911
  func_id_t* funcIds;
4912
  SArray*    colNames;
4913
} SRsmaInfoRsp;
4914

4915
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4916
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4917
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4918

4919
typedef struct {
4920
  char   name[TSDB_TABLE_FNAME_LEN];
4921
  int8_t igNotExists;
4922
} SMDropRsmaReq;
4923

4924
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4925
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4926

4927
typedef struct {
4928
  char    name[TSDB_TABLE_NAME_LEN];
4929
  char    tbName[TSDB_TABLE_NAME_LEN];
4930
  int64_t uid;
4931
  int64_t tbUid;
4932
  int8_t  tbType;
4933
} SVDropRsmaReq;
4934

4935
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4936
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4937

4938
typedef struct {
4939
  char   dbFName[TSDB_DB_FNAME_LEN];
4940
  char   stbName[TSDB_TABLE_NAME_LEN];
4941
  char   colName[TSDB_COL_NAME_LEN];
4942
  char   idxName[TSDB_INDEX_FNAME_LEN];
4943
  int8_t idxType;
4944
} SCreateTagIndexReq;
4945

4946
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4947
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4948

4949
typedef SMDropSmaReq SDropTagIndexReq;
4950

4951
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4952
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4953

4954
typedef struct {
4955
  int8_t         version;       // for compatibility(default 0)
4956
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4957
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4958
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4959
  int32_t        dstVgId;
4960
  char           indexName[TSDB_INDEX_NAME_LEN];
4961
  int32_t        exprLen;
4962
  int32_t        tagsFilterLen;
4963
  int64_t        indexUid;
4964
  tb_uid_t       tableUid;  // super/child/common table uid
4965
  tb_uid_t       dstTbUid;  // for dstVgroup
4966
  int64_t        interval;
4967
  int64_t        offset;  // use unit by precision of DB
4968
  int64_t        sliding;
4969
  char*          dstTbName;  // for dstVgroup
4970
  char*          expr;       // sma expression
4971
  char*          tagsFilter;
4972
  SSchemaWrapper schemaRow;  // for dstVgroup
4973
  SSchemaWrapper schemaTag;  // for dstVgroup
4974
} STSma;                     // Time-range-wise SMA
4975

4976
typedef STSma SVCreateTSmaReq;
4977

4978
typedef struct {
4979
  int8_t  type;  // 0 status report, 1 update data
4980
  int64_t indexUid;
4981
  int64_t skey;  // start TS key of interval/sliding window
4982
} STSmaMsg;
4983

4984
typedef struct {
4985
  int64_t indexUid;
4986
  char    indexName[TSDB_INDEX_NAME_LEN];
4987
} SVDropTSmaReq;
4988

4989
typedef struct {
4990
  int tmp;  // TODO: to avoid compile error
4991
} SVCreateTSmaRsp, SVDropTSmaRsp;
4992

4993
#if 0
4994
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4995
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4996
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4997
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4998
#endif
4999

5000
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5001
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5002
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5003
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5004

5005
typedef struct {
5006
  int32_t number;
5007
  STSma*  tSma;
5008
} STSmaWrapper;
5009

5010
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5011
  if (pSma) {
×
5012
    taosMemoryFreeClear(pSma->dstTbName);
×
5013
    taosMemoryFreeClear(pSma->expr);
×
5014
    taosMemoryFreeClear(pSma->tagsFilter);
×
5015
  }
5016
}
×
5017

5018
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5019
  if (pSW) {
×
5020
    if (pSW->tSma) {
×
5021
      if (deepCopy) {
×
5022
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5023
          tDestroyTSma(pSW->tSma + i);
×
5024
        }
5025
      }
5026
      taosMemoryFreeClear(pSW->tSma);
×
5027
    }
5028
  }
5029
}
×
5030

5031
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5032
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5033
  taosMemoryFreeClear(pSW);
×
5034
  return NULL;
×
5035
}
5036

5037
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5038
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5039

5040
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5041
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5042

5043
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5044
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5045
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5046
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5047
  }
5048
  return 0;
×
5049
}
5050

5051
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5052
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5053
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5054
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5055
  }
5056
  return 0;
×
5057
}
5058

5059
typedef struct {
5060
  int idx;
5061
} SMCreateFullTextReq;
5062

5063
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5064
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5065
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5066

5067
typedef struct {
5068
  char   name[TSDB_TABLE_FNAME_LEN];
5069
  int8_t igNotExists;
5070
} SMDropFullTextReq;
5071

5072
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5073
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5074

5075
typedef struct {
5076
  char indexFName[TSDB_INDEX_FNAME_LEN];
5077
} SUserIndexReq;
5078

5079
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5080
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5081

5082
typedef struct {
5083
  char dbFName[TSDB_DB_FNAME_LEN];
5084
  char tblFName[TSDB_TABLE_FNAME_LEN];
5085
  char colName[TSDB_COL_NAME_LEN];
5086
  char indexType[TSDB_INDEX_TYPE_LEN];
5087
  char indexExts[TSDB_INDEX_EXTS_LEN];
5088
} SUserIndexRsp;
5089

5090
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5091
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5092

5093
typedef struct {
5094
  char tbFName[TSDB_TABLE_FNAME_LEN];
5095
} STableIndexReq;
5096

5097
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5098
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5099

5100
typedef struct {
5101
  int8_t  intervalUnit;
5102
  int8_t  slidingUnit;
5103
  int64_t interval;
5104
  int64_t offset;
5105
  int64_t sliding;
5106
  int64_t dstTbUid;
5107
  int32_t dstVgId;
5108
  SEpSet  epSet;
5109
  char*   expr;
5110
} STableIndexInfo;
5111

5112
typedef struct {
5113
  char     tbName[TSDB_TABLE_NAME_LEN];
5114
  char     dbFName[TSDB_DB_FNAME_LEN];
5115
  uint64_t suid;
5116
  int32_t  version;
5117
  int32_t  indexSize;
5118
  SArray*  pIndex;  // STableIndexInfo
5119
} STableIndexRsp;
5120

5121
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5122
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5123
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5124

5125
void tFreeSTableIndexInfo(void* pInfo);
5126

5127
typedef struct {
5128
  int8_t  mqMsgType;
5129
  int32_t code;
5130
  int32_t epoch;
5131
  int64_t consumerId;
5132
  int64_t walsver;
5133
  int64_t walever;
5134
} SMqRspHead;
5135

5136
typedef struct {
5137
  SMsgHead     head;
5138
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5139
  int8_t       withTbName;
5140
  int8_t       useSnapshot;
5141
  int32_t      epoch;
5142
  uint64_t     reqId;
5143
  int64_t      consumerId;
5144
  int64_t      timeout;
5145
  STqOffsetVal reqOffset;
5146
  int8_t       enableReplay;
5147
  int8_t       sourceExcluded;
5148
  int8_t       rawData;
5149
  int32_t      minPollRows;
5150
  int8_t       enableBatchMeta;
5151
  SHashObj*    uidHash;  // to find if uid is duplicated
5152
} SMqPollReq;
5153

5154
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5155
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5156
void    tDestroySMqPollReq(SMqPollReq* pReq);
5157

5158
typedef struct {
5159
  int32_t vgId;
5160
  int64_t offset;
5161
  SEpSet  epSet;
5162
} SMqSubVgEp;
5163

5164
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5165
  int32_t tlen = 0;
367,492✔
5166
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
367,492✔
5167
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
367,492✔
5168
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
367,492✔
5169
  return tlen;
367,492✔
5170
}
5171

5172
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5173
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
205,086✔
5174
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
205,086✔
5175
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
205,086✔
5176
  return buf;
205,086✔
5177
}
5178

5179
typedef struct {
5180
  char           topic[TSDB_TOPIC_FNAME_LEN];
5181
  char           db[TSDB_DB_FNAME_LEN];
5182
  SArray*        vgs;  // SArray<SMqSubVgEp>
5183
} SMqSubTopicEp;
5184

5185
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5186
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5187
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5188

5189
typedef struct {
5190
  SMqRspHead   head;
5191
  STqOffsetVal rspOffset;
5192
  int16_t      resMsgType;
5193
  int32_t      metaRspLen;
5194
  void*        metaRsp;
5195
} SMqMetaRsp;
5196

5197
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5198
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5199
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5200

5201
#define MQ_DATA_RSP_VERSION 100
5202

5203
typedef struct {
5204
  SMqRspHead   head;
5205
  STqOffsetVal rspOffset;
5206
  STqOffsetVal reqOffset;
5207
  int32_t      blockNum;
5208
  int8_t       withTbName;
5209
  int8_t       withSchema;
5210
  SArray*      blockDataLen;
5211
  SArray*      blockData;
5212
  SArray*      blockTbName;
5213
  SArray*      blockSchema;
5214

5215
  union {
5216
    struct {
5217
      int64_t sleepTime;
5218
    };
5219
    struct {
5220
      int32_t createTableNum;
5221
      SArray* createTableLen;
5222
      SArray* createTableReq;
5223
    };
5224
    struct {
5225
      int32_t len;
5226
      void*   rawData;
5227
    };
5228
  };
5229
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5230
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5231
} SMqDataRsp;
5232

5233
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5234
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5235
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5236
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5237
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5238

5239
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5240
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5241
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5242

5243
typedef struct SMqBatchMetaRsp {
5244
  SMqRspHead   head;  // not serialize
5245
  STqOffsetVal rspOffset;
5246
  SArray*      batchMetaLen;
5247
  SArray*      batchMetaReq;
5248
  void*        pMetaBuff;    // not serialize
5249
  uint32_t     metaBuffLen;  // not serialize
5250
} SMqBatchMetaRsp;
5251

5252
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5253
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5254
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5255
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5256

5257
typedef struct {
5258
  int32_t    code;
5259
  SArray*    topics;  // SArray<SMqSubTopicEp>
5260
} SMqAskEpRsp;
5261

5262
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5263
  int32_t tlen = 0;
4,044,522✔
5264
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5265
  int32_t sz = taosArrayGetSize(pRsp->topics);
4,044,522✔
5266
  tlen += taosEncodeFixedI32(buf, sz);
4,044,522✔
5267
  for (int32_t i = 0; i < sz; i++) {
4,237,514✔
5268
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
193,304✔
5269
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
193,304✔
5270
  }
5271
  tlen += taosEncodeFixedI32(buf, pRsp->code);
4,044,210✔
5272

5273
  return tlen;
4,044,418✔
5274
}
5275

5276
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5277
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5278
  int32_t sz;
1,033,709✔
5279
  buf = taosDecodeFixedI32(buf, &sz);
1,129,144✔
5280
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
1,129,144✔
5281
  if (pRsp->topics == NULL) {
1,129,144✔
5282
    return NULL;
×
5283
  }
5284
  for (int32_t i = 0; i < sz; i++) {
1,261,288✔
5285
    SMqSubTopicEp topicEp;
115,322✔
5286
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
132,144✔
5287
    if (buf == NULL) {
132,144✔
5288
      return NULL;
×
5289
    }
5290
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
264,288✔
5291
      return NULL;
×
5292
    }
5293
  }
5294
  buf = taosDecodeFixedI32(buf, &pRsp->code);
1,129,144✔
5295

5296
  return buf;
1,129,144✔
5297
}
5298

5299
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5300
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
3,880,317✔
5301
}
3,880,109✔
5302

5303
typedef struct {
5304
  int32_t      vgId;
5305
  STqOffsetVal offset;
5306
  int64_t      rows;
5307
  int64_t      ever;
5308
} OffsetRows;
5309

5310
typedef struct {
5311
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5312
  SArray* offsetRows;
5313
} TopicOffsetRows;
5314

5315
typedef struct {
5316
  int64_t consumerId;
5317
  int32_t epoch;
5318
  SArray* topics;
5319
  int8_t  pollFlag;
5320
} SMqHbReq;
5321

5322
typedef struct {
5323
  char   topic[TSDB_TOPIC_FNAME_LEN];
5324
  int8_t noPrivilege;
5325
} STopicPrivilege;
5326

5327
typedef struct {
5328
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5329
  int32_t debugFlag;
5330
} SMqHbRsp;
5331

5332
typedef struct {
5333
  SMsgHead head;
5334
  int64_t  consumerId;
5335
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5336
} SMqSeekReq;
5337

5338
#define TD_AUTO_CREATE_TABLE 0x1
5339
typedef struct {
5340
  int64_t       suid;
5341
  int64_t       uid;
5342
  int32_t       sver;
5343
  uint32_t      nData;
5344
  uint8_t*      pData;
5345
  SVCreateTbReq cTbReq;
5346
} SVSubmitBlk;
5347

5348
typedef struct {
5349
  SMsgHead header;
5350
  uint64_t sId;
5351
  uint64_t queryId;
5352
  uint64_t clientId;
5353
  uint64_t taskId;
5354
  uint32_t sqlLen;
5355
  uint32_t phyLen;
5356
  char*    sql;
5357
  char*    msg;
5358
  int8_t   source;
5359
} SVDeleteReq;
5360

5361
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5362
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5363

5364
typedef struct {
5365
  int64_t affectedRows;
5366
} SVDeleteRsp;
5367

5368
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5369
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5370

5371
typedef struct SDeleteRes {
5372
  uint64_t suid;
5373
  SArray*  uidList;
5374
  int64_t  skey;
5375
  int64_t  ekey;
5376
  int64_t  affectedRows;
5377
  char     tableFName[TSDB_TABLE_NAME_LEN];
5378
  char     tsColName[TSDB_COL_NAME_LEN];
5379
  int64_t  ctimeMs;  // fill by vnode
5380
  int8_t   source;
5381
} SDeleteRes;
5382

5383
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5384
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5385

5386
typedef struct {
5387
  // int64_t uid;
5388
  char    tbname[TSDB_TABLE_NAME_LEN];
5389
  int64_t startTs;
5390
  int64_t endTs;
5391
} SSingleDeleteReq;
5392

5393
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5394
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5395

5396
typedef struct {
5397
  int64_t suid;
5398
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5399
  int64_t ctimeMs;     // fill by vnode
5400
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5401
} SBatchDeleteReq;
5402

5403
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5404
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5405
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5406

5407
typedef struct {
5408
  int32_t msgIdx;
5409
  int32_t msgType;
5410
  int32_t msgLen;
5411
  void*   msg;
5412
} SBatchMsg;
5413

5414
typedef struct {
5415
  SMsgHead header;
5416
  SArray*  pMsgs;  // SArray<SBatchMsg>
5417
} SBatchReq;
5418

5419
typedef struct {
5420
  int32_t reqType;
5421
  int32_t msgIdx;
5422
  int32_t msgLen;
5423
  int32_t rspCode;
5424
  void*   msg;
5425
} SBatchRspMsg;
5426

5427
typedef struct {
5428
  SArray* pRsps;  // SArray<SBatchRspMsg>
5429
} SBatchRsp;
5430

5431
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5432
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5433
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
94,419,102✔
5434
  if (NULL == msg) {
94,419,102✔
5435
    return;
×
5436
  }
5437
  SBatchMsg* pMsg = (SBatchMsg*)msg;
94,419,102✔
5438
  taosMemoryFree(pMsg->msg);
94,419,102✔
5439
}
5440

5441
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5442
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5443

5444
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
132,279,898✔
5445
  if (NULL == p) {
132,279,898✔
5446
    return;
×
5447
  }
5448

5449
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
132,279,898✔
5450
  taosMemoryFree(pRsp->msg);
132,279,898✔
5451
}
5452

5453
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5454
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5455
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5456
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5457
void    tDestroySMqHbReq(SMqHbReq* pReq);
5458

5459
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5460
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5461
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5462

5463
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5464
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5465

5466
#define TD_REQ_FROM_APP               0x0
5467
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5468
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5469
#define SUBMIT_REQ_FROM_FILE          0x4
5470
#define TD_REQ_FROM_TAOX              0x8
5471
#define TD_REQ_FROM_SML               0x10
5472
#define SUBMIT_REQUEST_VERSION        (2)
5473
#define SUBMIT_REQ_WITH_BLOB          0x10
5474
#define SUBMIT_REQ_SCHEMA_RES         0x20
5475
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5476

5477
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5478

5479
typedef struct {
5480
  int32_t        flags;
5481
  SVCreateTbReq* pCreateTbReq;
5482
  int64_t        suid;
5483
  int64_t        uid;
5484
  int32_t        sver;
5485
  union {
5486
    SArray* aRowP;
5487
    SArray* aCol;
5488
  };
5489
  int64_t   ctimeMs;
5490
  SBlobSet* pBlobSet;
5491
} SSubmitTbData;
5492

5493
typedef struct {
5494
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5495
  SArray* aSubmitBlobData;
5496
  bool    raw;
5497
} SSubmitReq2;
5498

5499
typedef struct {
5500
  SMsgHead header;
5501
  int64_t  version;
5502
  char     data[];  // SSubmitReq2
5503
} SSubmitReq2Msg;
5504

5505
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5506
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5507
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5508
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5509
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5510

5511
typedef struct {
5512
  int32_t affectedRows;
5513
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5514
} SSubmitRsp2;
5515

5516
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5517
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5518
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5519

5520
#define TSDB_MSG_FLG_ENCODE 0x1
5521
#define TSDB_MSG_FLG_DECODE 0x2
5522
#define TSDB_MSG_FLG_CMPT   0x3
5523

5524
typedef struct {
5525
  union {
5526
    struct {
5527
      void*   msgStr;
5528
      int32_t msgLen;
5529
      int64_t ver;
5530
    };
5531
    void* pDataBlock;
5532
  };
5533
} SPackedData;
5534

5535
typedef struct {
5536
  char     fullname[TSDB_VIEW_FNAME_LEN];
5537
  char     name[TSDB_VIEW_NAME_LEN];
5538
  char     dbFName[TSDB_DB_FNAME_LEN];
5539
  char*    querySql;
5540
  char*    sql;
5541
  int8_t   orReplace;
5542
  int8_t   precision;
5543
  int32_t  numOfCols;
5544
  SSchema* pSchema;
5545
} SCMCreateViewReq;
5546

5547
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5548
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5549
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5550

5551
typedef struct {
5552
  char   fullname[TSDB_VIEW_FNAME_LEN];
5553
  char   name[TSDB_VIEW_NAME_LEN];
5554
  char   dbFName[TSDB_DB_FNAME_LEN];
5555
  char*  sql;
5556
  int8_t igNotExists;
5557
} SCMDropViewReq;
5558

5559
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5560
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5561
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5562

5563
typedef struct {
5564
  char fullname[TSDB_VIEW_FNAME_LEN];
5565
} SViewMetaReq;
5566
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5567
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5568

5569
typedef struct {
5570
  char     name[TSDB_VIEW_NAME_LEN];
5571
  char     dbFName[TSDB_DB_FNAME_LEN];
5572
  char*    user;
5573
  uint64_t dbId;
5574
  uint64_t viewId;
5575
  char*    querySql;
5576
  int8_t   precision;
5577
  int8_t   type;
5578
  int32_t  version;
5579
  int32_t  numOfCols;
5580
  SSchema* pSchema;
5581
} SViewMetaRsp;
5582
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5583
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5584
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5585
typedef struct {
5586
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5587
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5588
} STableTSMAInfoReq;
5589

5590
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5591
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5592

5593
typedef struct {
5594
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5595
  union {
5596
    uint8_t flags;
5597
    struct {
5598
      uint8_t withColName : 1;
5599
      uint8_t reserved : 7;
5600
    };
5601
  };
5602

5603
} SRsmaInfoReq;
5604

5605
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5606
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5607

5608
typedef struct {
5609
  int32_t  funcId;
5610
  col_id_t colId;
5611
} STableTSMAFuncInfo;
5612

5613
typedef struct {
5614
  char     name[TSDB_TABLE_NAME_LEN];
5615
  uint64_t tsmaId;
5616
  char     targetTb[TSDB_TABLE_NAME_LEN];
5617
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5618
  char     tb[TSDB_TABLE_NAME_LEN];
5619
  char     dbFName[TSDB_DB_FNAME_LEN];
5620
  uint64_t suid;
5621
  uint64_t destTbUid;
5622
  uint64_t dbId;
5623
  int32_t  version;
5624
  int64_t  interval;
5625
  int8_t   unit;
5626
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5627
  SArray*  pTags;      // SArray<SSchema>
5628
  SArray*  pUsedCols;  // SArray<SSchema>
5629
  char*    ast;
5630

5631
  int64_t streamUid;
5632
  int64_t reqTs;
5633
  int64_t rspTs;
5634
  int64_t delayDuration;  // ms
5635
  bool    fillHistoryFinished;
5636

5637
  void* streamAddr;  // for stream task, the address of the stream task
5638
} STableTSMAInfo;
5639

5640
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5641
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5642
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5643
void    tFreeTableTSMAInfo(void* p);
5644
void    tFreeAndClearTableTSMAInfo(void* p);
5645
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5646

5647
#define STSMAHbRsp            STableTSMAInfoRsp
5648
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5649
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5650
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5651

5652
typedef struct SDropCtbWithTsmaSingleVgReq {
5653
  SVgroupInfo vgInfo;
5654
  SArray*     pTbs;  // SVDropTbReq
5655
} SMDropTbReqsOnSingleVg;
5656

5657
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5658
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5659
void    tFreeSMDropTbReqOnSingleVg(void* p);
5660

5661
typedef struct SDropTbsReq {
5662
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5663
} SMDropTbsReq;
5664

5665
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5666
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5667
void    tFreeSMDropTbsReq(void*);
5668

5669
typedef struct SVFetchTtlExpiredTbsRsp {
5670
  SArray* pExpiredTbs;  // SVDropTbReq
5671
  int32_t vgId;
5672
} SVFetchTtlExpiredTbsRsp;
5673

5674
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5675
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5676

5677
void tFreeFetchTtlExpiredTbsRsp(void* p);
5678

5679
void setDefaultOptionsForField(SFieldWithOptions* field);
5680
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5681

5682
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5683
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5684

5685
typedef struct {
5686
  char    id[TSDB_INSTANCE_ID_LEN];
5687
  char    type[TSDB_INSTANCE_TYPE_LEN];
5688
  char    desc[TSDB_INSTANCE_DESC_LEN];
5689
  int32_t expire;
5690
} SInstanceRegisterReq;
5691

5692
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5693
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5694

5695
typedef struct {
5696
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5697
} SInstanceListReq;
5698

5699
typedef struct {
5700
  int32_t count;
5701
  char**  ids;  // Array of instance IDs
5702
} SInstanceListRsp;
5703

5704
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5705
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5706
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5707
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5708

5709
#ifdef USE_MOUNT
5710
typedef struct {
5711
  char     mountName[TSDB_MOUNT_NAME_LEN];
5712
  int8_t   ignoreExist;
5713
  int16_t  nMounts;
5714
  int32_t* dnodeIds;
5715
  char**   mountPaths;
5716
  int32_t  sqlLen;
5717
  char*    sql;
5718
} SCreateMountReq;
5719

5720
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5721
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5722
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5723

5724
typedef struct {
5725
  char    mountName[TSDB_MOUNT_NAME_LEN];
5726
  int8_t  ignoreNotExists;
5727
  int32_t sqlLen;
5728
  char*   sql;
5729
} SDropMountReq;
5730

5731
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5732
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5733
void    tFreeSDropMountReq(SDropMountReq* pReq);
5734

5735
typedef struct {
5736
  char     mountName[TSDB_MOUNT_NAME_LEN];
5737
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5738
  int64_t  mountUid;
5739
  int32_t  dnodeId;
5740
  uint32_t valLen;
5741
  int8_t   ignoreExist;
5742
  void*    pVal;
5743
} SRetrieveMountPathReq;
5744

5745
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5746
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5747

5748
typedef struct {
5749
  // path
5750
  int32_t diskPrimary;
5751
  // vgInfo
5752
  int32_t  vgId;
5753
  int32_t  cacheLastSize;
5754
  int32_t  szPage;
5755
  int32_t  szCache;
5756
  uint64_t szBuf;
5757
  int8_t   cacheLast;
5758
  int8_t   standby;
5759
  int8_t   hashMethod;
5760
  uint32_t hashBegin;
5761
  uint32_t hashEnd;
5762
  int16_t  hashPrefix;
5763
  int16_t  hashSuffix;
5764
  int16_t  sttTrigger;
5765
  // syncInfo
5766
  int32_t replications;
5767
  // tsdbInfo
5768
  int8_t  precision;
5769
  int8_t  compression;
5770
  int8_t  slLevel;
5771
  int32_t daysPerFile;
5772
  int32_t keep0;
5773
  int32_t keep1;
5774
  int32_t keep2;
5775
  int32_t keepTimeOffset;
5776
  int32_t minRows;
5777
  int32_t maxRows;
5778
  int32_t tsdbPageSize;
5779
  int32_t ssChunkSize;
5780
  int32_t ssKeepLocal;
5781
  int8_t  ssCompact;
5782
  // walInfo
5783
  int32_t walFsyncPeriod;      // millisecond
5784
  int32_t walRetentionPeriod;  // secs
5785
  int32_t walRollPeriod;       // secs
5786
  int64_t walRetentionSize;
5787
  int64_t walSegSize;
5788
  int32_t walLevel;
5789
  // encryptInfo
5790
  int32_t encryptAlgorithm;
5791
  // SVState
5792
  int64_t committed;
5793
  int64_t commitID;
5794
  int64_t commitTerm;
5795
  // stats
5796
  int64_t numOfSTables;
5797
  int64_t numOfCTables;
5798
  int64_t numOfNTables;
5799
  // dbInfo
5800
  uint64_t dbId;
5801
} SMountVgInfo;
5802

5803
typedef struct {
5804
  SMCreateStbReq req;
5805
  SArray*        pColExts;  // element: column id
5806
  SArray*        pTagExts;  // element: tag id
5807
} SMountStbInfo;
5808

5809
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5810
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5811

5812
typedef struct {
5813
  char     dbName[TSDB_DB_FNAME_LEN];
5814
  uint64_t dbId;
5815
  SArray*  pVgs;   // SMountVgInfo
5816
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5817
} SMountDbInfo;
5818

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

5830
  // response fields
5831
  SArray* pDbs;  // SMountDbInfo
5832

5833
  // memory fields, no serialized
5834
  SArray*   pDisks[TFS_MAX_TIERS];
5835
  TdFilePtr pFile;
5836
} SMountInfo;
5837

5838
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5839
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5840
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5841

5842
typedef struct {
5843
  SCreateVnodeReq createReq;
5844
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5845
  char            mountName[TSDB_MOUNT_NAME_LEN];
5846
  int64_t         mountId;
5847
  int32_t         diskPrimary;
5848
  int32_t         mountVgId;
5849
  int64_t         committed;
5850
  int64_t         commitID;
5851
  int64_t         commitTerm;
5852
  int64_t         numOfSTables;
5853
  int64_t         numOfCTables;
5854
  int64_t         numOfNTables;
5855
} SMountVnodeReq;
5856

5857
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
5858
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5859
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5860

5861
#endif  // USE_MOUNT
5862

5863
#pragma pack(pop)
5864

5865
typedef struct {
5866
  char        db[TSDB_DB_FNAME_LEN];
5867
  STimeWindow timeRange;
5868
  int32_t     sqlLen;
5869
  char*       sql;
5870
  SArray*     vgroupIds;
5871
} SScanDbReq;
5872

5873
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5874
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5875
void    tFreeSScanDbReq(SScanDbReq* pReq);
5876

5877
typedef struct {
5878
  int32_t scanId;
5879
  int8_t  bAccepted;
5880
} SScanDbRsp;
5881

5882
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5883
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5884

5885
typedef struct {
5886
  int32_t scanId;
5887
  int32_t sqlLen;
5888
  char*   sql;
5889
} SKillScanReq;
5890

5891
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5892
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5893
void    tFreeSKillScanReq(SKillScanReq* pReq);
5894

5895
typedef struct {
5896
  int32_t scanId;
5897
  int32_t vgId;
5898
  int32_t dnodeId;
5899
} SVKillScanReq;
5900

5901
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5902
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5903

5904
typedef struct {
5905
  int32_t scanId;
5906
  int32_t vgId;
5907
  int32_t dnodeId;
5908
  int32_t numberFileset;
5909
  int32_t finished;
5910
  int32_t progress;
5911
  int64_t remainingTime;
5912
} SQueryScanProgressRsp;
5913

5914
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5915
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5916

5917
typedef struct {
5918
  int32_t scanId;
5919
  int32_t vgId;
5920
  int32_t dnodeId;
5921
} SQueryScanProgressReq;
5922

5923
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5924
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5925

5926
typedef struct {
5927
  int64_t     dbUid;
5928
  char        db[TSDB_DB_FNAME_LEN];
5929
  int64_t     scanStartTime;
5930
  STimeWindow tw;
5931
  int32_t     scanId;
5932
} SScanVnodeReq;
5933

5934
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5935
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5936

5937
#ifdef __cplusplus
5938
}
5939
#endif
5940

5941
#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