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

taosdata / TDengine / #4879

11 Dec 2025 02:43AM UTC coverage: 64.544% (-0.03%) from 64.569%
#4879

push

travis-ci

guanshengliang
feat(TS-7270): internal dependence

307 of 617 new or added lines in 24 files covered. (49.76%)

3883 existing lines in 125 files now uncovered.

163565 of 253417 relevant lines covered (64.54%)

105600506.39 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

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

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

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

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

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

110
static inline bool vnodeIsMsgBlock(tmsg_t type) {
714,013,867✔
111
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
673,570,808✔
112
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,387,584,675✔
113
         (type == TDMT_SYNC_CONFIG_CHANGE);
114
}
115

116
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,862,483,124✔
117
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,862,483,124✔
118
}
119

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

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

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

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

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

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

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

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

250

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

256

257
#define TSDB_ALTER_RSMA_FUNCTION        0x1
258

259
#define TSDB_KILL_MSG_LEN 30
260

261
#define TSDB_TABLE_NUM_UNIT 100000
262

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

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

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

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

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

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

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) {
424,054✔
UNCOV
914
    return TSDB_CODE_INVALID_PARA;
×
915
  }
916
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
424,054✔
917
  if (pRef->pColRef == NULL) {
424,054✔
UNCOV
918
    return terrno;
×
919
  }
920
  pRef->nCols = nCols;
424,054✔
921
  for (int32_t i = 0; i < nCols; i++) {
4,813,294✔
922
    pRef->pColRef[i].hasRef = false;
4,389,240✔
923
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4,389,240✔
924
  }
925
  return 0;
424,054✔
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)) {
2,226,036✔
UNCOV
954
    return TSDB_CODE_INVALID_PARA;
×
955
  }
956
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
2,226,036✔
957
  if (pCmpr->pColCmpr == NULL) {
2,226,036✔
UNCOV
958
    return terrno;
×
959
  }
960
  pCmpr->nCols = nCols;
2,226,036✔
961
  return 0;
2,226,036✔
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;
294,339,436✔
990

991
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
294,268,252✔
992
  if (pSW == NULL) {
294,326,283✔
UNCOV
993
    return NULL;
×
994
  }
995
  pSW->nCols = pSchemaWrapper->nCols;
294,326,283✔
996
  pSW->version = pSchemaWrapper->version;
294,315,282✔
997
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
294,379,413✔
998
  if (pSW->pSchema == NULL) {
294,282,083✔
UNCOV
999
    taosMemoryFree(pSW);
×
1000
    return NULL;
×
1001
  }
1002

1003
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
294,212,534✔
1004
  return pSW;
294,393,713✔
1005
}
1006

1007
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
70,633,435✔
1008
  if (pSchemaWrapper) {
774,207,484✔
1009
    taosMemoryFree(pSchemaWrapper->pSchema);
434,286,607✔
1010
    if(pSchemaWrapper->pRsma) {
434,209,193✔
1011
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
55,584✔
1012
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
55,584✔
1013
    }
1014
    taosMemoryFree(pSchemaWrapper);
434,238,537✔
1015
  }
1016
}
759,999,541✔
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) {
786,010✔
1029
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
786,010✔
1030
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
786,010✔
1031
  }
1032
}
786,010✔
1033

1034
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1035
  int32_t tlen = 0;
2,643,586✔
1036
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,654,818✔
1037
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,643,586✔
1038
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,643,586✔
1039
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,643,271✔
1040
  tlen += taosEncodeString(buf, pSchema->name);
2,643,061✔
1041
  return tlen;
2,643,271✔
1042
}
1043

1044
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1045
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,783,024✔
1046
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,460,834✔
1047
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,460,834✔
1048
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,460,834✔
1049
  buf = taosDecodeStringTo(buf, pSchema->name);
1,460,834✔
1050
  return (void*)buf;
1,460,834✔
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));
22,655,996✔
1087
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
22,655,996✔
1088
  if (pColRef->hasRef) {
11,327,998✔
1089
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
12,494,408✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
12,494,408✔
1091
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
12,494,408✔
1092
  }
1093
  return 0;
11,327,998✔
1094
}
1095

1096
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1097
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
14,149,532✔
1098
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
14,149,532✔
1099
  if (pColRef->hasRef) {
7,074,766✔
1100
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
4,205,316✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
4,205,316✔
1102
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
4,205,316✔
1103
  }
1104

1105
  return 0;
7,074,766✔
1106
}
1107

1108
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1109
  int32_t tlen = 0;
331,678✔
1110
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
331,678✔
1111
  tlen += taosEncodeVariantI32(buf, pSW->version);
331,678✔
1112
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,974,949✔
1113
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,286,647✔
1114
  }
1115
  return tlen;
331,678✔
1116
}
1117

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

1127
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,670,031✔
1128
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,921,668✔
1129
    }
1130
  } else {
1131
    pSW->pSchema = NULL;
18,553✔
1132
  }
1133
  return (void*)buf;
227,750✔
1134
}
1135

1136
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1137
  if (pSW == NULL) {
192,489,604✔
UNCOV
1138
    return TSDB_CODE_INVALID_PARA;
×
1139
  }
1140
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
384,956,150✔
1141
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
384,878,745✔
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;
192,611,763✔
1146
}
1147

1148
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1149
  if (pSW == NULL) {
56,554,811✔
UNCOV
1150
    return TSDB_CODE_INVALID_PARA;
×
1151
  }
1152
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
113,105,318✔
1153
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
113,123,528✔
1154

1155
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
56,573,021✔
1156
  if (pSW->pSchema == NULL) {
56,534,948✔
UNCOV
1157
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1158
  }
1159
  for (int32_t i = 0; i < pSW->nCols; i++) {
606,997,757✔
1160
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,100,732,700✔
1161
  }
1162

1163
  return 0;
56,583,589✔
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,375,083,170✔
UNCOV
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,375,495,695✔
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
// copyIpRange ensures that unused bytes are always zeroed, so that [pDst] can be used as a key in hash tables
1380
void copyIpRange(SIpRange* pDst, const SIpRange* pSrc);
1381

1382
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1383
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1384
typedef struct {
1385
  int16_t year;
1386
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1387
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1388
  int8_t hour;
1389
  int8_t minute;
1390
  int8_t neg;   // this is a negative entry
1391
  int32_t duration; // duration in minute
1392
} SDateTimeRange;
1393

1394
bool isValidDateTimeRange(SDateTimeRange* pRange);
1395
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1396
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1397

1398

1399
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1400
typedef struct {
1401
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1402
  bool neg;         // this is a negative entry
1403
  int32_t duration; // duration in seconds
1404
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1405
} SDateTimeWhiteListItem;
1406

1407
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1408
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1409

1410
typedef struct {
1411
  int32_t num;
1412
  SDateTimeWhiteListItem ranges[];
1413
} SDateTimeWhiteList;
1414

1415
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1416
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1417

1418

1419
typedef struct {
1420
  int8_t createType;
1421
  int8_t superUser;  // denote if it is a super user or not
1422
  int8_t ignoreExisting;
1423

1424
  char   user[TSDB_USER_LEN];
1425
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1426
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1427

1428
  int8_t sysInfo;
1429
  int8_t createDb;
1430
  int8_t isImport;
1431
  int8_t changepass;
1432
  int8_t enable;
1433

1434
  int8_t negIpRanges;
1435
  int8_t negTimeRanges;
1436

1437
  int32_t sessionPerUser;
1438
  int32_t connectTime;
1439
  int32_t connectIdleTime;
1440
  int32_t callPerSession;
1441
  int32_t vnodePerCall;
1442
  int32_t failedLoginAttempts;
1443
  int32_t passwordLifeTime;
1444
  int32_t passwordReuseTime;
1445
  int32_t passwordReuseMax;
1446
  int32_t passwordLockTime;
1447
  int32_t passwordGraceTime;
1448
  int32_t inactiveAccountTime;
1449
  int32_t allowTokenNum;
1450

1451
  int32_t         numIpRanges;
1452
  SIpRange*       pIpDualRanges;
1453
  int32_t         numTimeRanges;
1454
  SDateTimeRange* pTimeRanges;
1455

1456
  int32_t sqlLen;
1457
  char*   sql;
1458
} SCreateUserReq;
1459

1460
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1461
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1462
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1463

1464
typedef struct {
1465
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1466
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1467
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1468
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1469
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1470
  int32_t sqlLen;
1471
  char*   sql;
1472
} SCreateEncryptAlgrReq;
1473

1474
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1475
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1476
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1477

1478
typedef struct {
1479
  int32_t dnodeId;
1480
  int64_t analVer;
1481
} SRetrieveAnalyticsAlgoReq;
1482

1483
typedef struct {
1484
  int64_t   ver;
1485
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1486
} SRetrieveAnalyticAlgoRsp;
1487

1488
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1489
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1490
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1491
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1492
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1493

1494
typedef struct {
1495
  int8_t alterType;
1496

1497
  int8_t isView;
1498
  
1499
  int8_t hasPassword;
1500
  int8_t hasTotpseed;
1501
  int8_t hasEnable;
1502
  int8_t hasSysinfo;
1503
  int8_t hasCreatedb;
1504
  int8_t hasChangepass;
1505
  int8_t hasSessionPerUser;
1506
  int8_t hasConnectTime;
1507
  int8_t hasConnectIdleTime;
1508
  int8_t hasCallPerSession;
1509
  int8_t hasVnodePerCall;
1510
  int8_t hasFailedLoginAttempts;
1511
  int8_t hasPasswordLifeTime;
1512
  int8_t hasPasswordReuseTime;
1513
  int8_t hasPasswordReuseMax;
1514
  int8_t hasPasswordLockTime;
1515
  int8_t hasPasswordGraceTime;
1516
  int8_t hasInactiveAccountTime;
1517
  int8_t hasAllowTokenNum;
1518

1519
  int8_t enable;
1520
  int8_t sysinfo;
1521
  int8_t createdb;
1522
  int8_t changepass;
1523

1524
  char   user[TSDB_USER_LEN];
1525
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1526
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1527
  int32_t sessionPerUser;
1528
  int32_t connectTime;
1529
  int32_t connectIdleTime;
1530
  int32_t callPerSession;
1531
  int32_t vnodePerCall;
1532
  int32_t failedLoginAttempts;
1533
  int32_t passwordLifeTime;
1534
  int32_t passwordReuseTime;
1535
  int32_t passwordReuseMax;
1536
  int32_t passwordLockTime;
1537
  int32_t passwordGraceTime;
1538
  int32_t inactiveAccountTime;
1539
  int32_t allowTokenNum;
1540

1541
  int32_t         numIpRanges;
1542
  int32_t         numTimeRanges;
1543
  int32_t         numDropIpRanges;
1544
  int32_t         numDropTimeRanges;
1545
  SIpRange*       pIpRanges;
1546
  SDateTimeRange* pTimeRanges;
1547
  SIpRange*       pDropIpRanges;
1548
  SDateTimeRange* pDropTimeRanges;
1549

1550
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1551
  char        tabName[TSDB_TABLE_NAME_LEN];
1552
  char*       tagCond;
1553
  int32_t     tagCondLen;
1554
  int32_t     sqlLen;
1555
  char*       sql;
1556
  int64_t     privileges;
1557
} SAlterUserReq;
1558

1559
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1560
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1561
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1562

1563
typedef struct {
1564
  char user[TSDB_USER_LEN];
1565
} SGetUserAuthReq;
1566

1567
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1568
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1569

1570
typedef struct {
1571
  char      user[TSDB_USER_LEN];
1572
  int32_t   version;
1573
  int32_t   passVer;
1574
  int8_t    superAuth;
1575
  int8_t    sysInfo;
1576
  int8_t    enable;
1577
  int8_t    dropped;
1578
  SHashObj* createdDbs;
1579
  SHashObj* readDbs;
1580
  SHashObj* writeDbs;
1581
  SHashObj* readTbs;
1582
  SHashObj* writeTbs;
1583
  SHashObj* alterTbs;
1584
  SHashObj* readViews;
1585
  SHashObj* writeViews;
1586
  SHashObj* alterViews;
1587
  SHashObj* useDbs;
1588
  int64_t   whiteListVer;
1589
  int64_t   timeWhiteListVer;
1590
} SGetUserAuthRsp;
1591

1592
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1593
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1594
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1595

1596
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1597
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1598
typedef struct {
1599
  int64_t ver;
1600
  char    user[TSDB_USER_LEN];
1601
  int32_t numOfRange;
1602
  union {
1603
    SIpV4Range* pIpRanges;
1604
    SIpRange*   pIpDualRanges;
1605
  };
1606
} SUpdateUserIpWhite;
1607

1608
typedef struct {
1609
  int64_t             ver;
1610
  int                 numOfUser;
1611
  SUpdateUserIpWhite* pUserIpWhite;
1612
} SUpdateIpWhite;
1613

1614
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1615
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1616
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1617
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1618

1619
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1620
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1621
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1622

1623

1624
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1625
// corresponding response struct is different.
1626
typedef struct {
1627
  int64_t ver;
1628
} SRetrieveWhiteListReq;
1629

1630
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1631
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1632

1633

1634
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1635
// corresponding response struct is different.
1636
typedef struct {
1637
  char user[TSDB_USER_LEN];
1638
} SGetUserWhiteListReq;
1639

1640
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1641
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1642

1643
typedef struct {
1644
  char    user[TSDB_USER_LEN];
1645
  int32_t numWhiteLists;
1646
  union {
1647
    SIpV4Range* pWhiteLists;
1648
    SIpRange*   pWhiteListsDual;
1649
  };
1650
} SGetUserIpWhiteListRsp;
1651

1652
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1653
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1654
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1655
void    tIpRangeSetDefaultMask(SIpRange* range);
1656

1657
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1658
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1659
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1660

1661
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1662
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1663
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1664

1665
typedef struct {
1666
  int64_t ver;
1667
  char    user[TSDB_USER_LEN];
1668
  int32_t numWhiteLists;
1669
  SDateTimeWhiteListItem* pWhiteLists;
1670
} SUserDateTimeWhiteList;
1671

1672

1673
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1674
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1675
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1676

1677
typedef struct {
1678
  int64_t             ver;
1679
  int                 numOfUser;
1680
  SUserDateTimeWhiteList *pUsers;
1681
} SRetrieveDateTimeWhiteListRsp;
1682

1683
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1684
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1685
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1686

1687
/*
1688
 * for client side struct, only column id, type, bytes are necessary
1689
 * But for data in vnode side, we need all the following information.
1690
 */
1691
typedef struct {
1692
  union {
1693
    col_id_t colId;
1694
    int16_t  slotId;
1695
  };
1696

1697
  uint8_t precision;
1698
  uint8_t scale;
1699
  int32_t bytes;
1700
  int8_t  type;
1701
  uint8_t pk;
1702
  bool    noData;
1703
} SColumnInfo;
1704

1705
typedef struct STimeWindow {
1706
  TSKEY skey;
1707
  TSKEY ekey;
1708
} STimeWindow;
1709

1710
typedef struct SQueryHint {
1711
  bool batchScan;
1712
} SQueryHint;
1713

1714
typedef struct {
1715
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1716
  int32_t tsLen;          // total length of ts comp block
1717
  int32_t tsNumOfBlocks;  // ts comp block numbers
1718
  int32_t tsOrder;        // ts comp block order
1719
} STsBufInfo;
1720

1721
typedef struct {
1722
  void*       timezone;
1723
  char        intervalUnit;
1724
  char        slidingUnit;
1725
  char        offsetUnit;
1726
  int8_t      precision;
1727
  int64_t     interval;
1728
  int64_t     sliding;
1729
  int64_t     offset;
1730
  STimeWindow timeRange;
1731
} SInterval;
1732

1733
typedef struct STbVerInfo {
1734
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1735
  int32_t sversion;
1736
  int32_t tversion;
1737
  int32_t rversion;  // virtual table's column ref's version
1738
} STbVerInfo;
1739

1740
typedef struct {
1741
  int32_t code;
1742
  int64_t affectedRows;
1743
  SArray* tbVerInfo;  // STbVerInfo
1744
} SQueryTableRsp;
1745

1746
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1747

1748
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1749

1750
typedef struct {
1751
  SMsgHead header;
1752
  char     dbFName[TSDB_DB_FNAME_LEN];
1753
  char     tbName[TSDB_TABLE_NAME_LEN];
1754
} STableCfgReq;
1755

1756
typedef struct {
1757
  char        tbName[TSDB_TABLE_NAME_LEN];
1758
  char        stbName[TSDB_TABLE_NAME_LEN];
1759
  char        dbFName[TSDB_DB_FNAME_LEN];
1760
  int32_t     numOfTags;
1761
  int32_t     numOfColumns;
1762
  int8_t      tableType;
1763
  int64_t     delay1;
1764
  int64_t     delay2;
1765
  int64_t     watermark1;
1766
  int64_t     watermark2;
1767
  int32_t     ttl;
1768
  int32_t     keep;
1769
  SArray*     pFuncs;
1770
  int32_t     commentLen;
1771
  char*       pComment;
1772
  SSchema*    pSchemas;
1773
  int32_t     tagsLen;
1774
  char*       pTags;
1775
  SSchemaExt* pSchemaExt;
1776
  int8_t      virtualStb;
1777
  SColRef*    pColRefs;
1778
} STableCfg;
1779

1780
typedef STableCfg STableCfgRsp;
1781

1782
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1783
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1784

1785
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1786
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1787
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1788

1789
typedef struct {
1790
  SMsgHead header;
1791
  tb_uid_t suid;
1792
} SVSubTablesReq;
1793

1794
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1795
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1796

1797
typedef struct {
1798
  int32_t vgId;
1799
  SArray* pTables;  // SArray<SVCTableRefCols*>
1800
} SVSubTablesRsp;
1801

1802
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1803
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1804
void    tDestroySVSubTablesRsp(void* rsp);
1805

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

1811
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1812
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1813

1814
typedef struct {
1815
  int32_t vgId;
1816
  SArray* pDbs;  // SArray<char* (db name)>
1817
} SVStbRefDbsRsp;
1818

1819
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1820
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1821
void    tDestroySVStbRefDbsRsp(void* rsp);
1822

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

1873
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1874
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1875
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1876

1877
typedef struct {
1878
  char    db[TSDB_DB_FNAME_LEN];
1879
  int32_t buffer;
1880
  int32_t pageSize;
1881
  int32_t pages;
1882
  int32_t cacheLastSize;
1883
  int32_t daysPerFile;
1884
  int32_t daysToKeep0;
1885
  int32_t daysToKeep1;
1886
  int32_t daysToKeep2;
1887
  int32_t keepTimeOffset;
1888
  int32_t walFsyncPeriod;
1889
  int8_t  walLevel;
1890
  int8_t  strict;
1891
  int8_t  cacheLast;
1892
  int8_t  replications;
1893
  int32_t sstTrigger;
1894
  int32_t minRows;
1895
  int32_t walRetentionPeriod;
1896
  int32_t walRetentionSize;
1897
  int32_t ssKeepLocal;
1898
  int8_t  ssCompact;
1899
  int32_t sqlLen;
1900
  char*   sql;
1901
  int8_t  withArbitrator;
1902
  // 1. add auto-compact parameters
1903
  int32_t compactInterval;
1904
  int32_t compactStartTime;
1905
  int32_t compactEndTime;
1906
  int8_t  compactTimeOffset;
1907
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1908
} SAlterDbReq;
1909

1910
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1911
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1912
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1913

1914
typedef struct {
1915
  char    db[TSDB_DB_FNAME_LEN];
1916
  int8_t  ignoreNotExists;
1917
  int8_t  force;
1918
  int32_t sqlLen;
1919
  char*   sql;
1920
} SDropDbReq;
1921

1922
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1923
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1924
void    tFreeSDropDbReq(SDropDbReq* pReq);
1925

1926
typedef struct {
1927
  char    db[TSDB_DB_FNAME_LEN];
1928
  int64_t uid;
1929
} SDropDbRsp;
1930

1931
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1932
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1933

1934
typedef struct {
1935
  char    name[TSDB_MOUNT_NAME_LEN];
1936
  int64_t uid;
1937
} SDropMountRsp;
1938

1939
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1940
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1941

1942
typedef struct {
1943
  char    db[TSDB_DB_FNAME_LEN];
1944
  int64_t dbId;
1945
  int32_t vgVersion;
1946
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1947
  int64_t stateTs;     // ms
1948
} SUseDbReq;
1949

1950
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1951
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1952

1953
typedef struct {
1954
  char    db[TSDB_DB_FNAME_LEN];
1955
  int64_t uid;
1956
  int32_t vgVersion;
1957
  int32_t vgNum;
1958
  int16_t hashPrefix;
1959
  int16_t hashSuffix;
1960
  int8_t  hashMethod;
1961
  union {
1962
    uint8_t flags;
1963
    struct {
1964
      uint8_t isMount : 1;  // TS-5868
1965
      uint8_t padding : 7;
1966
    };
1967
  };
1968
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1969
  int32_t errCode;
1970
  int64_t stateTs;  // ms
1971
} SUseDbRsp;
1972

1973
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1974
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1975
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1976
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1977
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1978

1979
typedef struct {
1980
  char db[TSDB_DB_FNAME_LEN];
1981
} SDbCfgReq;
1982

1983
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1984
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1985

1986
typedef struct {
1987
  char db[TSDB_DB_FNAME_LEN];
1988
} SSsMigrateDbReq;
1989

1990
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1991
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1992

1993
typedef struct {
1994
  int32_t ssMigrateId;
1995
  bool    bAccepted;
1996
} SSsMigrateDbRsp;
1997

1998
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1999
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2000

2001

2002
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2003
typedef struct {
2004
  int32_t ssMigrateId;
2005
} SListSsMigrateFileSetsReq;
2006

2007
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2008
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2009

2010
typedef struct {
2011
  int32_t ssMigrateId;
2012
  int32_t vgId;   // vgroup id
2013
  SArray* pFileSets; // SArray<int32_t>
2014
} SListSsMigrateFileSetsRsp;
2015

2016
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2017
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2018
void tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2019

2020

2021
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2022
typedef struct {
2023
  int32_t ssMigrateId;
2024
  int32_t nodeId; // node id of the leader vnode, filled by vnode
2025
  int32_t fid;
2026
  int64_t startTimeSec;
2027
} SSsMigrateFileSetReq;
2028

2029
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2030
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2031

2032
typedef struct {
2033
  int32_t ssMigrateId;
2034
  int32_t nodeId; // node id of the leader vnode
2035
  int32_t vgId;
2036
  int32_t fid;
2037
} SSsMigrateFileSetRsp;
2038

2039
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2040
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2041

2042

2043
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS  0
2044
#define SSMIGRATE_FILESET_STATE_SUCCEEDED    1
2045
#define SSMIGRATE_FILESET_STATE_COMPACT      2
2046
#define SSMIGRATE_FILESET_STATE_SKIPPED      3
2047
#define SSMIGRATE_FILESET_STATE_FAILED       4
2048

2049
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2050
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2051
// while as a request, the 'state' field is not used.
2052
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2053
typedef struct {
2054
  int32_t ssMigrateId; // ss migrate id
2055
  int32_t nodeId;      // node id of the leader vnode
2056
  int32_t vgId;        // vgroup id
2057
  int32_t fid;         // file set id
2058
  int32_t state;       // SSMIGRATE_FILESET_STATE_*
2059
} SSsMigrateProgress;
2060

2061
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2062
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2063

2064

2065
// Request for TDMT_MND_KILL_SSMIGRATE
2066
typedef struct {
2067
  int32_t ssMigrateId;
2068
  int32_t sqlLen;
2069
  char*   sql;
2070
} SKillSsMigrateReq;
2071

2072
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2073
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2074
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2075

2076
// Request for TDMT_VND_KILL_SSMIGRATE
2077
typedef struct {
2078
  int32_t ssMigrateId;
2079
} SVnodeKillSsMigrateReq;
2080

2081
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2082
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2083

2084

2085
typedef struct {
2086
  int32_t vgId;
2087
  int64_t keepVersion;
2088
} SMndSetVgroupKeepVersionReq;
2089

2090
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2091
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2092

2093
typedef struct {
2094
  int32_t timestampSec;
2095
  int32_t ttlDropMaxCount;
2096
  int32_t nUids;
2097
  SArray* pTbUids;
2098
} SVDropTtlTableReq;
2099

2100
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2101
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2102

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

2158
typedef SDbCfgRsp SDbCfgInfo;
2159

2160
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2161
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2162
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2163
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2164
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2165

2166
typedef struct {
2167
  int32_t rowNum;
2168
} SQnodeListReq;
2169

2170
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2171
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2172

2173
typedef struct {
2174
  int32_t rowNum;
2175
} SDnodeListReq;
2176

2177
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2178

2179
typedef struct {
2180
  int32_t useless;  // useless
2181
} SServerVerReq;
2182

2183
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2184
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2185

2186
typedef struct {
2187
  char ver[TSDB_VERSION_LEN];
2188
} SServerVerRsp;
2189

2190
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2191
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2192

2193
typedef struct SQueryNodeAddr {
2194
  int32_t nodeId;  // vgId or qnodeId
2195
  SEpSet  epSet;
2196
} SQueryNodeAddr;
2197

2198
typedef struct {
2199
  SQueryNodeAddr addr;
2200
  uint64_t       load;
2201
} SQueryNodeLoad;
2202

2203
typedef struct {
2204
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2205
} SQnodeListRsp;
2206

2207
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2208
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2209
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2210

2211
typedef struct SDNodeAddr {
2212
  int32_t nodeId;  // dnodeId
2213
  SEpSet  epSet;
2214
} SDNodeAddr;
2215

2216
typedef struct {
2217
  SArray* dnodeList;  // SArray<SDNodeAddr>
2218
} SDnodeListRsp;
2219

2220
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2221
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2222
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2223

2224
typedef struct {
2225
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2226
} STableTSMAInfoRsp;
2227

2228
typedef struct {
2229
  SUseDbRsp*         useDbRsp;
2230
  SDbCfgRsp*         cfgRsp;
2231
  STableTSMAInfoRsp* pTsmaRsp;
2232
  int32_t            dbTsmaVersion;
2233
  char               db[TSDB_DB_FNAME_LEN];
2234
  int64_t            dbId;
2235
} SDbHbRsp;
2236

2237
typedef struct {
2238
  SArray* pArray;  // Array of SDbHbRsp
2239
} SDbHbBatchRsp;
2240

2241
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2242
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2243
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2244

2245
typedef struct {
2246
  SArray* pArray;  // Array of SGetUserAuthRsp
2247
} SUserAuthBatchRsp;
2248

2249
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2250
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2251
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2252

2253
typedef struct {
2254
  char        db[TSDB_DB_FNAME_LEN];
2255
  STimeWindow timeRange;
2256
  int32_t     sqlLen;
2257
  char*       sql;
2258
  SArray*     vgroupIds;
2259
  int32_t     compactId;
2260
  int8_t      metaOnly;
2261
  int8_t      force;
2262
} SCompactDbReq;
2263

2264
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2265
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2266
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2267

2268
typedef struct {
2269
  union {
2270
    int32_t compactId;
2271
    int32_t id;
2272
  };
2273
  int8_t bAccepted;
2274
} SCompactDbRsp;
2275

2276
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2277
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2278

2279
typedef struct {
2280
  union {
2281
    int32_t compactId;
2282
    int32_t id;
2283
  };
2284
  int32_t sqlLen;
2285
  char*   sql;
2286
} SKillCompactReq;
2287

2288
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2289
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2290
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2291

2292
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2293
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2294

2295
typedef struct {
2296
  char    name[TSDB_FUNC_NAME_LEN];
2297
  int8_t  igExists;
2298
  int8_t  funcType;
2299
  int8_t  scriptType;
2300
  int8_t  outputType;
2301
  int32_t outputLen;
2302
  int32_t bufSize;
2303
  int32_t codeLen;
2304
  int64_t signature;
2305
  char*   pComment;
2306
  char*   pCode;
2307
  int8_t  orReplace;
2308
} SCreateFuncReq;
2309

2310
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2311
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2312
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2313

2314
typedef struct {
2315
  char   name[TSDB_FUNC_NAME_LEN];
2316
  int8_t igNotExists;
2317
} SDropFuncReq;
2318

2319
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2320
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2321

2322
typedef struct {
2323
  int32_t numOfFuncs;
2324
  bool    ignoreCodeComment;
2325
  SArray* pFuncNames;
2326
} SRetrieveFuncReq;
2327

2328
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2329
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2330
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2331

2332
typedef struct {
2333
  char    name[TSDB_FUNC_NAME_LEN];
2334
  int8_t  funcType;
2335
  int8_t  scriptType;
2336
  int8_t  outputType;
2337
  int32_t outputLen;
2338
  int32_t bufSize;
2339
  int64_t signature;
2340
  int32_t commentSize;
2341
  int32_t codeSize;
2342
  char*   pComment;
2343
  char*   pCode;
2344
} SFuncInfo;
2345

2346
typedef struct {
2347
  int32_t funcVersion;
2348
  int64_t funcCreatedTime;
2349
} SFuncExtraInfo;
2350

2351
typedef struct {
2352
  int32_t numOfFuncs;
2353
  SArray* pFuncInfos;
2354
  SArray* pFuncExtraInfos;
2355
} SRetrieveFuncRsp;
2356

2357
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2358
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2359
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2360
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2361

2362
typedef struct {
2363
  int32_t       statusInterval;
2364
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2365
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2366
  char          locale[TD_LOCALE_LEN];      // tsLocale
2367
  char          charset[TD_LOCALE_LEN];     // tsCharset
2368
  int8_t        ttlChangeOnWrite;
2369
  int8_t        enableWhiteList;
2370
  int8_t        encryptionKeyStat;
2371
  uint32_t      encryptionKeyChksum;
2372
  SMonitorParas monitorParas;
2373
  int32_t       statusIntervalMs;
2374
} SClusterCfg;
2375

2376
typedef struct {
2377
  int32_t openVnodes;
2378
  int32_t dropVnodes;
2379
  int32_t totalVnodes;
2380
  int32_t masterNum;
2381
  int64_t numOfSelectReqs;
2382
  int64_t numOfInsertReqs;
2383
  int64_t numOfInsertSuccessReqs;
2384
  int64_t numOfBatchInsertReqs;
2385
  int64_t numOfBatchInsertSuccessReqs;
2386
  int64_t errors;
2387
} SVnodesStat;
2388

2389
typedef struct {
2390
  int32_t vgId;
2391
  int8_t  syncState;
2392
  int8_t  syncRestore;
2393
  int64_t syncTerm;
2394
  int64_t roleTimeMs;
2395
  int64_t startTimeMs;
2396
  int8_t  syncCanRead;
2397
  int64_t cacheUsage;
2398
  int64_t numOfTables;
2399
  int64_t numOfTimeSeries;
2400
  int64_t totalStorage;
2401
  int64_t compStorage;
2402
  int64_t pointsWritten;
2403
  int64_t numOfSelectReqs;
2404
  int64_t numOfInsertReqs;
2405
  int64_t numOfInsertSuccessReqs;
2406
  int64_t numOfBatchInsertReqs;
2407
  int64_t numOfBatchInsertSuccessReqs;
2408
  int32_t numOfCachedTables;
2409
  int32_t learnerProgress;  // use one reservered
2410
  int64_t syncAppliedIndex;
2411
  int64_t syncCommitIndex;
2412
  int64_t bufferSegmentUsed;
2413
  int64_t bufferSegmentSize;
2414
} SVnodeLoad;
2415

2416
typedef struct {
2417
  int64_t total_requests;
2418
  int64_t total_rows;
2419
  int64_t total_bytes;
2420
  double  write_size;
2421
  double  cache_hit_ratio;
2422
  int64_t rpc_queue_wait;
2423
  int64_t preprocess_time;
2424

2425
  int64_t memory_table_size;
2426
  int64_t commit_count;
2427
  int64_t merge_count;
2428
  double  commit_time;
2429
  double  merge_time;
2430
  int64_t block_commit_time;
2431
  int64_t memtable_wait_time;
2432
} SVnodeMetrics;
2433

2434
typedef struct {
2435
  int32_t     vgId;
2436
  int64_t     numOfTables;
2437
  int64_t     memSize;
2438
  int64_t     l1Size;
2439
  int64_t     l2Size;
2440
  int64_t     l3Size;
2441
  int64_t     cacheSize;
2442
  int64_t     walSize;
2443
  int64_t     metaSize;
2444
  int64_t     rawDataSize;
2445
  int64_t     ssSize;
2446
  const char* dbname;
2447
  int8_t      estimateRawData;
2448
} SDbSizeStatisInfo;
2449

2450
typedef struct {
2451
  int32_t vgId;
2452
  int64_t nTimeSeries;
2453
} SVnodeLoadLite;
2454

2455
typedef struct {
2456
  int8_t  syncState;
2457
  int64_t syncTerm;
2458
  int8_t  syncRestore;
2459
  int64_t roleTimeMs;
2460
} SMnodeLoad;
2461

2462
typedef struct {
2463
  int32_t dnodeId;
2464
  int64_t numOfProcessedQuery;
2465
  int64_t numOfProcessedCQuery;
2466
  int64_t numOfProcessedFetch;
2467
  int64_t numOfProcessedDrop;
2468
  int64_t numOfProcessedNotify;
2469
  int64_t numOfProcessedHb;
2470
  int64_t numOfProcessedDelete;
2471
  int64_t cacheDataSize;
2472
  int64_t numOfQueryInQueue;
2473
  int64_t numOfFetchInQueue;
2474
  int64_t timeInQueryQueue;
2475
  int64_t timeInFetchQueue;
2476
} SQnodeLoad;
2477

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

2503
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2504
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2505
void    tFreeSStatusReq(SStatusReq* pReq);
2506

2507
typedef struct {
2508
  int32_t forceReadConfig;
2509
  int32_t cver;
2510
  SArray* array;
2511
} SConfigReq;
2512

2513
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2514
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2515
void    tFreeSConfigReq(SConfigReq* pReq);
2516

2517
typedef struct {
2518
  int32_t dnodeId;
2519
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2520
} SDnodeInfoReq;
2521

2522
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2523
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2524

2525
typedef enum {
2526
  MONITOR_TYPE_COUNTER = 0,
2527
  MONITOR_TYPE_SLOW_LOG = 1,
2528
} MONITOR_TYPE;
2529

2530
typedef struct {
2531
  int32_t      contLen;
2532
  char*        pCont;
2533
  MONITOR_TYPE type;
2534
} SStatisReq;
2535

2536
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2537
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2538
void    tFreeSStatisReq(SStatisReq* pReq);
2539

2540
typedef struct {
2541
  char    db[TSDB_DB_FNAME_LEN];
2542
  char    table[TSDB_TABLE_NAME_LEN];
2543
  char    operation[AUDIT_OPERATION_LEN];
2544
  int32_t sqlLen;
2545
  char*   pSql;
2546
} SAuditReq;
2547
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2548
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2549
void    tFreeSAuditReq(SAuditReq* pReq);
2550

2551
typedef struct {
2552
  int32_t dnodeId;
2553
  int64_t clusterId;
2554
  SArray* pVloads;
2555
} SNotifyReq;
2556

2557
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2558
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2559
void    tFreeSNotifyReq(SNotifyReq* pReq);
2560

2561
typedef struct {
2562
  int32_t dnodeId;
2563
  int64_t clusterId;
2564
} SDnodeCfg;
2565

2566
typedef struct {
2567
  int32_t id;
2568
  int8_t  isMnode;
2569
  SEp     ep;
2570
} SDnodeEp;
2571

2572
typedef struct {
2573
  int32_t id;
2574
  int8_t  isMnode;
2575
  int8_t  offlineReason;
2576
  SEp     ep;
2577
  char    active[TSDB_ACTIVE_KEY_LEN];
2578
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2579
} SDnodeInfo;
2580

2581
typedef struct {
2582
  int64_t   dnodeVer;
2583
  SDnodeCfg dnodeCfg;
2584
  SArray*   pDnodeEps;  // Array of SDnodeEp
2585
  int32_t   statusSeq;
2586
  int64_t   ipWhiteVer;
2587
  int64_t   analVer;
2588
  int64_t   timeWhiteVer;
2589
} SStatusRsp;
2590

2591
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2592
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2593
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2594

2595
typedef struct {
2596
  int32_t forceReadConfig;
2597
  int32_t isConifgVerified;
2598
  int32_t isVersionVerified;
2599
  int32_t cver;
2600
  SArray* array;
2601
} SConfigRsp;
2602

2603
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2604
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2605
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2606

2607
typedef struct {
2608
  int32_t reserved;
2609
} SMTimerReq;
2610

2611
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2612
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2613

2614
typedef struct SOrphanTask {
2615
  int64_t streamId;
2616
  int32_t taskId;
2617
  int32_t nodeId;
2618
} SOrphanTask;
2619

2620
typedef struct SMStreamDropOrphanMsg {
2621
  SArray* pList;  // SArray<SOrphanTask>
2622
} SMStreamDropOrphanMsg;
2623

2624
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2625
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2626
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2627

2628
typedef struct {
2629
  int32_t  id;
2630
  uint16_t port;                 // node sync Port
2631
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2632
} SReplica;
2633

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

2687
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2688
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2689
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2690

2691
typedef struct {
2692
  union {
2693
    int32_t compactId;
2694
    int32_t id;
2695
  };
2696
  int32_t vgId;
2697
  int32_t dnodeId;
2698
} SQueryCompactProgressReq;
2699

2700
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2701
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2702

2703
typedef struct {
2704
  union {
2705
    int32_t compactId;
2706
    int32_t id;
2707
  };
2708
  int32_t vgId;
2709
  int32_t dnodeId;
2710
  int32_t numberFileset;
2711
  int32_t finished;
2712
  int32_t progress;
2713
  int64_t remainingTime;
2714
} SQueryCompactProgressRsp;
2715

2716
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2717
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2718

2719
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2720
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2721

2722
typedef struct {
2723
  int32_t vgId;
2724
  int32_t dnodeId;
2725
  int64_t dbUid;
2726
  char    db[TSDB_DB_FNAME_LEN];
2727
  int64_t reserved[8];
2728
} SDropVnodeReq;
2729

2730
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2731
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2732

2733
typedef struct {
2734
  char    colName[TSDB_COL_NAME_LEN];
2735
  char    stb[TSDB_TABLE_FNAME_LEN];
2736
  int64_t stbUid;
2737
  int64_t dbUid;
2738
  int64_t reserved[8];
2739
} SDropIndexReq;
2740

2741
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2742
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2743

2744
typedef struct {
2745
  int64_t dbUid;
2746
  char    db[TSDB_DB_FNAME_LEN];
2747
  union {
2748
    int64_t compactStartTime;
2749
    int64_t startTime;
2750
  };
2751

2752
  STimeWindow tw;
2753
  union {
2754
    int32_t compactId;
2755
    int32_t id;
2756
  };
2757
  int8_t metaOnly;
2758
  union {
2759
    uint16_t flags;
2760
    struct {
2761
      uint16_t optrType : 3;     // ETsdbOpType
2762
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2763
      uint16_t reserved : 12;
2764
    };
2765
  };
2766
  int8_t force;  // force compact
2767
} SCompactVnodeReq;
2768

2769
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2770
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2771

2772
typedef struct {
2773
  union {
2774
    int32_t compactId;
2775
    int32_t taskId;
2776
  };
2777
  int32_t vgId;
2778
  int32_t dnodeId;
2779
} SVKillCompactReq;
2780

2781
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2782
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2783

2784
typedef SVKillCompactReq SVKillRetentionReq;
2785

2786
typedef struct {
2787
  char        db[TSDB_DB_FNAME_LEN];
2788
  int32_t     maxSpeed;
2789
  int32_t     sqlLen;
2790
  char*       sql;
2791
  SArray*     vgroupIds;
2792
  STimeWindow tw;  // unit is second
2793
  union {
2794
    uint32_t flags;
2795
    struct {
2796
      uint32_t optrType : 3;     // ETsdbOpType
2797
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2798
      uint32_t reserved : 28;
2799
    };
2800
  };
2801
} STrimDbReq;
2802

2803
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2804
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2805
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2806

2807
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2808

2809
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2810
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2811

2812
typedef struct {
2813
  int32_t vgVersion;
2814
  int32_t buffer;
2815
  int32_t pageSize;
2816
  int32_t pages;
2817
  int32_t cacheLastSize;
2818
  int32_t daysPerFile;
2819
  int32_t daysToKeep0;
2820
  int32_t daysToKeep1;
2821
  int32_t daysToKeep2;
2822
  int32_t keepTimeOffset;
2823
  int32_t walFsyncPeriod;
2824
  int8_t  walLevel;
2825
  int8_t  strict;
2826
  int8_t  cacheLast;
2827
  int64_t reserved[7];
2828
  // 1st modification
2829
  int16_t sttTrigger;
2830
  int32_t minRows;
2831
  // 2nd modification
2832
  int32_t walRetentionPeriod;
2833
  int32_t walRetentionSize;
2834
  int32_t ssKeepLocal;
2835
  int8_t  ssCompact;
2836
} SAlterVnodeConfigReq;
2837

2838
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2839
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2840

2841
typedef struct {
2842
  int32_t  vgId;
2843
  int8_t   strict;
2844
  int8_t   selfIndex;
2845
  int8_t   replica;
2846
  SReplica replicas[TSDB_MAX_REPLICA];
2847
  int64_t  reserved[8];
2848
  int8_t   learnerSelfIndex;
2849
  int8_t   learnerReplica;
2850
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2851
  int32_t  changeVersion;
2852
  int32_t  electBaseLine;
2853
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2854

2855
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2856
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2857

2858
typedef struct {
2859
  int32_t vgId;
2860
  int8_t  disable;
2861
} SDisableVnodeWriteReq;
2862

2863
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2864
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2865

2866
typedef struct {
2867
  int32_t  srcVgId;
2868
  int32_t  dstVgId;
2869
  uint32_t hashBegin;
2870
  uint32_t hashEnd;
2871
  int32_t  changeVersion;
2872
  int32_t  reserved;
2873
} SAlterVnodeHashRangeReq;
2874

2875
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2876
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2877

2878
#define REQ_OPT_TBNAME 0x0
2879
#define REQ_OPT_TBUID  0x01
2880
typedef struct {
2881
  SMsgHead header;
2882
  char     dbFName[TSDB_DB_FNAME_LEN];
2883
  char     tbName[TSDB_TABLE_NAME_LEN];
2884
  uint8_t  option;
2885
  uint8_t  autoCreateCtb;
2886
} STableInfoReq;
2887

2888
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2889
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2890

2891
typedef struct {
2892
  int8_t  metaClone;  // create local clone of the cached table meta
2893
  int32_t numOfVgroups;
2894
  int32_t numOfTables;
2895
  int32_t numOfUdfs;
2896
  char    tableNames[];
2897
} SMultiTableInfoReq;
2898

2899
// todo refactor
2900
typedef struct SVgroupInfo {
2901
  int32_t  vgId;
2902
  uint32_t hashBegin;
2903
  uint32_t hashEnd;
2904
  SEpSet   epSet;
2905
  union {
2906
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2907
    int32_t taskId;      // used in stream
2908
  };
2909
} SVgroupInfo;
2910

2911
typedef struct {
2912
  int32_t     numOfVgroups;
2913
  SVgroupInfo vgroups[];
2914
} SVgroupsInfo;
2915

2916
typedef struct {
2917
  STableMetaRsp* pMeta;
2918
} SMAlterStbRsp;
2919

2920
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2921
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2922
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2923

2924
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2925
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2926
void    tFreeSTableMetaRsp(void* pRsp);
2927
void    tFreeSTableIndexRsp(void* info);
2928

2929
typedef struct {
2930
  SArray* pMetaRsp;   // Array of STableMetaRsp
2931
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2932
} SSTbHbRsp;
2933

2934
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2935
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2936
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2937

2938
typedef struct {
2939
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2940
} SViewHbRsp;
2941

2942
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2943
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2944
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2945

2946
typedef struct {
2947
  int32_t numOfTables;
2948
  int32_t numOfVgroup;
2949
  int32_t numOfUdf;
2950
  int32_t contLen;
2951
  int8_t  compressed;  // denote if compressed or not
2952
  int32_t rawLen;      // size before compress
2953
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2954
  char    meta[];
2955
} SMultiTableMeta;
2956

2957
typedef struct {
2958
  int32_t dataLen;
2959
  char    name[TSDB_TABLE_FNAME_LEN];
2960
  char*   data;
2961
} STagData;
2962

2963
typedef struct {
2964
  int32_t  opType;
2965
  uint32_t valLen;
2966
  char*    val;
2967
} SShowVariablesReq;
2968

2969
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2970
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2971
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2972

2973
typedef struct {
2974
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2975
  char value[TSDB_CONFIG_PATH_LEN + 1];
2976
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2977
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2978
  char info[TSDB_CONFIG_INFO_LEN + 1];
2979
} SVariablesInfo;
2980

2981
typedef struct {
2982
  SArray* variables;  // SArray<SVariablesInfo>
2983
} SShowVariablesRsp;
2984

2985
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2986
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2987

2988
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2989

2990
/*
2991
 * sql: show tables like '%a_%'
2992
 * payload is the query condition, e.g., '%a_%'
2993
 * payloadLen is the length of payload
2994
 */
2995
typedef struct {
2996
  int32_t type;
2997
  char    db[TSDB_DB_FNAME_LEN];
2998
  int32_t payloadLen;
2999
  char*   payload;
3000
} SShowReq;
3001

3002
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3003
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3004
void tFreeSShowReq(SShowReq* pReq);
3005

3006
typedef struct {
3007
  int64_t       showId;
3008
  STableMetaRsp tableMeta;
3009
} SShowRsp, SVShowTablesRsp;
3010

3011
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3012
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3013
// void    tFreeSShowRsp(SShowRsp* pRsp);
3014

3015
typedef struct {
3016
  char    db[TSDB_DB_FNAME_LEN];
3017
  char    tb[TSDB_TABLE_NAME_LEN];
3018
  char    user[TSDB_USER_LEN];
3019
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3020
  int64_t showId;
3021
  int64_t compactId;  // for compact
3022
  bool    withFull;   // for show users full
3023
} SRetrieveTableReq;
3024

3025
typedef struct SSysTableSchema {
3026
  int8_t   type;
3027
  col_id_t colId;
3028
  int32_t  bytes;
3029
} SSysTableSchema;
3030

3031
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3032
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3033

3034
#define RETRIEVE_TABLE_RSP_VERSION         0
3035
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3036
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3037

3038
typedef struct {
3039
  int64_t useconds;
3040
  int8_t  completed;  // all results are returned to client
3041
  int8_t  precision;
3042
  int8_t  compressed;
3043
  int8_t  streamBlockType;
3044
  int32_t payloadLen;
3045
  int32_t compLen;
3046
  int32_t numOfBlocks;
3047
  int64_t numOfRows;  // from int32_t change to int64_t
3048
  int64_t numOfCols;
3049
  int64_t skey;
3050
  int64_t ekey;
3051
  int64_t version;                         // for stream
3052
  TSKEY   watermark;                       // for stream
3053
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3054
  char    data[];
3055
} SRetrieveTableRsp;
3056

3057
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3058

3059
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3060
  do {                                          \
3061
    ((int32_t*)(_p))[0] = (_compLen);           \
3062
    ((int32_t*)(_p))[1] = (_fullLen);           \
3063
  } while (0);
3064

3065
typedef struct {
3066
  int64_t version;
3067
  int64_t numOfRows;
3068
  int8_t  compressed;
3069
  int8_t  precision;
3070
  char    data[];
3071
} SRetrieveTableRspForTmq;
3072

3073
typedef struct {
3074
  int64_t handle;
3075
  int64_t useconds;
3076
  int8_t  completed;  // all results are returned to client
3077
  int8_t  precision;
3078
  int8_t  compressed;
3079
  int32_t compLen;
3080
  int32_t numOfRows;
3081
  int32_t fullLen;
3082
  char    data[];
3083
} SRetrieveMetaTableRsp;
3084

3085
typedef struct SExplainExecInfo {
3086
  double   startupCost;
3087
  double   totalCost;
3088
  uint64_t numOfRows;
3089
  uint32_t verboseLen;
3090
  void*    verboseInfo;
3091
} SExplainExecInfo;
3092

3093
typedef struct {
3094
  int32_t           numOfPlans;
3095
  SExplainExecInfo* subplanInfo;
3096
} SExplainRsp;
3097

3098
typedef struct {
3099
  SExplainRsp rsp;
3100
  uint64_t    qId;
3101
  uint64_t    cId;
3102
  uint64_t    tId;
3103
  int64_t     rId;
3104
  int32_t     eId;
3105
} SExplainLocalRsp;
3106

3107
typedef struct STableScanAnalyzeInfo {
3108
  uint64_t totalRows;
3109
  uint64_t totalCheckedRows;
3110
  uint32_t totalBlocks;
3111
  uint32_t loadBlocks;
3112
  uint32_t loadBlockStatis;
3113
  uint32_t skipBlocks;
3114
  uint32_t filterOutBlocks;
3115
  double   elapsedTime;
3116
  double   filterTime;
3117
} STableScanAnalyzeInfo;
3118

3119
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3120
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3121
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3122

3123
typedef struct {
3124
  char    config[TSDB_DNODE_CONFIG_LEN];
3125
  char    value[TSDB_CLUSTER_VALUE_LEN];
3126
  int32_t sqlLen;
3127
  char*   sql;
3128
} SMCfgClusterReq;
3129

3130
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3131
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3132
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3133

3134
typedef struct {
3135
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3136
  int32_t port;
3137
  int32_t sqlLen;
3138
  char*   sql;
3139
} SCreateDnodeReq;
3140

3141
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3142
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3143
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3144

3145
typedef struct {
3146
  int32_t dnodeId;
3147
  char    fqdn[TSDB_FQDN_LEN];
3148
  int32_t port;
3149
  int8_t  force;
3150
  int8_t  unsafe;
3151
  int32_t sqlLen;
3152
  char*   sql;
3153
} SDropDnodeReq;
3154

3155
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3156
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3157
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3158

3159
enum {
3160
  RESTORE_TYPE__ALL = 1,
3161
  RESTORE_TYPE__MNODE,
3162
  RESTORE_TYPE__VNODE,
3163
  RESTORE_TYPE__QNODE,
3164
};
3165

3166
typedef struct {
3167
  int32_t dnodeId;
3168
  int8_t  restoreType;
3169
  int32_t sqlLen;
3170
  char*   sql;
3171
} SRestoreDnodeReq;
3172

3173
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3174
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3175
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3176

3177
typedef struct {
3178
  int32_t dnodeId;
3179
  char    config[TSDB_DNODE_CONFIG_LEN];
3180
  char    value[TSDB_DNODE_VALUE_LEN];
3181
  int32_t sqlLen;
3182
  char*   sql;
3183
} SMCfgDnodeReq;
3184

3185
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3186
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3187
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3188

3189
typedef struct {
3190
  char    config[TSDB_DNODE_CONFIG_LEN];
3191
  char    value[TSDB_DNODE_VALUE_LEN];
3192
  int32_t version;
3193
} SDCfgDnodeReq;
3194

3195
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3196
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3197

3198
typedef struct {
3199
  int32_t dnodeId;
3200
  int32_t sqlLen;
3201
  char*   sql;
3202
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3203
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
3204

3205

3206
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3207
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3208

3209

3210
typedef struct {
3211
  int32_t nodeId;
3212
  SEpSet  epSet;
3213
} SNodeEpSet;
3214

3215

3216
typedef struct {
3217
  int32_t    snodeId;
3218
  SNodeEpSet leaders[2];
3219
  SNodeEpSet replica;
3220
  int32_t    sqlLen;
3221
  char*      sql;
3222
} SDCreateSnodeReq;
3223

3224
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3225
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3226
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
3227

3228

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

3239
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3240
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3241

3242
typedef struct {
3243
  int32_t urlLen;
3244
  int32_t sqlLen;
3245
  char*   url;
3246
  char*   sql;
3247
} SMCreateAnodeReq;
3248

3249
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3250
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3251
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3252

3253
typedef struct {
3254
  int32_t anodeId;
3255
  int32_t sqlLen;
3256
  char*   sql;
3257
} SMDropAnodeReq, SMUpdateAnodeReq;
3258

3259
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3260
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3261
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3262
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3263
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3264
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3265

3266
typedef struct {
3267
  int32_t dnodeId;
3268
  int32_t bnodeProto;
3269
  int32_t sqlLen;
3270
  char*   sql;
3271
} SMCreateBnodeReq, SDCreateBnodeReq;
3272

3273
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3274
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3275
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3276

3277
typedef struct {
3278
  int32_t dnodeId;
3279
  int32_t sqlLen;
3280
  char*   sql;
3281
} SMDropBnodeReq, SDDropBnodeReq;
3282

3283
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3284
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3285
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3286

3287
typedef struct {
3288
  int32_t vgId;
3289
  int32_t hbSeq;
3290
} SVArbHbReqMember;
3291

3292
typedef struct {
3293
  int32_t dnodeId;
3294
  char*   arbToken;
3295
  int64_t arbTerm;
3296
  SArray* hbMembers;  // SVArbHbReqMember
3297
} SVArbHeartBeatReq;
3298

3299
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3300
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3301
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3302

3303
typedef struct {
3304
  int32_t vgId;
3305
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3306
  int32_t hbSeq;
3307
} SVArbHbRspMember;
3308

3309
typedef struct {
3310
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3311
  int32_t dnodeId;
3312
  SArray* hbMembers;  // SVArbHbRspMember
3313
} SVArbHeartBeatRsp;
3314

3315
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3316
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3317
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3318

3319
typedef struct {
3320
  char*   arbToken;
3321
  int64_t arbTerm;
3322
  char*   member0Token;
3323
  char*   member1Token;
3324
} SVArbCheckSyncReq;
3325

3326
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3327
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3328
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3329

3330
typedef struct {
3331
  char*   arbToken;
3332
  char*   member0Token;
3333
  char*   member1Token;
3334
  int32_t vgId;
3335
  int32_t errCode;
3336
} SVArbCheckSyncRsp;
3337

3338
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3339
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3340
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3341

3342
typedef struct {
3343
  char*   arbToken;
3344
  int64_t arbTerm;
3345
  char*   memberToken;
3346
  int8_t  force;
3347
} SVArbSetAssignedLeaderReq;
3348

3349
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3350
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3351
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3352

3353
typedef struct {
3354
  char*   arbToken;
3355
  char*   memberToken;
3356
  int32_t vgId;
3357
} SVArbSetAssignedLeaderRsp;
3358

3359
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3360
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3361
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3362

3363
typedef struct {
3364
  int32_t dnodeId;
3365
  char*   token;
3366
} SMArbUpdateGroupMember;
3367

3368
typedef struct {
3369
  int32_t dnodeId;
3370
  char*   token;
3371
  int8_t  acked;
3372
} SMArbUpdateGroupAssigned;
3373

3374
typedef struct {
3375
  int32_t                  vgId;
3376
  int64_t                  dbUid;
3377
  SMArbUpdateGroupMember   members[2];
3378
  int8_t                   isSync;
3379
  int8_t                   assignedAcked;
3380
  SMArbUpdateGroupAssigned assignedLeader;
3381
  int64_t                  version;
3382
  int32_t                  code;
3383
  int64_t                  updateTimeMs;
3384
} SMArbUpdateGroup;
3385

3386
typedef struct {
3387
  SArray* updateArray;  // SMArbUpdateGroup
3388
} SMArbUpdateGroupBatchReq;
3389

3390
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3391
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3392
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3393

3394
typedef struct {
3395
  char queryStrId[TSDB_QUERY_ID_LEN];
3396
} SKillQueryReq;
3397

3398
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3399
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3400

3401
typedef struct {
3402
  uint32_t connId;
3403
} SKillConnReq;
3404

3405
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3406
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3407

3408
typedef struct {
3409
  int32_t transId;
3410
} SKillTransReq;
3411

3412
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3413
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3414

3415
typedef struct {
3416
  int32_t useless;  // useless
3417
  int32_t sqlLen;
3418
  char*   sql;
3419
} SBalanceVgroupReq;
3420

3421
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3422
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3423
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3424

3425
typedef struct {
3426
  int32_t useless;  // useless
3427
  int32_t sqlLen;
3428
  char*   sql;
3429
} SAssignLeaderReq;
3430

3431
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3432
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3433
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3434
typedef struct {
3435
  int32_t vgId1;
3436
  int32_t vgId2;
3437
} SMergeVgroupReq;
3438

3439
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3440
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3441

3442
typedef struct {
3443
  int32_t vgId;
3444
  int32_t dnodeId1;
3445
  int32_t dnodeId2;
3446
  int32_t dnodeId3;
3447
  int32_t sqlLen;
3448
  char*   sql;
3449
} SRedistributeVgroupReq;
3450

3451
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3452
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3453
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3454

3455
typedef struct {
3456
  int32_t reserved;
3457
  int32_t vgId;
3458
  int32_t sqlLen;
3459
  char*   sql;
3460
  char    db[TSDB_DB_FNAME_LEN];
3461
} SBalanceVgroupLeaderReq;
3462

3463
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3464
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3465
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3466

3467
typedef struct {
3468
  int32_t vgId;
3469
} SForceBecomeFollowerReq;
3470

3471
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3472
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3473

3474
typedef struct {
3475
  int32_t vgId;
3476
  bool    force;
3477
} SSplitVgroupReq;
3478

3479
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3480
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3481

3482
typedef struct {
3483
  char user[TSDB_USER_LEN];
3484
  char spi;
3485
  char encrypt;
3486
  char secret[TSDB_PASSWORD_LEN];
3487
  char ckey[TSDB_PASSWORD_LEN];
3488
} SAuthReq, SAuthRsp;
3489

3490
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3491
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3492

3493
typedef struct {
3494
  int32_t statusCode;
3495
  char    details[1024];
3496
} SServerStatusRsp;
3497

3498
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3499
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3500

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

3527
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3528
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3529
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3530

3531
typedef struct {
3532
  SMsgHead header;
3533
  uint64_t sId;
3534
  uint64_t queryId;
3535
  uint64_t taskId;
3536
} SSinkDataReq;
3537

3538
typedef struct {
3539
  SMsgHead header;
3540
  uint64_t sId;
3541
  uint64_t queryId;
3542
  uint64_t clientId;
3543
  uint64_t taskId;
3544
  int32_t  execId;
3545
} SQueryContinueReq;
3546

3547
typedef struct {
3548
  SMsgHead header;
3549
  uint64_t sId;
3550
  uint64_t queryId;
3551
  uint64_t taskId;
3552
} SResReadyReq;
3553

3554
typedef struct {
3555
  int32_t code;
3556
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3557
  int32_t sversion;
3558
  int32_t tversion;
3559
} SResReadyRsp;
3560

3561
typedef struct SOperatorParam {
3562
  int32_t opType;
3563
  int32_t downstreamIdx;
3564
  void*   value;
3565
  SArray* pChildren;  // SArray<SOperatorParam*>
3566
  bool    reUse;
3567
} SOperatorParam;
3568

3569
typedef struct SColIdNameKV {
3570
  col_id_t colId;
3571
  char     colName[TSDB_COL_NAME_LEN];
3572
} SColIdNameKV;
3573

3574
typedef struct SColIdPair {
3575
  col_id_t vtbColId;
3576
  col_id_t orgColId;
3577
} SColIdPair;
3578

3579
typedef struct SColIdSlotIdPair {
3580
  int32_t  vtbSlotId;
3581
  col_id_t orgColId;
3582
} SColIdSlotIdPair;
3583

3584
typedef struct SOrgTbInfo {
3585
  int32_t vgId;
3586
  char    tbName[TSDB_TABLE_FNAME_LEN];
3587
  SArray* colMap;  // SArray<SColIdNameKV>
3588
} SOrgTbInfo;
3589

3590
typedef struct STableScanOperatorParam {
3591
  bool        tableSeq;
3592
  bool        isNewParam;
3593
  SArray*     pUidList;
3594
  SOrgTbInfo* pOrgTbInfo;
3595
  STimeWindow window;
3596
} STableScanOperatorParam;
3597

3598
typedef struct STagScanOperatorParam {
3599
  tb_uid_t       vcUid;
3600
} STagScanOperatorParam;
3601

3602
typedef struct SVTableScanOperatorParam {
3603
  uint64_t        uid;
3604
  STimeWindow     window;
3605
  SOperatorParam* pTagScanOp;
3606
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3607
} SVTableScanOperatorParam;
3608

3609
typedef struct SMergeOperatorParam {
3610
  int32_t         winNum;
3611
} SMergeOperatorParam;
3612

3613
typedef struct SExternalWindowOperatorParam {
3614
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3615
} SExternalWindowOperatorParam;
3616

3617
typedef struct SDynQueryCtrlOperatorParam {
3618
  STimeWindow    window;
3619
} SDynQueryCtrlOperatorParam;
3620

3621
struct SStreamRuntimeFuncInfo;
3622
typedef struct {
3623
  SMsgHead                       header;
3624
  uint64_t                       sId;
3625
  uint64_t                       queryId;
3626
  uint64_t                       clientId;
3627
  uint64_t                       taskId;
3628
  int32_t                        execId;
3629
  SOperatorParam*                pOpParam;
3630

3631
  // used for new-stream
3632
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3633
  bool                           reset;
3634
  bool                           dynTbname;
3635
  // used for new-stream
3636
} SResFetchReq;
3637

3638
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3639
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3640
void    tDestroySResFetchReq(SResFetchReq* pReq);
3641
typedef struct {
3642
  SMsgHead header;
3643
  uint64_t clientId;
3644
} SSchTasksStatusReq;
3645

3646
typedef struct {
3647
  uint64_t queryId;
3648
  uint64_t clientId;
3649
  uint64_t taskId;
3650
  int64_t  refId;
3651
  int32_t  execId;
3652
  int8_t   status;
3653
} STaskStatus;
3654

3655
typedef struct {
3656
  int64_t refId;
3657
  SArray* taskStatus;  // SArray<STaskStatus>
3658
} SSchedulerStatusRsp;
3659

3660
typedef struct {
3661
  uint64_t queryId;
3662
  uint64_t taskId;
3663
  int8_t   action;
3664
} STaskAction;
3665

3666
typedef struct SQueryNodeEpId {
3667
  int32_t nodeId;  // vgId or qnodeId
3668
  SEp     ep;
3669
} SQueryNodeEpId;
3670

3671
typedef struct {
3672
  SMsgHead       header;
3673
  uint64_t       clientId;
3674
  SQueryNodeEpId epId;
3675
  SArray*        taskAction;  // SArray<STaskAction>
3676
} SSchedulerHbReq;
3677

3678
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3679
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3680
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3681

3682
typedef struct {
3683
  SQueryNodeEpId epId;
3684
  SArray*        taskStatus;  // SArray<STaskStatus>
3685
} SSchedulerHbRsp;
3686

3687
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3688
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3689
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3690

3691
typedef struct {
3692
  SMsgHead header;
3693
  uint64_t sId;
3694
  uint64_t queryId;
3695
  uint64_t clientId;
3696
  uint64_t taskId;
3697
  int64_t  refId;
3698
  int32_t  execId;
3699
} STaskCancelReq;
3700

3701
typedef struct {
3702
  int32_t code;
3703
} STaskCancelRsp;
3704

3705
typedef struct {
3706
  SMsgHead header;
3707
  uint64_t sId;
3708
  uint64_t queryId;
3709
  uint64_t clientId;
3710
  uint64_t taskId;
3711
  int64_t  refId;
3712
  int32_t  execId;
3713
} STaskDropReq;
3714

3715
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3716
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3717

3718
typedef enum {
3719
  TASK_NOTIFY_FINISHED = 1,
3720
} ETaskNotifyType;
3721

3722
typedef struct {
3723
  SMsgHead        header;
3724
  uint64_t        sId;
3725
  uint64_t        queryId;
3726
  uint64_t        clientId;
3727
  uint64_t        taskId;
3728
  int64_t         refId;
3729
  int32_t         execId;
3730
  ETaskNotifyType type;
3731
} STaskNotifyReq;
3732

3733
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3734
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3735

3736
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3737
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3738

3739
typedef struct {
3740
  int32_t code;
3741
} STaskDropRsp;
3742

3743
#define STREAM_TRIGGER_AT_ONCE                 1
3744
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3745
#define STREAM_TRIGGER_MAX_DELAY               3
3746
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3747
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3748

3749
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3750
#define STREAM_FILL_HISTORY_ON        1
3751
#define STREAM_FILL_HISTORY_OFF       0
3752
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3753
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3754
#define STREAM_CREATE_STABLE_TRUE     1
3755
#define STREAM_CREATE_STABLE_FALSE    0
3756

3757
typedef struct SVgroupVer {
3758
  int32_t vgId;
3759
  int64_t ver;
3760
} SVgroupVer;
3761

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

3778
enum {
3779
  TOPIC_SUB_TYPE__DB = 1,
3780
  TOPIC_SUB_TYPE__TABLE,
3781
  TOPIC_SUB_TYPE__COLUMN,
3782
};
3783

3784
#define DEFAULT_MAX_POLL_INTERVAL  300000
3785
#define DEFAULT_SESSION_TIMEOUT    12000
3786
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3787
#define DEFAULT_MIN_POLL_ROWS      4096
3788

3789
typedef struct {
3790
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3791
  int8_t igExists;
3792
  int8_t subType;
3793
  int8_t withMeta;
3794
  char*  sql;
3795
  char   subDbName[TSDB_DB_FNAME_LEN];
3796
  char*  ast;
3797
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3798
} SCMCreateTopicReq;
3799

3800
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3801
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3802
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3803

3804
typedef struct {
3805
  int64_t consumerId;
3806
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3807

3808
typedef struct {
3809
  int64_t consumerId;
3810
  char    cgroup[TSDB_CGROUP_LEN];
3811
  char    clientId[TSDB_CLIENT_ID_LEN];
3812
  char    user[TSDB_USER_LEN];
3813
  char    fqdn[TSDB_FQDN_LEN];
3814
  SArray* topicNames;  // SArray<char**>
3815

3816
  int8_t  withTbName;
3817
  int8_t  autoCommit;
3818
  int32_t autoCommitInterval;
3819
  int8_t  resetOffsetCfg;
3820
  int8_t  enableReplay;
3821
  int8_t  enableBatchMeta;
3822
  int32_t sessionTimeoutMs;
3823
  int32_t maxPollIntervalMs;
3824
} SCMSubscribeReq;
3825

3826
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3827
  int32_t tlen = 0;
494,792✔
3828
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
494,792✔
3829
  tlen += taosEncodeString(buf, pReq->cgroup);
494,792✔
3830
  tlen += taosEncodeString(buf, pReq->clientId);
494,792✔
3831

3832
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
494,792✔
3833
  tlen += taosEncodeFixedI32(buf, topicNum);
494,792✔
3834

3835
  for (int32_t i = 0; i < topicNum; i++) {
704,804✔
3836
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
420,024✔
3837
  }
3838

3839
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
494,792✔
3840
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
494,792✔
3841
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
494,792✔
3842
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
494,792✔
3843
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
494,792✔
3844
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
494,792✔
3845
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
494,792✔
3846
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
494,792✔
3847
  tlen += taosEncodeString(buf, pReq->user);
494,792✔
3848
  tlen += taosEncodeString(buf, pReq->fqdn);
494,792✔
3849

3850
  return tlen;
494,792✔
3851
}
3852

3853
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3854
  void* start = buf;
117,262✔
3855
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
117,262✔
3856
  buf = taosDecodeStringTo(buf, pReq->cgroup);
117,262✔
3857
  buf = taosDecodeStringTo(buf, pReq->clientId);
117,262✔
3858

3859
  int32_t topicNum = 0;
117,262✔
3860
  buf = taosDecodeFixedI32(buf, &topicNum);
117,262✔
3861

3862
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
117,262✔
3863
  if (pReq->topicNames == NULL) {
117,262✔
UNCOV
3864
    return terrno;
×
3865
  }
3866
  for (int32_t i = 0; i < topicNum; i++) {
167,404✔
3867
    char* name = NULL;
50,142✔
3868
    buf = taosDecodeString(buf, &name);
50,142✔
3869
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
100,284✔
UNCOV
3870
      return terrno;
×
3871
    }
3872
  }
3873

3874
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
117,262✔
3875
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
117,262✔
3876
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
117,262✔
3877
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
117,262✔
3878
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
117,262✔
3879
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
117,262✔
3880
  if ((char*)buf - (char*)start < len) {
117,262✔
3881
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
117,262✔
3882
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
117,262✔
3883
    buf = taosDecodeStringTo(buf, pReq->user);
117,262✔
3884
    buf = taosDecodeStringTo(buf, pReq->fqdn);
234,524✔
3885
  } else {
UNCOV
3886
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3887
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3888
  }
3889

3890
  return 0;
117,262✔
3891
}
3892

3893
typedef struct {
3894
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3895
  SArray* removedConsumers;  // SArray<int64_t>
3896
  SArray* newConsumers;      // SArray<int64_t>
3897
} SMqRebInfo;
3898

3899
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3900
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
90,544✔
3901
  if (pRebInfo == NULL) {
90,544✔
UNCOV
3902
    return NULL;
×
3903
  }
3904
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
90,544✔
3905
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
90,544✔
3906
  if (pRebInfo->removedConsumers == NULL) {
90,544✔
UNCOV
3907
    goto _err;
×
3908
  }
3909
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
90,544✔
3910
  if (pRebInfo->newConsumers == NULL) {
90,544✔
UNCOV
3911
    goto _err;
×
3912
  }
3913
  return pRebInfo;
90,544✔
UNCOV
3914
_err:
×
3915
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3916
  taosArrayDestroy(pRebInfo->newConsumers);
×
3917
  taosMemoryFreeClear(pRebInfo);
×
3918
  return NULL;
×
3919
}
3920

3921
typedef struct {
3922
  int64_t streamId;
3923
  int64_t checkpointId;
3924
  char    streamName[TSDB_STREAM_FNAME_LEN];
3925
} SMStreamDoCheckpointMsg;
3926

3927
typedef struct {
3928
  int64_t status;
3929
} SMVSubscribeRsp;
3930

3931
typedef struct {
3932
  char    name[TSDB_TOPIC_FNAME_LEN];
3933
  int8_t  igNotExists;
3934
  int32_t sqlLen;
3935
  char*   sql;
3936
  int8_t  force;
3937
} SMDropTopicReq;
3938

3939
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3940
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3941
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3942

3943
typedef struct {
3944
  char   topic[TSDB_TOPIC_FNAME_LEN];
3945
  char   cgroup[TSDB_CGROUP_LEN];
3946
  int8_t igNotExists;
3947
  int8_t force;
3948
} SMDropCgroupReq;
3949

3950
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3951
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3952

3953
typedef struct {
3954
  int8_t reserved;
3955
} SMDropCgroupRsp;
3956

3957
typedef struct {
3958
  char    name[TSDB_TABLE_FNAME_LEN];
3959
  int8_t  alterType;
3960
  SSchema schema;
3961
} SAlterTopicReq;
3962

3963
typedef struct {
3964
  SMsgHead head;
3965
  char     name[TSDB_TABLE_FNAME_LEN];
3966
  int64_t  tuid;
3967
  int32_t  sverson;
3968
  int32_t  execLen;
3969
  char*    executor;
3970
  int32_t  sqlLen;
3971
  char*    sql;
3972
} SDCreateTopicReq;
3973

3974
typedef struct {
3975
  SMsgHead head;
3976
  char     name[TSDB_TABLE_FNAME_LEN];
3977
  int64_t  tuid;
3978
} SDDropTopicReq;
3979

3980
typedef struct {
3981
  char*      name;
3982
  int64_t    uid;
3983
  int64_t    interval[2];
3984
  int8_t     intervalUnit;
3985
  int16_t    nFuncs;
3986
  col_id_t*  funcColIds;  // column ids specified by user
3987
  func_id_t* funcIds;     // function ids specified by user
3988
} SRSmaParam;
3989

3990
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3991
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3992

3993
// TDMT_VND_CREATE_STB ==============
3994
typedef struct SVCreateStbReq {
3995
  char*           name;
3996
  tb_uid_t        suid;
3997
  int8_t          rollup;
3998
  SSchemaWrapper  schemaRow;
3999
  SSchemaWrapper  schemaTag;
4000
  SRSmaParam      rsmaParam;
4001
  int32_t         alterOriDataLen;
4002
  void*           alterOriData;
4003
  int8_t          source;
4004
  int8_t          colCmpred;
4005
  SColCmprWrapper colCmpr;
4006
  int64_t         keep;
4007
  SExtSchema*     pExtSchemas;
4008
  int8_t          virtualStb;
4009
} SVCreateStbReq;
4010

4011
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4012
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4013

4014
// TDMT_VND_DROP_STB ==============
4015
typedef struct SVDropStbReq {
4016
  char*    name;
4017
  tb_uid_t suid;
4018
} SVDropStbReq;
4019

4020
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4021
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4022

4023
// TDMT_VND_CREATE_TABLE ==============
4024
#define TD_CREATE_IF_NOT_EXISTS       0x1
4025
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4026
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4027
typedef struct SVCreateTbReq {
4028
  int32_t  flags;
4029
  char*    name;
4030
  tb_uid_t uid;
4031
  int64_t  btime;
4032
  int32_t  ttl;
4033
  int32_t  commentLen;
4034
  char*    comment;
4035
  int8_t   type;
4036
  union {
4037
    struct {
4038
      char*    stbName;  // super table name
4039
      uint8_t  tagNum;
4040
      tb_uid_t suid;
4041
      SArray*  tagName;
4042
      uint8_t* pTag;
4043
    } ctb;
4044
    struct {
4045
      SSchemaWrapper schemaRow;
4046
    } ntb;
4047
  };
4048
  int32_t         sqlLen;
4049
  char*           sql;
4050
  SColCmprWrapper colCmpr;
4051
  SExtSchema*     pExtSchemas;
4052
  SColRefWrapper  colRef;  // col reference for virtual table
4053
} SVCreateTbReq;
4054

4055
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4056
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4057
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4058
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
4059

4060
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4061
  if (NULL == req) {
2,126,436,982✔
4062
    return;
2,057,738,647✔
4063
  }
4064

4065
  taosMemoryFreeClear(req->sql);
68,698,671✔
4066
  taosMemoryFreeClear(req->name);
68,698,125✔
4067
  taosMemoryFreeClear(req->comment);
68,691,614✔
4068
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
68,693,893✔
4069
    taosMemoryFreeClear(req->ctb.pTag);
66,241,511✔
4070
    taosMemoryFreeClear(req->ctb.stbName);
66,230,854✔
4071
    taosArrayDestroy(req->ctb.tagName);
66,237,206✔
4072
    req->ctb.tagName = NULL;
66,219,940✔
4073
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,461,821✔
4074
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,461,821✔
4075
  }
4076
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
68,687,055✔
4077
  taosMemoryFreeClear(req->pExtSchemas);
68,699,822✔
4078
  taosMemoryFreeClear(req->colRef.pColRef);
68,702,242✔
4079
}
4080

4081
typedef struct {
4082
  int32_t nReqs;
4083
  union {
4084
    SVCreateTbReq* pReqs;
4085
    SArray*        pArray;
4086
  };
4087
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4088
} SVCreateTbBatchReq;
4089

4090
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4091
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4092
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4093

4094
typedef struct {
4095
  int32_t        code;
4096
  STableMetaRsp* pMeta;
4097
} SVCreateTbRsp, SVUpdateTbRsp;
4098

4099
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4100
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4101
void tFreeSVCreateTbRsp(void* param);
4102

4103
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4104
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4105

4106
typedef struct {
4107
  int32_t nRsps;
4108
  union {
4109
    SVCreateTbRsp* pRsps;
4110
    SArray*        pArray;
4111
  };
4112
} SVCreateTbBatchRsp;
4113

4114
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4115
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4116

4117
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4118
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4119

4120
// TDMT_VND_DROP_TABLE =================
4121
typedef struct {
4122
  char*    name;
4123
  uint64_t suid;  // for tmq in wal format
4124
  int64_t  uid;
4125
  int8_t   igNotExists;
4126
  int8_t   isVirtual;
4127
} SVDropTbReq;
4128

4129
typedef struct {
4130
  int32_t code;
4131
} SVDropTbRsp;
4132

4133
typedef struct {
4134
  int32_t nReqs;
4135
  union {
4136
    SVDropTbReq* pReqs;
4137
    SArray*      pArray;
4138
  };
4139
} SVDropTbBatchReq;
4140

4141
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4142
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4143

4144
typedef struct {
4145
  int32_t nRsps;
4146
  union {
4147
    SVDropTbRsp* pRsps;
4148
    SArray*      pArray;
4149
  };
4150
} SVDropTbBatchRsp;
4151

4152
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4153
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4154

4155
// TDMT_VND_ALTER_TABLE =====================
4156
typedef struct SMultiTagUpateVal {
4157
  char*    tagName;
4158
  int32_t  colId;
4159
  int8_t   tagType;
4160
  int8_t   tagFree;
4161
  uint32_t nTagVal;
4162
  uint8_t* pTagVal;
4163
  int8_t   isNull;
4164
  SArray*  pTagArray;
4165
} SMultiTagUpateVal;
4166
typedef struct SVAlterTbReq {
4167
  char*   tbName;
4168
  int8_t  action;
4169
  char*   colName;
4170
  int32_t colId;
4171
  // TSDB_ALTER_TABLE_ADD_COLUMN
4172
  int8_t  type;
4173
  int8_t  flags;
4174
  int32_t bytes;
4175
  // TSDB_ALTER_TABLE_DROP_COLUMN
4176
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4177
  int8_t   colModType;
4178
  int32_t  colModBytes;
4179
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4180
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4181
  int8_t   isNull;
4182
  int8_t   tagType;
4183
  int8_t   tagFree;
4184
  uint32_t nTagVal;
4185
  uint8_t* pTagVal;
4186
  SArray*  pTagArray;
4187
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4188
  int8_t   updateTTL;
4189
  int32_t  newTTL;
4190
  int32_t  newCommentLen;
4191
  char*    newComment;
4192
  int64_t  ctimeMs;    // fill by vnode
4193
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4194
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4195
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4196
  // for Add column
4197
  STypeMod typeMod;
4198
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4199
  char* refDbName;
4200
  char* refTbName;
4201
  char* refColName;
4202
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4203
} SVAlterTbReq;
4204

4205
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4206
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4207
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4208
void    tfreeMultiTagUpateVal(void* pMultiTag);
4209

4210
typedef struct {
4211
  int32_t        code;
4212
  STableMetaRsp* pMeta;
4213
} SVAlterTbRsp;
4214

4215
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4216
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4217
// ======================
4218

4219
typedef struct {
4220
  SMsgHead head;
4221
  int64_t  uid;
4222
  int32_t  tid;
4223
  int16_t  tversion;
4224
  int16_t  colId;
4225
  int8_t   type;
4226
  int16_t  bytes;
4227
  int32_t  tagValLen;
4228
  int16_t  numOfTags;
4229
  int32_t  schemaLen;
4230
  char     data[];
4231
} SUpdateTagValReq;
4232

4233
typedef struct {
4234
  SMsgHead head;
4235
} SUpdateTagValRsp;
4236

4237
typedef struct {
4238
  SMsgHead head;
4239
} SVShowTablesReq;
4240

4241
typedef struct {
4242
  SMsgHead head;
4243
  int32_t  id;
4244
} SVShowTablesFetchReq;
4245

4246
typedef struct {
4247
  int64_t useconds;
4248
  int8_t  completed;  // all results are returned to client
4249
  int8_t  precision;
4250
  int8_t  compressed;
4251
  int32_t compLen;
4252
  int32_t numOfRows;
4253
  char    data[];
4254
} SVShowTablesFetchRsp;
4255

4256
typedef struct {
4257
  int64_t consumerId;
4258
  int32_t epoch;
4259
  char    cgroup[TSDB_CGROUP_LEN];
4260
} SMqAskEpReq;
4261

4262
typedef struct {
4263
  int32_t key;
4264
  int32_t valueLen;
4265
  void*   value;
4266
} SKv;
4267

4268
typedef struct {
4269
  int64_t tscRid;
4270
  int8_t  connType;
4271
} SClientHbKey;
4272

4273
typedef struct {
4274
  int64_t tid;
4275
  char    status[TSDB_JOB_STATUS_LEN];
4276
} SQuerySubDesc;
4277

4278
typedef struct {
4279
  char     sql[TSDB_SHOW_SQL_LEN];
4280
  uint64_t queryId;
4281
  int64_t  useconds;
4282
  int64_t  stime;  // timestamp precision ms
4283
  int64_t  reqRid;
4284
  bool     stableQuery;
4285
  bool     isSubQuery;
4286
  char     fqdn[TSDB_FQDN_LEN];
4287
  int32_t  subPlanNum;
4288
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4289
} SQueryDesc;
4290

4291
typedef struct {
4292
  uint32_t connId;
4293
  SArray*  queryDesc;  // SArray<SQueryDesc>
4294
} SQueryHbReqBasic;
4295

4296
typedef struct {
4297
  uint32_t connId;
4298
  uint64_t killRid;
4299
  int32_t  totalDnodes;
4300
  int32_t  onlineDnodes;
4301
  int8_t   killConnection;
4302
  int8_t   align[3];
4303
  SEpSet   epSet;
4304
  SArray*  pQnodeList;
4305
} SQueryHbRspBasic;
4306

4307
typedef struct SAppClusterSummary {
4308
  uint64_t numOfInsertsReq;
4309
  uint64_t numOfInsertRows;
4310
  uint64_t insertElapsedTime;
4311
  uint64_t insertBytes;  // submit to tsdb since launched.
4312

4313
  uint64_t fetchBytes;
4314
  uint64_t numOfQueryReq;
4315
  uint64_t queryElapsedTime;
4316
  uint64_t numOfSlowQueries;
4317
  uint64_t totalRequests;
4318
  uint64_t currentRequests;  // the number of SRequestObj
4319
} SAppClusterSummary;
4320

4321
typedef struct {
4322
  int64_t            appId;
4323
  int32_t            pid;
4324
  char               name[TSDB_APP_NAME_LEN];
4325
  int64_t            startTime;
4326
  SAppClusterSummary summary;
4327
} SAppHbReq;
4328

4329
typedef struct {
4330
  SClientHbKey      connKey;
4331
  int64_t           clusterId;
4332
  SAppHbReq         app;
4333
  SQueryHbReqBasic* query;
4334
  SHashObj*         info;  // hash<Skv.key, Skv>
4335
  char              userApp[TSDB_APP_NAME_LEN];
4336
  uint32_t          userIp;
4337
  SIpRange          userDualIp;
4338
  char              sVer[TSDB_VERSION_LEN];
4339
  char              cInfo[CONNECTOR_INFO_LEN];
4340
} SClientHbReq;
4341

4342
typedef struct {
4343
  int64_t reqId;
4344
  SArray* reqs;  // SArray<SClientHbReq>
4345
  int64_t ipWhiteListVer;
4346
} SClientHbBatchReq;
4347

4348
typedef struct {
4349
  SClientHbKey      connKey;
4350
  int32_t           status;
4351
  SQueryHbRspBasic* query;
4352
  SArray*           info;  // Array<Skv>
4353
} SClientHbRsp;
4354

4355
typedef struct {
4356
  int64_t       reqId;
4357
  int64_t       rspId;
4358
  int32_t       svrTimestamp;
4359
  SArray*       rsps;  // SArray<SClientHbRsp>
4360
  SMonitorParas monitorParas;
4361
  int8_t        enableAuditDelete;
4362
  int8_t        enableStrongPass;
4363
} SClientHbBatchRsp;
4364

4365
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
58,664,165✔
4366

4367
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4368
  void* pIter = taosHashIterate(info, NULL);
36,277,064✔
4369
  while (pIter != NULL) {
79,849,973✔
4370
    SKv* kv = (SKv*)pIter;
43,572,067✔
4371
    taosMemoryFreeClear(kv->value);
43,572,067✔
4372
    pIter = taosHashIterate(info, pIter);
43,572,067✔
4373
  }
4374
}
36,277,906✔
4375

4376
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
20,924,431✔
4377
  SQueryDesc* desc = (SQueryDesc*)pDesc;
20,924,431✔
4378
  if (desc->subDesc) {
20,924,431✔
4379
    taosArrayDestroy(desc->subDesc);
18,391,106✔
4380
    desc->subDesc = NULL;
18,390,696✔
4381
  }
4382
}
20,924,431✔
4383

4384
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
44,323,087✔
4385
  SClientHbReq* req = (SClientHbReq*)pReq;
47,626,084✔
4386
  if (req->query) {
47,626,084✔
4387
    if (req->query->queryDesc) {
39,859,745✔
4388
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
19,507,906✔
4389
    }
4390
    taosMemoryFreeClear(req->query);
39,859,745✔
4391
  }
4392

4393
  if (req->info) {
47,627,131✔
4394
    tFreeReqKvHash(req->info);
36,277,500✔
4395
    taosHashCleanup(req->info);
36,277,906✔
4396
    req->info = NULL;
36,277,703✔
4397
  }
4398
}
23,752,346✔
4399

4400
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4401
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4402

4403
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4404
  if (pReq == NULL) return;
19,884,314✔
4405
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
19,884,314✔
4406
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
19,884,314✔
4407
  taosMemoryFree(pReq);
19,884,314✔
4408
}
4409

4410
static FORCE_INLINE void tFreeClientKv(void* pKv) {
16,170,284✔
4411
  SKv* kv = (SKv*)pKv;
16,170,284✔
4412
  if (kv) {
16,170,284✔
4413
    taosMemoryFreeClear(kv->value);
16,170,284✔
4414
  }
4415
}
16,170,705✔
4416

4417
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
43,903,352✔
4418
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
43,903,352✔
4419
  if (rsp->query) {
43,903,352✔
4420
    taosArrayDestroy(rsp->query->pQnodeList);
39,466,877✔
4421
    taosMemoryFreeClear(rsp->query);
39,461,812✔
4422
  }
4423
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
43,902,910✔
4424
}
23,454,627✔
4425

4426
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4427
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
36,471,034✔
4428
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
36,471,034✔
4429
}
36,471,661✔
4430

4431
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4432
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4433
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4434

4435
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4436
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
119,886,157✔
4437
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
119,887,200✔
4438
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
119,886,988✔
4439
  return 0;
59,943,402✔
4440
}
4441

4442
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4443
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
55,721,351✔
4444
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
55,721,674✔
4445
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
27,860,837✔
4446
  if (pKv->value == NULL) {
27,860,389✔
UNCOV
4447
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4448
  }
4449
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
27,860,837✔
4450
  return 0;
27,860,755✔
4451
}
4452

4453
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4454
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
171,548,001✔
4455
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
171,544,448✔
4456
  return 0;
85,770,770✔
4457
}
4458

4459
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4460
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
84,953,507✔
4461
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
84,953,894✔
4462
  return 0;
42,477,249✔
4463
}
4464

4465
typedef struct {
4466
  int32_t vgId;
4467
  // TODO stas
4468
} SMqReportVgInfo;
4469

4470
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4471
  int32_t tlen = 0;
4472
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4473
  return tlen;
4474
}
4475

4476
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4477
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4478
  return buf;
4479
}
4480

4481
typedef struct {
4482
  int32_t epoch;
4483
  int64_t topicUid;
4484
  char    name[TSDB_TOPIC_FNAME_LEN];
4485
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4486
} SMqTopicInfo;
4487

4488
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4489
  int32_t tlen = 0;
4490
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4491
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4492
  tlen += taosEncodeString(buf, pTopicInfo->name);
4493
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4494
  tlen += taosEncodeFixedI32(buf, sz);
4495
  for (int32_t i = 0; i < sz; i++) {
4496
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4497
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4498
  }
4499
  return tlen;
4500
}
4501

4502
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4503
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4504
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4505
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4506
  int32_t sz;
4507
  buf = taosDecodeFixedI32(buf, &sz);
4508
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4509
    return NULL;
4510
  }
4511
  for (int32_t i = 0; i < sz; i++) {
4512
    SMqReportVgInfo vgInfo;
4513
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4514
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4515
      return NULL;
4516
    }
4517
  }
4518
  return buf;
4519
}
4520

4521
typedef struct {
4522
  int32_t status;  // ask hb endpoint
4523
  int32_t epoch;
4524
  int64_t consumerId;
4525
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4526
} SMqReportReq;
4527

4528
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4529
  int32_t tlen = 0;
4530
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4531
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4532
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4533
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4534
  tlen += taosEncodeFixedI32(buf, sz);
4535
  for (int32_t i = 0; i < sz; i++) {
4536
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4537
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4538
  }
4539
  return tlen;
4540
}
4541

4542
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4543
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4544
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4545
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4546
  int32_t sz;
4547
  buf = taosDecodeFixedI32(buf, &sz);
4548
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4549
    return NULL;
4550
  }
4551
  for (int32_t i = 0; i < sz; i++) {
4552
    SMqTopicInfo topicInfo;
4553
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4554
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4555
      return NULL;
4556
    }
4557
  }
4558
  return buf;
4559
}
4560

4561
typedef struct {
4562
  SMsgHead head;
4563
  int64_t  leftForVer;
4564
  int32_t  vgId;
4565
  int64_t  consumerId;
4566
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4567
} SMqVDeleteReq;
4568

4569
typedef struct {
4570
  int8_t reserved;
4571
} SMqVDeleteRsp;
4572

4573
typedef struct {
4574
  char*   name;
4575
  int8_t  igNotExists;
4576
} SMDropStreamReq;
4577

4578
typedef struct {
4579
  int8_t reserved;
4580
} SMDropStreamRsp;
4581

4582
typedef struct {
4583
  SMsgHead head;
4584
  int64_t  resetRelHalt;  // reset related stream task halt status
4585
  int64_t  streamId;
4586
  int32_t  taskId;
4587
} SVDropStreamTaskReq;
4588

4589
typedef struct {
4590
  int8_t reserved;
4591
} SVDropStreamTaskRsp;
4592

4593
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4594
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4595
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4596

4597
typedef struct {
4598
  char*  name;
4599
  int8_t igNotExists;
4600
} SMPauseStreamReq;
4601

4602
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4603
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4604
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4605

4606
typedef struct {
4607
  char*  name;
4608
  int8_t igNotExists;
4609
  int8_t igUntreated;
4610
} SMResumeStreamReq;
4611

4612
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4613
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4614
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4615

4616
typedef struct {
4617
  char*       name;
4618
  int8_t      calcAll;
4619
  STimeWindow timeRange;
4620
} SMRecalcStreamReq;
4621

4622
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4623
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4624
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4625

4626
typedef struct SVndSetKeepVersionReq {
4627
  int64_t keepVersion;
4628
} SVndSetKeepVersionReq;
4629

4630
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4631
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4632

4633
typedef struct SVUpdateCheckpointInfoReq {
4634
  SMsgHead head;
4635
  int64_t  streamId;
4636
  int32_t  taskId;
4637
  int64_t  checkpointId;
4638
  int64_t  checkpointVer;
4639
  int64_t  checkpointTs;
4640
  int32_t  transId;
4641
  int64_t  hStreamId;  // add encode/decode
4642
  int64_t  hTaskId;
4643
  int8_t   dropRelHTask;
4644
} SVUpdateCheckpointInfoReq;
4645

4646
typedef struct {
4647
  int64_t leftForVer;
4648
  int32_t vgId;
4649
  int64_t oldConsumerId;
4650
  int64_t newConsumerId;
4651
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4652
  int8_t  subType;
4653
  int8_t  withMeta;
4654
  char*   qmsg;  // SubPlanToString
4655
  int64_t suid;
4656
} SMqRebVgReq;
4657

4658
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4659
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4660

4661
typedef struct {
4662
  char    topic[TSDB_TOPIC_FNAME_LEN];
4663
  int64_t ntbUid;
4664
  SArray* colIdList;  // SArray<int16_t>
4665
} STqCheckInfo;
4666

4667
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4668
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4669
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4670

4671
// tqOffset
4672
enum {
4673
  TMQ_OFFSET__RESET_NONE = -3,
4674
  TMQ_OFFSET__RESET_EARLIEST = -2,
4675
  TMQ_OFFSET__RESET_LATEST = -1,
4676
  TMQ_OFFSET__LOG = 1,
4677
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4678
  TMQ_OFFSET__SNAPSHOT_META = 3,
4679
};
4680

4681
enum {
4682
  WITH_DATA = 0,
4683
  WITH_META = 1,
4684
  ONLY_META = 2,
4685
};
4686

4687
#define TQ_OFFSET_VERSION 1
4688

4689
typedef struct {
4690
  int8_t type;
4691
  union {
4692
    // snapshot
4693
    struct {
4694
      int64_t uid;
4695
      int64_t ts;
4696
      SValue  primaryKey;
4697
    };
4698
    // log
4699
    struct {
4700
      int64_t version;
4701
    };
4702
  };
4703
} STqOffsetVal;
4704

4705
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4706
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,741,865✔
4707
  pOffsetVal->uid = uid;
1,741,577✔
4708
  pOffsetVal->ts = ts;
1,742,145✔
4709
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,742,140✔
UNCOV
4710
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4711
  }
4712
  pOffsetVal->primaryKey = primaryKey;
1,742,204✔
4713
}
1,741,272✔
4714

4715
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4716
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
6,160✔
4717
  pOffsetVal->uid = uid;
6,160✔
4718
}
6,160✔
4719

4720
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4721
  pOffsetVal->type = TMQ_OFFSET__LOG;
39,982,510✔
4722
  pOffsetVal->version = ver;
39,982,677✔
4723
}
39,981,783✔
4724

4725
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4726
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4727
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4728
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4729
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4730
void    tOffsetDestroy(void* pVal);
4731

4732
typedef struct {
4733
  STqOffsetVal val;
4734
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4735
} STqOffset;
4736

4737
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4738
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4739
void    tDeleteSTqOffset(void* val);
4740

4741
typedef struct SMqVgOffset {
4742
  int64_t   consumerId;
4743
  STqOffset offset;
4744
} SMqVgOffset;
4745

4746
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4747
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4748

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

4783
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4784
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4785
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4786

4787
typedef struct {
4788
  char   name[TSDB_TABLE_FNAME_LEN];
4789
  int8_t igNotExists;
4790
  char*   dropStreamReq;
4791
  int32_t dropStreamReqLen;
4792
} SMDropSmaReq;
4793

4794
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4795
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4796
void tFreeSMDropSmaReq(SMDropSmaReq *pReq);
4797

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

4820
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4821
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4822
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4823

4824
typedef SMCreateRsmaReq SVCreateRsmaReq;
4825

4826
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4827
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4828
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4829

4830
typedef SMCreateRsmaReq SVAlterRsmaReq;
4831

4832
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4833
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4834
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4835

4836
typedef struct {
4837
  char       name[TSDB_TABLE_NAME_LEN];
4838
  int8_t     alterType;
4839
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4840
  int8_t     igNotExists;
4841
  int16_t    nFuncs;      // number of functions specified by user
4842
  col_id_t*  funcColIds;  // column ids specified by user
4843
  func_id_t* funcIds;     // function ids specified by user
4844
  int32_t    sqlLen;      // strlen + 1
4845
  char*      sql;
4846
} SMAlterRsmaReq;
4847

4848
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4849
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4850
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4851

4852
typedef struct {
4853
  int64_t    id;
4854
  char       name[TSDB_TABLE_NAME_LEN];
4855
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4856
  int32_t    code;
4857
  int32_t    version;
4858
  int8_t     tbType;
4859
  int8_t     intervalUnit;
4860
  col_id_t   nFuncs;
4861
  col_id_t   nColNames;
4862
  int64_t    interval[2];
4863
  col_id_t*  funcColIds;
4864
  func_id_t* funcIds;
4865
  SArray*    colNames;
4866
} SRsmaInfoRsp;
4867

4868
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4869
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4870
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4871

4872
typedef struct {
4873
  char   name[TSDB_TABLE_FNAME_LEN];
4874
  int8_t igNotExists;
4875
} SMDropRsmaReq;
4876

4877
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4878
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4879

4880
typedef struct {
4881
  char    name[TSDB_TABLE_NAME_LEN];
4882
  char    tbName[TSDB_TABLE_NAME_LEN];
4883
  int64_t uid;
4884
  int64_t tbUid;
4885
  int8_t  tbType;
4886
} SVDropRsmaReq;
4887

4888
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4889
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4890

4891
typedef struct {
4892
  char   dbFName[TSDB_DB_FNAME_LEN];
4893
  char   stbName[TSDB_TABLE_NAME_LEN];
4894
  char   colName[TSDB_COL_NAME_LEN];
4895
  char   idxName[TSDB_INDEX_FNAME_LEN];
4896
  int8_t idxType;
4897
} SCreateTagIndexReq;
4898

4899
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4900
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4901

4902
typedef SMDropSmaReq SDropTagIndexReq;
4903

4904
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4905
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4906

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

4929
typedef STSma SVCreateTSmaReq;
4930

4931
typedef struct {
4932
  int8_t  type;  // 0 status report, 1 update data
4933
  int64_t indexUid;
4934
  int64_t skey;  // start TS key of interval/sliding window
4935
} STSmaMsg;
4936

4937
typedef struct {
4938
  int64_t indexUid;
4939
  char    indexName[TSDB_INDEX_NAME_LEN];
4940
} SVDropTSmaReq;
4941

4942
typedef struct {
4943
  int tmp;  // TODO: to avoid compile error
4944
} SVCreateTSmaRsp, SVDropTSmaRsp;
4945

4946
#if 0
4947
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4948
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4949
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4950
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4951
#endif
4952

4953
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4954
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4955
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4956
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4957

4958
typedef struct {
4959
  int32_t number;
4960
  STSma*  tSma;
4961
} STSmaWrapper;
4962

4963
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
4964
  if (pSma) {
×
4965
    taosMemoryFreeClear(pSma->dstTbName);
×
4966
    taosMemoryFreeClear(pSma->expr);
×
4967
    taosMemoryFreeClear(pSma->tagsFilter);
×
4968
  }
UNCOV
4969
}
×
4970

4971
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4972
  if (pSW) {
×
4973
    if (pSW->tSma) {
×
4974
      if (deepCopy) {
×
4975
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4976
          tDestroyTSma(pSW->tSma + i);
×
4977
        }
4978
      }
UNCOV
4979
      taosMemoryFreeClear(pSW->tSma);
×
4980
    }
4981
  }
UNCOV
4982
}
×
4983

4984
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4985
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4986
  taosMemoryFreeClear(pSW);
×
4987
  return NULL;
×
4988
}
4989

4990
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4991
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4992

4993
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4994
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4995

UNCOV
4996
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4997
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4998
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4999
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5000
  }
UNCOV
5001
  return 0;
×
5002
}
5003

UNCOV
5004
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5005
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5006
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5007
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5008
  }
UNCOV
5009
  return 0;
×
5010
}
5011

5012
typedef struct {
5013
  int idx;
5014
} SMCreateFullTextReq;
5015

5016
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5017
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5018
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5019

5020
typedef struct {
5021
  char   name[TSDB_TABLE_FNAME_LEN];
5022
  int8_t igNotExists;
5023
} SMDropFullTextReq;
5024

5025
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5026
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5027

5028
typedef struct {
5029
  char indexFName[TSDB_INDEX_FNAME_LEN];
5030
} SUserIndexReq;
5031

5032
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5033
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5034

5035
typedef struct {
5036
  char dbFName[TSDB_DB_FNAME_LEN];
5037
  char tblFName[TSDB_TABLE_FNAME_LEN];
5038
  char colName[TSDB_COL_NAME_LEN];
5039
  char indexType[TSDB_INDEX_TYPE_LEN];
5040
  char indexExts[TSDB_INDEX_EXTS_LEN];
5041
} SUserIndexRsp;
5042

5043
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5044
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5045

5046
typedef struct {
5047
  char tbFName[TSDB_TABLE_FNAME_LEN];
5048
} STableIndexReq;
5049

5050
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5051
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5052

5053
typedef struct {
5054
  int8_t  intervalUnit;
5055
  int8_t  slidingUnit;
5056
  int64_t interval;
5057
  int64_t offset;
5058
  int64_t sliding;
5059
  int64_t dstTbUid;
5060
  int32_t dstVgId;
5061
  SEpSet  epSet;
5062
  char*   expr;
5063
} STableIndexInfo;
5064

5065
typedef struct {
5066
  char     tbName[TSDB_TABLE_NAME_LEN];
5067
  char     dbFName[TSDB_DB_FNAME_LEN];
5068
  uint64_t suid;
5069
  int32_t  version;
5070
  int32_t  indexSize;
5071
  SArray*  pIndex;  // STableIndexInfo
5072
} STableIndexRsp;
5073

5074
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5075
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5076
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5077

5078
void tFreeSTableIndexInfo(void* pInfo);
5079

5080
typedef struct {
5081
  int8_t  mqMsgType;
5082
  int32_t code;
5083
  int32_t epoch;
5084
  int64_t consumerId;
5085
  int64_t walsver;
5086
  int64_t walever;
5087
} SMqRspHead;
5088

5089
typedef struct {
5090
  SMsgHead     head;
5091
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5092
  int8_t       withTbName;
5093
  int8_t       useSnapshot;
5094
  int32_t      epoch;
5095
  uint64_t     reqId;
5096
  int64_t      consumerId;
5097
  int64_t      timeout;
5098
  STqOffsetVal reqOffset;
5099
  int8_t       enableReplay;
5100
  int8_t       sourceExcluded;
5101
  int8_t       rawData;
5102
  int32_t      minPollRows;
5103
  int8_t       enableBatchMeta;
5104
  SHashObj*    uidHash;  // to find if uid is duplicated
5105
} SMqPollReq;
5106

5107
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5108
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5109
void    tDestroySMqPollReq(SMqPollReq* pReq);
5110

5111
typedef struct {
5112
  int32_t vgId;
5113
  int64_t offset;
5114
  SEpSet  epSet;
5115
} SMqSubVgEp;
5116

5117
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5118
  int32_t tlen = 0;
398,050✔
5119
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
398,050✔
5120
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
398,050✔
5121
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
398,050✔
5122
  return tlen;
398,050✔
5123
}
5124

5125
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5126
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
338,986✔
5127
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
338,986✔
5128
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
338,986✔
5129
  return buf;
338,986✔
5130
}
5131

5132
typedef struct {
5133
  char           topic[TSDB_TOPIC_FNAME_LEN];
5134
  char           db[TSDB_DB_FNAME_LEN];
5135
  SArray*        vgs;  // SArray<SMqSubVgEp>
5136
  SSchemaWrapper schema;
5137
} SMqSubTopicEp;
5138

5139
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5140
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5141
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5142

5143
typedef struct {
5144
  SMqRspHead   head;
5145
  STqOffsetVal rspOffset;
5146
  int16_t      resMsgType;
5147
  int32_t      metaRspLen;
5148
  void*        metaRsp;
5149
} SMqMetaRsp;
5150

5151
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5152
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5153
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5154

5155
#define MQ_DATA_RSP_VERSION 100
5156

5157
typedef struct {
5158
  SMqRspHead   head;
5159
  STqOffsetVal rspOffset;
5160
  STqOffsetVal reqOffset;
5161
  int32_t      blockNum;
5162
  int8_t       withTbName;
5163
  int8_t       withSchema;
5164
  SArray*      blockDataLen;
5165
  SArray*      blockData;
5166
  SArray*      blockTbName;
5167
  SArray*      blockSchema;
5168

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

5187
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5188
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5189
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5190
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5191
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5192

5193
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5194
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5195
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5196

5197
typedef struct SMqBatchMetaRsp {
5198
  SMqRspHead   head;  // not serialize
5199
  STqOffsetVal rspOffset;
5200
  SArray*      batchMetaLen;
5201
  SArray*      batchMetaReq;
5202
  void*        pMetaBuff;    // not serialize
5203
  uint32_t     metaBuffLen;  // not serialize
5204
} SMqBatchMetaRsp;
5205

5206
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5207
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5208
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5209
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5210

5211
typedef struct {
5212
  SMqRspHead head;
5213
  char       cgroup[TSDB_CGROUP_LEN];
5214
  SArray*    topics;  // SArray<SMqSubTopicEp>
5215
} SMqAskEpRsp;
5216

5217
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5218
  int32_t tlen = 0;
1,210,236✔
5219
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5220
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,210,236✔
5221
  tlen += taosEncodeFixedI32(buf, sz);
1,210,128✔
5222
  for (int32_t i = 0; i < sz; i++) {
1,405,782✔
5223
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
195,620✔
5224
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
195,620✔
5225
  }
5226
  return tlen;
1,210,162✔
5227
}
5228

5229
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5230
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5231
  int32_t sz;
586,708✔
5232
  buf = taosDecodeFixedI32(buf, &sz);
903,116✔
5233
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
903,116✔
5234
  if (pRsp->topics == NULL) {
903,116✔
UNCOV
5235
    return NULL;
×
5236
  }
5237
  for (int32_t i = 0; i < sz; i++) {
1,097,267✔
5238
    SMqSubTopicEp topicEp;
109,864✔
5239
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
194,151✔
5240
    if (buf == NULL) {
194,151✔
UNCOV
5241
      return NULL;
×
5242
    }
5243
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
388,302✔
UNCOV
5244
      return NULL;
×
5245
    }
5246
  }
5247
  return buf;
903,116✔
5248
}
5249

5250
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5251
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,855,262✔
5252
}
1,855,262✔
5253

5254
typedef struct {
5255
  int32_t      vgId;
5256
  STqOffsetVal offset;
5257
  int64_t      rows;
5258
  int64_t      ever;
5259
} OffsetRows;
5260

5261
typedef struct {
5262
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5263
  SArray* offsetRows;
5264
} TopicOffsetRows;
5265

5266
typedef struct {
5267
  int64_t consumerId;
5268
  int32_t epoch;
5269
  SArray* topics;
5270
  int8_t  pollFlag;
5271
} SMqHbReq;
5272

5273
typedef struct {
5274
  char   topic[TSDB_TOPIC_FNAME_LEN];
5275
  int8_t noPrivilege;
5276
} STopicPrivilege;
5277

5278
typedef struct {
5279
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5280
  int32_t debugFlag;
5281
} SMqHbRsp;
5282

5283
typedef struct {
5284
  SMsgHead head;
5285
  int64_t  consumerId;
5286
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5287
} SMqSeekReq;
5288

5289
#define TD_AUTO_CREATE_TABLE 0x1
5290
typedef struct {
5291
  int64_t       suid;
5292
  int64_t       uid;
5293
  int32_t       sver;
5294
  uint32_t      nData;
5295
  uint8_t*      pData;
5296
  SVCreateTbReq cTbReq;
5297
} SVSubmitBlk;
5298

5299
typedef struct {
5300
  SMsgHead header;
5301
  uint64_t sId;
5302
  uint64_t queryId;
5303
  uint64_t clientId;
5304
  uint64_t taskId;
5305
  uint32_t sqlLen;
5306
  uint32_t phyLen;
5307
  char*    sql;
5308
  char*    msg;
5309
  int8_t   source;
5310
} SVDeleteReq;
5311

5312
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5313
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5314

5315
typedef struct {
5316
  int64_t affectedRows;
5317
} SVDeleteRsp;
5318

5319
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5320
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5321

5322
typedef struct SDeleteRes {
5323
  uint64_t suid;
5324
  SArray*  uidList;
5325
  int64_t  skey;
5326
  int64_t  ekey;
5327
  int64_t  affectedRows;
5328
  char     tableFName[TSDB_TABLE_NAME_LEN];
5329
  char     tsColName[TSDB_COL_NAME_LEN];
5330
  int64_t  ctimeMs;  // fill by vnode
5331
  int8_t   source;
5332
} SDeleteRes;
5333

5334
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5335
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5336

5337
typedef struct {
5338
  // int64_t uid;
5339
  char    tbname[TSDB_TABLE_NAME_LEN];
5340
  int64_t startTs;
5341
  int64_t endTs;
5342
} SSingleDeleteReq;
5343

5344
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5345
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5346

5347
typedef struct {
5348
  int64_t suid;
5349
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5350
  int64_t ctimeMs;     // fill by vnode
5351
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5352
} SBatchDeleteReq;
5353

5354
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5355
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5356
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5357

5358
typedef struct {
5359
  int32_t msgIdx;
5360
  int32_t msgType;
5361
  int32_t msgLen;
5362
  void*   msg;
5363
} SBatchMsg;
5364

5365
typedef struct {
5366
  SMsgHead header;
5367
  SArray*  pMsgs;  // SArray<SBatchMsg>
5368
} SBatchReq;
5369

5370
typedef struct {
5371
  int32_t reqType;
5372
  int32_t msgIdx;
5373
  int32_t msgLen;
5374
  int32_t rspCode;
5375
  void*   msg;
5376
} SBatchRspMsg;
5377

5378
typedef struct {
5379
  SArray* pRsps;  // SArray<SBatchRspMsg>
5380
} SBatchRsp;
5381

5382
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5383
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5384
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
87,622,955✔
5385
  if (NULL == msg) {
87,622,955✔
UNCOV
5386
    return;
×
5387
  }
5388
  SBatchMsg* pMsg = (SBatchMsg*)msg;
87,622,955✔
5389
  taosMemoryFree(pMsg->msg);
87,622,955✔
5390
}
5391

5392
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5393
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5394

5395
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
126,504,326✔
5396
  if (NULL == p) {
126,504,326✔
UNCOV
5397
    return;
×
5398
  }
5399

5400
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
126,504,326✔
5401
  taosMemoryFree(pRsp->msg);
126,504,326✔
5402
}
5403

5404
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5405
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5406
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5407
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5408
void    tDestroySMqHbReq(SMqHbReq* pReq);
5409

5410
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5411
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5412
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5413

5414
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5415
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5416

5417
#define TD_REQ_FROM_APP               0x0
5418
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5419
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5420
#define SUBMIT_REQ_FROM_FILE          0x4
5421
#define TD_REQ_FROM_TAOX              0x8
5422
#define TD_REQ_FROM_SML               0x10
5423
#define SUBMIT_REQUEST_VERSION        (2)
5424
#define SUBMIT_REQ_WITH_BLOB          0x10
5425
#define SUBMIT_REQ_SCHEMA_RES         0x20
5426
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5427

5428
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5429

5430
typedef struct {
5431
  int32_t        flags;
5432
  SVCreateTbReq* pCreateTbReq;
5433
  int64_t        suid;
5434
  int64_t        uid;
5435
  int32_t        sver;
5436
  union {
5437
    SArray* aRowP;
5438
    SArray* aCol;
5439
  };
5440
  int64_t    ctimeMs;
5441
  SBlobSet*  pBlobSet;
5442
} SSubmitTbData;
5443

5444
typedef struct {
5445
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5446
  SArray* aSubmitBlobData;
5447
  bool    raw;
5448
} SSubmitReq2;
5449

5450
typedef struct {
5451
  SMsgHead header;
5452
  int64_t  version;
5453
  char     data[];  // SSubmitReq2
5454
} SSubmitReq2Msg;
5455

5456
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5457
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5458
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5459
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5460
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5461

5462
typedef struct {
5463
  int32_t affectedRows;
5464
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5465
} SSubmitRsp2;
5466

5467
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5468
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5469
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5470

5471
#define TSDB_MSG_FLG_ENCODE 0x1
5472
#define TSDB_MSG_FLG_DECODE 0x2
5473
#define TSDB_MSG_FLG_CMPT   0x3
5474

5475
typedef struct {
5476
  union {
5477
    struct {
5478
      void*   msgStr;
5479
      int32_t msgLen;
5480
      int64_t ver;
5481
    };
5482
    void* pDataBlock;
5483
  };
5484
} SPackedData;
5485

5486
typedef struct {
5487
  char     fullname[TSDB_VIEW_FNAME_LEN];
5488
  char     name[TSDB_VIEW_NAME_LEN];
5489
  char     dbFName[TSDB_DB_FNAME_LEN];
5490
  char*    querySql;
5491
  char*    sql;
5492
  int8_t   orReplace;
5493
  int8_t   precision;
5494
  int32_t  numOfCols;
5495
  SSchema* pSchema;
5496
} SCMCreateViewReq;
5497

5498
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5499
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5500
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5501

5502
typedef struct {
5503
  char   fullname[TSDB_VIEW_FNAME_LEN];
5504
  char   name[TSDB_VIEW_NAME_LEN];
5505
  char   dbFName[TSDB_DB_FNAME_LEN];
5506
  char*  sql;
5507
  int8_t igNotExists;
5508
} SCMDropViewReq;
5509

5510
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5511
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5512
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5513

5514
typedef struct {
5515
  char fullname[TSDB_VIEW_FNAME_LEN];
5516
} SViewMetaReq;
5517
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5518
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5519

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

5541
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5542
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5543

5544
typedef struct {
5545
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5546
  union {
5547
    uint8_t flags;
5548
    struct {
5549
      uint8_t withColName : 1;
5550
      uint8_t reserved : 7;
5551
    };
5552
  };
5553

5554
} SRsmaInfoReq;
5555

5556
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5557
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5558

5559
typedef struct {
5560
  int32_t  funcId;
5561
  col_id_t colId;
5562
} STableTSMAFuncInfo;
5563

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

5582
  int64_t streamUid;
5583
  int64_t reqTs;
5584
  int64_t rspTs;
5585
  int64_t delayDuration;  // ms
5586
  bool    fillHistoryFinished;
5587

5588
  void*   streamAddr;  // for stream task, the address of the stream task
5589
} STableTSMAInfo;
5590

5591
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5592
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5593
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5594
void    tFreeTableTSMAInfo(void* p);
5595
void    tFreeAndClearTableTSMAInfo(void* p);
5596
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5597

5598
#define STSMAHbRsp            STableTSMAInfoRsp
5599
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5600
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5601
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5602

5603
typedef struct SDropCtbWithTsmaSingleVgReq {
5604
  SVgroupInfo vgInfo;
5605
  SArray*     pTbs;  // SVDropTbReq
5606
} SMDropTbReqsOnSingleVg;
5607

5608
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5609
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5610
void    tFreeSMDropTbReqOnSingleVg(void* p);
5611

5612
typedef struct SDropTbsReq {
5613
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5614
} SMDropTbsReq;
5615

5616
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5617
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5618
void    tFreeSMDropTbsReq(void*);
5619

5620
typedef struct SVFetchTtlExpiredTbsRsp {
5621
  SArray* pExpiredTbs;  // SVDropTbReq
5622
  int32_t vgId;
5623
} SVFetchTtlExpiredTbsRsp;
5624

5625
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5626
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5627

5628
void tFreeFetchTtlExpiredTbsRsp(void* p);
5629

5630
void setDefaultOptionsForField(SFieldWithOptions* field);
5631
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5632

5633
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5634
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5635

5636
typedef struct {
5637
  char    id[TSDB_INSTANCE_ID_LEN];
5638
  char    type[TSDB_INSTANCE_TYPE_LEN];
5639
  char    desc[TSDB_INSTANCE_DESC_LEN];
5640
  int32_t expire;
5641
} SInstanceRegisterReq;
5642

5643
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5644
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5645

5646
typedef struct {
5647
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5648
} SInstanceListReq;
5649

5650
typedef struct {
5651
  int32_t count;
5652
  char**  ids;  // Array of instance IDs
5653
} SInstanceListRsp;
5654

5655
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5656
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5657
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5658
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5659

5660
#ifdef USE_MOUNT
5661
typedef struct {
5662
  char     mountName[TSDB_MOUNT_NAME_LEN];
5663
  int8_t   ignoreExist;
5664
  int16_t  nMounts;
5665
  int32_t* dnodeIds;
5666
  char**   mountPaths;
5667
  int32_t  sqlLen;
5668
  char*    sql;
5669
} SCreateMountReq;
5670

5671
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5672
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5673
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5674

5675
typedef struct {
5676
  char    mountName[TSDB_MOUNT_NAME_LEN];
5677
  int8_t  ignoreNotExists;
5678
  int32_t sqlLen;
5679
  char*   sql;
5680
} SDropMountReq;
5681

5682
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5683
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5684
void    tFreeSDropMountReq(SDropMountReq* pReq);
5685

5686
typedef struct {
5687
  char     mountName[TSDB_MOUNT_NAME_LEN];
5688
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5689
  int64_t  mountUid;
5690
  int32_t  dnodeId;
5691
  uint32_t valLen;
5692
  int8_t   ignoreExist;
5693
  void*    pVal;
5694
} SRetrieveMountPathReq;
5695

5696
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5697
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5698

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

5754
typedef struct {
5755
  SMCreateStbReq req;
5756
  SArray*        pColExts;  // element: column id
5757
  SArray*        pTagExts;  // element: tag id
5758
} SMountStbInfo;
5759

5760
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5761
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5762

5763
typedef struct {
5764
  char     dbName[TSDB_DB_FNAME_LEN];
5765
  uint64_t dbId;
5766
  SArray*  pVgs;      // SMountVgInfo
5767
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5768
} SMountDbInfo;
5769

5770
typedef struct {
5771
  // common fields
5772
  char     mountName[TSDB_MOUNT_NAME_LEN];
5773
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5774
  int8_t   ignoreExist;
5775
  int64_t  mountUid;
5776
  int64_t  clusterId;
5777
  int32_t  dnodeId;
5778
  uint32_t valLen;
5779
  void*    pVal;
5780

5781
  // response fields
5782
  SArray* pDbs;  // SMountDbInfo
5783

5784
  // memory fields, no serialized
5785
  SArray*   pDisks[TFS_MAX_TIERS];
5786
  TdFilePtr pFile;
5787
} SMountInfo;
5788

5789
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5790
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5791
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5792

5793
typedef struct {
5794
  SCreateVnodeReq createReq;
5795
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5796
  char            mountName[TSDB_MOUNT_NAME_LEN];
5797
  int64_t         mountId;
5798
  int32_t         diskPrimary;
5799
  int32_t         mountVgId;
5800
  int64_t         committed;
5801
  int64_t         commitID;
5802
  int64_t         commitTerm;
5803
  int64_t         numOfSTables;
5804
  int64_t         numOfCTables;
5805
  int64_t         numOfNTables;
5806
} SMountVnodeReq;
5807

5808
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5809
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5810
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5811

5812
#endif  // USE_MOUNT
5813

5814
#pragma pack(pop)
5815

5816
typedef struct {
5817
  char        db[TSDB_DB_FNAME_LEN];
5818
  STimeWindow timeRange;
5819
  int32_t     sqlLen;
5820
  char*       sql;
5821
  SArray*     vgroupIds;
5822
} SScanDbReq;
5823

5824
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5825
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5826
void    tFreeSScanDbReq(SScanDbReq* pReq);
5827

5828
typedef struct {
5829
  int32_t scanId;
5830
  int8_t  bAccepted;
5831
} SScanDbRsp;
5832

5833
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5834
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5835

5836
typedef struct {
5837
  int32_t scanId;
5838
  int32_t sqlLen;
5839
  char*   sql;
5840
} SKillScanReq;
5841

5842
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5843
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5844
void    tFreeSKillScanReq(SKillScanReq* pReq);
5845

5846
typedef struct {
5847
  int32_t scanId;
5848
  int32_t vgId;
5849
  int32_t dnodeId;
5850
} SVKillScanReq;
5851

5852
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5853
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5854

5855
typedef struct {
5856
  int32_t scanId;
5857
  int32_t vgId;
5858
  int32_t dnodeId;
5859
  int32_t numberFileset;
5860
  int32_t finished;
5861
  int32_t progress;
5862
  int64_t remainingTime;
5863
} SQueryScanProgressRsp;
5864

5865
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5866
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5867

5868
typedef struct {
5869
  int32_t scanId;
5870
  int32_t vgId;
5871
  int32_t dnodeId;
5872
} SQueryScanProgressReq;
5873

5874
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5875
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5876

5877
typedef struct {
5878
  int64_t     dbUid;
5879
  char        db[TSDB_DB_FNAME_LEN];
5880
  int64_t     scanStartTime;
5881
  STimeWindow tw;
5882
  int32_t     scanId;
5883
} SScanVnodeReq;
5884

5885
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5886
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5887

5888
#ifdef __cplusplus
5889
}
5890
#endif
5891

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