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

taosdata / TDengine / #4875

09 Dec 2025 01:22AM UTC coverage: 64.472% (-0.2%) from 64.623%
#4875

push

travis-ci

guanshengliang
fix: temporarily disable memory leak detection for UDF tests (#33856)

162014 of 251293 relevant lines covered (64.47%)

104318075.66 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;
359✔
106
}
107

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

110
static inline bool vnodeIsMsgBlock(tmsg_t type) {
739,368,968✔
111
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
697,245,474✔
112
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,436,614,442✔
113
         (type == TDMT_SYNC_CONFIG_CHANGE);
114
}
115

116
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,856,642,682✔
117
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,856,642,682✔
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__MAX,
135
};
136

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

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

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

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

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

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

249

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

255

256
#define TSDB_ALTER_RSMA_FUNCTION        0x1
257

258
#define TSDB_KILL_MSG_LEN 30
259

260
#define TSDB_TABLE_NUM_UNIT 100000
261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

891
bool hasExtSchema(const SExtSchema* pExtSchema);
892

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

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

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

911
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
912
  if (pRef->pColRef) {
392,074✔
913
    return TSDB_CODE_INVALID_PARA;
×
914
  }
915
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
392,074✔
916
  if (pRef->pColRef == NULL) {
392,074✔
917
    return terrno;
×
918
  }
919
  pRef->nCols = nCols;
392,074✔
920
  for (int32_t i = 0; i < nCols; i++) {
4,341,485✔
921
    pRef->pColRef[i].hasRef = false;
3,949,411✔
922
    pRef->pColRef[i].id = (col_id_t)(i + 1);
3,949,411✔
923
  }
924
  return 0;
392,074✔
925
}
926

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

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

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

948
  return pDstWrapper;
949
}
950

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

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

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

984
  taosMemoryFreeClear(pWrapper->pColCmpr);
985
  taosMemoryFreeClear(pWrapper);
986
}
987
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
988
  if (pSchemaWrapper->pSchema == NULL) return NULL;
294,595,406✔
989

990
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
294,552,783✔
991
  if (pSW == NULL) {
294,544,638✔
992
    return NULL;
×
993
  }
994
  pSW->nCols = pSchemaWrapper->nCols;
294,544,638✔
995
  pSW->version = pSchemaWrapper->version;
294,512,450✔
996
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
294,501,097✔
997
  if (pSW->pSchema == NULL) {
294,488,297✔
998
    taosMemoryFree(pSW);
×
999
    return NULL;
×
1000
  }
1001

1002
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
294,443,830✔
1003
  return pSW;
294,606,353✔
1004
}
1005

1006
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
72,385,380✔
1007
  if (pSchemaWrapper) {
767,810,180✔
1008
    taosMemoryFree(pSchemaWrapper->pSchema);
434,281,372✔
1009
    if(pSchemaWrapper->pRsma) {
434,279,933✔
1010
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
56,736✔
1011
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
56,736✔
1012
    }
1013
    taosMemoryFree(pSchemaWrapper);
434,231,377✔
1014
  }
1015
}
752,051,970✔
1016

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

1027
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
652,568✔
1028
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
652,568✔
1029
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
652,568✔
1030
  }
1031
}
652,568✔
1032

1033
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1034
  int32_t tlen = 0;
2,565,616✔
1035
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,577,160✔
1036
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,565,616✔
1037
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,565,616✔
1038
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,565,616✔
1039
  tlen += taosEncodeString(buf, pSchema->name);
2,565,616✔
1040
  return tlen;
2,565,616✔
1041
}
1042

1043
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1044
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,757,268✔
1045
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,421,681✔
1046
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,421,681✔
1047
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,421,681✔
1048
  buf = taosDecodeStringTo(buf, pSchema->name);
1,421,681✔
1049
  return (void*)buf;
1,421,681✔
1050
}
1051

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

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

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

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

1084
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1085
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
22,581,392✔
1086
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
22,581,392✔
1087
  if (pColRef->hasRef) {
11,290,696✔
1088
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
12,544,196✔
1089
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
12,544,196✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
12,544,196✔
1091
  }
1092
  return 0;
11,290,696✔
1093
}
1094

1095
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1096
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
13,108,182✔
1097
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
13,108,182✔
1098
  if (pColRef->hasRef) {
6,554,091✔
1099
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
3,886,521✔
1100
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
3,886,521✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
3,886,521✔
1102
  }
1103

1104
  return 0;
6,554,091✔
1105
}
1106

1107
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1108
  int32_t tlen = 0;
329,800✔
1109
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
329,800✔
1110
  tlen += taosEncodeVariantI32(buf, pSW->version);
329,800✔
1111
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,895,416✔
1112
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,131,232✔
1113
  }
1114
  return tlen;
329,800✔
1115
}
1116

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

1126
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,631,892✔
1127
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,843,362✔
1128
    }
1129
  } else {
1130
    pSW->pSchema = NULL;
18,392✔
1131
  }
1132
  return (void*)buf;
228,603✔
1133
}
1134

1135
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1136
  if (pSW == NULL) {
193,529,842✔
1137
    return TSDB_CODE_INVALID_PARA;
×
1138
  }
1139
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
386,963,528✔
1140
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
386,809,004✔
1141
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1142
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1143
  }
1144
  return 0;
193,736,994✔
1145
}
1146

1147
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1148
  if (pSW == NULL) {
58,398,630✔
1149
    return TSDB_CODE_INVALID_PARA;
×
1150
  }
1151
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
116,770,721✔
1152
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
116,757,277✔
1153

1154
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
58,385,186✔
1155
  if (pSW->pSchema == NULL) {
58,363,793✔
1156
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1157
  }
1158
  for (int32_t i = 0; i < pSW->nCols; i++) {
631,253,391✔
1159
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,145,644,744✔
1160
  }
1161

1162
  return 0;
58,415,109✔
1163
}
1164

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

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

1177
  return 0;
1,407,462,370✔
1178
}
1179

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

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

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

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

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

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

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

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

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

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

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

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

1282
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1283
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1284

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1378
// copyIpRange ensures that unused bytes are always zeroed, so that [pDst] can be used as a key in hash tables
1379
void copyIpRange(SIpRange* pDst, const SIpRange* pSrc);
1380

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

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

1397

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

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

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

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

1417

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

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

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

1433
  int8_t negIpRanges;
1434
  int8_t negTimeRanges;
1435

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

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

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

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

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

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

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

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

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

1493
typedef struct {
1494
  int8_t alterType;
1495

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1622

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

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

1632

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

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

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

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

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

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

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

1671

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1779
typedef STableCfg STableCfgRsp;
1780

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2000

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

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

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

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

2019

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

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

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

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

2041

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

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

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

2063

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

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

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

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

2083

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

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

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

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

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

2157
typedef SDbCfgRsp SDbCfgInfo;
2158

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2718
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2719
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2720

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

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

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

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

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

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

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

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

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

2783
typedef SVKillCompactReq SVKillRetentionReq;
2784

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2987
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2988

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3204

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

3208

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

3214

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

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

3227

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3831
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
462,066✔
3832
  tlen += taosEncodeFixedI32(buf, topicNum);
462,066✔
3833

3834
  for (int32_t i = 0; i < topicNum; i++) {
659,070✔
3835
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
394,008✔
3836
  }
3837

3838
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
462,066✔
3839
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
462,066✔
3840
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
462,066✔
3841
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
461,996✔
3842
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
462,066✔
3843
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
461,996✔
3844
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
461,986✔
3845
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
461,996✔
3846
  tlen += taosEncodeString(buf, pReq->user);
461,916✔
3847
  tlen += taosEncodeString(buf, pReq->fqdn);
462,066✔
3848

3849
  return tlen;
461,996✔
3850
}
3851

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

3858
  int32_t topicNum = 0;
125,918✔
3859
  buf = taosDecodeFixedI32(buf, &topicNum);
125,918✔
3860

3861
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
125,918✔
3862
  if (pReq->topicNames == NULL) {
125,918✔
3863
    return terrno;
×
3864
  }
3865
  for (int32_t i = 0; i < topicNum; i++) {
179,796✔
3866
    char* name = NULL;
53,878✔
3867
    buf = taosDecodeString(buf, &name);
53,878✔
3868
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
107,756✔
3869
      return terrno;
×
3870
    }
3871
  }
3872

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

3889
  return 0;
125,918✔
3890
}
3891

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4059
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4060
  if (NULL == req) {
2,098,480,362✔
4061
    return;
2,031,043,190✔
4062
  }
4063

4064
  taosMemoryFreeClear(req->sql);
67,437,330✔
4065
  taosMemoryFreeClear(req->name);
67,437,937✔
4066
  taosMemoryFreeClear(req->comment);
67,436,963✔
4067
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
67,417,899✔
4068
    taosMemoryFreeClear(req->ctb.pTag);
65,082,904✔
4069
    taosMemoryFreeClear(req->ctb.stbName);
65,074,931✔
4070
    taosArrayDestroy(req->ctb.tagName);
65,077,106✔
4071
    req->ctb.tagName = NULL;
65,079,123✔
4072
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,337,361✔
4073
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,337,361✔
4074
  }
4075
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
67,419,239✔
4076
  taosMemoryFreeClear(req->pExtSchemas);
67,441,117✔
4077
  taosMemoryFreeClear(req->colRef.pColRef);
67,425,580✔
4078
}
4079

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4364
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
54,989,588✔
4365

4366
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4367
  void* pIter = taosHashIterate(info, NULL);
35,930,440✔
4368
  while (pIter != NULL) {
79,055,295✔
4369
    SKv* kv = (SKv*)pIter;
43,124,660✔
4370
    taosMemoryFreeClear(kv->value);
43,124,660✔
4371
    pIter = taosHashIterate(info, pIter);
43,124,660✔
4372
  }
4373
}
35,930,635✔
4374

4375
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
19,699,896✔
4376
  SQueryDesc* desc = (SQueryDesc*)pDesc;
19,699,896✔
4377
  if (desc->subDesc) {
19,699,896✔
4378
    taosArrayDestroy(desc->subDesc);
17,654,808✔
4379
    desc->subDesc = NULL;
17,653,712✔
4380
  }
4381
}
19,698,995✔
4382

4383
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
43,142,858✔
4384
  SClientHbReq* req = (SClientHbReq*)pReq;
46,192,286✔
4385
  if (req->query) {
46,192,286✔
4386
    if (req->query->queryDesc) {
39,291,633✔
4387
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
18,445,052✔
4388
    }
4389
    taosMemoryFreeClear(req->query);
39,291,617✔
4390
  }
4391

4392
  if (req->info) {
46,193,224✔
4393
    tFreeReqKvHash(req->info);
35,930,440✔
4394
    taosHashCleanup(req->info);
35,930,635✔
4395
    req->info = NULL;
35,929,864✔
4396
  }
4397
}
23,887,613✔
4398

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

4402
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4403
  if (pReq == NULL) return;
18,593,981✔
4404
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
18,593,981✔
4405
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
18,593,981✔
4406
  taosMemoryFree(pReq);
18,593,981✔
4407
}
4408

4409
static FORCE_INLINE void tFreeClientKv(void* pKv) {
16,005,264✔
4410
  SKv* kv = (SKv*)pKv;
16,005,264✔
4411
  if (kv) {
16,005,264✔
4412
    taosMemoryFreeClear(kv->value);
16,005,379✔
4413
  }
4414
}
16,005,072✔
4415

4416
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
42,662,908✔
4417
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
42,662,908✔
4418
  if (rsp->query) {
42,662,908✔
4419
    taosArrayDestroy(rsp->query->pQnodeList);
38,843,757✔
4420
    taosMemoryFreeClear(rsp->query);
38,840,462✔
4421
  }
4422
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
42,664,015✔
4423
}
21,825,825✔
4424

4425
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4426
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
35,525,869✔
4427
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
35,525,869✔
4428
}
35,530,370✔
4429

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

4434
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4435
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
119,392,855✔
4436
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
119,392,195✔
4437
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
119,392,991✔
4438
  return 0;
59,697,018✔
4439
}
4440

4441
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4442
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
55,916,988✔
4443
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
55,916,988✔
4444
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
27,958,494✔
4445
  if (pKv->value == NULL) {
27,958,494✔
4446
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4447
  }
4448
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
27,958,494✔
4449
  return 0;
27,958,413✔
4450
}
4451

4452
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4453
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
168,495,960✔
4454
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
168,491,122✔
4455
  return 0;
84,243,834✔
4456
}
4457

4458
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4459
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
83,292,165✔
4460
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
83,293,366✔
4461
  return 0;
41,647,776✔
4462
}
4463

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4686
#define TQ_OFFSET_VERSION 1
4687

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

4704
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4705
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,615,485✔
4706
  pOffsetVal->uid = uid;
1,615,073✔
4707
  pOffsetVal->ts = ts;
1,614,995✔
4708
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,614,652✔
4709
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4710
  }
4711
  pOffsetVal->primaryKey = primaryKey;
1,613,667✔
4712
}
1,614,658✔
4713

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

4719
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4720
  pOffsetVal->type = TMQ_OFFSET__LOG;
37,003,517✔
4721
  pOffsetVal->version = ver;
37,003,231✔
4722
}
37,003,201✔
4723

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

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

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

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

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

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

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

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

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

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

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

4823
typedef SMCreateRsmaReq SVCreateRsmaReq;
4824

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

4829
typedef SMCreateRsmaReq SVAlterRsmaReq;
4830

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

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

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

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

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

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

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

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

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

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

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

4901
typedef SMDropSmaReq SDropTagIndexReq;
4902

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

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

4928
typedef STSma SVCreateTSmaReq;
4929

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5077
void tFreeSTableIndexInfo(void* pInfo);
5078

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

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

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

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

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

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

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

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

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

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

5154
#define MQ_DATA_RSP_VERSION 100
5155

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

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

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

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

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

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

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

5216
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5217
  int32_t tlen = 0;
1,325,020✔
5218
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5219
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,325,020✔
5220
  tlen += taosEncodeFixedI32(buf, sz);
1,324,905✔
5221
  for (int32_t i = 0; i < sz; i++) {
1,545,679✔
5222
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
220,774✔
5223
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
220,774✔
5224
  }
5225
  return tlen;
1,324,905✔
5226
}
5227

5228
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5229
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5230
  int32_t sz;
478,596✔
5231
  buf = taosDecodeFixedI32(buf, &sz);
762,746✔
5232
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
762,746✔
5233
  if (pRsp->topics == NULL) {
762,746✔
5234
    return NULL;
×
5235
  }
5236
  for (int32_t i = 0; i < sz; i++) {
920,345✔
5237
    SMqSubTopicEp topicEp;
73,398✔
5238
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
157,599✔
5239
    if (buf == NULL) {
157,599✔
5240
      return NULL;
×
5241
    }
5242
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
315,198✔
5243
      return NULL;
×
5244
    }
5245
  }
5246
  return buf;
762,746✔
5247
}
5248

5249
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5250
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,753,138✔
5251
}
1,753,023✔
5252

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5394
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
125,367,524✔
5395
  if (NULL == p) {
125,367,524✔
5396
    return;
×
5397
  }
5398

5399
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
125,367,524✔
5400
  taosMemoryFree(pRsp->msg);
125,367,524✔
5401
}
5402

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

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

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

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

5427
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5428

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5553
} SRsmaInfoReq;
5554

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

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

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

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

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

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

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

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

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

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

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

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

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

5627
void tFreeFetchTtlExpiredTbsRsp(void* p);
5628

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5811
#endif  // USE_MOUNT
5812

5813
#pragma pack(pop)
5814

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5887
#ifdef __cplusplus
5888
}
5889
#endif
5890

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