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

taosdata / TDengine / #4886

16 Dec 2025 01:13AM UTC coverage: 65.292% (+0.03%) from 65.258%
#4886

push

travis-ci

web-flow
fix: compile error (#33938)

178718 of 273721 relevant lines covered (65.29%)

103311111.65 hits per line

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

84.31
/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;
1,380✔
105
}
106

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

109
static inline bool vnodeIsMsgBlock(tmsg_t type) {
783,785,729✔
110
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
726,906,633✔
111
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,510,692,362✔
112
         (type == TDMT_SYNC_CONFIG_CHANGE);
113
}
114

115
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,992,697,687✔
116
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,992,697,687✔
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

892
bool hasExtSchema(const SExtSchema* pExtSchema);
893

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

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

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

912
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
913
  if (pRef->pColRef) {
346,126✔
914
    return TSDB_CODE_INVALID_PARA;
×
915
  }
916
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
346,126✔
917
  if (pRef->pColRef == NULL) {
346,126✔
918
    return terrno;
×
919
  }
920
  pRef->nCols = nCols;
346,126✔
921
  for (int32_t i = 0; i < nCols; i++) {
135,388,622✔
922
    pRef->pColRef[i].hasRef = false;
135,042,496✔
923
    pRef->pColRef[i].id = (col_id_t)(i + 1);
135,042,496✔
924
  }
925
  return 0;
346,126✔
926
}
927

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

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

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

949
  return pDstWrapper;
950
}
951

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

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

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

985
  taosMemoryFreeClear(pWrapper->pColCmpr);
986
  taosMemoryFreeClear(pWrapper);
987
}
988
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
989
  if (pSchemaWrapper->pSchema == NULL) return NULL;
326,600,018✔
990

991
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
326,525,624✔
992
  if (pSW == NULL) {
326,544,803✔
993
    return NULL;
×
994
  }
995
  pSW->nCols = pSchemaWrapper->nCols;
326,544,803✔
996
  pSW->version = pSchemaWrapper->version;
326,520,164✔
997
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
326,612,960✔
998
  if (pSW->pSchema == NULL) {
326,452,142✔
999
    taosMemoryFree(pSW);
×
1000
    return NULL;
×
1001
  }
1002

1003
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
326,454,693✔
1004
  return pSW;
326,626,346✔
1005
}
1006

1007
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
122,940,212✔
1008
  if (pSchemaWrapper) {
891,782,634✔
1009
    taosMemoryFree(pSchemaWrapper->pSchema);
504,473,770✔
1010
    if (pSchemaWrapper->pRsma) {
504,408,959✔
1011
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
27,864✔
1012
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
27,864✔
1013
    }
1014
    taosMemoryFree(pSchemaWrapper);
504,420,829✔
1015
  }
1016
}
877,083,676✔
1017

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

1028
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,307,462✔
1029
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,307,462✔
1030
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
1,307,462✔
1031
  }
1032
}
1,306,837✔
1033

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

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

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

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

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

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

1085
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1086
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
684,523,480✔
1087
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
684,523,480✔
1088
  if (pColRef->hasRef) {
342,261,740✔
1089
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
409,705,844✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
409,705,844✔
1091
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
409,705,844✔
1092
  }
1093
  return 0;
342,261,740✔
1094
}
1095

1096
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1097
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
343,823,292✔
1098
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
343,823,292✔
1099
  if (pColRef->hasRef) {
171,911,646✔
1100
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
102,955,359✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
102,955,359✔
1102
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
102,955,359✔
1103
  }
1104

1105
  return 0;
171,911,646✔
1106
}
1107

1108
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1109
  int32_t tlen = 0;
176,446✔
1110
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
176,446✔
1111
  tlen += taosEncodeVariantI32(buf, pSW->version);
176,446✔
1112
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,552,880✔
1113
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
2,752,868✔
1114
  }
1115
  return tlen;
176,446✔
1116
}
1117

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

1127
    for (int32_t i = 0; i < pSW->nCols; i++) {
660,421✔
1128
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
1,173,666✔
1129
    }
1130
  } else {
1131
    pSW->pSchema = NULL;
×
1132
  }
1133
  return (void*)buf;
73,588✔
1134
}
1135

1136
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1137
  if (pSW == NULL) {
396,518,563✔
1138
    return TSDB_CODE_INVALID_PARA;
×
1139
  }
1140
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
793,030,430✔
1141
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
792,943,115✔
1142
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1143
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1144
  }
1145
  return 0;
396,654,986✔
1146
}
1147

1148
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1149
  if (pSW == NULL) {
118,962,961✔
1150
    return TSDB_CODE_INVALID_PARA;
×
1151
  }
1152
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
237,854,726✔
1153
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
237,805,043✔
1154

1155
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
118,913,278✔
1156
  if (pSW->pSchema == NULL) {
118,858,583✔
1157
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1158
  }
1159
  for (int32_t i = 0; i < pSW->nCols; i++) {
908,443,566✔
1160
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,578,999,275✔
1161
  }
1162

1163
  return 0;
118,986,850✔
1164
}
1165

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

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

1178
  return 0;
1,464,489,511✔
1179
}
1180

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1307
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1308
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1309

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

1321
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1322
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1323

1324
typedef struct {
1325
  char    user[TSDB_USER_LEN];
1326
  int32_t sqlLen;
1327
  char*   sql;
1328
} SDropUserReq, SDropAcctReq;
1329

1330
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1331
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1332
void    tFreeSDropUserReq(SDropUserReq* pReq);
1333

1334
typedef struct {
1335
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1336
  int32_t sqlLen;
1337
  char*   sql;
1338
} SDropEncryptAlgrReq;
1339

1340
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1341
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1342
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1343

1344
typedef struct SIpV4Range {
1345
  uint32_t ip;
1346
  uint32_t mask;
1347
} SIpV4Range;
1348

1349
typedef struct SIpv6Range {
1350
  uint64_t addr[2];
1351
  uint32_t mask;
1352
} SIpV6Range;
1353

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

1363
typedef struct {
1364
  int32_t    num;
1365
  SIpV4Range pIpRange[];
1366
} SIpWhiteList;
1367

1368
typedef struct {
1369
  int32_t  num;
1370
  SIpRange pIpRanges[];
1371
} SIpWhiteListDual;
1372

1373
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1374
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1375
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1376
int32_t           createDefaultIp6Range(SIpRange* pRange);
1377
int32_t           createDefaultIp4Range(SIpRange* pRange);
1378

1379
typedef struct {
1380
  int32_t sessPerUser;
1381
  int32_t sessConnTime;
1382
  int32_t sessConnIdleTime;
1383
  int32_t sessMaxConcurrency;
1384
  int32_t sessMaxCallVnodeNum;
1385
} SUserSessCfg;
1386

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

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

1403
bool isValidDateTimeRange(SDateTimeRange* pRange);
1404
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1405
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1406

1407

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

1416
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1417
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1418

1419
typedef struct {
1420
  int32_t num;
1421
  SDateTimeWhiteListItem ranges[];
1422
} SDateTimeWhiteList;
1423

1424
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1425
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1426

1427

1428
typedef struct {
1429
  int8_t createType;
1430
  int8_t superUser;  // denote if it is a super user or not
1431
  int8_t ignoreExisting;
1432

1433
  char   user[TSDB_USER_LEN];
1434
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1435
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1436

1437
  int8_t sysInfo;
1438
  int8_t createDb;
1439
  int8_t isImport;
1440
  int8_t changepass;
1441
  int8_t enable;
1442

1443
  int8_t negIpRanges;
1444
  int8_t negTimeRanges;
1445

1446
  int32_t sessionPerUser;
1447
  int32_t connectTime;
1448
  int32_t connectIdleTime;
1449
  int32_t callPerSession;
1450
  int32_t vnodePerCall;
1451
  int32_t failedLoginAttempts;
1452
  int32_t passwordLifeTime;
1453
  int32_t passwordReuseTime;
1454
  int32_t passwordReuseMax;
1455
  int32_t passwordLockTime;
1456
  int32_t passwordGraceTime;
1457
  int32_t inactiveAccountTime;
1458
  int32_t allowTokenNum;
1459

1460
  int32_t         numIpRanges;
1461
  SIpRange*       pIpDualRanges;
1462
  int32_t         numTimeRanges;
1463
  SDateTimeRange* pTimeRanges;
1464

1465
  int32_t sqlLen;
1466
  char*   sql;
1467
} SCreateUserReq;
1468

1469
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1470
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1471
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1472

1473
typedef struct {
1474
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1475
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1476
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1477
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1478
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1479
  int32_t sqlLen;
1480
  char*   sql;
1481
} SCreateEncryptAlgrReq;
1482

1483
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1484
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1485
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1486

1487
typedef struct {
1488
  int32_t dnodeId;
1489
  int64_t analVer;
1490
} SRetrieveAnalyticsAlgoReq;
1491

1492
typedef struct {
1493
  int64_t   ver;
1494
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1495
} SRetrieveAnalyticAlgoRsp;
1496

1497
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1498
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1499
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1500
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1501
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1502

1503
typedef struct {
1504
  int8_t alterType;
1505

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

1528
  int8_t enable;
1529
  int8_t sysinfo;
1530
  int8_t createdb;
1531
  int8_t changepass;
1532

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

1550
  int32_t         numIpRanges;
1551
  int32_t         numTimeRanges;
1552
  int32_t         numDropIpRanges;
1553
  int32_t         numDropTimeRanges;
1554
  SIpRange*       pIpRanges;
1555
  SDateTimeRange* pTimeRanges;
1556
  SIpRange*       pDropIpRanges;
1557
  SDateTimeRange* pDropTimeRanges;
1558

1559
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1560
  char        tabName[TSDB_TABLE_NAME_LEN];
1561
  char*       tagCond;
1562
  int32_t     tagCondLen;
1563
  int32_t     sqlLen;
1564
  char*       sql;
1565
  int64_t     privileges;
1566
} SAlterUserReq;
1567

1568
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1569
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1570
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1571

1572
typedef struct {
1573
  char user[TSDB_USER_LEN];
1574
} SGetUserAuthReq;
1575

1576
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1577
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1578

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

1599
  SUserSessCfg sessCfg;
1600
  int64_t      timeWhiteListVer;
1601
} SGetUserAuthRsp;
1602

1603
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1604
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1605
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1606

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

1619
typedef struct {
1620
  int64_t             ver;
1621
  int                 numOfUser;
1622
  SUpdateUserIpWhite* pUserIpWhite;
1623
} SUpdateIpWhite;
1624

1625
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1626
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1627
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1628
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1629

1630
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1631
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1632
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1633

1634

1635
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1636
// corresponding response struct is different.
1637
typedef struct {
1638
  int64_t ver;
1639
} SRetrieveWhiteListReq;
1640

1641
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1642
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1643

1644

1645
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1646
// corresponding response struct is different.
1647
typedef struct {
1648
  char user[TSDB_USER_LEN];
1649
} SGetUserWhiteListReq;
1650

1651
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1652
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1653

1654
typedef struct {
1655
  char    user[TSDB_USER_LEN];
1656
  int32_t numWhiteLists;
1657
  union {
1658
    SIpV4Range* pWhiteLists;
1659
    SIpRange*   pWhiteListsDual;
1660
  };
1661
} SGetUserIpWhiteListRsp;
1662

1663
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1664
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1665
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1666
void    tIpRangeSetDefaultMask(SIpRange* range);
1667

1668
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1669
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1670
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1671

1672
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1673
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1674
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1675

1676
typedef struct {
1677
  int64_t ver;
1678
  char    user[TSDB_USER_LEN];
1679
  int32_t numWhiteLists;
1680
  SDateTimeWhiteListItem* pWhiteLists;
1681
} SUserDateTimeWhiteList;
1682

1683

1684
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1685
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1686
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1687
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1688

1689
typedef struct {
1690
  int64_t             ver;
1691
  int                 numOfUser;
1692
  SUserDateTimeWhiteList *pUsers;
1693
} SRetrieveDateTimeWhiteListRsp;
1694

1695
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1696
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1697
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1698
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1699

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

1710
  uint8_t precision;
1711
  uint8_t scale;
1712
  int32_t bytes;
1713
  int8_t  type;
1714
  uint8_t pk;
1715
  bool    noData;
1716
} SColumnInfo;
1717

1718
typedef struct STimeWindow {
1719
  TSKEY skey;
1720
  TSKEY ekey;
1721
} STimeWindow;
1722

1723
typedef struct SQueryHint {
1724
  bool batchScan;
1725
} SQueryHint;
1726

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

1734
typedef struct {
1735
  void*       timezone;
1736
  char        intervalUnit;
1737
  char        slidingUnit;
1738
  char        offsetUnit;
1739
  int8_t      precision;
1740
  int64_t     interval;
1741
  int64_t     sliding;
1742
  int64_t     offset;
1743
  STimeWindow timeRange;
1744
} SInterval;
1745

1746
typedef struct STbVerInfo {
1747
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1748
  int32_t sversion;
1749
  int32_t tversion;
1750
  int32_t rversion;  // virtual table's column ref's version
1751
} STbVerInfo;
1752

1753
typedef struct {
1754
  int32_t code;
1755
  int64_t affectedRows;
1756
  SArray* tbVerInfo;  // STbVerInfo
1757
} SQueryTableRsp;
1758

1759
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1760

1761
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1762

1763
typedef struct {
1764
  SMsgHead header;
1765
  char     dbFName[TSDB_DB_FNAME_LEN];
1766
  char     tbName[TSDB_TABLE_NAME_LEN];
1767
} STableCfgReq;
1768

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

1793
typedef STableCfg STableCfgRsp;
1794

1795
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1796
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1797

1798
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1799
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1800
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1801

1802
typedef struct {
1803
  SMsgHead header;
1804
  tb_uid_t suid;
1805
} SVSubTablesReq;
1806

1807
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1808
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1809

1810
typedef struct {
1811
  int32_t vgId;
1812
  SArray* pTables;  // SArray<SVCTableRefCols*>
1813
} SVSubTablesRsp;
1814

1815
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1816
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1817
void    tDestroySVSubTablesRsp(void* rsp);
1818

1819
typedef struct {
1820
  SMsgHead header;
1821
  tb_uid_t suid;
1822
} SVStbRefDbsReq;
1823

1824
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1825
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1826

1827
typedef struct {
1828
  int32_t vgId;
1829
  SArray* pDbs;  // SArray<char* (db name)>
1830
} SVStbRefDbsRsp;
1831

1832
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1833
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1834
void    tDestroySVStbRefDbsRsp(void* rsp);
1835

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

1886
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1887
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1888
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1889

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

1923
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1924
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1925
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1926

1927
typedef struct {
1928
  char    db[TSDB_DB_FNAME_LEN];
1929
  int8_t  ignoreNotExists;
1930
  int8_t  force;
1931
  int32_t sqlLen;
1932
  char*   sql;
1933
} SDropDbReq;
1934

1935
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1936
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1937
void    tFreeSDropDbReq(SDropDbReq* pReq);
1938

1939
typedef struct {
1940
  char    db[TSDB_DB_FNAME_LEN];
1941
  int64_t uid;
1942
} SDropDbRsp;
1943

1944
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1945
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1946

1947
typedef struct {
1948
  char    name[TSDB_MOUNT_NAME_LEN];
1949
  int64_t uid;
1950
} SDropMountRsp;
1951

1952
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1953
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1954

1955
typedef struct {
1956
  char    db[TSDB_DB_FNAME_LEN];
1957
  int64_t dbId;
1958
  int32_t vgVersion;
1959
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1960
  int64_t stateTs;     // ms
1961
} SUseDbReq;
1962

1963
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1964
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1965

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

1986
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1987
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1988
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1989
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1990
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1991

1992
typedef struct {
1993
  char db[TSDB_DB_FNAME_LEN];
1994
} SDbCfgReq;
1995

1996
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1997
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1998

1999
typedef struct {
2000
  char db[TSDB_DB_FNAME_LEN];
2001
} SSsMigrateDbReq;
2002

2003
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2004
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2005

2006
typedef struct {
2007
  int32_t ssMigrateId;
2008
  bool    bAccepted;
2009
} SSsMigrateDbRsp;
2010

2011
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2012
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2013

2014
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2015
typedef struct {
2016
  int32_t ssMigrateId;
2017
} SListSsMigrateFileSetsReq;
2018

2019
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2020
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2021

2022
typedef struct {
2023
  int32_t ssMigrateId;
2024
  int32_t vgId;       // vgroup id
2025
  SArray* pFileSets;  // SArray<int32_t>
2026
} SListSsMigrateFileSetsRsp;
2027

2028
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2029
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2030
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2031

2032
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2033
typedef struct {
2034
  int32_t ssMigrateId;
2035
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2036
  int32_t fid;
2037
  int64_t startTimeSec;
2038
} SSsMigrateFileSetReq;
2039

2040
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2041
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2042

2043
typedef struct {
2044
  int32_t ssMigrateId;
2045
  int32_t nodeId;  // node id of the leader vnode
2046
  int32_t vgId;
2047
  int32_t fid;
2048
} SSsMigrateFileSetRsp;
2049

2050
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2051
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2052

2053
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2054
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2055
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2056
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2057
#define SSMIGRATE_FILESET_STATE_FAILED      4
2058

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

2071
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2072
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2073

2074
// Request for TDMT_MND_KILL_SSMIGRATE
2075
typedef struct {
2076
  int32_t ssMigrateId;
2077
  int32_t sqlLen;
2078
  char*   sql;
2079
} SKillSsMigrateReq;
2080

2081
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2082
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2083
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2084

2085
// Request for TDMT_VND_KILL_SSMIGRATE
2086
typedef struct {
2087
  int32_t ssMigrateId;
2088
} SVnodeKillSsMigrateReq;
2089

2090
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2091
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2092

2093
typedef struct {
2094
  int32_t vgId;
2095
  int64_t keepVersion;
2096
} SMndSetVgroupKeepVersionReq;
2097

2098
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2099
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2100

2101
typedef struct {
2102
  int32_t timestampSec;
2103
  int32_t ttlDropMaxCount;
2104
  int32_t nUids;
2105
  SArray* pTbUids;
2106
} SVDropTtlTableReq;
2107

2108
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2109
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2110

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

2166
typedef SDbCfgRsp SDbCfgInfo;
2167

2168
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2169
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2170
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2171
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2172
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2173

2174
typedef struct {
2175
  int32_t rowNum;
2176
} SQnodeListReq;
2177

2178
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2179
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2180

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

2185
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2186

2187
typedef struct {
2188
  int32_t useless;  // useless
2189
} SServerVerReq;
2190

2191
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2192
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2193

2194
typedef struct {
2195
  char ver[TSDB_VERSION_LEN];
2196
} SServerVerRsp;
2197

2198
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2199
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2200

2201
typedef struct SQueryNodeAddr {
2202
  int32_t nodeId;  // vgId or qnodeId
2203
  SEpSet  epSet;
2204
} SQueryNodeAddr;
2205

2206
typedef struct {
2207
  SQueryNodeAddr addr;
2208
  uint64_t       load;
2209
} SQueryNodeLoad;
2210

2211
typedef struct {
2212
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2213
} SQnodeListRsp;
2214

2215
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2216
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2217
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2218

2219
typedef struct SDNodeAddr {
2220
  int32_t nodeId;  // dnodeId
2221
  SEpSet  epSet;
2222
} SDNodeAddr;
2223

2224
typedef struct {
2225
  SArray* dnodeList;  // SArray<SDNodeAddr>
2226
} SDnodeListRsp;
2227

2228
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2229
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2230
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2231

2232
typedef struct {
2233
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2234
} STableTSMAInfoRsp;
2235

2236
typedef struct {
2237
  SUseDbRsp*         useDbRsp;
2238
  SDbCfgRsp*         cfgRsp;
2239
  STableTSMAInfoRsp* pTsmaRsp;
2240
  int32_t            dbTsmaVersion;
2241
  char               db[TSDB_DB_FNAME_LEN];
2242
  int64_t            dbId;
2243
} SDbHbRsp;
2244

2245
typedef struct {
2246
  SArray* pArray;  // Array of SDbHbRsp
2247
} SDbHbBatchRsp;
2248

2249
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2250
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2251
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2252

2253
typedef struct {
2254
  SArray* pArray;  // Array of SGetUserAuthRsp
2255
} SUserAuthBatchRsp;
2256

2257
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2258
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2259
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2260

2261
typedef struct {
2262
  char        db[TSDB_DB_FNAME_LEN];
2263
  STimeWindow timeRange;
2264
  int32_t     sqlLen;
2265
  char*       sql;
2266
  SArray*     vgroupIds;
2267
  int32_t     compactId;
2268
  int8_t      metaOnly;
2269
  int8_t      force;
2270
} SCompactDbReq;
2271

2272
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2273
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2274
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2275

2276
typedef struct {
2277
  union {
2278
    int32_t compactId;
2279
    int32_t id;
2280
  };
2281
  int8_t bAccepted;
2282
} SCompactDbRsp;
2283

2284
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2285
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2286

2287
typedef struct {
2288
  union {
2289
    int32_t compactId;
2290
    int32_t id;
2291
  };
2292
  int32_t sqlLen;
2293
  char*   sql;
2294
} SKillCompactReq;
2295

2296
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2297
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2298
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2299

2300
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2301
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2302

2303
typedef struct {
2304
  char    name[TSDB_FUNC_NAME_LEN];
2305
  int8_t  igExists;
2306
  int8_t  funcType;
2307
  int8_t  scriptType;
2308
  int8_t  outputType;
2309
  int32_t outputLen;
2310
  int32_t bufSize;
2311
  int32_t codeLen;
2312
  int64_t signature;
2313
  char*   pComment;
2314
  char*   pCode;
2315
  int8_t  orReplace;
2316
} SCreateFuncReq;
2317

2318
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2319
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2320
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2321

2322
typedef struct {
2323
  char   name[TSDB_FUNC_NAME_LEN];
2324
  int8_t igNotExists;
2325
} SDropFuncReq;
2326

2327
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2328
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2329

2330
typedef struct {
2331
  int32_t numOfFuncs;
2332
  bool    ignoreCodeComment;
2333
  SArray* pFuncNames;
2334
} SRetrieveFuncReq;
2335

2336
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2337
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2338
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2339

2340
typedef struct {
2341
  char    name[TSDB_FUNC_NAME_LEN];
2342
  int8_t  funcType;
2343
  int8_t  scriptType;
2344
  int8_t  outputType;
2345
  int32_t outputLen;
2346
  int32_t bufSize;
2347
  int64_t signature;
2348
  int32_t commentSize;
2349
  int32_t codeSize;
2350
  char*   pComment;
2351
  char*   pCode;
2352
} SFuncInfo;
2353

2354
typedef struct {
2355
  int32_t funcVersion;
2356
  int64_t funcCreatedTime;
2357
} SFuncExtraInfo;
2358

2359
typedef struct {
2360
  int32_t numOfFuncs;
2361
  SArray* pFuncInfos;
2362
  SArray* pFuncExtraInfos;
2363
} SRetrieveFuncRsp;
2364

2365
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2366
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2367
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2368
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2369

2370
typedef struct {
2371
  int32_t       statusInterval;
2372
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2373
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2374
  char          locale[TD_LOCALE_LEN];      // tsLocale
2375
  char          charset[TD_LOCALE_LEN];     // tsCharset
2376
  int8_t        ttlChangeOnWrite;
2377
  int8_t        enableWhiteList;
2378
  int8_t        encryptionKeyStat;
2379
  uint32_t      encryptionKeyChksum;
2380
  SMonitorParas monitorParas;
2381
  int32_t       statusIntervalMs;
2382
} SClusterCfg;
2383

2384
typedef struct {
2385
  int32_t openVnodes;
2386
  int32_t dropVnodes;
2387
  int32_t totalVnodes;
2388
  int32_t masterNum;
2389
  int64_t numOfSelectReqs;
2390
  int64_t numOfInsertReqs;
2391
  int64_t numOfInsertSuccessReqs;
2392
  int64_t numOfBatchInsertReqs;
2393
  int64_t numOfBatchInsertSuccessReqs;
2394
  int64_t errors;
2395
} SVnodesStat;
2396

2397
typedef struct {
2398
  int32_t vgId;
2399
  int8_t  syncState;
2400
  int8_t  syncRestore;
2401
  int64_t syncTerm;
2402
  int64_t roleTimeMs;
2403
  int64_t startTimeMs;
2404
  int8_t  syncCanRead;
2405
  int64_t cacheUsage;
2406
  int64_t numOfTables;
2407
  int64_t numOfTimeSeries;
2408
  int64_t totalStorage;
2409
  int64_t compStorage;
2410
  int64_t pointsWritten;
2411
  int64_t numOfSelectReqs;
2412
  int64_t numOfInsertReqs;
2413
  int64_t numOfInsertSuccessReqs;
2414
  int64_t numOfBatchInsertReqs;
2415
  int64_t numOfBatchInsertSuccessReqs;
2416
  int32_t numOfCachedTables;
2417
  int32_t learnerProgress;  // use one reservered
2418
  int64_t syncAppliedIndex;
2419
  int64_t syncCommitIndex;
2420
  int64_t bufferSegmentUsed;
2421
  int64_t bufferSegmentSize;
2422
} SVnodeLoad;
2423

2424
typedef struct {
2425
  int64_t total_requests;
2426
  int64_t total_rows;
2427
  int64_t total_bytes;
2428
  double  write_size;
2429
  double  cache_hit_ratio;
2430
  int64_t rpc_queue_wait;
2431
  int64_t preprocess_time;
2432

2433
  int64_t memory_table_size;
2434
  int64_t commit_count;
2435
  int64_t merge_count;
2436
  double  commit_time;
2437
  double  merge_time;
2438
  int64_t block_commit_time;
2439
  int64_t memtable_wait_time;
2440
} SVnodeMetrics;
2441

2442
typedef struct {
2443
  int32_t     vgId;
2444
  int64_t     numOfTables;
2445
  int64_t     memSize;
2446
  int64_t     l1Size;
2447
  int64_t     l2Size;
2448
  int64_t     l3Size;
2449
  int64_t     cacheSize;
2450
  int64_t     walSize;
2451
  int64_t     metaSize;
2452
  int64_t     rawDataSize;
2453
  int64_t     ssSize;
2454
  const char* dbname;
2455
  int8_t      estimateRawData;
2456
} SDbSizeStatisInfo;
2457

2458
typedef struct {
2459
  int32_t vgId;
2460
  int64_t nTimeSeries;
2461
} SVnodeLoadLite;
2462

2463
typedef struct {
2464
  int8_t  syncState;
2465
  int64_t syncTerm;
2466
  int8_t  syncRestore;
2467
  int64_t roleTimeMs;
2468
} SMnodeLoad;
2469

2470
typedef struct {
2471
  int32_t dnodeId;
2472
  int64_t numOfProcessedQuery;
2473
  int64_t numOfProcessedCQuery;
2474
  int64_t numOfProcessedFetch;
2475
  int64_t numOfProcessedDrop;
2476
  int64_t numOfProcessedNotify;
2477
  int64_t numOfProcessedHb;
2478
  int64_t numOfProcessedDelete;
2479
  int64_t cacheDataSize;
2480
  int64_t numOfQueryInQueue;
2481
  int64_t numOfFetchInQueue;
2482
  int64_t timeInQueryQueue;
2483
  int64_t timeInFetchQueue;
2484
} SQnodeLoad;
2485

2486
typedef struct {
2487
  int32_t     sver;      // software version
2488
  int64_t     dnodeVer;  // dnode table version in sdb
2489
  int32_t     dnodeId;
2490
  int64_t     clusterId;
2491
  int64_t     rebootTime;
2492
  int64_t     updateTime;
2493
  float       numOfCores;
2494
  int32_t     numOfSupportVnodes;
2495
  int32_t     numOfDiskCfg;
2496
  int64_t     memTotal;
2497
  int64_t     memAvail;
2498
  char        dnodeEp[TSDB_EP_LEN];
2499
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2500
  SMnodeLoad  mload;
2501
  SQnodeLoad  qload;
2502
  SClusterCfg clusterCfg;
2503
  SArray*     pVloads;  // array of SVnodeLoad
2504
  int32_t     statusSeq;
2505
  int64_t     ipWhiteVer;
2506
  int64_t     timeWhiteVer;
2507
  int64_t     analVer;
2508
  int64_t     timestamp;
2509
} SStatusReq;
2510

2511
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2512
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2513
void    tFreeSStatusReq(SStatusReq* pReq);
2514

2515
typedef struct {
2516
  int32_t forceReadConfig;
2517
  int32_t cver;
2518
  SArray* array;
2519
} SConfigReq;
2520

2521
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2522
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2523
void    tFreeSConfigReq(SConfigReq* pReq);
2524

2525
typedef struct {
2526
  int32_t dnodeId;
2527
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2528
} SDnodeInfoReq;
2529

2530
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2531
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2532

2533
typedef enum {
2534
  MONITOR_TYPE_COUNTER = 0,
2535
  MONITOR_TYPE_SLOW_LOG = 1,
2536
} MONITOR_TYPE;
2537

2538
typedef struct {
2539
  int32_t      contLen;
2540
  char*        pCont;
2541
  MONITOR_TYPE type;
2542
} SStatisReq;
2543

2544
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2545
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2546
void    tFreeSStatisReq(SStatisReq* pReq);
2547

2548
typedef struct {
2549
  char    db[TSDB_DB_FNAME_LEN];
2550
  char    table[TSDB_TABLE_NAME_LEN];
2551
  char    operation[AUDIT_OPERATION_LEN];
2552
  int32_t sqlLen;
2553
  char*   pSql;
2554
} SAuditReq;
2555
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2556
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2557
void    tFreeSAuditReq(SAuditReq* pReq);
2558

2559
typedef struct {
2560
  int32_t dnodeId;
2561
  int64_t clusterId;
2562
  SArray* pVloads;
2563
} SNotifyReq;
2564

2565
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2566
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2567
void    tFreeSNotifyReq(SNotifyReq* pReq);
2568

2569
typedef struct {
2570
  int32_t dnodeId;
2571
  int64_t clusterId;
2572
} SDnodeCfg;
2573

2574
typedef struct {
2575
  int32_t id;
2576
  int8_t  isMnode;
2577
  SEp     ep;
2578
} SDnodeEp;
2579

2580
typedef struct {
2581
  int32_t id;
2582
  int8_t  isMnode;
2583
  int8_t  offlineReason;
2584
  SEp     ep;
2585
  char    active[TSDB_ACTIVE_KEY_LEN];
2586
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2587
} SDnodeInfo;
2588

2589
typedef struct {
2590
  int64_t   dnodeVer;
2591
  SDnodeCfg dnodeCfg;
2592
  SArray*   pDnodeEps;  // Array of SDnodeEp
2593
  int32_t   statusSeq;
2594
  int64_t   ipWhiteVer;
2595
  int64_t   analVer;
2596
  int64_t   timeWhiteVer;
2597
} SStatusRsp;
2598

2599
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2600
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2601
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2602

2603
typedef struct {
2604
  int32_t forceReadConfig;
2605
  int32_t isConifgVerified;
2606
  int32_t isVersionVerified;
2607
  int32_t cver;
2608
  SArray* array;
2609
} SConfigRsp;
2610

2611
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2612
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2613
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2614

2615
typedef struct {
2616
  int32_t reserved;
2617
} SMTimerReq;
2618

2619
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2620
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2621

2622
typedef struct SOrphanTask {
2623
  int64_t streamId;
2624
  int32_t taskId;
2625
  int32_t nodeId;
2626
} SOrphanTask;
2627

2628
typedef struct SMStreamDropOrphanMsg {
2629
  SArray* pList;  // SArray<SOrphanTask>
2630
} SMStreamDropOrphanMsg;
2631

2632
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2633
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2634
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2635

2636
typedef struct {
2637
  int32_t  id;
2638
  uint16_t port;                 // node sync Port
2639
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2640
} SReplica;
2641

2642
typedef struct {
2643
  int32_t  vgId;
2644
  char     db[TSDB_DB_FNAME_LEN];
2645
  int64_t  dbUid;
2646
  int32_t  vgVersion;
2647
  int32_t  numOfStables;
2648
  int32_t  buffer;
2649
  int32_t  pageSize;
2650
  int32_t  pages;
2651
  int32_t  cacheLastSize;
2652
  int32_t  daysPerFile;
2653
  int32_t  daysToKeep0;
2654
  int32_t  daysToKeep1;
2655
  int32_t  daysToKeep2;
2656
  int32_t  keepTimeOffset;
2657
  int32_t  minRows;
2658
  int32_t  maxRows;
2659
  int32_t  walFsyncPeriod;
2660
  uint32_t hashBegin;
2661
  uint32_t hashEnd;
2662
  int8_t   hashMethod;
2663
  int8_t   walLevel;
2664
  int8_t   precision;
2665
  int8_t   compression;
2666
  int8_t   strict;
2667
  int8_t   cacheLast;
2668
  int8_t   isTsma;
2669
  int8_t   replica;
2670
  int8_t   selfIndex;
2671
  SReplica replicas[TSDB_MAX_REPLICA];
2672
  int32_t  numOfRetensions;
2673
  SArray*  pRetensions;  // SRetention
2674
  void*    pTsma;
2675
  int32_t  walRetentionPeriod;
2676
  int64_t  walRetentionSize;
2677
  int32_t  walRollPeriod;
2678
  int64_t  walSegmentSize;
2679
  int16_t  sstTrigger;
2680
  int16_t  hashPrefix;
2681
  int16_t  hashSuffix;
2682
  int32_t  tsdbPageSize;
2683
  int32_t  ssChunkSize;
2684
  int32_t  ssKeepLocal;
2685
  int8_t   ssCompact;
2686
  int64_t  reserved[6];
2687
  int8_t   learnerReplica;
2688
  int8_t   learnerSelfIndex;
2689
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2690
  int32_t  changeVersion;
2691
  int8_t   encryptAlgorithm;
2692
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2693
} SCreateVnodeReq;
2694

2695
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2696
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2697
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2698

2699
typedef struct {
2700
  union {
2701
    int32_t compactId;
2702
    int32_t id;
2703
  };
2704
  int32_t vgId;
2705
  int32_t dnodeId;
2706
} SQueryCompactProgressReq;
2707

2708
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2709
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2710

2711
typedef struct {
2712
  union {
2713
    int32_t compactId;
2714
    int32_t id;
2715
  };
2716
  int32_t vgId;
2717
  int32_t dnodeId;
2718
  int32_t numberFileset;
2719
  int32_t finished;
2720
  int32_t progress;
2721
  int64_t remainingTime;
2722
} SQueryCompactProgressRsp;
2723

2724
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2725
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2726

2727
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2728
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2729

2730
typedef struct {
2731
  int32_t vgId;
2732
  int32_t dnodeId;
2733
  int64_t dbUid;
2734
  char    db[TSDB_DB_FNAME_LEN];
2735
  int64_t reserved[8];
2736
} SDropVnodeReq;
2737

2738
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2739
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2740

2741
typedef struct {
2742
  char    colName[TSDB_COL_NAME_LEN];
2743
  char    stb[TSDB_TABLE_FNAME_LEN];
2744
  int64_t stbUid;
2745
  int64_t dbUid;
2746
  int64_t reserved[8];
2747
} SDropIndexReq;
2748

2749
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2750
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2751

2752
typedef struct {
2753
  int64_t dbUid;
2754
  char    db[TSDB_DB_FNAME_LEN];
2755
  union {
2756
    int64_t compactStartTime;
2757
    int64_t startTime;
2758
  };
2759

2760
  STimeWindow tw;
2761
  union {
2762
    int32_t compactId;
2763
    int32_t id;
2764
  };
2765
  int8_t metaOnly;
2766
  union {
2767
    uint16_t flags;
2768
    struct {
2769
      uint16_t optrType : 3;     // ETsdbOpType
2770
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2771
      uint16_t reserved : 12;
2772
    };
2773
  };
2774
  int8_t force;  // force compact
2775
} SCompactVnodeReq;
2776

2777
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2778
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2779

2780
typedef struct {
2781
  union {
2782
    int32_t compactId;
2783
    int32_t taskId;
2784
  };
2785
  int32_t vgId;
2786
  int32_t dnodeId;
2787
} SVKillCompactReq;
2788

2789
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2790
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2791

2792
typedef SVKillCompactReq SVKillRetentionReq;
2793

2794
typedef struct {
2795
  char        db[TSDB_DB_FNAME_LEN];
2796
  int32_t     maxSpeed;
2797
  int32_t     sqlLen;
2798
  char*       sql;
2799
  SArray*     vgroupIds;
2800
  STimeWindow tw;  // unit is second
2801
  union {
2802
    uint32_t flags;
2803
    struct {
2804
      uint32_t optrType : 3;     // ETsdbOpType
2805
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2806
      uint32_t reserved : 28;
2807
    };
2808
  };
2809
} STrimDbReq;
2810

2811
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2812
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2813
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2814

2815
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2816

2817
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2818
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2819

2820
typedef struct {
2821
  int32_t vgVersion;
2822
  int32_t buffer;
2823
  int32_t pageSize;
2824
  int32_t pages;
2825
  int32_t cacheLastSize;
2826
  int32_t daysPerFile;
2827
  int32_t daysToKeep0;
2828
  int32_t daysToKeep1;
2829
  int32_t daysToKeep2;
2830
  int32_t keepTimeOffset;
2831
  int32_t walFsyncPeriod;
2832
  int8_t  walLevel;
2833
  int8_t  strict;
2834
  int8_t  cacheLast;
2835
  int64_t reserved[7];
2836
  // 1st modification
2837
  int16_t sttTrigger;
2838
  int32_t minRows;
2839
  // 2nd modification
2840
  int32_t walRetentionPeriod;
2841
  int32_t walRetentionSize;
2842
  int32_t ssKeepLocal;
2843
  int8_t  ssCompact;
2844
} SAlterVnodeConfigReq;
2845

2846
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2847
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2848

2849
typedef struct {
2850
  int32_t  vgId;
2851
  int8_t   strict;
2852
  int8_t   selfIndex;
2853
  int8_t   replica;
2854
  SReplica replicas[TSDB_MAX_REPLICA];
2855
  int64_t  reserved[8];
2856
  int8_t   learnerSelfIndex;
2857
  int8_t   learnerReplica;
2858
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2859
  int32_t  changeVersion;
2860
  int32_t  electBaseLine;
2861
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2862

2863
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2864
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2865

2866
typedef struct {
2867
  int32_t vgId;
2868
  int8_t  disable;
2869
} SDisableVnodeWriteReq;
2870

2871
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2872
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2873

2874
typedef struct {
2875
  int32_t  srcVgId;
2876
  int32_t  dstVgId;
2877
  uint32_t hashBegin;
2878
  uint32_t hashEnd;
2879
  int32_t  changeVersion;
2880
  int32_t  reserved;
2881
} SAlterVnodeHashRangeReq;
2882

2883
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2884
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2885

2886
#define REQ_OPT_TBNAME 0x0
2887
#define REQ_OPT_TBUID  0x01
2888
typedef struct {
2889
  SMsgHead header;
2890
  char     dbFName[TSDB_DB_FNAME_LEN];
2891
  char     tbName[TSDB_TABLE_NAME_LEN];
2892
  uint8_t  option;
2893
  uint8_t  autoCreateCtb;
2894
} STableInfoReq;
2895

2896
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2897
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2898

2899
typedef struct {
2900
  int8_t  metaClone;  // create local clone of the cached table meta
2901
  int32_t numOfVgroups;
2902
  int32_t numOfTables;
2903
  int32_t numOfUdfs;
2904
  char    tableNames[];
2905
} SMultiTableInfoReq;
2906

2907
// todo refactor
2908
typedef struct SVgroupInfo {
2909
  int32_t  vgId;
2910
  uint32_t hashBegin;
2911
  uint32_t hashEnd;
2912
  SEpSet   epSet;
2913
  union {
2914
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2915
    int32_t taskId;      // used in stream
2916
  };
2917
} SVgroupInfo;
2918

2919
typedef struct {
2920
  int32_t     numOfVgroups;
2921
  SVgroupInfo vgroups[];
2922
} SVgroupsInfo;
2923

2924
typedef struct {
2925
  STableMetaRsp* pMeta;
2926
} SMAlterStbRsp;
2927

2928
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2929
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2930
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2931

2932
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2933
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2934
void    tFreeSTableMetaRsp(void* pRsp);
2935
void    tFreeSTableIndexRsp(void* info);
2936

2937
typedef struct {
2938
  SArray* pMetaRsp;   // Array of STableMetaRsp
2939
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2940
} SSTbHbRsp;
2941

2942
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2943
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2944
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2945

2946
typedef struct {
2947
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2948
} SViewHbRsp;
2949

2950
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2951
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2952
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2953

2954
typedef struct {
2955
  int32_t numOfTables;
2956
  int32_t numOfVgroup;
2957
  int32_t numOfUdf;
2958
  int32_t contLen;
2959
  int8_t  compressed;  // denote if compressed or not
2960
  int32_t rawLen;      // size before compress
2961
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2962
  char    meta[];
2963
} SMultiTableMeta;
2964

2965
typedef struct {
2966
  int32_t dataLen;
2967
  char    name[TSDB_TABLE_FNAME_LEN];
2968
  char*   data;
2969
} STagData;
2970

2971
typedef struct {
2972
  int32_t  opType;
2973
  uint32_t valLen;
2974
  char*    val;
2975
} SShowVariablesReq;
2976

2977
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2978
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2979
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2980

2981
typedef struct {
2982
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2983
  char value[TSDB_CONFIG_PATH_LEN + 1];
2984
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2985
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2986
  char info[TSDB_CONFIG_INFO_LEN + 1];
2987
} SVariablesInfo;
2988

2989
typedef struct {
2990
  SArray* variables;  // SArray<SVariablesInfo>
2991
} SShowVariablesRsp;
2992

2993
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2994
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2995

2996
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2997

2998
/*
2999
 * sql: show tables like '%a_%'
3000
 * payload is the query condition, e.g., '%a_%'
3001
 * payloadLen is the length of payload
3002
 */
3003
typedef struct {
3004
  int32_t type;
3005
  char    db[TSDB_DB_FNAME_LEN];
3006
  int32_t payloadLen;
3007
  char*   payload;
3008
} SShowReq;
3009

3010
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3011
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3012
void tFreeSShowReq(SShowReq* pReq);
3013

3014
typedef struct {
3015
  int64_t       showId;
3016
  STableMetaRsp tableMeta;
3017
} SShowRsp, SVShowTablesRsp;
3018

3019
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3020
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3021
// void    tFreeSShowRsp(SShowRsp* pRsp);
3022

3023
typedef struct {
3024
  char    db[TSDB_DB_FNAME_LEN];
3025
  char    tb[TSDB_TABLE_NAME_LEN];
3026
  char    user[TSDB_USER_LEN];
3027
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3028
  int64_t showId;
3029
  int64_t compactId;  // for compact
3030
  bool    withFull;   // for show users full
3031
} SRetrieveTableReq;
3032

3033
typedef struct SSysTableSchema {
3034
  int8_t   type;
3035
  col_id_t colId;
3036
  int32_t  bytes;
3037
} SSysTableSchema;
3038

3039
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3040
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3041

3042
#define RETRIEVE_TABLE_RSP_VERSION         0
3043
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3044
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3045

3046
typedef struct {
3047
  int64_t useconds;
3048
  int8_t  completed;  // all results are returned to client
3049
  int8_t  precision;
3050
  int8_t  compressed;
3051
  int8_t  streamBlockType;
3052
  int32_t payloadLen;
3053
  int32_t compLen;
3054
  int32_t numOfBlocks;
3055
  int64_t numOfRows;  // from int32_t change to int64_t
3056
  int64_t numOfCols;
3057
  int64_t skey;
3058
  int64_t ekey;
3059
  int64_t version;                         // for stream
3060
  TSKEY   watermark;                       // for stream
3061
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3062
  char    data[];
3063
} SRetrieveTableRsp;
3064

3065
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3066

3067
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3068
  do {                                          \
3069
    ((int32_t*)(_p))[0] = (_compLen);           \
3070
    ((int32_t*)(_p))[1] = (_fullLen);           \
3071
  } while (0);
3072

3073
typedef struct {
3074
  int64_t version;
3075
  int64_t numOfRows;
3076
  int8_t  compressed;
3077
  int8_t  precision;
3078
  char    data[];
3079
} SRetrieveTableRspForTmq;
3080

3081
typedef struct {
3082
  int64_t handle;
3083
  int64_t useconds;
3084
  int8_t  completed;  // all results are returned to client
3085
  int8_t  precision;
3086
  int8_t  compressed;
3087
  int32_t compLen;
3088
  int32_t numOfRows;
3089
  int32_t fullLen;
3090
  char    data[];
3091
} SRetrieveMetaTableRsp;
3092

3093
typedef struct SExplainExecInfo {
3094
  double   startupCost;
3095
  double   totalCost;
3096
  uint64_t numOfRows;
3097
  uint32_t verboseLen;
3098
  void*    verboseInfo;
3099
} SExplainExecInfo;
3100

3101
typedef struct {
3102
  int32_t           numOfPlans;
3103
  SExplainExecInfo* subplanInfo;
3104
} SExplainRsp;
3105

3106
typedef struct {
3107
  SExplainRsp rsp;
3108
  uint64_t    qId;
3109
  uint64_t    cId;
3110
  uint64_t    tId;
3111
  int64_t     rId;
3112
  int32_t     eId;
3113
} SExplainLocalRsp;
3114

3115
typedef struct STableScanAnalyzeInfo {
3116
  uint64_t totalRows;
3117
  uint64_t totalCheckedRows;
3118
  uint32_t totalBlocks;
3119
  uint32_t loadBlocks;
3120
  uint32_t loadBlockStatis;
3121
  uint32_t skipBlocks;
3122
  uint32_t filterOutBlocks;
3123
  double   elapsedTime;
3124
  double   filterTime;
3125
} STableScanAnalyzeInfo;
3126

3127
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3128
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3129
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3130

3131
typedef struct {
3132
  char    config[TSDB_DNODE_CONFIG_LEN];
3133
  char    value[TSDB_CLUSTER_VALUE_LEN];
3134
  int32_t sqlLen;
3135
  char*   sql;
3136
} SMCfgClusterReq;
3137

3138
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3139
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3140
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3141

3142
typedef struct {
3143
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3144
  int32_t port;
3145
  int32_t sqlLen;
3146
  char*   sql;
3147
} SCreateDnodeReq;
3148

3149
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3150
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3151
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3152

3153
typedef struct {
3154
  int32_t dnodeId;
3155
  char    fqdn[TSDB_FQDN_LEN];
3156
  int32_t port;
3157
  int8_t  force;
3158
  int8_t  unsafe;
3159
  int32_t sqlLen;
3160
  char*   sql;
3161
} SDropDnodeReq;
3162

3163
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3164
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3165
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3166

3167
enum {
3168
  RESTORE_TYPE__ALL = 1,
3169
  RESTORE_TYPE__MNODE,
3170
  RESTORE_TYPE__VNODE,
3171
  RESTORE_TYPE__QNODE,
3172
};
3173

3174
typedef struct {
3175
  int32_t dnodeId;
3176
  int8_t  restoreType;
3177
  int32_t sqlLen;
3178
  char*   sql;
3179
} SRestoreDnodeReq;
3180

3181
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3182
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3183
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3184

3185
typedef struct {
3186
  int32_t dnodeId;
3187
  char    config[TSDB_DNODE_CONFIG_LEN];
3188
  char    value[TSDB_DNODE_VALUE_LEN];
3189
  int32_t sqlLen;
3190
  char*   sql;
3191
} SMCfgDnodeReq;
3192

3193
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3194
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3195
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3196

3197
typedef struct {
3198
  char    config[TSDB_DNODE_CONFIG_LEN];
3199
  char    value[TSDB_DNODE_VALUE_LEN];
3200
  int32_t version;
3201
} SDCfgDnodeReq;
3202

3203
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3204
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3205

3206
typedef struct {
3207
  int32_t dnodeId;
3208
  int32_t sqlLen;
3209
  char*   sql;
3210
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3211
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3212

3213
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3214
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3215

3216
typedef struct {
3217
  int32_t nodeId;
3218
  SEpSet  epSet;
3219
} SNodeEpSet;
3220

3221
typedef struct {
3222
  int32_t    snodeId;
3223
  SNodeEpSet leaders[2];
3224
  SNodeEpSet replica;
3225
  int32_t    sqlLen;
3226
  char*      sql;
3227
} SDCreateSnodeReq;
3228

3229
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3230
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3231
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3232

3233
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3234
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3235
typedef struct {
3236
  int8_t   replica;
3237
  SReplica replicas[TSDB_MAX_REPLICA];
3238
  int8_t   learnerReplica;
3239
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3240
  int64_t  lastIndex;
3241
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3242

3243
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3244
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3245

3246
typedef struct {
3247
  int32_t urlLen;
3248
  int32_t sqlLen;
3249
  char*   url;
3250
  char*   sql;
3251
} SMCreateAnodeReq;
3252

3253
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3254
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3255
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3256

3257
typedef struct {
3258
  int32_t anodeId;
3259
  int32_t sqlLen;
3260
  char*   sql;
3261
} SMDropAnodeReq, SMUpdateAnodeReq;
3262

3263
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3264
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3265
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3266
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3267
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3268
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3269

3270
typedef struct {
3271
  int32_t dnodeId;
3272
  int32_t bnodeProto;
3273
  int32_t sqlLen;
3274
  char*   sql;
3275
} SMCreateBnodeReq, SDCreateBnodeReq;
3276

3277
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3278
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3279
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3280

3281
typedef struct {
3282
  int32_t dnodeId;
3283
  int32_t sqlLen;
3284
  char*   sql;
3285
} SMDropBnodeReq, SDDropBnodeReq;
3286

3287
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3288
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3289
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3290

3291
typedef struct {
3292
  int32_t vgId;
3293
  int32_t hbSeq;
3294
} SVArbHbReqMember;
3295

3296
typedef struct {
3297
  int32_t dnodeId;
3298
  char*   arbToken;
3299
  int64_t arbTerm;
3300
  SArray* hbMembers;  // SVArbHbReqMember
3301
} SVArbHeartBeatReq;
3302

3303
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3304
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3305
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3306

3307
typedef struct {
3308
  int32_t vgId;
3309
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3310
  int32_t hbSeq;
3311
} SVArbHbRspMember;
3312

3313
typedef struct {
3314
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3315
  int32_t dnodeId;
3316
  SArray* hbMembers;  // SVArbHbRspMember
3317
} SVArbHeartBeatRsp;
3318

3319
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3320
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3321
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3322

3323
typedef struct {
3324
  char*   arbToken;
3325
  int64_t arbTerm;
3326
  char*   member0Token;
3327
  char*   member1Token;
3328
} SVArbCheckSyncReq;
3329

3330
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3331
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3332
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3333

3334
typedef struct {
3335
  char*   arbToken;
3336
  char*   member0Token;
3337
  char*   member1Token;
3338
  int32_t vgId;
3339
  int32_t errCode;
3340
} SVArbCheckSyncRsp;
3341

3342
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3343
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3344
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3345

3346
typedef struct {
3347
  char*   arbToken;
3348
  int64_t arbTerm;
3349
  char*   memberToken;
3350
  int8_t  force;
3351
} SVArbSetAssignedLeaderReq;
3352

3353
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3354
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3355
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3356

3357
typedef struct {
3358
  char*   arbToken;
3359
  char*   memberToken;
3360
  int32_t vgId;
3361
} SVArbSetAssignedLeaderRsp;
3362

3363
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3364
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3365
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3366

3367
typedef struct {
3368
  int32_t dnodeId;
3369
  char*   token;
3370
} SMArbUpdateGroupMember;
3371

3372
typedef struct {
3373
  int32_t dnodeId;
3374
  char*   token;
3375
  int8_t  acked;
3376
} SMArbUpdateGroupAssigned;
3377

3378
typedef struct {
3379
  int32_t                  vgId;
3380
  int64_t                  dbUid;
3381
  SMArbUpdateGroupMember   members[2];
3382
  int8_t                   isSync;
3383
  int8_t                   assignedAcked;
3384
  SMArbUpdateGroupAssigned assignedLeader;
3385
  int64_t                  version;
3386
  int32_t                  code;
3387
  int64_t                  updateTimeMs;
3388
} SMArbUpdateGroup;
3389

3390
typedef struct {
3391
  SArray* updateArray;  // SMArbUpdateGroup
3392
} SMArbUpdateGroupBatchReq;
3393

3394
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3395
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3396
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3397

3398
typedef struct {
3399
  char queryStrId[TSDB_QUERY_ID_LEN];
3400
} SKillQueryReq;
3401

3402
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3403
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3404

3405
typedef struct {
3406
  uint32_t connId;
3407
} SKillConnReq;
3408

3409
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3410
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3411

3412
typedef struct {
3413
  int32_t transId;
3414
} SKillTransReq;
3415

3416
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3417
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3418

3419
typedef struct {
3420
  int32_t useless;  // useless
3421
  int32_t sqlLen;
3422
  char*   sql;
3423
} SBalanceVgroupReq;
3424

3425
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3426
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3427
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3428

3429
typedef struct {
3430
  int32_t useless;  // useless
3431
  int32_t sqlLen;
3432
  char*   sql;
3433
} SAssignLeaderReq;
3434

3435
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3436
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3437
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3438
typedef struct {
3439
  int32_t vgId1;
3440
  int32_t vgId2;
3441
} SMergeVgroupReq;
3442

3443
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3444
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3445

3446
typedef struct {
3447
  int32_t vgId;
3448
  int32_t dnodeId1;
3449
  int32_t dnodeId2;
3450
  int32_t dnodeId3;
3451
  int32_t sqlLen;
3452
  char*   sql;
3453
} SRedistributeVgroupReq;
3454

3455
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3456
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3457
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3458

3459
typedef struct {
3460
  int32_t reserved;
3461
  int32_t vgId;
3462
  int32_t sqlLen;
3463
  char*   sql;
3464
  char    db[TSDB_DB_FNAME_LEN];
3465
} SBalanceVgroupLeaderReq;
3466

3467
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3468
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3469
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3470

3471
typedef struct {
3472
  int32_t vgId;
3473
} SForceBecomeFollowerReq;
3474

3475
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3476
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3477

3478
typedef struct {
3479
  int32_t vgId;
3480
  bool    force;
3481
} SSplitVgroupReq;
3482

3483
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3484
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3485

3486
typedef struct {
3487
  char user[TSDB_USER_LEN];
3488
  char spi;
3489
  char encrypt;
3490
  char secret[TSDB_PASSWORD_LEN];
3491
  char ckey[TSDB_PASSWORD_LEN];
3492
} SAuthReq, SAuthRsp;
3493

3494
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3495
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3496

3497
typedef struct {
3498
  int32_t statusCode;
3499
  char    details[1024];
3500
} SServerStatusRsp;
3501

3502
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3503
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3504

3505
/**
3506
 * The layout of the query message payload is as following:
3507
 * +--------------------+---------------------------------+
3508
 * |Sql statement       | Physical plan                   |
3509
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3510
 * +--------------------+---------------------------------+
3511
 */
3512
typedef struct SSubQueryMsg {
3513
  SMsgHead header;
3514
  uint64_t sId;
3515
  uint64_t queryId;
3516
  uint64_t clientId;
3517
  uint64_t taskId;
3518
  int64_t  refId;
3519
  int32_t  execId;
3520
  int32_t  msgMask;
3521
  int8_t   taskType;
3522
  int8_t   explain;
3523
  int8_t   needFetch;
3524
  int8_t   compress;
3525
  uint32_t sqlLen;
3526
  char*    sql;
3527
  uint32_t msgLen;
3528
  char*    msg;
3529
} SSubQueryMsg;
3530

3531
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3532
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3533
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3534

3535
typedef struct {
3536
  SMsgHead header;
3537
  uint64_t sId;
3538
  uint64_t queryId;
3539
  uint64_t taskId;
3540
} SSinkDataReq;
3541

3542
typedef struct {
3543
  SMsgHead header;
3544
  uint64_t sId;
3545
  uint64_t queryId;
3546
  uint64_t clientId;
3547
  uint64_t taskId;
3548
  int32_t  execId;
3549
} SQueryContinueReq;
3550

3551
typedef struct {
3552
  SMsgHead header;
3553
  uint64_t sId;
3554
  uint64_t queryId;
3555
  uint64_t taskId;
3556
} SResReadyReq;
3557

3558
typedef struct {
3559
  int32_t code;
3560
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3561
  int32_t sversion;
3562
  int32_t tversion;
3563
} SResReadyRsp;
3564

3565
typedef struct SOperatorParam {
3566
  int32_t opType;
3567
  int32_t downstreamIdx;
3568
  void*   value;
3569
  SArray* pChildren;  // SArray<SOperatorParam*>
3570
  bool    reUse;
3571
} SOperatorParam;
3572

3573
typedef struct SColIdNameKV {
3574
  col_id_t colId;
3575
  char     colName[TSDB_COL_NAME_LEN];
3576
} SColIdNameKV;
3577

3578
typedef struct SColIdPair {
3579
  col_id_t vtbColId;
3580
  col_id_t orgColId;
3581
} SColIdPair;
3582

3583
typedef struct SColIdSlotIdPair {
3584
  int32_t  vtbSlotId;
3585
  col_id_t orgColId;
3586
} SColIdSlotIdPair;
3587

3588
typedef struct SOrgTbInfo {
3589
  int32_t vgId;
3590
  char    tbName[TSDB_TABLE_FNAME_LEN];
3591
  SArray* colMap;  // SArray<SColIdNameKV>
3592
} SOrgTbInfo;
3593

3594
typedef struct STableScanOperatorParam {
3595
  bool        tableSeq;
3596
  bool        isNewParam;
3597
  SArray*     pUidList;
3598
  SOrgTbInfo* pOrgTbInfo;
3599
  STimeWindow window;
3600
} STableScanOperatorParam;
3601

3602
typedef struct STagScanOperatorParam {
3603
  tb_uid_t vcUid;
3604
} STagScanOperatorParam;
3605

3606
typedef struct SVTableScanOperatorParam {
3607
  uint64_t        uid;
3608
  STimeWindow     window;
3609
  SOperatorParam* pTagScanOp;
3610
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3611
} SVTableScanOperatorParam;
3612

3613
typedef struct SMergeOperatorParam {
3614
  int32_t         winNum;
3615
} SMergeOperatorParam;
3616

3617
typedef struct SExternalWindowOperatorParam {
3618
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3619
} SExternalWindowOperatorParam;
3620

3621
typedef struct SDynQueryCtrlOperatorParam {
3622
  STimeWindow    window;
3623
} SDynQueryCtrlOperatorParam;
3624

3625
struct SStreamRuntimeFuncInfo;
3626
typedef struct {
3627
  SMsgHead        header;
3628
  uint64_t        sId;
3629
  uint64_t        queryId;
3630
  uint64_t        clientId;
3631
  uint64_t        taskId;
3632
  int32_t         execId;
3633
  SOperatorParam* pOpParam;
3634

3635
  // used for new-stream
3636
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3637
  bool                           reset;
3638
  bool                           dynTbname;
3639
  // used for new-stream
3640
} SResFetchReq;
3641

3642
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3643
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3644
void    tDestroySResFetchReq(SResFetchReq* pReq);
3645
typedef struct {
3646
  SMsgHead header;
3647
  uint64_t clientId;
3648
} SSchTasksStatusReq;
3649

3650
typedef struct {
3651
  uint64_t queryId;
3652
  uint64_t clientId;
3653
  uint64_t taskId;
3654
  int64_t  refId;
3655
  int32_t  execId;
3656
  int8_t   status;
3657
} STaskStatus;
3658

3659
typedef struct {
3660
  int64_t refId;
3661
  SArray* taskStatus;  // SArray<STaskStatus>
3662
} SSchedulerStatusRsp;
3663

3664
typedef struct {
3665
  uint64_t queryId;
3666
  uint64_t taskId;
3667
  int8_t   action;
3668
} STaskAction;
3669

3670
typedef struct SQueryNodeEpId {
3671
  int32_t nodeId;  // vgId or qnodeId
3672
  SEp     ep;
3673
} SQueryNodeEpId;
3674

3675
typedef struct {
3676
  SMsgHead       header;
3677
  uint64_t       clientId;
3678
  SQueryNodeEpId epId;
3679
  SArray*        taskAction;  // SArray<STaskAction>
3680
} SSchedulerHbReq;
3681

3682
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3683
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3684
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3685

3686
typedef struct {
3687
  SQueryNodeEpId epId;
3688
  SArray*        taskStatus;  // SArray<STaskStatus>
3689
} SSchedulerHbRsp;
3690

3691
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3692
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3693
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3694

3695
typedef struct {
3696
  SMsgHead header;
3697
  uint64_t sId;
3698
  uint64_t queryId;
3699
  uint64_t clientId;
3700
  uint64_t taskId;
3701
  int64_t  refId;
3702
  int32_t  execId;
3703
} STaskCancelReq;
3704

3705
typedef struct {
3706
  int32_t code;
3707
} STaskCancelRsp;
3708

3709
typedef struct {
3710
  SMsgHead header;
3711
  uint64_t sId;
3712
  uint64_t queryId;
3713
  uint64_t clientId;
3714
  uint64_t taskId;
3715
  int64_t  refId;
3716
  int32_t  execId;
3717
} STaskDropReq;
3718

3719
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3720
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3721

3722
typedef enum {
3723
  TASK_NOTIFY_FINISHED = 1,
3724
} ETaskNotifyType;
3725

3726
typedef struct {
3727
  SMsgHead        header;
3728
  uint64_t        sId;
3729
  uint64_t        queryId;
3730
  uint64_t        clientId;
3731
  uint64_t        taskId;
3732
  int64_t         refId;
3733
  int32_t         execId;
3734
  ETaskNotifyType type;
3735
} STaskNotifyReq;
3736

3737
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3738
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3739

3740
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3741
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3742

3743
typedef struct {
3744
  int32_t code;
3745
} STaskDropRsp;
3746

3747
#define STREAM_TRIGGER_AT_ONCE                 1
3748
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3749
#define STREAM_TRIGGER_MAX_DELAY               3
3750
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3751
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3752

3753
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3754
#define STREAM_FILL_HISTORY_ON        1
3755
#define STREAM_FILL_HISTORY_OFF       0
3756
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3757
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3758
#define STREAM_CREATE_STABLE_TRUE     1
3759
#define STREAM_CREATE_STABLE_FALSE    0
3760

3761
typedef struct SVgroupVer {
3762
  int32_t vgId;
3763
  int64_t ver;
3764
} SVgroupVer;
3765

3766
typedef struct STaskNotifyEventStat {
3767
  int64_t notifyEventAddTimes;     // call times of add function
3768
  int64_t notifyEventAddElems;     // elements added by add function
3769
  double  notifyEventAddCostSec;   // time cost of add function
3770
  int64_t notifyEventPushTimes;    // call times of push function
3771
  int64_t notifyEventPushElems;    // elements pushed by push function
3772
  double  notifyEventPushCostSec;  // time cost of push function
3773
  int64_t notifyEventPackTimes;    // call times of pack function
3774
  int64_t notifyEventPackElems;    // elements packed by pack function
3775
  double  notifyEventPackCostSec;  // time cost of pack function
3776
  int64_t notifyEventSendTimes;    // call times of send function
3777
  int64_t notifyEventSendElems;    // elements sent by send function
3778
  double  notifyEventSendCostSec;  // time cost of send function
3779
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3780
} STaskNotifyEventStat;
3781

3782
enum {
3783
  TOPIC_SUB_TYPE__DB = 1,
3784
  TOPIC_SUB_TYPE__TABLE,
3785
  TOPIC_SUB_TYPE__COLUMN,
3786
};
3787

3788
#define DEFAULT_MAX_POLL_INTERVAL  300000
3789
#define DEFAULT_SESSION_TIMEOUT    12000
3790
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3791
#define DEFAULT_MIN_POLL_ROWS      4096
3792

3793
typedef struct {
3794
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3795
  int8_t igExists;
3796
  int8_t subType;
3797
  int8_t withMeta;
3798
  char*  sql;
3799
  char   subDbName[TSDB_DB_FNAME_LEN];
3800
  char*  ast;
3801
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3802
  int8_t reload;
3803
} SCMCreateTopicReq;
3804

3805
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3806
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3807
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3808

3809
typedef struct {
3810
  int64_t consumerId;
3811
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3812

3813
typedef struct {
3814
  int64_t consumerId;
3815
  char    cgroup[TSDB_CGROUP_LEN];
3816
  char    clientId[TSDB_CLIENT_ID_LEN];
3817
  char    user[TSDB_USER_LEN];
3818
  char    fqdn[TSDB_FQDN_LEN];
3819
  SArray* topicNames;  // SArray<char**>
3820

3821
  int8_t  withTbName;
3822
  int8_t  autoCommit;
3823
  int32_t autoCommitInterval;
3824
  int8_t  resetOffsetCfg;
3825
  int8_t  enableReplay;
3826
  int8_t  enableBatchMeta;
3827
  int32_t sessionTimeoutMs;
3828
  int32_t maxPollIntervalMs;
3829
} SCMSubscribeReq;
3830

3831
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3832
  int32_t tlen = 0;
288,566✔
3833
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
288,566✔
3834
  tlen += taosEncodeString(buf, pReq->cgroup);
288,566✔
3835
  tlen += taosEncodeString(buf, pReq->clientId);
288,566✔
3836

3837
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
288,566✔
3838
  tlen += taosEncodeFixedI32(buf, topicNum);
288,566✔
3839

3840
  for (int32_t i = 0; i < topicNum; i++) {
398,444✔
3841
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
219,756✔
3842
  }
3843

3844
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
288,566✔
3845
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
288,566✔
3846
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
288,566✔
3847
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
288,566✔
3848
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
288,566✔
3849
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
288,566✔
3850
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
288,566✔
3851
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
288,566✔
3852
  tlen += taosEncodeString(buf, pReq->user);
288,566✔
3853
  tlen += taosEncodeString(buf, pReq->fqdn);
288,566✔
3854

3855
  return tlen;
288,566✔
3856
}
3857

3858
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3859
  void* start = buf;
130,863✔
3860
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
130,863✔
3861
  buf = taosDecodeStringTo(buf, pReq->cgroup);
130,863✔
3862
  buf = taosDecodeStringTo(buf, pReq->clientId);
130,863✔
3863

3864
  int32_t topicNum = 0;
130,863✔
3865
  buf = taosDecodeFixedI32(buf, &topicNum);
130,863✔
3866

3867
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
130,863✔
3868
  if (pReq->topicNames == NULL) {
130,863✔
3869
    return terrno;
×
3870
  }
3871
  for (int32_t i = 0; i < topicNum; i++) {
185,229✔
3872
    char* name = NULL;
54,366✔
3873
    buf = taosDecodeString(buf, &name);
54,366✔
3874
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
108,732✔
3875
      return terrno;
×
3876
    }
3877
  }
3878

3879
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
130,863✔
3880
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
130,863✔
3881
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
130,863✔
3882
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
130,863✔
3883
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
130,863✔
3884
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
130,863✔
3885
  if ((char*)buf - (char*)start < len) {
130,863✔
3886
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
130,863✔
3887
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
130,863✔
3888
    buf = taosDecodeStringTo(buf, pReq->user);
130,863✔
3889
    buf = taosDecodeStringTo(buf, pReq->fqdn);
261,726✔
3890
  } else {
3891
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3892
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3893
  }
3894

3895
  return 0;
130,863✔
3896
}
3897

3898
typedef struct {
3899
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3900
  SArray* removedConsumers;  // SArray<int64_t>
3901
  SArray* newConsumers;      // SArray<int64_t>
3902
} SMqRebInfo;
3903

3904
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3905
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
98,058✔
3906
  if (pRebInfo == NULL) {
98,058✔
3907
    return NULL;
×
3908
  }
3909
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
98,058✔
3910
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
98,058✔
3911
  if (pRebInfo->removedConsumers == NULL) {
98,058✔
3912
    goto _err;
×
3913
  }
3914
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
98,058✔
3915
  if (pRebInfo->newConsumers == NULL) {
98,058✔
3916
    goto _err;
×
3917
  }
3918
  return pRebInfo;
98,058✔
3919
_err:
×
3920
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3921
  taosArrayDestroy(pRebInfo->newConsumers);
×
3922
  taosMemoryFreeClear(pRebInfo);
×
3923
  return NULL;
×
3924
}
3925

3926
typedef struct {
3927
  int64_t streamId;
3928
  int64_t checkpointId;
3929
  char    streamName[TSDB_STREAM_FNAME_LEN];
3930
} SMStreamDoCheckpointMsg;
3931

3932
typedef struct {
3933
  int64_t status;
3934
} SMVSubscribeRsp;
3935

3936
typedef struct {
3937
  char    name[TSDB_TOPIC_FNAME_LEN];
3938
  int8_t  igNotExists;
3939
  int32_t sqlLen;
3940
  char*   sql;
3941
  int8_t  force;
3942
} SMDropTopicReq;
3943

3944
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3945
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3946
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3947

3948
typedef struct {
3949
  char    name[TSDB_TOPIC_FNAME_LEN];
3950
  int8_t  igNotExists;
3951
  int32_t sqlLen;
3952
  char*   sql;
3953
} SMReloadTopicReq;
3954

3955
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3956
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3957
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
3958

3959
typedef struct {
3960
  char   topic[TSDB_TOPIC_FNAME_LEN];
3961
  char   cgroup[TSDB_CGROUP_LEN];
3962
  int8_t igNotExists;
3963
  int8_t force;
3964
} SMDropCgroupReq;
3965

3966
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3967
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3968

3969
typedef struct {
3970
  int8_t reserved;
3971
} SMDropCgroupRsp;
3972

3973
typedef struct {
3974
  char    name[TSDB_TABLE_FNAME_LEN];
3975
  int8_t  alterType;
3976
  SSchema schema;
3977
} SAlterTopicReq;
3978

3979
typedef struct {
3980
  SMsgHead head;
3981
  char     name[TSDB_TABLE_FNAME_LEN];
3982
  int64_t  tuid;
3983
  int32_t  sverson;
3984
  int32_t  execLen;
3985
  char*    executor;
3986
  int32_t  sqlLen;
3987
  char*    sql;
3988
} SDCreateTopicReq;
3989

3990
typedef struct {
3991
  SMsgHead head;
3992
  char     name[TSDB_TABLE_FNAME_LEN];
3993
  int64_t  tuid;
3994
} SDDropTopicReq;
3995

3996
typedef struct {
3997
  char*      name;
3998
  int64_t    uid;
3999
  int64_t    interval[2];
4000
  int8_t     intervalUnit;
4001
  int16_t    nFuncs;
4002
  col_id_t*  funcColIds;  // column ids specified by user
4003
  func_id_t* funcIds;     // function ids specified by user
4004
} SRSmaParam;
4005

4006
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4007
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4008

4009
// TDMT_VND_CREATE_STB ==============
4010
typedef struct SVCreateStbReq {
4011
  char*           name;
4012
  tb_uid_t        suid;
4013
  int8_t          rollup;
4014
  SSchemaWrapper  schemaRow;
4015
  SSchemaWrapper  schemaTag;
4016
  SRSmaParam      rsmaParam;
4017
  int32_t         alterOriDataLen;
4018
  void*           alterOriData;
4019
  int8_t          source;
4020
  int8_t          colCmpred;
4021
  SColCmprWrapper colCmpr;
4022
  int64_t         keep;
4023
  SExtSchema*     pExtSchemas;
4024
  int8_t          virtualStb;
4025
} SVCreateStbReq;
4026

4027
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4028
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4029

4030
// TDMT_VND_DROP_STB ==============
4031
typedef struct SVDropStbReq {
4032
  char*    name;
4033
  tb_uid_t suid;
4034
} SVDropStbReq;
4035

4036
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4037
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4038

4039
// TDMT_VND_CREATE_TABLE ==============
4040
#define TD_CREATE_IF_NOT_EXISTS       0x1
4041
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4042
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4043
typedef struct SVCreateTbReq {
4044
  int32_t  flags;
4045
  char*    name;
4046
  tb_uid_t uid;
4047
  int64_t  btime;
4048
  int32_t  ttl;
4049
  int32_t  commentLen;
4050
  char*    comment;
4051
  int8_t   type;
4052
  union {
4053
    struct {
4054
      char*    stbName;  // super table name
4055
      uint8_t  tagNum;
4056
      tb_uid_t suid;
4057
      SArray*  tagName;
4058
      uint8_t* pTag;
4059
    } ctb;
4060
    struct {
4061
      SSchemaWrapper schemaRow;
4062
    } ntb;
4063
  };
4064
  int32_t         sqlLen;
4065
  char*           sql;
4066
  SColCmprWrapper colCmpr;
4067
  SExtSchema*     pExtSchemas;
4068
  SColRefWrapper  colRef;  // col reference for virtual table
4069
} SVCreateTbReq;
4070

4071
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4072
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4073
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4074
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4075

4076
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4077
  if (NULL == req) {
2,147,483,647✔
4078
    return;
2,121,712,598✔
4079
  }
4080

4081
  taosMemoryFreeClear(req->sql);
74,570,437✔
4082
  taosMemoryFreeClear(req->name);
74,570,023✔
4083
  taosMemoryFreeClear(req->comment);
74,573,724✔
4084
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
74,572,067✔
4085
    taosMemoryFreeClear(req->ctb.pTag);
55,737,842✔
4086
    taosMemoryFreeClear(req->ctb.stbName);
55,735,990✔
4087
    taosArrayDestroy(req->ctb.tagName);
55,729,025✔
4088
    req->ctb.tagName = NULL;
55,697,100✔
4089
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
18,841,422✔
4090
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
18,841,422✔
4091
  }
4092
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
74,537,371✔
4093
  taosMemoryFreeClear(req->pExtSchemas);
74,578,494✔
4094
  taosMemoryFreeClear(req->colRef.pColRef);
74,575,309✔
4095
}
4096

4097
typedef struct {
4098
  int32_t nReqs;
4099
  union {
4100
    SVCreateTbReq* pReqs;
4101
    SArray*        pArray;
4102
  };
4103
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4104
} SVCreateTbBatchReq;
4105

4106
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4107
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4108
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4109

4110
typedef struct {
4111
  int32_t        code;
4112
  STableMetaRsp* pMeta;
4113
} SVCreateTbRsp, SVUpdateTbRsp;
4114

4115
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4116
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4117
void tFreeSVCreateTbRsp(void* param);
4118

4119
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4120
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4121

4122
typedef struct {
4123
  int32_t nRsps;
4124
  union {
4125
    SVCreateTbRsp* pRsps;
4126
    SArray*        pArray;
4127
  };
4128
} SVCreateTbBatchRsp;
4129

4130
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4131
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4132

4133
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4134
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4135

4136
// TDMT_VND_DROP_TABLE =================
4137
typedef struct {
4138
  char*    name;
4139
  uint64_t suid;  // for tmq in wal format
4140
  int64_t  uid;
4141
  int8_t   igNotExists;
4142
  int8_t   isVirtual;
4143
} SVDropTbReq;
4144

4145
typedef struct {
4146
  int32_t code;
4147
} SVDropTbRsp;
4148

4149
typedef struct {
4150
  int32_t nReqs;
4151
  union {
4152
    SVDropTbReq* pReqs;
4153
    SArray*      pArray;
4154
  };
4155
} SVDropTbBatchReq;
4156

4157
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4158
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4159

4160
typedef struct {
4161
  int32_t nRsps;
4162
  union {
4163
    SVDropTbRsp* pRsps;
4164
    SArray*      pArray;
4165
  };
4166
} SVDropTbBatchRsp;
4167

4168
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4169
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4170

4171
// TDMT_VND_ALTER_TABLE =====================
4172
typedef struct SMultiTagUpateVal {
4173
  char*    tagName;
4174
  int32_t  colId;
4175
  int8_t   tagType;
4176
  int8_t   tagFree;
4177
  uint32_t nTagVal;
4178
  uint8_t* pTagVal;
4179
  int8_t   isNull;
4180
  SArray*  pTagArray;
4181
} SMultiTagUpateVal;
4182
typedef struct SVAlterTbReq {
4183
  char*   tbName;
4184
  int8_t  action;
4185
  char*   colName;
4186
  int32_t colId;
4187
  // TSDB_ALTER_TABLE_ADD_COLUMN
4188
  int8_t  type;
4189
  int8_t  flags;
4190
  int32_t bytes;
4191
  // TSDB_ALTER_TABLE_DROP_COLUMN
4192
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4193
  int8_t   colModType;
4194
  int32_t  colModBytes;
4195
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4196
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4197
  int8_t   isNull;
4198
  int8_t   tagType;
4199
  int8_t   tagFree;
4200
  uint32_t nTagVal;
4201
  uint8_t* pTagVal;
4202
  SArray*  pTagArray;
4203
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4204
  int8_t   updateTTL;
4205
  int32_t  newTTL;
4206
  int32_t  newCommentLen;
4207
  char*    newComment;
4208
  int64_t  ctimeMs;    // fill by vnode
4209
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4210
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4211
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4212
  // for Add column
4213
  STypeMod typeMod;
4214
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4215
  char* refDbName;
4216
  char* refTbName;
4217
  char* refColName;
4218
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4219
} SVAlterTbReq;
4220

4221
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4222
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4223
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4224
void    tfreeMultiTagUpateVal(void* pMultiTag);
4225

4226
typedef struct {
4227
  int32_t        code;
4228
  STableMetaRsp* pMeta;
4229
} SVAlterTbRsp;
4230

4231
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4232
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4233
// ======================
4234

4235
typedef struct {
4236
  SMsgHead head;
4237
  int64_t  uid;
4238
  int32_t  tid;
4239
  int16_t  tversion;
4240
  int16_t  colId;
4241
  int8_t   type;
4242
  int16_t  bytes;
4243
  int32_t  tagValLen;
4244
  int16_t  numOfTags;
4245
  int32_t  schemaLen;
4246
  char     data[];
4247
} SUpdateTagValReq;
4248

4249
typedef struct {
4250
  SMsgHead head;
4251
} SUpdateTagValRsp;
4252

4253
typedef struct {
4254
  SMsgHead head;
4255
} SVShowTablesReq;
4256

4257
typedef struct {
4258
  SMsgHead head;
4259
  int32_t  id;
4260
} SVShowTablesFetchReq;
4261

4262
typedef struct {
4263
  int64_t useconds;
4264
  int8_t  completed;  // all results are returned to client
4265
  int8_t  precision;
4266
  int8_t  compressed;
4267
  int32_t compLen;
4268
  int32_t numOfRows;
4269
  char    data[];
4270
} SVShowTablesFetchRsp;
4271

4272
typedef struct {
4273
  int64_t consumerId;
4274
  int32_t epoch;
4275
  char    cgroup[TSDB_CGROUP_LEN];
4276
} SMqAskEpReq;
4277

4278
typedef struct {
4279
  int32_t key;
4280
  int32_t valueLen;
4281
  void*   value;
4282
} SKv;
4283

4284
typedef struct {
4285
  int64_t tscRid;
4286
  int8_t  connType;
4287
} SClientHbKey;
4288

4289
typedef struct {
4290
  int64_t tid;
4291
  char    status[TSDB_JOB_STATUS_LEN];
4292
} SQuerySubDesc;
4293

4294
typedef struct {
4295
  char     sql[TSDB_SHOW_SQL_LEN];
4296
  uint64_t queryId;
4297
  int64_t  useconds;
4298
  int64_t  stime;  // timestamp precision ms
4299
  int64_t  reqRid;
4300
  bool     stableQuery;
4301
  bool     isSubQuery;
4302
  char     fqdn[TSDB_FQDN_LEN];
4303
  int32_t  subPlanNum;
4304
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4305
} SQueryDesc;
4306

4307
typedef struct {
4308
  uint32_t connId;
4309
  SArray*  queryDesc;  // SArray<SQueryDesc>
4310
} SQueryHbReqBasic;
4311

4312
typedef struct {
4313
  uint32_t connId;
4314
  uint64_t killRid;
4315
  int32_t  totalDnodes;
4316
  int32_t  onlineDnodes;
4317
  int8_t   killConnection;
4318
  int8_t   align[3];
4319
  SEpSet   epSet;
4320
  SArray*  pQnodeList;
4321
} SQueryHbRspBasic;
4322

4323
typedef struct SAppClusterSummary {
4324
  uint64_t numOfInsertsReq;
4325
  uint64_t numOfInsertRows;
4326
  uint64_t insertElapsedTime;
4327
  uint64_t insertBytes;  // submit to tsdb since launched.
4328

4329
  uint64_t fetchBytes;
4330
  uint64_t numOfQueryReq;
4331
  uint64_t queryElapsedTime;
4332
  uint64_t numOfSlowQueries;
4333
  uint64_t totalRequests;
4334
  uint64_t currentRequests;  // the number of SRequestObj
4335
} SAppClusterSummary;
4336

4337
typedef struct {
4338
  int64_t            appId;
4339
  int32_t            pid;
4340
  char               name[TSDB_APP_NAME_LEN];
4341
  int64_t            startTime;
4342
  SAppClusterSummary summary;
4343
} SAppHbReq;
4344

4345
typedef struct {
4346
  SClientHbKey      connKey;
4347
  int64_t           clusterId;
4348
  SAppHbReq         app;
4349
  SQueryHbReqBasic* query;
4350
  SHashObj*         info;  // hash<Skv.key, Skv>
4351
  char              userApp[TSDB_APP_NAME_LEN];
4352
  uint32_t          userIp;
4353
  SIpRange          userDualIp;
4354
  char              sVer[TSDB_VERSION_LEN];
4355
  char              cInfo[CONNECTOR_INFO_LEN];
4356
} SClientHbReq;
4357

4358
typedef struct {
4359
  int64_t reqId;
4360
  SArray* reqs;  // SArray<SClientHbReq>
4361
  int64_t ipWhiteListVer;
4362
} SClientHbBatchReq;
4363

4364
typedef struct {
4365
  SClientHbKey      connKey;
4366
  int32_t           status;
4367
  SQueryHbRspBasic* query;
4368
  SArray*           info;  // Array<Skv>
4369
} SClientHbRsp;
4370

4371
typedef struct {
4372
  int64_t       reqId;
4373
  int64_t       rspId;
4374
  int32_t       svrTimestamp;
4375
  SArray*       rsps;  // SArray<SClientHbRsp>
4376
  SMonitorParas monitorParas;
4377
  int8_t        enableAuditDelete;
4378
  int8_t        enableStrongPass;
4379
} SClientHbBatchRsp;
4380

4381
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
53,067,032✔
4382

4383
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4384
  void* pIter = taosHashIterate(info, NULL);
36,538,535✔
4385
  while (pIter != NULL) {
79,201,774✔
4386
    SKv* kv = (SKv*)pIter;
42,662,290✔
4387
    taosMemoryFreeClear(kv->value);
42,662,290✔
4388
    pIter = taosHashIterate(info, pIter);
42,662,290✔
4389
  }
4390
}
36,539,484✔
4391

4392
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
20,266,112✔
4393
  SQueryDesc* desc = (SQueryDesc*)pDesc;
20,266,112✔
4394
  if (desc->subDesc) {
20,266,112✔
4395
    taosArrayDestroy(desc->subDesc);
18,014,591✔
4396
    desc->subDesc = NULL;
18,013,857✔
4397
  }
4398
}
20,266,220✔
4399

4400
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
44,633,397✔
4401
  SClientHbReq* req = (SClientHbReq*)pReq;
47,262,682✔
4402
  if (req->query) {
47,262,682✔
4403
    if (req->query->queryDesc) {
40,329,472✔
4404
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
18,457,011✔
4405
    }
4406
    taosMemoryFreeClear(req->query);
40,329,925✔
4407
  }
4408

4409
  if (req->info) {
47,262,954✔
4410
    tFreeReqKvHash(req->info);
36,538,694✔
4411
    taosHashCleanup(req->info);
36,539,484✔
4412
    req->info = NULL;
36,539,151✔
4413
  }
4414
}
24,736,311✔
4415

4416
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4417
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4418

4419
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4420
  if (pReq == NULL) return;
18,122,594✔
4421
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
18,122,594✔
4422
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
18,122,594✔
4423
  taosMemoryFree(pReq);
18,122,594✔
4424
}
4425

4426
static FORCE_INLINE void tFreeClientKv(void* pKv) {
15,603,271✔
4427
  SKv* kv = (SKv*)pKv;
15,603,271✔
4428
  if (kv) {
15,603,271✔
4429
    taosMemoryFreeClear(kv->value);
15,603,271✔
4430
  }
4431
}
15,603,724✔
4432

4433
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
44,445,462✔
4434
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
44,445,462✔
4435
  if (rsp->query) {
44,445,462✔
4436
    taosArrayDestroy(rsp->query->pQnodeList);
40,171,056✔
4437
    taosMemoryFreeClear(rsp->query);
40,168,781✔
4438
  }
4439
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
44,443,474✔
4440
}
22,340,514✔
4441

4442
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4443
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
35,636,659✔
4444
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
35,636,659✔
4445
}
35,637,257✔
4446

4447
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4448
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4449
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4450

4451
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4452
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
122,630,711✔
4453
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
122,631,182✔
4454
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
122,631,322✔
4455
  return 0;
61,315,661✔
4456
}
4457

4458
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4459
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
60,236,698✔
4460
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
60,237,029✔
4461
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
30,118,680✔
4462
  if (pKv->value == NULL) {
30,117,908✔
4463
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4464
  }
4465
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
30,118,349✔
4466
  return 0;
30,118,680✔
4467
}
4468

4469
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4470
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
186,300,947✔
4471
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
186,297,271✔
4472
  return 0;
93,147,455✔
4473
}
4474

4475
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4476
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
92,763,161✔
4477
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
92,762,271✔
4478
  return 0;
46,381,210✔
4479
}
4480

4481
typedef struct {
4482
  int32_t vgId;
4483
  // TODO stas
4484
} SMqReportVgInfo;
4485

4486
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4487
  int32_t tlen = 0;
4488
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4489
  return tlen;
4490
}
4491

4492
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4493
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4494
  return buf;
4495
}
4496

4497
typedef struct {
4498
  int32_t epoch;
4499
  int64_t topicUid;
4500
  char    name[TSDB_TOPIC_FNAME_LEN];
4501
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4502
} SMqTopicInfo;
4503

4504
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4505
  int32_t tlen = 0;
4506
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4507
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4508
  tlen += taosEncodeString(buf, pTopicInfo->name);
4509
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4510
  tlen += taosEncodeFixedI32(buf, sz);
4511
  for (int32_t i = 0; i < sz; i++) {
4512
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4513
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4514
  }
4515
  return tlen;
4516
}
4517

4518
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4519
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4520
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4521
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4522
  int32_t sz;
4523
  buf = taosDecodeFixedI32(buf, &sz);
4524
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4525
    return NULL;
4526
  }
4527
  for (int32_t i = 0; i < sz; i++) {
4528
    SMqReportVgInfo vgInfo;
4529
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4530
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4531
      return NULL;
4532
    }
4533
  }
4534
  return buf;
4535
}
4536

4537
typedef struct {
4538
  int32_t status;  // ask hb endpoint
4539
  int32_t epoch;
4540
  int64_t consumerId;
4541
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4542
} SMqReportReq;
4543

4544
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4545
  int32_t tlen = 0;
4546
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4547
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4548
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4549
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4550
  tlen += taosEncodeFixedI32(buf, sz);
4551
  for (int32_t i = 0; i < sz; i++) {
4552
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4553
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4554
  }
4555
  return tlen;
4556
}
4557

4558
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4559
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4560
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4561
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4562
  int32_t sz;
4563
  buf = taosDecodeFixedI32(buf, &sz);
4564
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4565
    return NULL;
4566
  }
4567
  for (int32_t i = 0; i < sz; i++) {
4568
    SMqTopicInfo topicInfo;
4569
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4570
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4571
      return NULL;
4572
    }
4573
  }
4574
  return buf;
4575
}
4576

4577
typedef struct {
4578
  SMsgHead head;
4579
  int64_t  leftForVer;
4580
  int32_t  vgId;
4581
  int64_t  consumerId;
4582
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4583
} SMqVDeleteReq;
4584

4585
typedef struct {
4586
  int8_t reserved;
4587
} SMqVDeleteRsp;
4588

4589
typedef struct {
4590
  char*  name;
4591
  int8_t igNotExists;
4592
} SMDropStreamReq;
4593

4594
typedef struct {
4595
  int8_t reserved;
4596
} SMDropStreamRsp;
4597

4598
typedef struct {
4599
  SMsgHead head;
4600
  int64_t  resetRelHalt;  // reset related stream task halt status
4601
  int64_t  streamId;
4602
  int32_t  taskId;
4603
} SVDropStreamTaskReq;
4604

4605
typedef struct {
4606
  int8_t reserved;
4607
} SVDropStreamTaskRsp;
4608

4609
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4610
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4611
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4612

4613
typedef struct {
4614
  char*  name;
4615
  int8_t igNotExists;
4616
} SMPauseStreamReq;
4617

4618
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4619
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4620
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4621

4622
typedef struct {
4623
  char*  name;
4624
  int8_t igNotExists;
4625
  int8_t igUntreated;
4626
} SMResumeStreamReq;
4627

4628
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4629
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4630
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4631

4632
typedef struct {
4633
  char*       name;
4634
  int8_t      calcAll;
4635
  STimeWindow timeRange;
4636
} SMRecalcStreamReq;
4637

4638
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4639
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4640
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4641

4642
typedef struct SVndSetKeepVersionReq {
4643
  int64_t keepVersion;
4644
} SVndSetKeepVersionReq;
4645

4646
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4647
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4648

4649
typedef struct SVUpdateCheckpointInfoReq {
4650
  SMsgHead head;
4651
  int64_t  streamId;
4652
  int32_t  taskId;
4653
  int64_t  checkpointId;
4654
  int64_t  checkpointVer;
4655
  int64_t  checkpointTs;
4656
  int32_t  transId;
4657
  int64_t  hStreamId;  // add encode/decode
4658
  int64_t  hTaskId;
4659
  int8_t   dropRelHTask;
4660
} SVUpdateCheckpointInfoReq;
4661

4662
typedef struct {
4663
  int64_t leftForVer;
4664
  int32_t vgId;
4665
  int64_t oldConsumerId;
4666
  int64_t newConsumerId;
4667
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4668
  int8_t  subType;
4669
  int8_t  withMeta;
4670
  char*   qmsg;  // SubPlanToString
4671
  SSchemaWrapper schema;
4672
  int64_t suid;
4673
} SMqRebVgReq;
4674

4675
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4676
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4677

4678
// tqOffset
4679
enum {
4680
  TMQ_OFFSET__RESET_NONE = -3,
4681
  TMQ_OFFSET__RESET_EARLIEST = -2,
4682
  TMQ_OFFSET__RESET_LATEST = -1,
4683
  TMQ_OFFSET__LOG = 1,
4684
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4685
  TMQ_OFFSET__SNAPSHOT_META = 3,
4686
};
4687

4688
enum {
4689
  WITH_DATA = 0,
4690
  WITH_META = 1,
4691
  ONLY_META = 2,
4692
};
4693

4694
#define TQ_OFFSET_VERSION 1
4695

4696
typedef struct {
4697
  int8_t type;
4698
  union {
4699
    // snapshot
4700
    struct {
4701
      int64_t uid;
4702
      int64_t ts;
4703
      SValue  primaryKey;
4704
    };
4705
    // log
4706
    struct {
4707
      int64_t version;
4708
    };
4709
  };
4710
} STqOffsetVal;
4711

4712
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4713
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,659,028✔
4714
  pOffsetVal->uid = uid;
1,658,318✔
4715
  pOffsetVal->ts = ts;
1,658,136✔
4716
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,657,403✔
4717
    taosMemoryFree(pOffsetVal->primaryKey.pData);
59✔
4718
  }
4719
  pOffsetVal->primaryKey = primaryKey;
1,658,311✔
4720
}
1,657,596✔
4721

4722
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4723
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
6,538✔
4724
  pOffsetVal->uid = uid;
6,538✔
4725
}
6,538✔
4726

4727
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4728
  pOffsetVal->type = TMQ_OFFSET__LOG;
51,272,162✔
4729
  pOffsetVal->version = ver;
51,272,011✔
4730
}
51,269,487✔
4731

4732
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4733
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4734
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4735
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4736
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4737
void    tOffsetDestroy(void* pVal);
4738

4739
typedef struct {
4740
  STqOffsetVal val;
4741
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4742
} STqOffset;
4743

4744
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4745
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4746
void    tDeleteSTqOffset(void* val);
4747

4748
typedef struct SMqVgOffset {
4749
  int64_t   consumerId;
4750
  STqOffset offset;
4751
} SMqVgOffset;
4752

4753
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4754
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4755

4756
typedef struct {
4757
  char    name[TSDB_TABLE_FNAME_LEN];
4758
  char    stb[TSDB_TABLE_FNAME_LEN];
4759
  int8_t  igExists;
4760
  int8_t  intervalUnit;
4761
  int8_t  slidingUnit;
4762
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4763
  int32_t dstVgId;   // for stream
4764
  int64_t interval;
4765
  int64_t offset;
4766
  int64_t sliding;
4767
  int64_t maxDelay;
4768
  int64_t watermark;
4769
  int32_t exprLen;        // strlen + 1
4770
  int32_t tagsFilterLen;  // strlen + 1
4771
  int32_t sqlLen;         // strlen + 1
4772
  int32_t astLen;         // strlen + 1
4773
  char*   expr;
4774
  char*   tagsFilter;
4775
  char*   sql;
4776
  char*   ast;
4777
  int64_t deleteMark;
4778
  int64_t lastTs;
4779
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4780
  SArray* pVgroupVerList;
4781
  int8_t  recursiveTsma;
4782
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4783
  char*   createStreamReq;
4784
  int32_t streamReqLen;
4785
  char*   dropStreamReq;
4786
  int32_t dropStreamReqLen;
4787
  int64_t uid;
4788
} SMCreateSmaReq;
4789

4790
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4791
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4792
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4793

4794
typedef struct {
4795
  char    name[TSDB_TABLE_FNAME_LEN];
4796
  int8_t  igNotExists;
4797
  char*   dropStreamReq;
4798
  int32_t dropStreamReqLen;
4799
} SMDropSmaReq;
4800

4801
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4802
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4803
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
4804

4805
typedef struct {
4806
  char name[TSDB_TABLE_NAME_LEN];
4807
  union {
4808
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4809
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4810
  };
4811
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4812
  union {
4813
    int8_t igExists;   // used by mnode
4814
    int8_t alterType;  // used by vnode
4815
  };
4816
  int8_t     intervalUnit;
4817
  int16_t    nFuncs;       // number of functions specified by user
4818
  col_id_t*  funcColIds;   // column ids specified by user
4819
  func_id_t* funcIds;      // function ids specified by user
4820
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4821
  int64_t    tbUid;
4822
  int64_t    uid;     // rsma uid
4823
  int32_t    sqlLen;  // strlen + 1
4824
  char*      sql;
4825
} SMCreateRsmaReq;
4826

4827
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4828
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4829
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4830

4831
typedef SMCreateRsmaReq SVCreateRsmaReq;
4832

4833
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4834
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4835
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4836

4837
typedef SMCreateRsmaReq SVAlterRsmaReq;
4838

4839
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4840
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4841
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4842

4843
typedef struct {
4844
  char       name[TSDB_TABLE_NAME_LEN];
4845
  int8_t     alterType;
4846
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4847
  int8_t     igNotExists;
4848
  int16_t    nFuncs;      // number of functions specified by user
4849
  col_id_t*  funcColIds;  // column ids specified by user
4850
  func_id_t* funcIds;     // function ids specified by user
4851
  int32_t    sqlLen;      // strlen + 1
4852
  char*      sql;
4853
} SMAlterRsmaReq;
4854

4855
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4856
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4857
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4858

4859
typedef struct {
4860
  int64_t    id;
4861
  char       name[TSDB_TABLE_NAME_LEN];
4862
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4863
  int32_t    code;
4864
  int32_t    version;
4865
  int8_t     tbType;
4866
  int8_t     intervalUnit;
4867
  col_id_t   nFuncs;
4868
  col_id_t   nColNames;
4869
  int64_t    interval[2];
4870
  col_id_t*  funcColIds;
4871
  func_id_t* funcIds;
4872
  SArray*    colNames;
4873
} SRsmaInfoRsp;
4874

4875
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4876
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4877
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4878

4879
typedef struct {
4880
  char   name[TSDB_TABLE_FNAME_LEN];
4881
  int8_t igNotExists;
4882
} SMDropRsmaReq;
4883

4884
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4885
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4886

4887
typedef struct {
4888
  char    name[TSDB_TABLE_NAME_LEN];
4889
  char    tbName[TSDB_TABLE_NAME_LEN];
4890
  int64_t uid;
4891
  int64_t tbUid;
4892
  int8_t  tbType;
4893
} SVDropRsmaReq;
4894

4895
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4896
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4897

4898
typedef struct {
4899
  char   dbFName[TSDB_DB_FNAME_LEN];
4900
  char   stbName[TSDB_TABLE_NAME_LEN];
4901
  char   colName[TSDB_COL_NAME_LEN];
4902
  char   idxName[TSDB_INDEX_FNAME_LEN];
4903
  int8_t idxType;
4904
} SCreateTagIndexReq;
4905

4906
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4907
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4908

4909
typedef SMDropSmaReq SDropTagIndexReq;
4910

4911
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4912
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4913

4914
typedef struct {
4915
  int8_t         version;       // for compatibility(default 0)
4916
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4917
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4918
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4919
  int32_t        dstVgId;
4920
  char           indexName[TSDB_INDEX_NAME_LEN];
4921
  int32_t        exprLen;
4922
  int32_t        tagsFilterLen;
4923
  int64_t        indexUid;
4924
  tb_uid_t       tableUid;  // super/child/common table uid
4925
  tb_uid_t       dstTbUid;  // for dstVgroup
4926
  int64_t        interval;
4927
  int64_t        offset;  // use unit by precision of DB
4928
  int64_t        sliding;
4929
  char*          dstTbName;  // for dstVgroup
4930
  char*          expr;       // sma expression
4931
  char*          tagsFilter;
4932
  SSchemaWrapper schemaRow;  // for dstVgroup
4933
  SSchemaWrapper schemaTag;  // for dstVgroup
4934
} STSma;                     // Time-range-wise SMA
4935

4936
typedef STSma SVCreateTSmaReq;
4937

4938
typedef struct {
4939
  int8_t  type;  // 0 status report, 1 update data
4940
  int64_t indexUid;
4941
  int64_t skey;  // start TS key of interval/sliding window
4942
} STSmaMsg;
4943

4944
typedef struct {
4945
  int64_t indexUid;
4946
  char    indexName[TSDB_INDEX_NAME_LEN];
4947
} SVDropTSmaReq;
4948

4949
typedef struct {
4950
  int tmp;  // TODO: to avoid compile error
4951
} SVCreateTSmaRsp, SVDropTSmaRsp;
4952

4953
#if 0
4954
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4955
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4956
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4957
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4958
#endif
4959

4960
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4961
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4962
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4963
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4964

4965
typedef struct {
4966
  int32_t number;
4967
  STSma*  tSma;
4968
} STSmaWrapper;
4969

4970
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4971
  if (pSma) {
×
4972
    taosMemoryFreeClear(pSma->dstTbName);
×
4973
    taosMemoryFreeClear(pSma->expr);
×
4974
    taosMemoryFreeClear(pSma->tagsFilter);
×
4975
  }
4976
}
×
4977

4978
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4979
  if (pSW) {
×
4980
    if (pSW->tSma) {
×
4981
      if (deepCopy) {
×
4982
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4983
          tDestroyTSma(pSW->tSma + i);
×
4984
        }
4985
      }
4986
      taosMemoryFreeClear(pSW->tSma);
×
4987
    }
4988
  }
4989
}
×
4990

4991
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4992
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4993
  taosMemoryFreeClear(pSW);
×
4994
  return NULL;
×
4995
}
4996

4997
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4998
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4999

5000
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5001
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5002

5003
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5004
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5005
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5006
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5007
  }
5008
  return 0;
×
5009
}
5010

5011
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5012
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5013
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5014
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5015
  }
5016
  return 0;
×
5017
}
5018

5019
typedef struct {
5020
  int idx;
5021
} SMCreateFullTextReq;
5022

5023
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5024
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5025
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5026

5027
typedef struct {
5028
  char   name[TSDB_TABLE_FNAME_LEN];
5029
  int8_t igNotExists;
5030
} SMDropFullTextReq;
5031

5032
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5033
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5034

5035
typedef struct {
5036
  char indexFName[TSDB_INDEX_FNAME_LEN];
5037
} SUserIndexReq;
5038

5039
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5040
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5041

5042
typedef struct {
5043
  char dbFName[TSDB_DB_FNAME_LEN];
5044
  char tblFName[TSDB_TABLE_FNAME_LEN];
5045
  char colName[TSDB_COL_NAME_LEN];
5046
  char indexType[TSDB_INDEX_TYPE_LEN];
5047
  char indexExts[TSDB_INDEX_EXTS_LEN];
5048
} SUserIndexRsp;
5049

5050
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5051
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5052

5053
typedef struct {
5054
  char tbFName[TSDB_TABLE_FNAME_LEN];
5055
} STableIndexReq;
5056

5057
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5058
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5059

5060
typedef struct {
5061
  int8_t  intervalUnit;
5062
  int8_t  slidingUnit;
5063
  int64_t interval;
5064
  int64_t offset;
5065
  int64_t sliding;
5066
  int64_t dstTbUid;
5067
  int32_t dstVgId;
5068
  SEpSet  epSet;
5069
  char*   expr;
5070
} STableIndexInfo;
5071

5072
typedef struct {
5073
  char     tbName[TSDB_TABLE_NAME_LEN];
5074
  char     dbFName[TSDB_DB_FNAME_LEN];
5075
  uint64_t suid;
5076
  int32_t  version;
5077
  int32_t  indexSize;
5078
  SArray*  pIndex;  // STableIndexInfo
5079
} STableIndexRsp;
5080

5081
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5082
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5083
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5084

5085
void tFreeSTableIndexInfo(void* pInfo);
5086

5087
typedef struct {
5088
  int8_t  mqMsgType;
5089
  int32_t code;
5090
  int32_t epoch;
5091
  int64_t consumerId;
5092
  int64_t walsver;
5093
  int64_t walever;
5094
} SMqRspHead;
5095

5096
typedef struct {
5097
  SMsgHead     head;
5098
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5099
  int8_t       withTbName;
5100
  int8_t       useSnapshot;
5101
  int32_t      epoch;
5102
  uint64_t     reqId;
5103
  int64_t      consumerId;
5104
  int64_t      timeout;
5105
  STqOffsetVal reqOffset;
5106
  int8_t       enableReplay;
5107
  int8_t       sourceExcluded;
5108
  int8_t       rawData;
5109
  int32_t      minPollRows;
5110
  int8_t       enableBatchMeta;
5111
  SHashObj*    uidHash;  // to find if uid is duplicated
5112
} SMqPollReq;
5113

5114
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5115
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5116
void    tDestroySMqPollReq(SMqPollReq* pReq);
5117

5118
typedef struct {
5119
  int32_t vgId;
5120
  int64_t offset;
5121
  SEpSet  epSet;
5122
} SMqSubVgEp;
5123

5124
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5125
  int32_t tlen = 0;
532,392✔
5126
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
532,392✔
5127
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
532,392✔
5128
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
532,392✔
5129
  return tlen;
532,392✔
5130
}
5131

5132
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5133
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
287,942✔
5134
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
287,942✔
5135
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
287,942✔
5136
  return buf;
287,942✔
5137
}
5138

5139
typedef struct {
5140
  char           topic[TSDB_TOPIC_FNAME_LEN];
5141
  char           db[TSDB_DB_FNAME_LEN];
5142
  SArray*        vgs;  // SArray<SMqSubVgEp>
5143
} SMqSubTopicEp;
5144

5145
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5146
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5147
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5148

5149
typedef struct {
5150
  SMqRspHead   head;
5151
  STqOffsetVal rspOffset;
5152
  int16_t      resMsgType;
5153
  int32_t      metaRspLen;
5154
  void*        metaRsp;
5155
} SMqMetaRsp;
5156

5157
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5158
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5159
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5160

5161
#define MQ_DATA_RSP_VERSION 100
5162

5163
typedef struct {
5164
  SMqRspHead   head;
5165
  STqOffsetVal rspOffset;
5166
  STqOffsetVal reqOffset;
5167
  int32_t      blockNum;
5168
  int8_t       withTbName;
5169
  // int8_t       withSchema;
5170
  SArray*      blockDataLen;
5171
  SArray*      blockData;
5172
  SArray*      blockTbName;
5173
  SArray*      blockSchema;
5174

5175
  union {
5176
    struct {
5177
      int64_t sleepTime;
5178
    };
5179
    struct {
5180
      int32_t createTableNum;
5181
      SArray* createTableLen;
5182
      SArray* createTableReq;
5183
    };
5184
    struct {
5185
      int32_t len;
5186
      void*   rawData;
5187
    };
5188
  };
5189
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5190
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5191
} SMqDataRsp;
5192

5193
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5194
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5195
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5196
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5197
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5198

5199
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5200
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5201
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5202

5203
typedef struct SMqBatchMetaRsp {
5204
  SMqRspHead   head;  // not serialize
5205
  STqOffsetVal rspOffset;
5206
  SArray*      batchMetaLen;
5207
  SArray*      batchMetaReq;
5208
  void*        pMetaBuff;    // not serialize
5209
  uint32_t     metaBuffLen;  // not serialize
5210
} SMqBatchMetaRsp;
5211

5212
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5213
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5214
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5215
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5216

5217
typedef struct {
5218
  SMqRspHead head;
5219
  char       cgroup[TSDB_CGROUP_LEN];
5220
  SArray*    topics;  // SArray<SMqSubTopicEp>
5221
} SMqAskEpRsp;
5222

5223
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5224
  int32_t tlen = 0;
1,299,740✔
5225
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5226
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,299,740✔
5227
  tlen += taosEncodeFixedI32(buf, sz);
1,299,482✔
5228
  for (int32_t i = 0; i < sz; i++) {
1,466,984✔
5229
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
167,398✔
5230
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
167,398✔
5231
  }
5232
  return tlen;
1,299,586✔
5233
}
5234

5235
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5236
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5237
  int32_t sz;
493,728✔
5238
  buf = taosDecodeFixedI32(buf, &sz);
536,652✔
5239
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
536,652✔
5240
  if (pRsp->topics == NULL) {
536,652✔
5241
    return NULL;
×
5242
  }
5243
  for (int32_t i = 0; i < sz; i++) {
623,868✔
5244
    SMqSubTopicEp topicEp;
71,591✔
5245
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
87,216✔
5246
    if (buf == NULL) {
87,216✔
5247
      return NULL;
×
5248
    }
5249
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
174,432✔
5250
      return NULL;
×
5251
    }
5252
  }
5253
  return buf;
536,652✔
5254
}
5255

5256
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5257
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,489,758✔
5258
}
1,489,937✔
5259

5260
typedef struct {
5261
  int32_t      vgId;
5262
  STqOffsetVal offset;
5263
  int64_t      rows;
5264
  int64_t      ever;
5265
} OffsetRows;
5266

5267
typedef struct {
5268
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5269
  SArray* offsetRows;
5270
} TopicOffsetRows;
5271

5272
typedef struct {
5273
  int64_t consumerId;
5274
  int32_t epoch;
5275
  SArray* topics;
5276
  int8_t  pollFlag;
5277
} SMqHbReq;
5278

5279
typedef struct {
5280
  char   topic[TSDB_TOPIC_FNAME_LEN];
5281
  int8_t noPrivilege;
5282
} STopicPrivilege;
5283

5284
typedef struct {
5285
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5286
  int32_t debugFlag;
5287
} SMqHbRsp;
5288

5289
typedef struct {
5290
  SMsgHead head;
5291
  int64_t  consumerId;
5292
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5293
} SMqSeekReq;
5294

5295
#define TD_AUTO_CREATE_TABLE 0x1
5296
typedef struct {
5297
  int64_t       suid;
5298
  int64_t       uid;
5299
  int32_t       sver;
5300
  uint32_t      nData;
5301
  uint8_t*      pData;
5302
  SVCreateTbReq cTbReq;
5303
} SVSubmitBlk;
5304

5305
typedef struct {
5306
  SMsgHead header;
5307
  uint64_t sId;
5308
  uint64_t queryId;
5309
  uint64_t clientId;
5310
  uint64_t taskId;
5311
  uint32_t sqlLen;
5312
  uint32_t phyLen;
5313
  char*    sql;
5314
  char*    msg;
5315
  int8_t   source;
5316
} SVDeleteReq;
5317

5318
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5319
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5320

5321
typedef struct {
5322
  int64_t affectedRows;
5323
} SVDeleteRsp;
5324

5325
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5326
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5327

5328
typedef struct SDeleteRes {
5329
  uint64_t suid;
5330
  SArray*  uidList;
5331
  int64_t  skey;
5332
  int64_t  ekey;
5333
  int64_t  affectedRows;
5334
  char     tableFName[TSDB_TABLE_NAME_LEN];
5335
  char     tsColName[TSDB_COL_NAME_LEN];
5336
  int64_t  ctimeMs;  // fill by vnode
5337
  int8_t   source;
5338
} SDeleteRes;
5339

5340
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5341
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5342

5343
typedef struct {
5344
  // int64_t uid;
5345
  char    tbname[TSDB_TABLE_NAME_LEN];
5346
  int64_t startTs;
5347
  int64_t endTs;
5348
} SSingleDeleteReq;
5349

5350
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5351
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5352

5353
typedef struct {
5354
  int64_t suid;
5355
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5356
  int64_t ctimeMs;     // fill by vnode
5357
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5358
} SBatchDeleteReq;
5359

5360
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5361
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5362
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5363

5364
typedef struct {
5365
  int32_t msgIdx;
5366
  int32_t msgType;
5367
  int32_t msgLen;
5368
  void*   msg;
5369
} SBatchMsg;
5370

5371
typedef struct {
5372
  SMsgHead header;
5373
  SArray*  pMsgs;  // SArray<SBatchMsg>
5374
} SBatchReq;
5375

5376
typedef struct {
5377
  int32_t reqType;
5378
  int32_t msgIdx;
5379
  int32_t msgLen;
5380
  int32_t rspCode;
5381
  void*   msg;
5382
} SBatchRspMsg;
5383

5384
typedef struct {
5385
  SArray* pRsps;  // SArray<SBatchRspMsg>
5386
} SBatchRsp;
5387

5388
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5389
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5390
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
90,576,748✔
5391
  if (NULL == msg) {
90,576,748✔
5392
    return;
×
5393
  }
5394
  SBatchMsg* pMsg = (SBatchMsg*)msg;
90,576,748✔
5395
  taosMemoryFree(pMsg->msg);
90,576,748✔
5396
}
5397

5398
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5399
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5400

5401
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
126,850,515✔
5402
  if (NULL == p) {
126,850,515✔
5403
    return;
×
5404
  }
5405

5406
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
126,850,515✔
5407
  taosMemoryFree(pRsp->msg);
126,850,515✔
5408
}
5409

5410
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5411
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5412
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5413
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5414
void    tDestroySMqHbReq(SMqHbReq* pReq);
5415

5416
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5417
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5418
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5419

5420
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5421
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5422

5423
#define TD_REQ_FROM_APP               0x0
5424
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5425
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5426
#define SUBMIT_REQ_FROM_FILE          0x4
5427
#define TD_REQ_FROM_TAOX              0x8
5428
#define TD_REQ_FROM_SML               0x10
5429
#define SUBMIT_REQUEST_VERSION        (2)
5430
#define SUBMIT_REQ_WITH_BLOB          0x10
5431
#define SUBMIT_REQ_SCHEMA_RES         0x20
5432
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5433

5434
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5435

5436
typedef struct {
5437
  int32_t        flags;
5438
  SVCreateTbReq* pCreateTbReq;
5439
  int64_t        suid;
5440
  int64_t        uid;
5441
  int32_t        sver;
5442
  union {
5443
    SArray* aRowP;
5444
    SArray* aCol;
5445
  };
5446
  int64_t   ctimeMs;
5447
  SBlobSet* pBlobSet;
5448
} SSubmitTbData;
5449

5450
typedef struct {
5451
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5452
  SArray* aSubmitBlobData;
5453
  bool    raw;
5454
} SSubmitReq2;
5455

5456
typedef struct {
5457
  SMsgHead header;
5458
  int64_t  version;
5459
  char     data[];  // SSubmitReq2
5460
} SSubmitReq2Msg;
5461

5462
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5463
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5464
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5465
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5466
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5467

5468
typedef struct {
5469
  int32_t affectedRows;
5470
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5471
} SSubmitRsp2;
5472

5473
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5474
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5475
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5476

5477
#define TSDB_MSG_FLG_ENCODE 0x1
5478
#define TSDB_MSG_FLG_DECODE 0x2
5479
#define TSDB_MSG_FLG_CMPT   0x3
5480

5481
typedef struct {
5482
  union {
5483
    struct {
5484
      void*   msgStr;
5485
      int32_t msgLen;
5486
      int64_t ver;
5487
    };
5488
    void* pDataBlock;
5489
  };
5490
} SPackedData;
5491

5492
typedef struct {
5493
  char     fullname[TSDB_VIEW_FNAME_LEN];
5494
  char     name[TSDB_VIEW_NAME_LEN];
5495
  char     dbFName[TSDB_DB_FNAME_LEN];
5496
  char*    querySql;
5497
  char*    sql;
5498
  int8_t   orReplace;
5499
  int8_t   precision;
5500
  int32_t  numOfCols;
5501
  SSchema* pSchema;
5502
} SCMCreateViewReq;
5503

5504
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5505
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5506
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5507

5508
typedef struct {
5509
  char   fullname[TSDB_VIEW_FNAME_LEN];
5510
  char   name[TSDB_VIEW_NAME_LEN];
5511
  char   dbFName[TSDB_DB_FNAME_LEN];
5512
  char*  sql;
5513
  int8_t igNotExists;
5514
} SCMDropViewReq;
5515

5516
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5517
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5518
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5519

5520
typedef struct {
5521
  char fullname[TSDB_VIEW_FNAME_LEN];
5522
} SViewMetaReq;
5523
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5524
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5525

5526
typedef struct {
5527
  char     name[TSDB_VIEW_NAME_LEN];
5528
  char     dbFName[TSDB_DB_FNAME_LEN];
5529
  char*    user;
5530
  uint64_t dbId;
5531
  uint64_t viewId;
5532
  char*    querySql;
5533
  int8_t   precision;
5534
  int8_t   type;
5535
  int32_t  version;
5536
  int32_t  numOfCols;
5537
  SSchema* pSchema;
5538
} SViewMetaRsp;
5539
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5540
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5541
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5542
typedef struct {
5543
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5544
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5545
} STableTSMAInfoReq;
5546

5547
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5548
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5549

5550
typedef struct {
5551
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5552
  union {
5553
    uint8_t flags;
5554
    struct {
5555
      uint8_t withColName : 1;
5556
      uint8_t reserved : 7;
5557
    };
5558
  };
5559

5560
} SRsmaInfoReq;
5561

5562
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5563
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5564

5565
typedef struct {
5566
  int32_t  funcId;
5567
  col_id_t colId;
5568
} STableTSMAFuncInfo;
5569

5570
typedef struct {
5571
  char     name[TSDB_TABLE_NAME_LEN];
5572
  uint64_t tsmaId;
5573
  char     targetTb[TSDB_TABLE_NAME_LEN];
5574
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5575
  char     tb[TSDB_TABLE_NAME_LEN];
5576
  char     dbFName[TSDB_DB_FNAME_LEN];
5577
  uint64_t suid;
5578
  uint64_t destTbUid;
5579
  uint64_t dbId;
5580
  int32_t  version;
5581
  int64_t  interval;
5582
  int8_t   unit;
5583
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5584
  SArray*  pTags;      // SArray<SSchema>
5585
  SArray*  pUsedCols;  // SArray<SSchema>
5586
  char*    ast;
5587

5588
  int64_t streamUid;
5589
  int64_t reqTs;
5590
  int64_t rspTs;
5591
  int64_t delayDuration;  // ms
5592
  bool    fillHistoryFinished;
5593

5594
  void* streamAddr;  // for stream task, the address of the stream task
5595
} STableTSMAInfo;
5596

5597
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5598
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5599
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5600
void    tFreeTableTSMAInfo(void* p);
5601
void    tFreeAndClearTableTSMAInfo(void* p);
5602
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5603

5604
#define STSMAHbRsp            STableTSMAInfoRsp
5605
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5606
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5607
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5608

5609
typedef struct SDropCtbWithTsmaSingleVgReq {
5610
  SVgroupInfo vgInfo;
5611
  SArray*     pTbs;  // SVDropTbReq
5612
} SMDropTbReqsOnSingleVg;
5613

5614
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5615
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5616
void    tFreeSMDropTbReqOnSingleVg(void* p);
5617

5618
typedef struct SDropTbsReq {
5619
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5620
} SMDropTbsReq;
5621

5622
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5623
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5624
void    tFreeSMDropTbsReq(void*);
5625

5626
typedef struct SVFetchTtlExpiredTbsRsp {
5627
  SArray* pExpiredTbs;  // SVDropTbReq
5628
  int32_t vgId;
5629
} SVFetchTtlExpiredTbsRsp;
5630

5631
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5632
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5633

5634
void tFreeFetchTtlExpiredTbsRsp(void* p);
5635

5636
void setDefaultOptionsForField(SFieldWithOptions* field);
5637
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5638

5639
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5640
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5641

5642
typedef struct {
5643
  char    id[TSDB_INSTANCE_ID_LEN];
5644
  char    type[TSDB_INSTANCE_TYPE_LEN];
5645
  char    desc[TSDB_INSTANCE_DESC_LEN];
5646
  int32_t expire;
5647
} SInstanceRegisterReq;
5648

5649
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5650
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5651

5652
typedef struct {
5653
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5654
} SInstanceListReq;
5655

5656
typedef struct {
5657
  int32_t count;
5658
  char**  ids;  // Array of instance IDs
5659
} SInstanceListRsp;
5660

5661
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5662
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5663
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5664
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5665

5666
#ifdef USE_MOUNT
5667
typedef struct {
5668
  char     mountName[TSDB_MOUNT_NAME_LEN];
5669
  int8_t   ignoreExist;
5670
  int16_t  nMounts;
5671
  int32_t* dnodeIds;
5672
  char**   mountPaths;
5673
  int32_t  sqlLen;
5674
  char*    sql;
5675
} SCreateMountReq;
5676

5677
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5678
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5679
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5680

5681
typedef struct {
5682
  char    mountName[TSDB_MOUNT_NAME_LEN];
5683
  int8_t  ignoreNotExists;
5684
  int32_t sqlLen;
5685
  char*   sql;
5686
} SDropMountReq;
5687

5688
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5689
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5690
void    tFreeSDropMountReq(SDropMountReq* pReq);
5691

5692
typedef struct {
5693
  char     mountName[TSDB_MOUNT_NAME_LEN];
5694
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5695
  int64_t  mountUid;
5696
  int32_t  dnodeId;
5697
  uint32_t valLen;
5698
  int8_t   ignoreExist;
5699
  void*    pVal;
5700
} SRetrieveMountPathReq;
5701

5702
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5703
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5704

5705
typedef struct {
5706
  // path
5707
  int32_t diskPrimary;
5708
  // vgInfo
5709
  int32_t  vgId;
5710
  int32_t  cacheLastSize;
5711
  int32_t  szPage;
5712
  int32_t  szCache;
5713
  uint64_t szBuf;
5714
  int8_t   cacheLast;
5715
  int8_t   standby;
5716
  int8_t   hashMethod;
5717
  uint32_t hashBegin;
5718
  uint32_t hashEnd;
5719
  int16_t  hashPrefix;
5720
  int16_t  hashSuffix;
5721
  int16_t  sttTrigger;
5722
  // syncInfo
5723
  int32_t replications;
5724
  // tsdbInfo
5725
  int8_t  precision;
5726
  int8_t  compression;
5727
  int8_t  slLevel;
5728
  int32_t daysPerFile;
5729
  int32_t keep0;
5730
  int32_t keep1;
5731
  int32_t keep2;
5732
  int32_t keepTimeOffset;
5733
  int32_t minRows;
5734
  int32_t maxRows;
5735
  int32_t tsdbPageSize;
5736
  int32_t ssChunkSize;
5737
  int32_t ssKeepLocal;
5738
  int8_t  ssCompact;
5739
  // walInfo
5740
  int32_t walFsyncPeriod;      // millisecond
5741
  int32_t walRetentionPeriod;  // secs
5742
  int32_t walRollPeriod;       // secs
5743
  int64_t walRetentionSize;
5744
  int64_t walSegSize;
5745
  int32_t walLevel;
5746
  // encryptInfo
5747
  int32_t encryptAlgorithm;
5748
  // SVState
5749
  int64_t committed;
5750
  int64_t commitID;
5751
  int64_t commitTerm;
5752
  // stats
5753
  int64_t numOfSTables;
5754
  int64_t numOfCTables;
5755
  int64_t numOfNTables;
5756
  // dbInfo
5757
  uint64_t dbId;
5758
} SMountVgInfo;
5759

5760
typedef struct {
5761
  SMCreateStbReq req;
5762
  SArray*        pColExts;  // element: column id
5763
  SArray*        pTagExts;  // element: tag id
5764
} SMountStbInfo;
5765

5766
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5767
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5768

5769
typedef struct {
5770
  char     dbName[TSDB_DB_FNAME_LEN];
5771
  uint64_t dbId;
5772
  SArray*  pVgs;   // SMountVgInfo
5773
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5774
} SMountDbInfo;
5775

5776
typedef struct {
5777
  // common fields
5778
  char     mountName[TSDB_MOUNT_NAME_LEN];
5779
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5780
  int8_t   ignoreExist;
5781
  int64_t  mountUid;
5782
  int64_t  clusterId;
5783
  int32_t  dnodeId;
5784
  uint32_t valLen;
5785
  void*    pVal;
5786

5787
  // response fields
5788
  SArray* pDbs;  // SMountDbInfo
5789

5790
  // memory fields, no serialized
5791
  SArray*   pDisks[TFS_MAX_TIERS];
5792
  TdFilePtr pFile;
5793
} SMountInfo;
5794

5795
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5796
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5797
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5798

5799
typedef struct {
5800
  SCreateVnodeReq createReq;
5801
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5802
  char            mountName[TSDB_MOUNT_NAME_LEN];
5803
  int64_t         mountId;
5804
  int32_t         diskPrimary;
5805
  int32_t         mountVgId;
5806
  int64_t         committed;
5807
  int64_t         commitID;
5808
  int64_t         commitTerm;
5809
  int64_t         numOfSTables;
5810
  int64_t         numOfCTables;
5811
  int64_t         numOfNTables;
5812
} SMountVnodeReq;
5813

5814
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
5815
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5816
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5817

5818
#endif  // USE_MOUNT
5819

5820
#pragma pack(pop)
5821

5822
typedef struct {
5823
  char        db[TSDB_DB_FNAME_LEN];
5824
  STimeWindow timeRange;
5825
  int32_t     sqlLen;
5826
  char*       sql;
5827
  SArray*     vgroupIds;
5828
} SScanDbReq;
5829

5830
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5831
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5832
void    tFreeSScanDbReq(SScanDbReq* pReq);
5833

5834
typedef struct {
5835
  int32_t scanId;
5836
  int8_t  bAccepted;
5837
} SScanDbRsp;
5838

5839
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5840
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5841

5842
typedef struct {
5843
  int32_t scanId;
5844
  int32_t sqlLen;
5845
  char*   sql;
5846
} SKillScanReq;
5847

5848
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5849
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5850
void    tFreeSKillScanReq(SKillScanReq* pReq);
5851

5852
typedef struct {
5853
  int32_t scanId;
5854
  int32_t vgId;
5855
  int32_t dnodeId;
5856
} SVKillScanReq;
5857

5858
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5859
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5860

5861
typedef struct {
5862
  int32_t scanId;
5863
  int32_t vgId;
5864
  int32_t dnodeId;
5865
  int32_t numberFileset;
5866
  int32_t finished;
5867
  int32_t progress;
5868
  int64_t remainingTime;
5869
} SQueryScanProgressRsp;
5870

5871
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5872
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5873

5874
typedef struct {
5875
  int32_t scanId;
5876
  int32_t vgId;
5877
  int32_t dnodeId;
5878
} SQueryScanProgressReq;
5879

5880
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5881
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5882

5883
typedef struct {
5884
  int64_t     dbUid;
5885
  char        db[TSDB_DB_FNAME_LEN];
5886
  int64_t     scanStartTime;
5887
  STimeWindow tw;
5888
  int32_t     scanId;
5889
} SScanVnodeReq;
5890

5891
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5892
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5893

5894
#ifdef __cplusplus
5895
}
5896
#endif
5897

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