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

taosdata / TDengine / #4862

22 Nov 2025 07:23AM UTC coverage: 64.294% (+0.02%) from 64.274%
#4862

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

0 of 79 new or added lines in 2 files covered. (0.0%)

702 existing lines in 95 files now uncovered.

154514 of 240326 relevant lines covered (64.29%)

114708483.42 hits per line

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

84.03
/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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
708,155,328✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
668,139,922✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,376,295,250✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,864,633,283✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,864,633,283✔
119
}
120

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

131
enum {
132
  CONN_TYPE__QUERY = 1,
133
  CONN_TYPE__TMQ,
134
  CONN_TYPE__UDFD,
135
  CONN_TYPE__MAX,
136
};
137

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

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

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

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

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

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

248
#define TSDB_ALTER_USER_PASSWD          0x1
249
#define TSDB_ALTER_USER_SUPERUSER       0x2
250
#define TSDB_ALTER_USER_ENABLE          0x3
251
#define TSDB_ALTER_USER_SYSINFO         0x4
252
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
253
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
254
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
255
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
256
#define TSDB_ALTER_USER_CREATEDB        0x9
257

258
#define TSDB_ALTER_RSMA_FUNCTION        0x1
259

260
#define TSDB_KILL_MSG_LEN 30
261

262
#define TSDB_TABLE_NUM_UNIT 100000
263

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

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

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

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

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

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

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

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

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

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

608
typedef struct {
609
  int32_t     vgId;
610
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
611
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
612
  const char* dbFName;
613
  const char* tbName;
614
} SBuildTableInput;
615

616
typedef struct {
617
  char    db[TSDB_DB_FNAME_LEN];
618
  int64_t dbId;
619
  int32_t vgVersion;
620
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
621
  int64_t stateTs;
622
} SBuildUseDBInput;
623

624
typedef struct SField {
625
  char    name[TSDB_COL_NAME_LEN];
626
  uint8_t type;
627
  int8_t  flags;
628
  int32_t bytes;
629
} SField;
630

631
typedef struct SFieldWithOptions {
632
  char     name[TSDB_COL_NAME_LEN];
633
  uint8_t  type;
634
  int8_t   flags;
635
  int32_t  bytes;
636
  uint32_t compress;
637
  STypeMod typeMod;
638
} SFieldWithOptions;
639

640
typedef struct SRetention {
641
  int64_t freq;
642
  int64_t keep;
643
  int8_t  freqUnit;
644
  int8_t  keepUnit;
645
} SRetention;
646

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

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

656
typedef struct {
657
  int32_t contLen;
658
  int32_t vgId;
659
} SMsgHead;
660

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

672
// Submit message for this TSDB
673
typedef struct {
674
  SMsgHead header;
675
  int64_t  version;
676
  int32_t  length;
677
  int32_t  numOfBlocks;
678
  char     blocks[];
679
} SSubmitReq;
680

681
typedef struct {
682
  int32_t totalLen;
683
  int32_t len;
684
  STSRow* row;
685
} SSubmitBlkIter;
686

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

702
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
703
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
704
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
705
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
706
// for debug
707
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
708

709
typedef struct {
710
  bool     hasRef;
711
  col_id_t id;
712
  char     refDbName[TSDB_DB_NAME_LEN];
713
  char     refTableName[TSDB_TABLE_NAME_LEN];
714
  char     refColName[TSDB_COL_NAME_LEN];
715
} SColRef;
716

717
typedef struct {
718
  int32_t  nCols;
719
  int32_t  version;
720
  SColRef* pColRef;
721
} SColRefWrapper;
722

723
int32_t tEncodeSColRefWrapper(SEncoder *pCoder, const SColRefWrapper *pWrapper);
724
int32_t tDecodeSColRefWrapperEx(SDecoder *pDecoder, SColRefWrapper *pWrapper, bool decoderMalloc);
725
typedef struct {
726
  int32_t vgId;
727
  SColRef colRef;
728
} SColRefEx;
729

730
typedef struct {
731
  int16_t colId;
732
  char    refDbName[TSDB_DB_NAME_LEN];
733
  char    refTableName[TSDB_TABLE_NAME_LEN];
734
  char    refColName[TSDB_COL_NAME_LEN];
735
} SRefColInfo;
736

737
typedef struct SVCTableRefCols {
738
  uint64_t     uid;
739
  int32_t      numOfSrcTbls;
740
  int32_t      numOfColRefs;
741
  SRefColInfo* refCols;
742
} SVCTableRefCols;
743

744
typedef struct SVCTableMergeInfo {
745
  uint64_t uid;
746
  int32_t  numOfSrcTbls;
747
} SVCTableMergeInfo;
748

749
typedef struct {
750
  int32_t    nCols;
751
  SColRefEx* pColRefEx;
752
} SColRefExWrapper;
753

754
struct SSchema {
755
  int8_t   type;
756
  int8_t   flags;
757
  col_id_t colId;
758
  int32_t  bytes;
759
  char     name[TSDB_COL_NAME_LEN];
760
};
761
struct SSchemaExt {
762
  col_id_t colId;
763
  uint32_t compress;
764
  STypeMod typeMod;
765
};
766

767
struct SSchemaRsma {
768
  int64_t    interval[2];
769
  int32_t    nFuncs;
770
  int8_t     tbType;
771
  tb_uid_t   tbUid;
772
  func_id_t* funcIds;
773
  char       tbName[TSDB_TABLE_NAME_LEN];
774
};
775

776
struct SSchema2 {
777
  int8_t   type;
778
  int8_t   flags;
779
  col_id_t colId;
780
  int32_t  bytes;
781
  char     name[TSDB_COL_NAME_LEN];
782
  uint32_t compress;
783
};
784

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

808
typedef struct {
809
  int32_t        code;
810
  int64_t        uid;
811
  char*          tblFName;
812
  int32_t        numOfRows;
813
  int32_t        affectedRows;
814
  int64_t        sver;
815
  STableMetaRsp* pMeta;
816
} SSubmitBlkRsp;
817

818
typedef struct {
819
  int32_t numOfRows;
820
  int32_t affectedRows;
821
  int32_t nBlocks;
822
  union {
823
    SArray*        pArray;
824
    SSubmitBlkRsp* pBlocks;
825
  };
826
} SSubmitRsp;
827

828
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
829
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
830
// void    tFreeSSubmitBlkRsp(void* param);
831
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
832

833
#define COL_SMA_ON       ((int8_t)0x1)
834
#define COL_IDX_ON       ((int8_t)0x2)
835
#define COL_IS_KEY       ((int8_t)0x4)
836
#define COL_SET_NULL     ((int8_t)0x10)
837
#define COL_SET_VAL      ((int8_t)0x20)
838
#define COL_IS_SYSINFO   ((int8_t)0x40)
839
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
840
#define COL_REF_BY_STM   ((int8_t)0x08)
841

842
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
843
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
844

845
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
846
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
847
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
848

849
#define SSCHMEA_SET_IDX_ON(s) \
850
  do {                        \
851
    (s)->flags |= COL_IDX_ON; \
852
  } while (0)
853

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

859
#define SSCHEMA_SET_TYPE_MOD(s)     \
860
  do {                              \
861
    (s)->flags |= COL_HAS_TYPE_MOD; \
862
  } while (0)
863

864
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
865

866
#define SSCHMEA_TYPE(s)  ((s)->type)
867
#define SSCHMEA_FLAGS(s) ((s)->flags)
868
#define SSCHMEA_COLID(s) ((s)->colId)
869
#define SSCHMEA_BYTES(s) ((s)->bytes)
870
#define SSCHMEA_NAME(s)  ((s)->name)
871

872
typedef struct {
873
  bool    tsEnableMonitor;
874
  int32_t tsMonitorInterval;
875
  int32_t tsSlowLogThreshold;
876
  int32_t tsSlowLogMaxLen;
877
  int32_t tsSlowLogScope;
878
  int32_t tsSlowLogThresholdTest;  // Obsolete
879
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
880
} SMonitorParas;
881

882
typedef struct {
883
  STypeMod typeMod;
884
} SExtSchema;
885

886
bool hasExtSchema(const SExtSchema* pExtSchema);
887

888
typedef struct {
889
  int32_t      nCols;
890
  int32_t      version;
891
  SSchema*     pSchema;
892
  SSchemaRsma* pRsma;
893
} SSchemaWrapper;
894

895
typedef struct {
896
  col_id_t id;
897
  uint32_t alg;
898
} SColCmpr;
899

900
typedef struct {
901
  int32_t   nCols;
902
  int32_t   version;
903
  SColCmpr* pColCmpr;
904
} SColCmprWrapper;
905

906
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
907
  if (pRef->pColRef) {
479,836✔
908
    return TSDB_CODE_INVALID_PARA;
×
909
  }
910
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
479,836✔
911
  if (pRef->pColRef == NULL) {
479,836✔
912
    return terrno;
×
913
  }
914
  pRef->nCols = nCols;
479,836✔
915
  for (int32_t i = 0; i < nCols; i++) {
5,338,308✔
916
    pRef->pColRef[i].hasRef = false;
4,858,472✔
917
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4,858,472✔
918
  }
919
  return 0;
479,836✔
920
}
921

922
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
923
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
924
    terrno = TSDB_CODE_INVALID_PARA;
925
    return NULL;
926
  }
927

928
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
929
  if (pDstWrapper == NULL) {
930
    return NULL;
931
  }
932
  pDstWrapper->nCols = pSrcWrapper->nCols;
933
  pDstWrapper->version = pSrcWrapper->version;
934

935
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
936
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
937
  if (pDstWrapper->pColCmpr == NULL) {
938
    taosMemoryFree(pDstWrapper);
939
    return NULL;
940
  }
941
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
942

943
  return pDstWrapper;
944
}
945

946
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
947
  if (!(!pCmpr->pColCmpr)) {
2,376,237✔
948
    return TSDB_CODE_INVALID_PARA;
×
949
  }
950
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
2,376,237✔
951
  if (pCmpr->pColCmpr == NULL) {
2,376,237✔
952
    return terrno;
×
953
  }
954
  pCmpr->nCols = nCols;
2,376,237✔
955
  return 0;
2,376,237✔
956
}
957

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

976
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
977
  if (pWrapper == NULL) return;
978

979
  taosMemoryFreeClear(pWrapper->pColCmpr);
980
  taosMemoryFreeClear(pWrapper);
981
}
982
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
983
  if (pSchemaWrapper->pSchema == NULL) return NULL;
314,731,484✔
984

985
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
314,694,335✔
986
  if (pSW == NULL) {
314,616,311✔
987
    return NULL;
×
988
  }
989
  pSW->nCols = pSchemaWrapper->nCols;
314,616,311✔
990
  pSW->version = pSchemaWrapper->version;
314,654,450✔
991
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
314,653,582✔
992
  if (pSW->pSchema == NULL) {
314,564,812✔
993
    taosMemoryFree(pSW);
×
994
    return NULL;
×
995
  }
996

997
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
314,605,634✔
998
  return pSW;
314,720,605✔
999
}
1000

1001
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
78,663,422✔
1002
  if (pSchemaWrapper) {
850,435,183✔
1003
    taosMemoryFree(pSchemaWrapper->pSchema);
472,715,051✔
1004
    if(pSchemaWrapper->pRsma) {
472,675,021✔
1005
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
54,504✔
1006
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
54,504✔
1007
    }
1008
    taosMemoryFree(pSchemaWrapper);
472,666,199✔
1009
  }
1010
}
836,637,256✔
1011

1012
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1013
  if (pSchemaWrapper) {
1014
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1015
    if(pSchemaWrapper->pRsma) {
1016
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1017
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1018
    }
1019
  }
1020
}
1021

1022
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
2,267,762✔
1023
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
2,267,762✔
1024
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
2,267,762✔
1025
  }
1026
}
2,267,762✔
1027

1028
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1029
  int32_t tlen = 0;
3,242,872✔
1030
  tlen += taosEncodeFixedI8(buf, pSchema->type);
3,254,836✔
1031
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
3,242,872✔
1032
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
3,242,872✔
1033
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
3,242,872✔
1034
  tlen += taosEncodeString(buf, pSchema->name);
3,242,872✔
1035
  return tlen;
3,242,872✔
1036
}
1037

1038
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1039
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,934,201✔
1040
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,667,060✔
1041
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,667,060✔
1042
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,667,060✔
1043
  buf = taosDecodeStringTo(buf, pSchema->name);
1,667,060✔
1044
  return (void*)buf;
1,667,060✔
1045
}
1046

1047
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1048
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1049
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1050
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1051
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1052
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1053
  return 0;
2,147,483,647✔
1054
}
1055

1056
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1057
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1058
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1059
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1060
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1061
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1062
  return 0;
2,147,483,647✔
1063
}
1064

1065
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1066
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1067
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1068
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1069
  return 0;
2,147,483,647✔
1070
}
1071

1072
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1073
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1074
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1075
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1076
  return 0;
2,147,483,647✔
1077
}
1078

1079
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1080
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
28,973,268✔
1081
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
28,973,268✔
1082
  if (pColRef->hasRef) {
14,486,634✔
1083
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
17,261,780✔
1084
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
17,261,780✔
1085
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
17,261,780✔
1086
  }
1087
  return 0;
14,486,634✔
1088
}
1089

1090
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1091
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
17,031,652✔
1092
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
17,031,652✔
1093
  if (pColRef->hasRef) {
8,515,826✔
1094
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
5,406,821✔
1095
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
5,406,821✔
1096
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
5,406,821✔
1097
  }
1098

1099
  return 0;
8,515,826✔
1100
}
1101

1102
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1103
  int32_t tlen = 0;
402,876✔
1104
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
402,876✔
1105
  tlen += taosEncodeVariantI32(buf, pSW->version);
402,876✔
1106
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,645,748✔
1107
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
6,485,744✔
1108
  }
1109
  return tlen;
402,876✔
1110
}
1111

1112
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1113
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
263,273✔
1114
  buf = taosDecodeVariantI32(buf, &pSW->version);
263,273✔
1115
  if (pSW->nCols > 0) {
263,273✔
1116
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
227,606✔
1117
    if (pSW->pSchema == NULL) {
227,606✔
1118
      return NULL;
×
1119
    }
1120

1121
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,894,666✔
1122
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
3,334,120✔
1123
    }
1124
  } else {
1125
    pSW->pSchema = NULL;
35,667✔
1126
  }
1127
  return (void*)buf;
263,273✔
1128
}
1129

1130
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1131
  if (pSW == NULL) {
198,935,631✔
1132
    return TSDB_CODE_INVALID_PARA;
×
1133
  }
1134
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
397,815,998✔
1135
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
397,717,387✔
1136
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1137
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1138
  }
1139
  return 0;
198,993,515✔
1140
}
1141

1142
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1143
  if (pSW == NULL) {
57,823,966✔
1144
    return TSDB_CODE_INVALID_PARA;
×
1145
  }
1146
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
115,631,563✔
1147
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
115,631,846✔
1148

1149
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
57,824,249✔
1150
  if (pSW->pSchema == NULL) {
57,772,811✔
1151
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1152
  }
1153
  for (int32_t i = 0; i < pSW->nCols; i++) {
607,578,405✔
1154
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,099,409,639✔
1155
  }
1156

1157
  return 0;
57,845,136✔
1158
}
1159

1160
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1161
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1162
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1163

1164
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1165
  if (pSW->pSchema == NULL) {
1,520,601,198✔
1166
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1167
  }
1168
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1169
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1170
  }
1171

1172
  return 0;
1,520,858,409✔
1173
}
1174

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

1208
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1209
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1210
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1211

1212
typedef struct {
1213
  STableMetaRsp* pMeta;
1214
} SMCreateStbRsp;
1215

1216
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1217
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1218
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1219

1220
typedef struct {
1221
  char     name[TSDB_TABLE_FNAME_LEN];
1222
  int8_t   igNotExists;
1223
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1224
  int8_t   reserved[6];
1225
  tb_uid_t suid;
1226
  int32_t  sqlLen;
1227
  char*    sql;
1228
} SMDropStbReq;
1229

1230
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1231
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1232
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1233

1234
typedef struct {
1235
  char    name[TSDB_TABLE_FNAME_LEN];
1236
  int8_t  alterType;
1237
  int32_t numOfFields;
1238
  SArray* pFields;
1239
  int32_t ttl;
1240
  int32_t commentLen;
1241
  char*   comment;
1242
  int32_t sqlLen;
1243
  char*   sql;
1244
  int64_t keep;
1245
  SArray* pTypeMods;
1246
} SMAlterStbReq;
1247

1248
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1249
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1250
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1251

1252
typedef struct SEpSet {
1253
  int8_t inUse;
1254
  int8_t numOfEps;
1255
  SEp    eps[TSDB_MAX_REPLICA];
1256
} SEpSet;
1257

1258
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1259
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1260
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1261
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1262

1263
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1264
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1265

1266
typedef struct {
1267
  int8_t  connType;
1268
  int32_t pid;
1269
  char    app[TSDB_APP_NAME_LEN];
1270
  char    db[TSDB_DB_NAME_LEN];
1271
  char    user[TSDB_USER_LEN];
1272
  char    passwd[TSDB_PASSWORD_LEN];
1273
  int64_t startTime;
1274
  char    sVer[TSDB_VERSION_LEN];
1275
} SConnectReq;
1276

1277
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1278
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1279

1280
typedef struct {
1281
  int32_t       acctId;
1282
  int64_t       clusterId;
1283
  uint32_t      connId;
1284
  int32_t       dnodeNum;
1285
  int8_t        superUser;
1286
  int8_t        sysInfo;
1287
  int8_t        connType;
1288
  SEpSet        epSet;
1289
  int32_t       svrTimestamp;
1290
  int32_t       passVer;
1291
  int32_t       authVer;
1292
  char          sVer[TSDB_VERSION_LEN];
1293
  char          sDetailVer[128];
1294
  int64_t       whiteListVer;
1295
  SMonitorParas monitorParas;
1296
  int8_t        enableAuditDelete;
1297
} SConnectRsp;
1298

1299
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1300
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1301

1302
typedef struct {
1303
  char    user[TSDB_USER_LEN];
1304
  char    pass[TSDB_PASSWORD_LEN];
1305
  int32_t maxUsers;
1306
  int32_t maxDbs;
1307
  int32_t maxTimeSeries;
1308
  int32_t maxStreams;
1309
  int32_t accessState;  // Configured only by command
1310
  int64_t maxStorage;
1311
} SCreateAcctReq, SAlterAcctReq;
1312

1313
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1314
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1315

1316
typedef struct {
1317
  char    user[TSDB_USER_LEN];
1318
  int32_t sqlLen;
1319
  char*   sql;
1320
} SDropUserReq, SDropAcctReq;
1321

1322
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1323
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1324
void    tFreeSDropUserReq(SDropUserReq* pReq);
1325

1326
typedef struct SIpV4Range {
1327
  uint32_t ip;
1328
  uint32_t mask;
1329
} SIpV4Range;
1330

1331
typedef struct SIpv6Range {
1332
  uint64_t addr[2];
1333
  uint32_t mask;
1334
} SIpV6Range;
1335

1336
typedef struct {
1337
  int8_t type;
1338
  union {
1339
    SIpV4Range ipV4;
1340
    SIpV6Range ipV6;
1341
  };
1342
} SIpRange;
1343

1344
typedef struct {
1345
  int32_t    num;
1346
  SIpV4Range pIpRange[];
1347
} SIpWhiteList;
1348

1349
typedef struct {
1350
  int32_t  num;
1351
  SIpRange pIpRanges[];
1352
} SIpWhiteListDual;
1353

1354
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1355
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1356
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1357
int32_t           createDefaultIp6Range(SIpRange* pRange);
1358
int32_t           createDefaultIp4Range(SIpRange* pRange);
1359

1360
typedef struct {
1361
  int8_t  createType;
1362
  int8_t  superUser;  // denote if it is a super user or not
1363
  int8_t  sysInfo;
1364
  int8_t  enable;
1365
  char    user[TSDB_USER_LEN];
1366
  char    pass[TSDB_USET_PASSWORD_LEN];
1367
  int32_t numIpRanges;
1368

1369
  SIpV4Range* pIpRanges;
1370
  int32_t     sqlLen;
1371
  char*       sql;
1372
  int8_t      isImport;
1373
  int8_t      createDb;
1374
  int8_t      passIsMd5;
1375
  SIpRange*   pIpDualRanges;
1376
} SCreateUserReq;
1377

1378
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1379
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1380
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1381

1382
typedef struct {
1383
  int32_t dnodeId;
1384
  int64_t analVer;
1385
} SRetrieveAnalyticsAlgoReq;
1386

1387
typedef struct {
1388
  int64_t   ver;
1389
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1390
} SRetrieveAnalyticAlgoRsp;
1391

1392
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1393
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1394
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1395
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1396
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1397

1398
typedef struct {
1399
  int8_t alterType;
1400
  int8_t superUser;
1401
  int8_t sysInfo;
1402
  int8_t enable;
1403
  int8_t isView;
1404
  union {
1405
    uint8_t flag;
1406
    struct {
1407
      uint8_t createdb : 1;
1408
      uint8_t reserve : 7;
1409
    };
1410
  };
1411
  char        user[TSDB_USER_LEN];
1412
  char        pass[TSDB_USET_PASSWORD_LEN];
1413
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1414
  char        tabName[TSDB_TABLE_NAME_LEN];
1415
  char*       tagCond;
1416
  int32_t     tagCondLen;
1417
  int32_t     numIpRanges;
1418
  SIpV4Range* pIpRanges;
1419
  int64_t     privileges;
1420
  int32_t     sqlLen;
1421
  char*       sql;
1422
  int8_t      passIsMd5;
1423
  SIpRange*   pIpDualRanges;
1424
} SAlterUserReq;
1425

1426
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1427
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1428
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1429

1430
typedef struct {
1431
  char user[TSDB_USER_LEN];
1432
} SGetUserAuthReq;
1433

1434
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1435
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1436

1437
typedef struct {
1438
  char      user[TSDB_USER_LEN];
1439
  int32_t   version;
1440
  int32_t   passVer;
1441
  int8_t    superAuth;
1442
  int8_t    sysInfo;
1443
  int8_t    enable;
1444
  int8_t    dropped;
1445
  SHashObj* createdDbs;
1446
  SHashObj* readDbs;
1447
  SHashObj* writeDbs;
1448
  SHashObj* readTbs;
1449
  SHashObj* writeTbs;
1450
  SHashObj* alterTbs;
1451
  SHashObj* readViews;
1452
  SHashObj* writeViews;
1453
  SHashObj* alterViews;
1454
  SHashObj* useDbs;
1455
  int64_t   whiteListVer;
1456
} SGetUserAuthRsp;
1457

1458
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1459
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1460
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1461

1462
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1463
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1464
typedef struct {
1465
  int64_t ver;
1466
  char    user[TSDB_USER_LEN];
1467
  int32_t numOfRange;
1468
  union {
1469
    SIpV4Range* pIpRanges;
1470
    SIpRange*   pIpDualRanges;
1471
  };
1472
} SUpdateUserIpWhite;
1473

1474
typedef struct {
1475
  int64_t             ver;
1476
  int                 numOfUser;
1477
  SUpdateUserIpWhite* pUserIpWhite;
1478
} SUpdateIpWhite;
1479

1480
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1481
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1482
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1483
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1484

1485
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1486
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1487
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1488

1489
typedef struct {
1490
  int64_t ipWhiteVer;
1491
} SRetrieveIpWhiteReq;
1492

1493
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1494
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1495
typedef struct {
1496
  char user[TSDB_USER_LEN];
1497
} SGetUserWhiteListReq;
1498

1499
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1500
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1501

1502
typedef struct {
1503
  char    user[TSDB_USER_LEN];
1504
  int32_t numWhiteLists;
1505
  union {
1506
    SIpV4Range* pWhiteLists;
1507
    SIpRange*   pWhiteListsDual;
1508
  };
1509
} SGetUserWhiteListRsp;
1510

1511
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1512
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1513
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1514
void    tIpRangeSetDefaultMask(SIpRange* range);
1515

1516
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1517
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1518
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1519

1520
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1521
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1522
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1523

1524
/*
1525
 * for client side struct, only column id, type, bytes are necessary
1526
 * But for data in vnode side, we need all the following information.
1527
 */
1528
typedef struct {
1529
  union {
1530
    col_id_t colId;
1531
    int16_t  slotId;
1532
  };
1533

1534
  uint8_t precision;
1535
  uint8_t scale;
1536
  int32_t bytes;
1537
  int8_t  type;
1538
  uint8_t pk;
1539
  bool    noData;
1540
} SColumnInfo;
1541

1542
typedef struct STimeWindow {
1543
  TSKEY skey;
1544
  TSKEY ekey;
1545
} STimeWindow;
1546

1547
typedef struct SQueryHint {
1548
  bool batchScan;
1549
} SQueryHint;
1550

1551
typedef struct {
1552
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1553
  int32_t tsLen;          // total length of ts comp block
1554
  int32_t tsNumOfBlocks;  // ts comp block numbers
1555
  int32_t tsOrder;        // ts comp block order
1556
} STsBufInfo;
1557

1558
typedef struct {
1559
  void*       timezone;
1560
  char        intervalUnit;
1561
  char        slidingUnit;
1562
  char        offsetUnit;
1563
  int8_t      precision;
1564
  int64_t     interval;
1565
  int64_t     sliding;
1566
  int64_t     offset;
1567
  STimeWindow timeRange;
1568
} SInterval;
1569

1570
typedef struct STbVerInfo {
1571
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1572
  int32_t sversion;
1573
  int32_t tversion;
1574
  int32_t rversion;  // virtual table's column ref's version
1575
} STbVerInfo;
1576

1577
typedef struct {
1578
  int32_t code;
1579
  int64_t affectedRows;
1580
  SArray* tbVerInfo;  // STbVerInfo
1581
} SQueryTableRsp;
1582

1583
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1584

1585
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1586

1587
typedef struct {
1588
  SMsgHead header;
1589
  char     dbFName[TSDB_DB_FNAME_LEN];
1590
  char     tbName[TSDB_TABLE_NAME_LEN];
1591
} STableCfgReq;
1592

1593
typedef struct {
1594
  char        tbName[TSDB_TABLE_NAME_LEN];
1595
  char        stbName[TSDB_TABLE_NAME_LEN];
1596
  char        dbFName[TSDB_DB_FNAME_LEN];
1597
  int32_t     numOfTags;
1598
  int32_t     numOfColumns;
1599
  int8_t      tableType;
1600
  int64_t     delay1;
1601
  int64_t     delay2;
1602
  int64_t     watermark1;
1603
  int64_t     watermark2;
1604
  int32_t     ttl;
1605
  int32_t     keep;
1606
  SArray*     pFuncs;
1607
  int32_t     commentLen;
1608
  char*       pComment;
1609
  SSchema*    pSchemas;
1610
  int32_t     tagsLen;
1611
  char*       pTags;
1612
  SSchemaExt* pSchemaExt;
1613
  int8_t      virtualStb;
1614
  SColRef*    pColRefs;
1615
} STableCfg;
1616

1617
typedef STableCfg STableCfgRsp;
1618

1619
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1620
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1621

1622
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1623
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1624
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1625

1626
typedef struct {
1627
  SMsgHead header;
1628
  tb_uid_t suid;
1629
} SVSubTablesReq;
1630

1631
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1632
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1633

1634
typedef struct {
1635
  int32_t vgId;
1636
  SArray* pTables;  // SArray<SVCTableRefCols*>
1637
} SVSubTablesRsp;
1638

1639
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1640
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1641
void    tDestroySVSubTablesRsp(void* rsp);
1642

1643
typedef struct {
1644
  SMsgHead header;
1645
  tb_uid_t suid;
1646
} SVStbRefDbsReq;
1647

1648
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1649
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1650

1651
typedef struct {
1652
  int32_t vgId;
1653
  SArray* pDbs;  // SArray<char* (db name)>
1654
} SVStbRefDbsRsp;
1655

1656
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1657
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1658
void    tDestroySVStbRefDbsRsp(void* rsp);
1659

1660
typedef struct {
1661
  char    db[TSDB_DB_FNAME_LEN];
1662
  int32_t numOfVgroups;
1663
  int32_t numOfStables;  // single_stable
1664
  int32_t buffer;        // MB
1665
  int32_t pageSize;
1666
  int32_t pages;
1667
  int32_t cacheLastSize;
1668
  int32_t daysPerFile;
1669
  int32_t daysToKeep0;
1670
  int32_t daysToKeep1;
1671
  int32_t daysToKeep2;
1672
  int32_t keepTimeOffset;
1673
  int32_t minRows;
1674
  int32_t maxRows;
1675
  int32_t walFsyncPeriod;
1676
  int8_t  walLevel;
1677
  int8_t  precision;  // time resolution
1678
  int8_t  compression;
1679
  int8_t  replications;
1680
  int8_t  strict;
1681
  int8_t  cacheLast;
1682
  int8_t  schemaless;
1683
  int8_t  ignoreExist;
1684
  int32_t numOfRetensions;
1685
  SArray* pRetensions;  // SRetention
1686
  int32_t walRetentionPeriod;
1687
  int64_t walRetentionSize;
1688
  int32_t walRollPeriod;
1689
  int64_t walSegmentSize;
1690
  int32_t sstTrigger;
1691
  int16_t hashPrefix;
1692
  int16_t hashSuffix;
1693
  int32_t ssChunkSize;
1694
  int32_t ssKeepLocal;
1695
  int8_t  ssCompact;
1696
  int32_t tsdbPageSize;
1697
  int32_t sqlLen;
1698
  char*   sql;
1699
  int8_t  withArbitrator;
1700
  int8_t  encryptAlgorithm;
1701
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1702
  // 1. add auto-compact parameters
1703
  int32_t compactInterval;    // minutes
1704
  int32_t compactStartTime;   // minutes
1705
  int32_t compactEndTime;     // minutes
1706
  int8_t  compactTimeOffset;  // hour
1707
} SCreateDbReq;
1708

1709
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1710
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1711
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1712

1713
typedef struct {
1714
  char    db[TSDB_DB_FNAME_LEN];
1715
  int32_t buffer;
1716
  int32_t pageSize;
1717
  int32_t pages;
1718
  int32_t cacheLastSize;
1719
  int32_t daysPerFile;
1720
  int32_t daysToKeep0;
1721
  int32_t daysToKeep1;
1722
  int32_t daysToKeep2;
1723
  int32_t keepTimeOffset;
1724
  int32_t walFsyncPeriod;
1725
  int8_t  walLevel;
1726
  int8_t  strict;
1727
  int8_t  cacheLast;
1728
  int8_t  replications;
1729
  int32_t sstTrigger;
1730
  int32_t minRows;
1731
  int32_t walRetentionPeriod;
1732
  int32_t walRetentionSize;
1733
  int32_t ssKeepLocal;
1734
  int8_t  ssCompact;
1735
  int32_t sqlLen;
1736
  char*   sql;
1737
  int8_t  withArbitrator;
1738
  // 1. add auto-compact parameters
1739
  int32_t compactInterval;
1740
  int32_t compactStartTime;
1741
  int32_t compactEndTime;
1742
  int8_t  compactTimeOffset;
1743
} SAlterDbReq;
1744

1745
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1746
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1747
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1748

1749
typedef struct {
1750
  char    db[TSDB_DB_FNAME_LEN];
1751
  int8_t  ignoreNotExists;
1752
  int8_t  force;
1753
  int32_t sqlLen;
1754
  char*   sql;
1755
} SDropDbReq;
1756

1757
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1758
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1759
void    tFreeSDropDbReq(SDropDbReq* pReq);
1760

1761
typedef struct {
1762
  char    db[TSDB_DB_FNAME_LEN];
1763
  int64_t uid;
1764
} SDropDbRsp;
1765

1766
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1767
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1768

1769
typedef struct {
1770
  char    name[TSDB_MOUNT_NAME_LEN];
1771
  int64_t uid;
1772
} SDropMountRsp;
1773

1774
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1775
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1776

1777
typedef struct {
1778
  char    db[TSDB_DB_FNAME_LEN];
1779
  int64_t dbId;
1780
  int32_t vgVersion;
1781
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1782
  int64_t stateTs;     // ms
1783
} SUseDbReq;
1784

1785
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1786
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1787

1788
typedef struct {
1789
  char    db[TSDB_DB_FNAME_LEN];
1790
  int64_t uid;
1791
  int32_t vgVersion;
1792
  int32_t vgNum;
1793
  int16_t hashPrefix;
1794
  int16_t hashSuffix;
1795
  int8_t  hashMethod;
1796
  union {
1797
    uint8_t flags;
1798
    struct {
1799
      uint8_t isMount : 1;  // TS-5868
1800
      uint8_t padding : 7;
1801
    };
1802
  };
1803
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1804
  int32_t errCode;
1805
  int64_t stateTs;  // ms
1806
} SUseDbRsp;
1807

1808
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1809
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1810
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1811
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1812
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1813

1814
typedef struct {
1815
  char db[TSDB_DB_FNAME_LEN];
1816
} SDbCfgReq;
1817

1818
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1819
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1820

1821
typedef struct {
1822
  char db[TSDB_DB_FNAME_LEN];
1823
} SSsMigrateDbReq;
1824

1825
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1826
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1827

1828
typedef struct {
1829
  int32_t ssMigrateId;
1830
  bool    bAccepted;
1831
} SSsMigrateDbRsp;
1832

1833
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1834
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1835

1836

1837
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
1838
typedef struct {
1839
  int32_t ssMigrateId;
1840
} SListSsMigrateFileSetsReq;
1841

1842
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1843
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1844

1845
typedef struct {
1846
  int32_t ssMigrateId;
1847
  int32_t vgId;   // vgroup id
1848
  SArray* pFileSets; // SArray<int32_t>
1849
} SListSsMigrateFileSetsRsp;
1850

1851
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1852
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1853
void tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
1854

1855

1856
// Request and response for TDMT_VND_SSMIGRATE_FILESET
1857
typedef struct {
1858
  int32_t ssMigrateId;
1859
  int32_t nodeId; // node id of the leader vnode, filled by vnode
1860
  int32_t fid;
1861
  int64_t startTimeSec;
1862
} SSsMigrateFileSetReq;
1863

1864
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1865
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1866

1867
typedef struct {
1868
  int32_t ssMigrateId;
1869
  int32_t nodeId; // node id of the leader vnode
1870
  int32_t vgId;
1871
  int32_t fid;
1872
} SSsMigrateFileSetRsp;
1873

1874
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1875
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1876

1877

1878
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS  0
1879
#define SSMIGRATE_FILESET_STATE_SUCCEEDED    1
1880
#define SSMIGRATE_FILESET_STATE_COMPACT      2
1881
#define SSMIGRATE_FILESET_STATE_SKIPPED      3
1882
#define SSMIGRATE_FILESET_STATE_FAILED       4
1883

1884
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
1885
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
1886
// while as a request, the 'state' field is not used.
1887
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
1888
typedef struct {
1889
  int32_t ssMigrateId; // ss migrate id
1890
  int32_t nodeId;      // node id of the leader vnode
1891
  int32_t vgId;        // vgroup id
1892
  int32_t fid;         // file set id
1893
  int32_t state;       // SSMIGRATE_FILESET_STATE_*
1894
} SSsMigrateProgress;
1895

1896
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1897
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1898

1899

1900
// Request for TDMT_MND_KILL_SSMIGRATE
1901
typedef struct {
1902
  int32_t ssMigrateId;
1903
  int32_t sqlLen;
1904
  char*   sql;
1905
} SKillSsMigrateReq;
1906

1907
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
1908
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
1909
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
1910

1911
// Request for TDMT_VND_KILL_SSMIGRATE
1912
typedef struct {
1913
  int32_t ssMigrateId;
1914
} SVnodeKillSsMigrateReq;
1915

1916
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1917
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1918

1919

1920
typedef struct {
1921
  int32_t vgId;
1922
  int64_t keepVersion;
1923
} SMndSetVgroupKeepVersionReq;
1924

1925
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
1926
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
1927

1928
typedef struct {
1929
  int32_t timestampSec;
1930
  int32_t ttlDropMaxCount;
1931
  int32_t nUids;
1932
  SArray* pTbUids;
1933
} SVDropTtlTableReq;
1934

1935
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1936
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1937

1938
typedef struct {
1939
  char    db[TSDB_DB_FNAME_LEN];
1940
  int64_t dbId;
1941
  int32_t cfgVersion;
1942
  int32_t numOfVgroups;
1943
  int32_t numOfStables;
1944
  int32_t buffer;
1945
  int32_t cacheSize;
1946
  int32_t pageSize;
1947
  int32_t pages;
1948
  int32_t daysPerFile;
1949
  int32_t daysToKeep0;
1950
  int32_t daysToKeep1;
1951
  int32_t daysToKeep2;
1952
  int32_t keepTimeOffset;
1953
  int32_t minRows;
1954
  int32_t maxRows;
1955
  int32_t walFsyncPeriod;
1956
  int16_t hashPrefix;
1957
  int16_t hashSuffix;
1958
  int8_t  hashMethod;
1959
  int8_t  walLevel;
1960
  int8_t  precision;
1961
  int8_t  compression;
1962
  int8_t  replications;
1963
  int8_t  strict;
1964
  int8_t  cacheLast;
1965
  int8_t  encryptAlgorithm;
1966
  int32_t ssChunkSize;
1967
  int32_t ssKeepLocal;
1968
  int8_t  ssCompact;
1969
  union {
1970
    uint8_t flags;
1971
    struct {
1972
      uint8_t isMount : 1;  // TS-5868
1973
      uint8_t padding : 7;
1974
    };
1975
  };
1976
  int8_t  compactTimeOffset;
1977
  int32_t compactInterval;
1978
  int32_t compactStartTime;
1979
  int32_t compactEndTime;
1980
  int32_t tsdbPageSize;
1981
  int32_t walRetentionPeriod;
1982
  int32_t walRollPeriod;
1983
  int64_t walRetentionSize;
1984
  int64_t walSegmentSize;
1985
  int32_t numOfRetensions;
1986
  SArray* pRetensions;
1987
  int8_t  schemaless;
1988
  int16_t sstTrigger;
1989
  int8_t  withArbitrator;
1990
} SDbCfgRsp;
1991

1992
typedef SDbCfgRsp SDbCfgInfo;
1993

1994
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1995
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1996
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1997
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1998
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1999

2000
typedef struct {
2001
  int32_t rowNum;
2002
} SQnodeListReq;
2003

2004
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2005
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2006

2007
typedef struct {
2008
  int32_t rowNum;
2009
} SDnodeListReq;
2010

2011
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2012

2013
typedef struct {
2014
  int32_t useless;  // useless
2015
} SServerVerReq;
2016

2017
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2018
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2019

2020
typedef struct {
2021
  char ver[TSDB_VERSION_LEN];
2022
} SServerVerRsp;
2023

2024
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2025
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2026

2027
typedef struct SQueryNodeAddr {
2028
  int32_t nodeId;  // vgId or qnodeId
2029
  SEpSet  epSet;
2030
} SQueryNodeAddr;
2031

2032
typedef struct {
2033
  SQueryNodeAddr addr;
2034
  uint64_t       load;
2035
} SQueryNodeLoad;
2036

2037
typedef struct {
2038
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2039
} SQnodeListRsp;
2040

2041
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2042
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2043
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2044

2045
typedef struct SDNodeAddr {
2046
  int32_t nodeId;  // dnodeId
2047
  SEpSet  epSet;
2048
} SDNodeAddr;
2049

2050
typedef struct {
2051
  SArray* dnodeList;  // SArray<SDNodeAddr>
2052
} SDnodeListRsp;
2053

2054
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2055
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2056
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2057

2058
typedef struct {
2059
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2060
} STableTSMAInfoRsp;
2061

2062
typedef struct {
2063
  SUseDbRsp*         useDbRsp;
2064
  SDbCfgRsp*         cfgRsp;
2065
  STableTSMAInfoRsp* pTsmaRsp;
2066
  int32_t            dbTsmaVersion;
2067
  char               db[TSDB_DB_FNAME_LEN];
2068
  int64_t            dbId;
2069
} SDbHbRsp;
2070

2071
typedef struct {
2072
  SArray* pArray;  // Array of SDbHbRsp
2073
} SDbHbBatchRsp;
2074

2075
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2076
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2077
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2078

2079
typedef struct {
2080
  SArray* pArray;  // Array of SGetUserAuthRsp
2081
} SUserAuthBatchRsp;
2082

2083
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2084
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2085
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2086

2087
typedef struct {
2088
  char        db[TSDB_DB_FNAME_LEN];
2089
  STimeWindow timeRange;
2090
  int32_t     sqlLen;
2091
  char*       sql;
2092
  SArray*     vgroupIds;
2093
  int32_t     compactId;
2094
  int8_t      metaOnly;
2095
  int8_t      force;
2096
} SCompactDbReq;
2097

2098
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2099
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2100
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2101

2102
typedef struct {
2103
  union {
2104
    int32_t compactId;
2105
    int32_t id;
2106
  };
2107
  int8_t bAccepted;
2108
} SCompactDbRsp;
2109

2110
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2111
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2112

2113
typedef struct {
2114
  union {
2115
    int32_t compactId;
2116
    int32_t id;
2117
  };
2118
  int32_t sqlLen;
2119
  char*   sql;
2120
} SKillCompactReq;
2121

2122
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2123
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2124
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2125

2126
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2127
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2128

2129
typedef struct {
2130
  char    name[TSDB_FUNC_NAME_LEN];
2131
  int8_t  igExists;
2132
  int8_t  funcType;
2133
  int8_t  scriptType;
2134
  int8_t  outputType;
2135
  int32_t outputLen;
2136
  int32_t bufSize;
2137
  int32_t codeLen;
2138
  int64_t signature;
2139
  char*   pComment;
2140
  char*   pCode;
2141
  int8_t  orReplace;
2142
} SCreateFuncReq;
2143

2144
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2145
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2146
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2147

2148
typedef struct {
2149
  char   name[TSDB_FUNC_NAME_LEN];
2150
  int8_t igNotExists;
2151
} SDropFuncReq;
2152

2153
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2154
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2155

2156
typedef struct {
2157
  int32_t numOfFuncs;
2158
  bool    ignoreCodeComment;
2159
  SArray* pFuncNames;
2160
} SRetrieveFuncReq;
2161

2162
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2163
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2164
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2165

2166
typedef struct {
2167
  char    name[TSDB_FUNC_NAME_LEN];
2168
  int8_t  funcType;
2169
  int8_t  scriptType;
2170
  int8_t  outputType;
2171
  int32_t outputLen;
2172
  int32_t bufSize;
2173
  int64_t signature;
2174
  int32_t commentSize;
2175
  int32_t codeSize;
2176
  char*   pComment;
2177
  char*   pCode;
2178
} SFuncInfo;
2179

2180
typedef struct {
2181
  int32_t funcVersion;
2182
  int64_t funcCreatedTime;
2183
} SFuncExtraInfo;
2184

2185
typedef struct {
2186
  int32_t numOfFuncs;
2187
  SArray* pFuncInfos;
2188
  SArray* pFuncExtraInfos;
2189
} SRetrieveFuncRsp;
2190

2191
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2192
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2193
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2194
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2195

2196
typedef struct {
2197
  int32_t       statusInterval;
2198
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2199
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2200
  char          locale[TD_LOCALE_LEN];      // tsLocale
2201
  char          charset[TD_LOCALE_LEN];     // tsCharset
2202
  int8_t        ttlChangeOnWrite;
2203
  int8_t        enableWhiteList;
2204
  int8_t        encryptionKeyStat;
2205
  uint32_t      encryptionKeyChksum;
2206
  SMonitorParas monitorParas;
2207
  int32_t       statusIntervalMs;
2208
} SClusterCfg;
2209

2210
typedef struct {
2211
  int32_t openVnodes;
2212
  int32_t dropVnodes;
2213
  int32_t totalVnodes;
2214
  int32_t masterNum;
2215
  int64_t numOfSelectReqs;
2216
  int64_t numOfInsertReqs;
2217
  int64_t numOfInsertSuccessReqs;
2218
  int64_t numOfBatchInsertReqs;
2219
  int64_t numOfBatchInsertSuccessReqs;
2220
  int64_t errors;
2221
} SVnodesStat;
2222

2223
typedef struct {
2224
  int32_t vgId;
2225
  int8_t  syncState;
2226
  int8_t  syncRestore;
2227
  int64_t syncTerm;
2228
  int64_t roleTimeMs;
2229
  int64_t startTimeMs;
2230
  int8_t  syncCanRead;
2231
  int64_t cacheUsage;
2232
  int64_t numOfTables;
2233
  int64_t numOfTimeSeries;
2234
  int64_t totalStorage;
2235
  int64_t compStorage;
2236
  int64_t pointsWritten;
2237
  int64_t numOfSelectReqs;
2238
  int64_t numOfInsertReqs;
2239
  int64_t numOfInsertSuccessReqs;
2240
  int64_t numOfBatchInsertReqs;
2241
  int64_t numOfBatchInsertSuccessReqs;
2242
  int32_t numOfCachedTables;
2243
  int32_t learnerProgress;  // use one reservered
2244
  int64_t syncAppliedIndex;
2245
  int64_t syncCommitIndex;
2246
  int64_t bufferSegmentUsed;
2247
  int64_t bufferSegmentSize;
2248
} SVnodeLoad;
2249

2250
typedef struct {
2251
  int64_t total_requests;
2252
  int64_t total_rows;
2253
  int64_t total_bytes;
2254
  double  write_size;
2255
  double  cache_hit_ratio;
2256
  int64_t rpc_queue_wait;
2257
  int64_t preprocess_time;
2258

2259
  int64_t memory_table_size;
2260
  int64_t commit_count;
2261
  int64_t merge_count;
2262
  double  commit_time;
2263
  double  merge_time;
2264
  int64_t block_commit_time;
2265
  int64_t memtable_wait_time;
2266
} SVnodeMetrics;
2267

2268
typedef struct {
2269
  int32_t     vgId;
2270
  int64_t     numOfTables;
2271
  int64_t     memSize;
2272
  int64_t     l1Size;
2273
  int64_t     l2Size;
2274
  int64_t     l3Size;
2275
  int64_t     cacheSize;
2276
  int64_t     walSize;
2277
  int64_t     metaSize;
2278
  int64_t     rawDataSize;
2279
  int64_t     ssSize;
2280
  const char* dbname;
2281
  int8_t      estimateRawData;
2282
} SDbSizeStatisInfo;
2283

2284
typedef struct {
2285
  int32_t vgId;
2286
  int64_t nTimeSeries;
2287
} SVnodeLoadLite;
2288

2289
typedef struct {
2290
  int8_t  syncState;
2291
  int64_t syncTerm;
2292
  int8_t  syncRestore;
2293
  int64_t roleTimeMs;
2294
} SMnodeLoad;
2295

2296
typedef struct {
2297
  int32_t dnodeId;
2298
  int64_t numOfProcessedQuery;
2299
  int64_t numOfProcessedCQuery;
2300
  int64_t numOfProcessedFetch;
2301
  int64_t numOfProcessedDrop;
2302
  int64_t numOfProcessedNotify;
2303
  int64_t numOfProcessedHb;
2304
  int64_t numOfProcessedDelete;
2305
  int64_t cacheDataSize;
2306
  int64_t numOfQueryInQueue;
2307
  int64_t numOfFetchInQueue;
2308
  int64_t timeInQueryQueue;
2309
  int64_t timeInFetchQueue;
2310
} SQnodeLoad;
2311

2312
typedef struct {
2313
  int32_t     sver;      // software version
2314
  int64_t     dnodeVer;  // dnode table version in sdb
2315
  int32_t     dnodeId;
2316
  int64_t     clusterId;
2317
  int64_t     rebootTime;
2318
  int64_t     updateTime;
2319
  float       numOfCores;
2320
  int32_t     numOfSupportVnodes;
2321
  int32_t     numOfDiskCfg;
2322
  int64_t     memTotal;
2323
  int64_t     memAvail;
2324
  char        dnodeEp[TSDB_EP_LEN];
2325
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2326
  SMnodeLoad  mload;
2327
  SQnodeLoad  qload;
2328
  SClusterCfg clusterCfg;
2329
  SArray*     pVloads;  // array of SVnodeLoad
2330
  int32_t     statusSeq;
2331
  int64_t     ipWhiteVer;
2332
  int64_t     analVer;
2333
  int64_t     timestamp;
2334
} SStatusReq;
2335

2336
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2337
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2338
void    tFreeSStatusReq(SStatusReq* pReq);
2339

2340
typedef struct {
2341
  int32_t forceReadConfig;
2342
  int32_t cver;
2343
  SArray* array;
2344
} SConfigReq;
2345

2346
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2347
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2348
void    tFreeSConfigReq(SConfigReq* pReq);
2349

2350
typedef struct {
2351
  int32_t dnodeId;
2352
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2353
} SDnodeInfoReq;
2354

2355
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2356
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2357

2358
typedef enum {
2359
  MONITOR_TYPE_COUNTER = 0,
2360
  MONITOR_TYPE_SLOW_LOG = 1,
2361
} MONITOR_TYPE;
2362

2363
typedef struct {
2364
  int32_t      contLen;
2365
  char*        pCont;
2366
  MONITOR_TYPE type;
2367
} SStatisReq;
2368

2369
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2370
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2371
void    tFreeSStatisReq(SStatisReq* pReq);
2372

2373
typedef struct {
2374
  char    db[TSDB_DB_FNAME_LEN];
2375
  char    table[TSDB_TABLE_NAME_LEN];
2376
  char    operation[AUDIT_OPERATION_LEN];
2377
  int32_t sqlLen;
2378
  char*   pSql;
2379
} SAuditReq;
2380
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2381
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2382
void    tFreeSAuditReq(SAuditReq* pReq);
2383

2384
typedef struct {
2385
  int32_t dnodeId;
2386
  int64_t clusterId;
2387
  SArray* pVloads;
2388
} SNotifyReq;
2389

2390
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2391
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2392
void    tFreeSNotifyReq(SNotifyReq* pReq);
2393

2394
typedef struct {
2395
  int32_t dnodeId;
2396
  int64_t clusterId;
2397
} SDnodeCfg;
2398

2399
typedef struct {
2400
  int32_t id;
2401
  int8_t  isMnode;
2402
  SEp     ep;
2403
} SDnodeEp;
2404

2405
typedef struct {
2406
  int32_t id;
2407
  int8_t  isMnode;
2408
  int8_t  offlineReason;
2409
  SEp     ep;
2410
  char    active[TSDB_ACTIVE_KEY_LEN];
2411
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2412
} SDnodeInfo;
2413

2414
typedef struct {
2415
  int64_t   dnodeVer;
2416
  SDnodeCfg dnodeCfg;
2417
  SArray*   pDnodeEps;  // Array of SDnodeEp
2418
  int32_t   statusSeq;
2419
  int64_t   ipWhiteVer;
2420
  int64_t   analVer;
2421
} SStatusRsp;
2422

2423
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2424
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2425
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2426

2427
typedef struct {
2428
  int32_t forceReadConfig;
2429
  int32_t isConifgVerified;
2430
  int32_t isVersionVerified;
2431
  int32_t cver;
2432
  SArray* array;
2433
} SConfigRsp;
2434

2435
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2436
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2437
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2438

2439
typedef struct {
2440
  int32_t reserved;
2441
} SMTimerReq;
2442

2443
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2444
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2445

2446
typedef struct SOrphanTask {
2447
  int64_t streamId;
2448
  int32_t taskId;
2449
  int32_t nodeId;
2450
} SOrphanTask;
2451

2452
typedef struct SMStreamDropOrphanMsg {
2453
  SArray* pList;  // SArray<SOrphanTask>
2454
} SMStreamDropOrphanMsg;
2455

2456
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2457
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2458
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2459

2460
typedef struct {
2461
  int32_t  id;
2462
  uint16_t port;                 // node sync Port
2463
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2464
} SReplica;
2465

2466
typedef struct {
2467
  int32_t  vgId;
2468
  char     db[TSDB_DB_FNAME_LEN];
2469
  int64_t  dbUid;
2470
  int32_t  vgVersion;
2471
  int32_t  numOfStables;
2472
  int32_t  buffer;
2473
  int32_t  pageSize;
2474
  int32_t  pages;
2475
  int32_t  cacheLastSize;
2476
  int32_t  daysPerFile;
2477
  int32_t  daysToKeep0;
2478
  int32_t  daysToKeep1;
2479
  int32_t  daysToKeep2;
2480
  int32_t  keepTimeOffset;
2481
  int32_t  minRows;
2482
  int32_t  maxRows;
2483
  int32_t  walFsyncPeriod;
2484
  uint32_t hashBegin;
2485
  uint32_t hashEnd;
2486
  int8_t   hashMethod;
2487
  int8_t   walLevel;
2488
  int8_t   precision;
2489
  int8_t   compression;
2490
  int8_t   strict;
2491
  int8_t   cacheLast;
2492
  int8_t   isTsma;
2493
  int8_t   replica;
2494
  int8_t   selfIndex;
2495
  SReplica replicas[TSDB_MAX_REPLICA];
2496
  int32_t  numOfRetensions;
2497
  SArray*  pRetensions;  // SRetention
2498
  void*    pTsma;
2499
  int32_t  walRetentionPeriod;
2500
  int64_t  walRetentionSize;
2501
  int32_t  walRollPeriod;
2502
  int64_t  walSegmentSize;
2503
  int16_t  sstTrigger;
2504
  int16_t  hashPrefix;
2505
  int16_t  hashSuffix;
2506
  int32_t  tsdbPageSize;
2507
  int32_t  ssChunkSize;
2508
  int32_t  ssKeepLocal;
2509
  int8_t   ssCompact;
2510
  int64_t  reserved[6];
2511
  int8_t   learnerReplica;
2512
  int8_t   learnerSelfIndex;
2513
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2514
  int32_t  changeVersion;
2515
  int8_t   encryptAlgorithm;
2516
} SCreateVnodeReq;
2517

2518
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2519
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2520
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2521

2522
typedef struct {
2523
  union {
2524
    int32_t compactId;
2525
    int32_t id;
2526
  };
2527
  int32_t vgId;
2528
  int32_t dnodeId;
2529
} SQueryCompactProgressReq;
2530

2531
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2532
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2533

2534
typedef struct {
2535
  union {
2536
    int32_t compactId;
2537
    int32_t id;
2538
  };
2539
  int32_t vgId;
2540
  int32_t dnodeId;
2541
  int32_t numberFileset;
2542
  int32_t finished;
2543
  int32_t progress;
2544
  int64_t remainingTime;
2545
} SQueryCompactProgressRsp;
2546

2547
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2548
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2549

2550
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2551
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2552

2553
typedef struct {
2554
  int32_t vgId;
2555
  int32_t dnodeId;
2556
  int64_t dbUid;
2557
  char    db[TSDB_DB_FNAME_LEN];
2558
  int64_t reserved[8];
2559
} SDropVnodeReq;
2560

2561
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2562
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2563

2564
typedef struct {
2565
  char    colName[TSDB_COL_NAME_LEN];
2566
  char    stb[TSDB_TABLE_FNAME_LEN];
2567
  int64_t stbUid;
2568
  int64_t dbUid;
2569
  int64_t reserved[8];
2570
} SDropIndexReq;
2571

2572
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2573
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2574

2575
typedef struct {
2576
  int64_t dbUid;
2577
  char    db[TSDB_DB_FNAME_LEN];
2578
  union {
2579
    int64_t compactStartTime;
2580
    int64_t startTime;
2581
  };
2582

2583
  STimeWindow tw;
2584
  union {
2585
    int32_t compactId;
2586
    int32_t id;
2587
  };
2588
  int8_t metaOnly;
2589
  union {
2590
    uint16_t flags;
2591
    struct {
2592
      uint16_t optrType : 3;     // ETsdbOpType
2593
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2594
      uint16_t reserved : 12;
2595
    };
2596
  };
2597
  int8_t force;  // force compact
2598
} SCompactVnodeReq;
2599

2600
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2601
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2602

2603
typedef struct {
2604
  union {
2605
    int32_t compactId;
2606
    int32_t taskId;
2607
  };
2608
  int32_t vgId;
2609
  int32_t dnodeId;
2610
} SVKillCompactReq;
2611

2612
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2613
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2614

2615
typedef SVKillCompactReq SVKillRetentionReq;
2616

2617
typedef struct {
2618
  char        db[TSDB_DB_FNAME_LEN];
2619
  int32_t     maxSpeed;
2620
  int32_t     sqlLen;
2621
  char*       sql;
2622
  SArray*     vgroupIds;
2623
  STimeWindow tw;  // unit is second
2624
  union {
2625
    uint32_t flags;
2626
    struct {
2627
      uint32_t optrType : 3;     // ETsdbOpType
2628
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2629
      uint32_t reserved : 28;
2630
    };
2631
  };
2632
} STrimDbReq;
2633

2634
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2635
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2636
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2637

2638
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2639

2640
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2641
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2642

2643
typedef struct {
2644
  int32_t vgVersion;
2645
  int32_t buffer;
2646
  int32_t pageSize;
2647
  int32_t pages;
2648
  int32_t cacheLastSize;
2649
  int32_t daysPerFile;
2650
  int32_t daysToKeep0;
2651
  int32_t daysToKeep1;
2652
  int32_t daysToKeep2;
2653
  int32_t keepTimeOffset;
2654
  int32_t walFsyncPeriod;
2655
  int8_t  walLevel;
2656
  int8_t  strict;
2657
  int8_t  cacheLast;
2658
  int64_t reserved[7];
2659
  // 1st modification
2660
  int16_t sttTrigger;
2661
  int32_t minRows;
2662
  // 2nd modification
2663
  int32_t walRetentionPeriod;
2664
  int32_t walRetentionSize;
2665
  int32_t ssKeepLocal;
2666
  int8_t  ssCompact;
2667
} SAlterVnodeConfigReq;
2668

2669
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2670
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2671

2672
typedef struct {
2673
  int32_t  vgId;
2674
  int8_t   strict;
2675
  int8_t   selfIndex;
2676
  int8_t   replica;
2677
  SReplica replicas[TSDB_MAX_REPLICA];
2678
  int64_t  reserved[8];
2679
  int8_t   learnerSelfIndex;
2680
  int8_t   learnerReplica;
2681
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2682
  int32_t  changeVersion;
2683
  int32_t  electBaseLine;
2684
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2685

2686
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2687
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2688

2689
typedef struct {
2690
  int32_t vgId;
2691
  int8_t  disable;
2692
} SDisableVnodeWriteReq;
2693

2694
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2695
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2696

2697
typedef struct {
2698
  int32_t  srcVgId;
2699
  int32_t  dstVgId;
2700
  uint32_t hashBegin;
2701
  uint32_t hashEnd;
2702
  int32_t  changeVersion;
2703
  int32_t  reserved;
2704
} SAlterVnodeHashRangeReq;
2705

2706
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2707
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2708

2709
#define REQ_OPT_TBNAME 0x0
2710
#define REQ_OPT_TBUID  0x01
2711
typedef struct {
2712
  SMsgHead header;
2713
  char     dbFName[TSDB_DB_FNAME_LEN];
2714
  char     tbName[TSDB_TABLE_NAME_LEN];
2715
  uint8_t  option;
2716
  uint8_t  autoCreateCtb;
2717
} STableInfoReq;
2718

2719
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2720
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2721

2722
typedef struct {
2723
  int8_t  metaClone;  // create local clone of the cached table meta
2724
  int32_t numOfVgroups;
2725
  int32_t numOfTables;
2726
  int32_t numOfUdfs;
2727
  char    tableNames[];
2728
} SMultiTableInfoReq;
2729

2730
// todo refactor
2731
typedef struct SVgroupInfo {
2732
  int32_t  vgId;
2733
  uint32_t hashBegin;
2734
  uint32_t hashEnd;
2735
  SEpSet   epSet;
2736
  union {
2737
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2738
    int32_t taskId;      // used in stream
2739
  };
2740
} SVgroupInfo;
2741

2742
typedef struct {
2743
  int32_t     numOfVgroups;
2744
  SVgroupInfo vgroups[];
2745
} SVgroupsInfo;
2746

2747
typedef struct {
2748
  STableMetaRsp* pMeta;
2749
} SMAlterStbRsp;
2750

2751
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2752
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2753
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2754

2755
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2756
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2757
void    tFreeSTableMetaRsp(void* pRsp);
2758
void    tFreeSTableIndexRsp(void* info);
2759

2760
typedef struct {
2761
  SArray* pMetaRsp;   // Array of STableMetaRsp
2762
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2763
} SSTbHbRsp;
2764

2765
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2766
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2767
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2768

2769
typedef struct {
2770
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2771
} SViewHbRsp;
2772

2773
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2774
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2775
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2776

2777
typedef struct {
2778
  int32_t numOfTables;
2779
  int32_t numOfVgroup;
2780
  int32_t numOfUdf;
2781
  int32_t contLen;
2782
  int8_t  compressed;  // denote if compressed or not
2783
  int32_t rawLen;      // size before compress
2784
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2785
  char    meta[];
2786
} SMultiTableMeta;
2787

2788
typedef struct {
2789
  int32_t dataLen;
2790
  char    name[TSDB_TABLE_FNAME_LEN];
2791
  char*   data;
2792
} STagData;
2793

2794
typedef struct {
2795
  int32_t  opType;
2796
  uint32_t valLen;
2797
  char*    val;
2798
} SShowVariablesReq;
2799

2800
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2801
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2802
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2803

2804
typedef struct {
2805
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2806
  char value[TSDB_CONFIG_PATH_LEN + 1];
2807
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2808
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2809
  char info[TSDB_CONFIG_INFO_LEN + 1];
2810
} SVariablesInfo;
2811

2812
typedef struct {
2813
  SArray* variables;  // SArray<SVariablesInfo>
2814
} SShowVariablesRsp;
2815

2816
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2817
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2818

2819
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2820

2821
/*
2822
 * sql: show tables like '%a_%'
2823
 * payload is the query condition, e.g., '%a_%'
2824
 * payloadLen is the length of payload
2825
 */
2826
typedef struct {
2827
  int32_t type;
2828
  char    db[TSDB_DB_FNAME_LEN];
2829
  int32_t payloadLen;
2830
  char*   payload;
2831
} SShowReq;
2832

2833
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2834
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2835
void tFreeSShowReq(SShowReq* pReq);
2836

2837
typedef struct {
2838
  int64_t       showId;
2839
  STableMetaRsp tableMeta;
2840
} SShowRsp, SVShowTablesRsp;
2841

2842
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2843
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2844
// void    tFreeSShowRsp(SShowRsp* pRsp);
2845

2846
typedef struct {
2847
  char    db[TSDB_DB_FNAME_LEN];
2848
  char    tb[TSDB_TABLE_NAME_LEN];
2849
  char    user[TSDB_USER_LEN];
2850
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2851
  int64_t showId;
2852
  int64_t compactId;  // for compact
2853
  bool    withFull;   // for show users full
2854
} SRetrieveTableReq;
2855

2856
typedef struct SSysTableSchema {
2857
  int8_t   type;
2858
  col_id_t colId;
2859
  int32_t  bytes;
2860
} SSysTableSchema;
2861

2862
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2863
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2864

2865
#define RETRIEVE_TABLE_RSP_VERSION         0
2866
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2867
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2868

2869
typedef struct {
2870
  int64_t useconds;
2871
  int8_t  completed;  // all results are returned to client
2872
  int8_t  precision;
2873
  int8_t  compressed;
2874
  int8_t  streamBlockType;
2875
  int32_t payloadLen;
2876
  int32_t compLen;
2877
  int32_t numOfBlocks;
2878
  int64_t numOfRows;  // from int32_t change to int64_t
2879
  int64_t numOfCols;
2880
  int64_t skey;
2881
  int64_t ekey;
2882
  int64_t version;                         // for stream
2883
  TSKEY   watermark;                       // for stream
2884
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2885
  char    data[];
2886
} SRetrieveTableRsp;
2887

2888
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2889

2890
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2891
  do {                                          \
2892
    ((int32_t*)(_p))[0] = (_compLen);           \
2893
    ((int32_t*)(_p))[1] = (_fullLen);           \
2894
  } while (0);
2895

2896
typedef struct {
2897
  int64_t version;
2898
  int64_t numOfRows;
2899
  int8_t  compressed;
2900
  int8_t  precision;
2901
  char    data[];
2902
} SRetrieveTableRspForTmq;
2903

2904
typedef struct {
2905
  int64_t handle;
2906
  int64_t useconds;
2907
  int8_t  completed;  // all results are returned to client
2908
  int8_t  precision;
2909
  int8_t  compressed;
2910
  int32_t compLen;
2911
  int32_t numOfRows;
2912
  int32_t fullLen;
2913
  char    data[];
2914
} SRetrieveMetaTableRsp;
2915

2916
typedef struct SExplainExecInfo {
2917
  double   startupCost;
2918
  double   totalCost;
2919
  uint64_t numOfRows;
2920
  uint32_t verboseLen;
2921
  void*    verboseInfo;
2922
} SExplainExecInfo;
2923

2924
typedef struct {
2925
  int32_t           numOfPlans;
2926
  SExplainExecInfo* subplanInfo;
2927
} SExplainRsp;
2928

2929
typedef struct {
2930
  SExplainRsp rsp;
2931
  uint64_t    qId;
2932
  uint64_t    cId;
2933
  uint64_t    tId;
2934
  int64_t     rId;
2935
  int32_t     eId;
2936
} SExplainLocalRsp;
2937

2938
typedef struct STableScanAnalyzeInfo {
2939
  uint64_t totalRows;
2940
  uint64_t totalCheckedRows;
2941
  uint32_t totalBlocks;
2942
  uint32_t loadBlocks;
2943
  uint32_t loadBlockStatis;
2944
  uint32_t skipBlocks;
2945
  uint32_t filterOutBlocks;
2946
  double   elapsedTime;
2947
  double   filterTime;
2948
} STableScanAnalyzeInfo;
2949

2950
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2951
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2952
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2953

2954
typedef struct {
2955
  char    config[TSDB_DNODE_CONFIG_LEN];
2956
  char    value[TSDB_CLUSTER_VALUE_LEN];
2957
  int32_t sqlLen;
2958
  char*   sql;
2959
} SMCfgClusterReq;
2960

2961
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2962
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2963
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2964

2965
typedef struct {
2966
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2967
  int32_t port;
2968
  int32_t sqlLen;
2969
  char*   sql;
2970
} SCreateDnodeReq;
2971

2972
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2973
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2974
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2975

2976
typedef struct {
2977
  int32_t dnodeId;
2978
  char    fqdn[TSDB_FQDN_LEN];
2979
  int32_t port;
2980
  int8_t  force;
2981
  int8_t  unsafe;
2982
  int32_t sqlLen;
2983
  char*   sql;
2984
} SDropDnodeReq;
2985

2986
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2987
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2988
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2989

2990
enum {
2991
  RESTORE_TYPE__ALL = 1,
2992
  RESTORE_TYPE__MNODE,
2993
  RESTORE_TYPE__VNODE,
2994
  RESTORE_TYPE__QNODE,
2995
};
2996

2997
typedef struct {
2998
  int32_t dnodeId;
2999
  int8_t  restoreType;
3000
  int32_t sqlLen;
3001
  char*   sql;
3002
} SRestoreDnodeReq;
3003

3004
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3005
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3006
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3007

3008
typedef struct {
3009
  int32_t dnodeId;
3010
  char    config[TSDB_DNODE_CONFIG_LEN];
3011
  char    value[TSDB_DNODE_VALUE_LEN];
3012
  int32_t sqlLen;
3013
  char*   sql;
3014
} SMCfgDnodeReq;
3015

3016
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3017
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3018
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3019

3020
typedef struct {
3021
  char    config[TSDB_DNODE_CONFIG_LEN];
3022
  char    value[TSDB_DNODE_VALUE_LEN];
3023
  int32_t version;
3024
} SDCfgDnodeReq;
3025

3026
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3027
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3028

3029
typedef struct {
3030
  int32_t dnodeId;
3031
  int32_t sqlLen;
3032
  char*   sql;
3033
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3034
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
3035

3036

3037
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3038
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3039

3040

3041
typedef struct {
3042
  int32_t nodeId;
3043
  SEpSet  epSet;
3044
} SNodeEpSet;
3045

3046

3047
typedef struct {
3048
  int32_t    snodeId;
3049
  SNodeEpSet leaders[2];
3050
  SNodeEpSet replica;
3051
  int32_t    sqlLen;
3052
  char*      sql;
3053
} SDCreateSnodeReq;
3054

3055
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3056
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3057
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
3058

3059

3060
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3061
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3062
typedef struct {
3063
  int8_t   replica;
3064
  SReplica replicas[TSDB_MAX_REPLICA];
3065
  int8_t   learnerReplica;
3066
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3067
  int64_t  lastIndex;
3068
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3069

3070
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3071
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3072

3073
typedef struct {
3074
  int32_t urlLen;
3075
  int32_t sqlLen;
3076
  char*   url;
3077
  char*   sql;
3078
} SMCreateAnodeReq;
3079

3080
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3081
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3082
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3083

3084
typedef struct {
3085
  int32_t anodeId;
3086
  int32_t sqlLen;
3087
  char*   sql;
3088
} SMDropAnodeReq, SMUpdateAnodeReq;
3089

3090
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3091
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3092
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3093
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3094
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3095
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3096

3097
typedef struct {
3098
  int32_t dnodeId;
3099
  int32_t bnodeProto;
3100
  int32_t sqlLen;
3101
  char*   sql;
3102
} SMCreateBnodeReq, SDCreateBnodeReq;
3103

3104
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3105
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3106
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3107

3108
typedef struct {
3109
  int32_t dnodeId;
3110
  int32_t sqlLen;
3111
  char*   sql;
3112
} SMDropBnodeReq, SDDropBnodeReq;
3113

3114
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3115
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3116
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3117

3118
typedef struct {
3119
  int32_t vgId;
3120
  int32_t hbSeq;
3121
} SVArbHbReqMember;
3122

3123
typedef struct {
3124
  int32_t dnodeId;
3125
  char*   arbToken;
3126
  int64_t arbTerm;
3127
  SArray* hbMembers;  // SVArbHbReqMember
3128
} SVArbHeartBeatReq;
3129

3130
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3131
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3132
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3133

3134
typedef struct {
3135
  int32_t vgId;
3136
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3137
  int32_t hbSeq;
3138
} SVArbHbRspMember;
3139

3140
typedef struct {
3141
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3142
  int32_t dnodeId;
3143
  SArray* hbMembers;  // SVArbHbRspMember
3144
} SVArbHeartBeatRsp;
3145

3146
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3147
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3148
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3149

3150
typedef struct {
3151
  char*   arbToken;
3152
  int64_t arbTerm;
3153
  char*   member0Token;
3154
  char*   member1Token;
3155
} SVArbCheckSyncReq;
3156

3157
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3158
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3159
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3160

3161
typedef struct {
3162
  char*   arbToken;
3163
  char*   member0Token;
3164
  char*   member1Token;
3165
  int32_t vgId;
3166
  int32_t errCode;
3167
} SVArbCheckSyncRsp;
3168

3169
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3170
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3171
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3172

3173
typedef struct {
3174
  char*   arbToken;
3175
  int64_t arbTerm;
3176
  char*   memberToken;
3177
  int8_t  force;
3178
} SVArbSetAssignedLeaderReq;
3179

3180
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3181
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3182
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3183

3184
typedef struct {
3185
  char*   arbToken;
3186
  char*   memberToken;
3187
  int32_t vgId;
3188
} SVArbSetAssignedLeaderRsp;
3189

3190
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3191
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3192
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3193

3194
typedef struct {
3195
  int32_t dnodeId;
3196
  char*   token;
3197
} SMArbUpdateGroupMember;
3198

3199
typedef struct {
3200
  int32_t dnodeId;
3201
  char*   token;
3202
  int8_t  acked;
3203
} SMArbUpdateGroupAssigned;
3204

3205
typedef struct {
3206
  int32_t                  vgId;
3207
  int64_t                  dbUid;
3208
  SMArbUpdateGroupMember   members[2];
3209
  int8_t                   isSync;
3210
  int8_t                   assignedAcked;
3211
  SMArbUpdateGroupAssigned assignedLeader;
3212
  int64_t                  version;
3213
  int32_t                  code;
3214
  int64_t                  updateTimeMs;
3215
} SMArbUpdateGroup;
3216

3217
typedef struct {
3218
  SArray* updateArray;  // SMArbUpdateGroup
3219
} SMArbUpdateGroupBatchReq;
3220

3221
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3222
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3223
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3224

3225
typedef struct {
3226
  char queryStrId[TSDB_QUERY_ID_LEN];
3227
} SKillQueryReq;
3228

3229
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3230
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3231

3232
typedef struct {
3233
  uint32_t connId;
3234
} SKillConnReq;
3235

3236
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3237
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3238

3239
typedef struct {
3240
  int32_t transId;
3241
} SKillTransReq;
3242

3243
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3244
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3245

3246
typedef struct {
3247
  int32_t useless;  // useless
3248
  int32_t sqlLen;
3249
  char*   sql;
3250
} SBalanceVgroupReq;
3251

3252
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3253
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3254
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3255

3256
typedef struct {
3257
  int32_t useless;  // useless
3258
  int32_t sqlLen;
3259
  char*   sql;
3260
} SAssignLeaderReq;
3261

3262
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3263
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3264
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3265
typedef struct {
3266
  int32_t vgId1;
3267
  int32_t vgId2;
3268
} SMergeVgroupReq;
3269

3270
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3271
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3272

3273
typedef struct {
3274
  int32_t vgId;
3275
  int32_t dnodeId1;
3276
  int32_t dnodeId2;
3277
  int32_t dnodeId3;
3278
  int32_t sqlLen;
3279
  char*   sql;
3280
} SRedistributeVgroupReq;
3281

3282
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3283
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3284
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3285

3286
typedef struct {
3287
  int32_t reserved;
3288
  int32_t vgId;
3289
  int32_t sqlLen;
3290
  char*   sql;
3291
  char    db[TSDB_DB_FNAME_LEN];
3292
} SBalanceVgroupLeaderReq;
3293

3294
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3295
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3296
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3297

3298
typedef struct {
3299
  int32_t vgId;
3300
} SForceBecomeFollowerReq;
3301

3302
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3303
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3304

3305
typedef struct {
3306
  int32_t vgId;
3307
  bool    force;
3308
} SSplitVgroupReq;
3309

3310
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3311
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3312

3313
typedef struct {
3314
  char user[TSDB_USER_LEN];
3315
  char spi;
3316
  char encrypt;
3317
  char secret[TSDB_PASSWORD_LEN];
3318
  char ckey[TSDB_PASSWORD_LEN];
3319
} SAuthReq, SAuthRsp;
3320

3321
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3322
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3323

3324
typedef struct {
3325
  int32_t statusCode;
3326
  char    details[1024];
3327
} SServerStatusRsp;
3328

3329
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3330
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3331

3332
/**
3333
 * The layout of the query message payload is as following:
3334
 * +--------------------+---------------------------------+
3335
 * |Sql statement       | Physical plan                   |
3336
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3337
 * +--------------------+---------------------------------+
3338
 */
3339
typedef struct SSubQueryMsg {
3340
  SMsgHead header;
3341
  uint64_t sId;
3342
  uint64_t queryId;
3343
  uint64_t clientId;
3344
  uint64_t taskId;
3345
  int64_t  refId;
3346
  int32_t  execId;
3347
  int32_t  msgMask;
3348
  int8_t   taskType;
3349
  int8_t   explain;
3350
  int8_t   needFetch;
3351
  int8_t   compress;
3352
  uint32_t sqlLen;
3353
  char*    sql;
3354
  uint32_t msgLen;
3355
  char*    msg;
3356
} SSubQueryMsg;
3357

3358
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3359
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3360
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3361

3362
typedef struct {
3363
  SMsgHead header;
3364
  uint64_t sId;
3365
  uint64_t queryId;
3366
  uint64_t taskId;
3367
} SSinkDataReq;
3368

3369
typedef struct {
3370
  SMsgHead header;
3371
  uint64_t sId;
3372
  uint64_t queryId;
3373
  uint64_t clientId;
3374
  uint64_t taskId;
3375
  int32_t  execId;
3376
} SQueryContinueReq;
3377

3378
typedef struct {
3379
  SMsgHead header;
3380
  uint64_t sId;
3381
  uint64_t queryId;
3382
  uint64_t taskId;
3383
} SResReadyReq;
3384

3385
typedef struct {
3386
  int32_t code;
3387
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3388
  int32_t sversion;
3389
  int32_t tversion;
3390
} SResReadyRsp;
3391

3392
typedef struct SOperatorParam {
3393
  int32_t opType;
3394
  int32_t downstreamIdx;
3395
  void*   value;
3396
  SArray* pChildren;  // SArray<SOperatorParam*>
3397
  bool    reUse;
3398
} SOperatorParam;
3399

3400
typedef struct SColIdNameKV {
3401
  col_id_t colId;
3402
  char     colName[TSDB_COL_NAME_LEN];
3403
} SColIdNameKV;
3404

3405
typedef struct SColIdPair {
3406
  col_id_t vtbColId;
3407
  col_id_t orgColId;
3408
} SColIdPair;
3409

3410
typedef struct SOrgTbInfo {
3411
  int32_t vgId;
3412
  char    tbName[TSDB_TABLE_FNAME_LEN];
3413
  SArray* colMap;  // SArray<SColIdNameKV>
3414
} SOrgTbInfo;
3415

3416
typedef struct STableScanOperatorParam {
3417
  bool        tableSeq;
3418
  SArray*     pUidList;
3419
  SOrgTbInfo* pOrgTbInfo;
3420
  STimeWindow window;
3421
} STableScanOperatorParam;
3422

3423
typedef struct STagScanOperatorParam {
3424
  tb_uid_t       vcUid;
3425
} STagScanOperatorParam;
3426

3427
typedef struct SVTableScanOperatorParam {
3428
  uint64_t        uid;
3429
  SOperatorParam* pTagScanOp;
3430
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3431
} SVTableScanOperatorParam;
3432

3433
struct SStreamRuntimeFuncInfo;
3434
typedef struct {
3435
  SMsgHead                       header;
3436
  uint64_t                       sId;
3437
  uint64_t                       queryId;
3438
  uint64_t                       clientId;
3439
  uint64_t                       taskId;
3440
  int32_t                        execId;
3441
  SOperatorParam*                pOpParam;
3442

3443
  // used for new-stream
3444
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3445
  bool                           reset;
3446
  bool                           dynTbname;
3447
  // used for new-stream
3448
} SResFetchReq;
3449

3450
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3451
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3452
void    tDestroySResFetchReq(SResFetchReq* pReq);
3453
typedef struct {
3454
  SMsgHead header;
3455
  uint64_t clientId;
3456
} SSchTasksStatusReq;
3457

3458
typedef struct {
3459
  uint64_t queryId;
3460
  uint64_t clientId;
3461
  uint64_t taskId;
3462
  int64_t  refId;
3463
  int32_t  execId;
3464
  int8_t   status;
3465
} STaskStatus;
3466

3467
typedef struct {
3468
  int64_t refId;
3469
  SArray* taskStatus;  // SArray<STaskStatus>
3470
} SSchedulerStatusRsp;
3471

3472
typedef struct {
3473
  uint64_t queryId;
3474
  uint64_t taskId;
3475
  int8_t   action;
3476
} STaskAction;
3477

3478
typedef struct SQueryNodeEpId {
3479
  int32_t nodeId;  // vgId or qnodeId
3480
  SEp     ep;
3481
} SQueryNodeEpId;
3482

3483
typedef struct {
3484
  SMsgHead       header;
3485
  uint64_t       clientId;
3486
  SQueryNodeEpId epId;
3487
  SArray*        taskAction;  // SArray<STaskAction>
3488
} SSchedulerHbReq;
3489

3490
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3491
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3492
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3493

3494
typedef struct {
3495
  SQueryNodeEpId epId;
3496
  SArray*        taskStatus;  // SArray<STaskStatus>
3497
} SSchedulerHbRsp;
3498

3499
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3500
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3501
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3502

3503
typedef struct {
3504
  SMsgHead header;
3505
  uint64_t sId;
3506
  uint64_t queryId;
3507
  uint64_t clientId;
3508
  uint64_t taskId;
3509
  int64_t  refId;
3510
  int32_t  execId;
3511
} STaskCancelReq;
3512

3513
typedef struct {
3514
  int32_t code;
3515
} STaskCancelRsp;
3516

3517
typedef struct {
3518
  SMsgHead header;
3519
  uint64_t sId;
3520
  uint64_t queryId;
3521
  uint64_t clientId;
3522
  uint64_t taskId;
3523
  int64_t  refId;
3524
  int32_t  execId;
3525
} STaskDropReq;
3526

3527
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3528
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3529

3530
typedef enum {
3531
  TASK_NOTIFY_FINISHED = 1,
3532
} ETaskNotifyType;
3533

3534
typedef struct {
3535
  SMsgHead        header;
3536
  uint64_t        sId;
3537
  uint64_t        queryId;
3538
  uint64_t        clientId;
3539
  uint64_t        taskId;
3540
  int64_t         refId;
3541
  int32_t         execId;
3542
  ETaskNotifyType type;
3543
} STaskNotifyReq;
3544

3545
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3546
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3547

3548
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3549
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3550

3551
typedef struct {
3552
  int32_t code;
3553
} STaskDropRsp;
3554

3555
#define STREAM_TRIGGER_AT_ONCE                 1
3556
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3557
#define STREAM_TRIGGER_MAX_DELAY               3
3558
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3559
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3560

3561
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3562
#define STREAM_FILL_HISTORY_ON        1
3563
#define STREAM_FILL_HISTORY_OFF       0
3564
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3565
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3566
#define STREAM_CREATE_STABLE_TRUE     1
3567
#define STREAM_CREATE_STABLE_FALSE    0
3568

3569
typedef struct SVgroupVer {
3570
  int32_t vgId;
3571
  int64_t ver;
3572
} SVgroupVer;
3573

3574
typedef struct STaskNotifyEventStat {
3575
  int64_t notifyEventAddTimes;     // call times of add function
3576
  int64_t notifyEventAddElems;     // elements added by add function
3577
  double  notifyEventAddCostSec;   // time cost of add function
3578
  int64_t notifyEventPushTimes;    // call times of push function
3579
  int64_t notifyEventPushElems;    // elements pushed by push function
3580
  double  notifyEventPushCostSec;  // time cost of push function
3581
  int64_t notifyEventPackTimes;    // call times of pack function
3582
  int64_t notifyEventPackElems;    // elements packed by pack function
3583
  double  notifyEventPackCostSec;  // time cost of pack function
3584
  int64_t notifyEventSendTimes;    // call times of send function
3585
  int64_t notifyEventSendElems;    // elements sent by send function
3586
  double  notifyEventSendCostSec;  // time cost of send function
3587
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3588
} STaskNotifyEventStat;
3589

3590
enum {
3591
  TOPIC_SUB_TYPE__DB = 1,
3592
  TOPIC_SUB_TYPE__TABLE,
3593
  TOPIC_SUB_TYPE__COLUMN,
3594
};
3595

3596
#define DEFAULT_MAX_POLL_INTERVAL  300000
3597
#define DEFAULT_SESSION_TIMEOUT    12000
3598
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3599
#define DEFAULT_MIN_POLL_ROWS      4096
3600

3601
typedef struct {
3602
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3603
  int8_t igExists;
3604
  int8_t subType;
3605
  int8_t withMeta;
3606
  char*  sql;
3607
  char   subDbName[TSDB_DB_FNAME_LEN];
3608
  char*  ast;
3609
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3610
} SCMCreateTopicReq;
3611

3612
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3613
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3614
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3615

3616
typedef struct {
3617
  int64_t consumerId;
3618
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3619

3620
typedef struct {
3621
  int64_t consumerId;
3622
  char    cgroup[TSDB_CGROUP_LEN];
3623
  char    clientId[TSDB_CLIENT_ID_LEN];
3624
  char    user[TSDB_USER_LEN];
3625
  char    fqdn[TSDB_FQDN_LEN];
3626
  SArray* topicNames;  // SArray<char**>
3627

3628
  int8_t  withTbName;
3629
  int8_t  autoCommit;
3630
  int32_t autoCommitInterval;
3631
  int8_t  resetOffsetCfg;
3632
  int8_t  enableReplay;
3633
  int8_t  enableBatchMeta;
3634
  int32_t sessionTimeoutMs;
3635
  int32_t maxPollIntervalMs;
3636
} SCMSubscribeReq;
3637

3638
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3639
  int32_t tlen = 0;
474,534✔
3640
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
474,534✔
3641
  tlen += taosEncodeString(buf, pReq->cgroup);
474,534✔
3642
  tlen += taosEncodeString(buf, pReq->clientId);
474,534✔
3643

3644
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
474,534✔
3645
  tlen += taosEncodeFixedI32(buf, topicNum);
474,534✔
3646

3647
  for (int32_t i = 0; i < topicNum; i++) {
676,940✔
3648
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
404,812✔
3649
  }
3650

3651
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
474,534✔
3652
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
474,534✔
3653
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
474,534✔
3654
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
474,534✔
3655
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
474,534✔
3656
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
474,534✔
3657
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
474,534✔
3658
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
474,534✔
3659
  tlen += taosEncodeString(buf, pReq->user);
474,534✔
3660
  tlen += taosEncodeString(buf, pReq->fqdn);
474,534✔
3661

3662
  return tlen;
474,534✔
3663
}
3664

3665
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3666
  void* start = buf;
118,691✔
3667
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
118,691✔
3668
  buf = taosDecodeStringTo(buf, pReq->cgroup);
118,691✔
3669
  buf = taosDecodeStringTo(buf, pReq->clientId);
118,691✔
3670

3671
  int32_t topicNum = 0;
118,691✔
3672
  buf = taosDecodeFixedI32(buf, &topicNum);
118,691✔
3673

3674
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
118,691✔
3675
  if (pReq->topicNames == NULL) {
118,691✔
3676
    return terrno;
×
3677
  }
3678
  for (int32_t i = 0; i < topicNum; i++) {
169,488✔
3679
    char* name = NULL;
50,797✔
3680
    buf = taosDecodeString(buf, &name);
50,797✔
3681
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
101,594✔
3682
      return terrno;
×
3683
    }
3684
  }
3685

3686
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
118,691✔
3687
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
118,691✔
3688
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
118,691✔
3689
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
118,691✔
3690
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
118,691✔
3691
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
118,691✔
3692
  if ((char*)buf - (char*)start < len) {
118,691✔
3693
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
118,691✔
3694
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
118,691✔
3695
    buf = taosDecodeStringTo(buf, pReq->user);
118,691✔
3696
    buf = taosDecodeStringTo(buf, pReq->fqdn);
237,382✔
3697
  } else {
3698
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3699
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3700
  }
3701

3702
  return 0;
118,691✔
3703
}
3704

3705
typedef struct {
3706
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3707
  SArray* removedConsumers;  // SArray<int64_t>
3708
  SArray* newConsumers;      // SArray<int64_t>
3709
} SMqRebInfo;
3710

3711
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3712
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
87,941✔
3713
  if (pRebInfo == NULL) {
87,941✔
3714
    return NULL;
×
3715
  }
3716
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
87,941✔
3717
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
87,941✔
3718
  if (pRebInfo->removedConsumers == NULL) {
87,941✔
3719
    goto _err;
×
3720
  }
3721
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
87,941✔
3722
  if (pRebInfo->newConsumers == NULL) {
87,941✔
3723
    goto _err;
×
3724
  }
3725
  return pRebInfo;
87,941✔
3726
_err:
×
3727
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3728
  taosArrayDestroy(pRebInfo->newConsumers);
×
3729
  taosMemoryFreeClear(pRebInfo);
×
3730
  return NULL;
×
3731
}
3732

3733
typedef struct {
3734
  int64_t streamId;
3735
  int64_t checkpointId;
3736
  char    streamName[TSDB_STREAM_FNAME_LEN];
3737
} SMStreamDoCheckpointMsg;
3738

3739
typedef struct {
3740
  int64_t status;
3741
} SMVSubscribeRsp;
3742

3743
typedef struct {
3744
  char    name[TSDB_TOPIC_FNAME_LEN];
3745
  int8_t  igNotExists;
3746
  int32_t sqlLen;
3747
  char*   sql;
3748
  int8_t  force;
3749
} SMDropTopicReq;
3750

3751
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3752
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3753
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3754

3755
typedef struct {
3756
  char   topic[TSDB_TOPIC_FNAME_LEN];
3757
  char   cgroup[TSDB_CGROUP_LEN];
3758
  int8_t igNotExists;
3759
  int8_t force;
3760
} SMDropCgroupReq;
3761

3762
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3763
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3764

3765
typedef struct {
3766
  int8_t reserved;
3767
} SMDropCgroupRsp;
3768

3769
typedef struct {
3770
  char    name[TSDB_TABLE_FNAME_LEN];
3771
  int8_t  alterType;
3772
  SSchema schema;
3773
} SAlterTopicReq;
3774

3775
typedef struct {
3776
  SMsgHead head;
3777
  char     name[TSDB_TABLE_FNAME_LEN];
3778
  int64_t  tuid;
3779
  int32_t  sverson;
3780
  int32_t  execLen;
3781
  char*    executor;
3782
  int32_t  sqlLen;
3783
  char*    sql;
3784
} SDCreateTopicReq;
3785

3786
typedef struct {
3787
  SMsgHead head;
3788
  char     name[TSDB_TABLE_FNAME_LEN];
3789
  int64_t  tuid;
3790
} SDDropTopicReq;
3791

3792
typedef struct {
3793
  char*      name;
3794
  int64_t    uid;
3795
  int64_t    interval[2];
3796
  int8_t     intervalUnit;
3797
  int16_t    nFuncs;
3798
  col_id_t*  funcColIds;  // column ids specified by user
3799
  func_id_t* funcIds;     // function ids specified by user
3800
} SRSmaParam;
3801

3802
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3803
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3804

3805
// TDMT_VND_CREATE_STB ==============
3806
typedef struct SVCreateStbReq {
3807
  char*           name;
3808
  tb_uid_t        suid;
3809
  int8_t          rollup;
3810
  SSchemaWrapper  schemaRow;
3811
  SSchemaWrapper  schemaTag;
3812
  SRSmaParam      rsmaParam;
3813
  int32_t         alterOriDataLen;
3814
  void*           alterOriData;
3815
  int8_t          source;
3816
  int8_t          colCmpred;
3817
  SColCmprWrapper colCmpr;
3818
  int64_t         keep;
3819
  SExtSchema*     pExtSchemas;
3820
  int8_t          virtualStb;
3821
} SVCreateStbReq;
3822

3823
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3824
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3825

3826
// TDMT_VND_DROP_STB ==============
3827
typedef struct SVDropStbReq {
3828
  char*    name;
3829
  tb_uid_t suid;
3830
} SVDropStbReq;
3831

3832
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3833
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3834

3835
// TDMT_VND_CREATE_TABLE ==============
3836
#define TD_CREATE_IF_NOT_EXISTS       0x1
3837
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
3838
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
3839
typedef struct SVCreateTbReq {
3840
  int32_t  flags;
3841
  char*    name;
3842
  tb_uid_t uid;
3843
  int64_t  btime;
3844
  int32_t  ttl;
3845
  int32_t  commentLen;
3846
  char*    comment;
3847
  int8_t   type;
3848
  union {
3849
    struct {
3850
      char*    stbName;  // super table name
3851
      uint8_t  tagNum;
3852
      tb_uid_t suid;
3853
      SArray*  tagName;
3854
      uint8_t* pTag;
3855
    } ctb;
3856
    struct {
3857
      SSchemaWrapper schemaRow;
3858
    } ntb;
3859
  };
3860
  int32_t         sqlLen;
3861
  char*           sql;
3862
  SColCmprWrapper colCmpr;
3863
  SExtSchema*     pExtSchemas;
3864
  SColRefWrapper  colRef;  // col reference for virtual table
3865
} SVCreateTbReq;
3866

3867
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3868
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3869
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3870
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
3871

3872
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3873
  if (NULL == req) {
2,147,483,647✔
3874
    return;
2,128,827,855✔
3875
  }
3876

3877
  taosMemoryFreeClear(req->sql);
70,073,288✔
3878
  taosMemoryFreeClear(req->name);
70,073,452✔
3879
  taosMemoryFreeClear(req->comment);
70,079,483✔
3880
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
70,074,777✔
3881
    taosMemoryFreeClear(req->ctb.pTag);
67,506,311✔
3882
    taosMemoryFreeClear(req->ctb.stbName);
67,498,206✔
3883
    taosArrayDestroy(req->ctb.tagName);
67,517,456✔
3884
    req->ctb.tagName = NULL;
67,492,540✔
3885
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,567,866✔
3886
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,567,866✔
3887
  }
3888
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
70,062,306✔
3889
  taosMemoryFreeClear(req->pExtSchemas);
70,074,815✔
3890
  taosMemoryFreeClear(req->colRef.pColRef);
70,075,447✔
3891
}
3892

3893
typedef struct {
3894
  int32_t nReqs;
3895
  union {
3896
    SVCreateTbReq* pReqs;
3897
    SArray*        pArray;
3898
  };
3899
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3900
} SVCreateTbBatchReq;
3901

3902
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3903
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3904
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3905

3906
typedef struct {
3907
  int32_t        code;
3908
  STableMetaRsp* pMeta;
3909
} SVCreateTbRsp, SVUpdateTbRsp;
3910

3911
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3912
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3913
void tFreeSVCreateTbRsp(void* param);
3914

3915
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3916
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3917

3918
typedef struct {
3919
  int32_t nRsps;
3920
  union {
3921
    SVCreateTbRsp* pRsps;
3922
    SArray*        pArray;
3923
  };
3924
} SVCreateTbBatchRsp;
3925

3926
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3927
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3928

3929
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3930
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3931

3932
// TDMT_VND_DROP_TABLE =================
3933
typedef struct {
3934
  char*    name;
3935
  uint64_t suid;  // for tmq in wal format
3936
  int64_t  uid;
3937
  int8_t   igNotExists;
3938
  int8_t   isVirtual;
3939
} SVDropTbReq;
3940

3941
typedef struct {
3942
  int32_t code;
3943
} SVDropTbRsp;
3944

3945
typedef struct {
3946
  int32_t nReqs;
3947
  union {
3948
    SVDropTbReq* pReqs;
3949
    SArray*      pArray;
3950
  };
3951
} SVDropTbBatchReq;
3952

3953
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3954
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3955

3956
typedef struct {
3957
  int32_t nRsps;
3958
  union {
3959
    SVDropTbRsp* pRsps;
3960
    SArray*      pArray;
3961
  };
3962
} SVDropTbBatchRsp;
3963

3964
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3965
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3966

3967
// TDMT_VND_ALTER_TABLE =====================
3968
typedef struct SMultiTagUpateVal {
3969
  char*    tagName;
3970
  int32_t  colId;
3971
  int8_t   tagType;
3972
  int8_t   tagFree;
3973
  uint32_t nTagVal;
3974
  uint8_t* pTagVal;
3975
  int8_t   isNull;
3976
  SArray*  pTagArray;
3977
} SMultiTagUpateVal;
3978
typedef struct SVAlterTbReq {
3979
  char*   tbName;
3980
  int8_t  action;
3981
  char*   colName;
3982
  int32_t colId;
3983
  // TSDB_ALTER_TABLE_ADD_COLUMN
3984
  int8_t  type;
3985
  int8_t  flags;
3986
  int32_t bytes;
3987
  // TSDB_ALTER_TABLE_DROP_COLUMN
3988
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3989
  int8_t   colModType;
3990
  int32_t  colModBytes;
3991
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3992
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3993
  int8_t   isNull;
3994
  int8_t   tagType;
3995
  int8_t   tagFree;
3996
  uint32_t nTagVal;
3997
  uint8_t* pTagVal;
3998
  SArray*  pTagArray;
3999
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4000
  int8_t   updateTTL;
4001
  int32_t  newTTL;
4002
  int32_t  newCommentLen;
4003
  char*    newComment;
4004
  int64_t  ctimeMs;    // fill by vnode
4005
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4006
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4007
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4008
  // for Add column
4009
  STypeMod typeMod;
4010
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4011
  char* refDbName;
4012
  char* refTbName;
4013
  char* refColName;
4014
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4015
} SVAlterTbReq;
4016

4017
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4018
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4019
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4020
void    tfreeMultiTagUpateVal(void* pMultiTag);
4021

4022
typedef struct {
4023
  int32_t        code;
4024
  STableMetaRsp* pMeta;
4025
} SVAlterTbRsp;
4026

4027
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4028
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4029
// ======================
4030

4031
typedef struct {
4032
  SMsgHead head;
4033
  int64_t  uid;
4034
  int32_t  tid;
4035
  int16_t  tversion;
4036
  int16_t  colId;
4037
  int8_t   type;
4038
  int16_t  bytes;
4039
  int32_t  tagValLen;
4040
  int16_t  numOfTags;
4041
  int32_t  schemaLen;
4042
  char     data[];
4043
} SUpdateTagValReq;
4044

4045
typedef struct {
4046
  SMsgHead head;
4047
} SUpdateTagValRsp;
4048

4049
typedef struct {
4050
  SMsgHead head;
4051
} SVShowTablesReq;
4052

4053
typedef struct {
4054
  SMsgHead head;
4055
  int32_t  id;
4056
} SVShowTablesFetchReq;
4057

4058
typedef struct {
4059
  int64_t useconds;
4060
  int8_t  completed;  // all results are returned to client
4061
  int8_t  precision;
4062
  int8_t  compressed;
4063
  int32_t compLen;
4064
  int32_t numOfRows;
4065
  char    data[];
4066
} SVShowTablesFetchRsp;
4067

4068
typedef struct {
4069
  int64_t consumerId;
4070
  int32_t epoch;
4071
  char    cgroup[TSDB_CGROUP_LEN];
4072
} SMqAskEpReq;
4073

4074
typedef struct {
4075
  int32_t key;
4076
  int32_t valueLen;
4077
  void*   value;
4078
} SKv;
4079

4080
typedef struct {
4081
  int64_t tscRid;
4082
  int8_t  connType;
4083
} SClientHbKey;
4084

4085
typedef struct {
4086
  int64_t tid;
4087
  char    status[TSDB_JOB_STATUS_LEN];
4088
} SQuerySubDesc;
4089

4090
typedef struct {
4091
  char     sql[TSDB_SHOW_SQL_LEN];
4092
  uint64_t queryId;
4093
  int64_t  useconds;
4094
  int64_t  stime;  // timestamp precision ms
4095
  int64_t  reqRid;
4096
  bool     stableQuery;
4097
  bool     isSubQuery;
4098
  char     fqdn[TSDB_FQDN_LEN];
4099
  int32_t  subPlanNum;
4100
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4101
} SQueryDesc;
4102

4103
typedef struct {
4104
  uint32_t connId;
4105
  SArray*  queryDesc;  // SArray<SQueryDesc>
4106
} SQueryHbReqBasic;
4107

4108
typedef struct {
4109
  uint32_t connId;
4110
  uint64_t killRid;
4111
  int32_t  totalDnodes;
4112
  int32_t  onlineDnodes;
4113
  int8_t   killConnection;
4114
  int8_t   align[3];
4115
  SEpSet   epSet;
4116
  SArray*  pQnodeList;
4117
} SQueryHbRspBasic;
4118

4119
typedef struct SAppClusterSummary {
4120
  uint64_t numOfInsertsReq;
4121
  uint64_t numOfInsertRows;
4122
  uint64_t insertElapsedTime;
4123
  uint64_t insertBytes;  // submit to tsdb since launched.
4124

4125
  uint64_t fetchBytes;
4126
  uint64_t numOfQueryReq;
4127
  uint64_t queryElapsedTime;
4128
  uint64_t numOfSlowQueries;
4129
  uint64_t totalRequests;
4130
  uint64_t currentRequests;  // the number of SRequestObj
4131
} SAppClusterSummary;
4132

4133
typedef struct {
4134
  int64_t            appId;
4135
  int32_t            pid;
4136
  char               name[TSDB_APP_NAME_LEN];
4137
  int64_t            startTime;
4138
  SAppClusterSummary summary;
4139
} SAppHbReq;
4140

4141
typedef struct {
4142
  SClientHbKey      connKey;
4143
  int64_t           clusterId;
4144
  SAppHbReq         app;
4145
  SQueryHbReqBasic* query;
4146
  SHashObj*         info;  // hash<Skv.key, Skv>
4147
  char              userApp[TSDB_APP_NAME_LEN];
4148
  uint32_t          userIp;
4149
  SIpRange          userDualIp;
4150
  char              sVer[TSDB_VERSION_LEN];
4151
  char              cInfo[CONNECTOR_INFO_LEN];
4152
} SClientHbReq;
4153

4154
typedef struct {
4155
  int64_t reqId;
4156
  SArray* reqs;  // SArray<SClientHbReq>
4157
  int64_t ipWhiteListVer;
4158
} SClientHbBatchReq;
4159

4160
typedef struct {
4161
  SClientHbKey      connKey;
4162
  int32_t           status;
4163
  SQueryHbRspBasic* query;
4164
  SArray*           info;  // Array<Skv>
4165
} SClientHbRsp;
4166

4167
typedef struct {
4168
  int64_t       reqId;
4169
  int64_t       rspId;
4170
  int32_t       svrTimestamp;
4171
  SArray*       rsps;  // SArray<SClientHbRsp>
4172
  SMonitorParas monitorParas;
4173
  int8_t        enableAuditDelete;
4174
  int8_t        enableStrongPass;
4175
} SClientHbBatchRsp;
4176

4177
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
67,047,529✔
4178

4179
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4180
  void* pIter = taosHashIterate(info, NULL);
42,471,296✔
4181
  while (pIter != NULL) {
93,373,975✔
4182
    SKv* kv = (SKv*)pIter;
50,902,922✔
4183
    taosMemoryFreeClear(kv->value);
50,902,922✔
4184
    pIter = taosHashIterate(info, pIter);
50,902,364✔
4185
  }
4186
}
42,471,053✔
4187

4188
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
25,799,352✔
4189
  SQueryDesc* desc = (SQueryDesc*)pDesc;
25,799,352✔
4190
  if (desc->subDesc) {
25,799,352✔
4191
    taosArrayDestroy(desc->subDesc);
22,149,616✔
4192
    desc->subDesc = NULL;
22,148,093✔
4193
  }
4194
}
25,799,157✔
4195

4196
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
51,705,732✔
4197
  SClientHbReq* req = (SClientHbReq*)pReq;
55,450,331✔
4198
  if (req->query) {
55,450,331✔
4199
    if (req->query->queryDesc) {
44,702,349✔
4200
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
21,758,422✔
4201
    }
4202
    taosMemoryFreeClear(req->query);
44,702,946✔
4203
  }
4204

4205
  if (req->info) {
55,450,928✔
4206
    tFreeReqKvHash(req->info);
42,471,296✔
4207
    taosHashCleanup(req->info);
42,471,053✔
4208
    req->info = NULL;
42,470,054✔
4209
  }
4210
}
28,112,694✔
4211

4212
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4213
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4214

4215
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4216
  if (pReq == NULL) return;
23,324,581✔
4217
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
23,324,581✔
4218
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
23,324,581✔
4219
  taosMemoryFree(pReq);
23,324,581✔
4220
}
4221

4222
static FORCE_INLINE void tFreeClientKv(void* pKv) {
19,234,028✔
4223
  SKv* kv = (SKv*)pKv;
19,234,028✔
4224
  if (kv) {
19,234,028✔
4225
    taosMemoryFreeClear(kv->value);
19,234,028✔
4226
  }
4227
}
19,233,968✔
4228

4229
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
51,008,884✔
4230
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
51,008,884✔
4231
  if (rsp->query) {
51,008,884✔
4232
    taosArrayDestroy(rsp->query->pQnodeList);
44,034,576✔
4233
    taosMemoryFreeClear(rsp->query);
44,035,268✔
4234
  }
4235
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
51,008,237✔
4236
}
26,641,149✔
4237

4238
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4239
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
43,678,513✔
4240
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
43,678,513✔
4241
}
43,680,004✔
4242

4243
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4244
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4245
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4246

4247
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4248
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
150,072,541✔
4249
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
150,073,057✔
4250
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
150,073,057✔
4251
  return 0;
75,036,242✔
4252
}
4253

4254
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4255
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
69,849,657✔
4256
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
69,849,510✔
4257
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
34,924,673✔
4258
  if (pKv->value == NULL) {
34,924,837✔
4259
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4260
  }
4261
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
34,924,837✔
4262
  return 0;
34,924,837✔
4263
}
4264

4265
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4266
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
213,986,202✔
4267
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
213,984,788✔
4268
  return 0;
106,993,469✔
4269
}
4270

4271
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4272
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
105,581,027✔
4273
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
105,583,292✔
4274
  return 0;
52,793,379✔
4275
}
4276

4277
typedef struct {
4278
  int32_t vgId;
4279
  // TODO stas
4280
} SMqReportVgInfo;
4281

4282
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4283
  int32_t tlen = 0;
4284
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4285
  return tlen;
4286
}
4287

4288
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4289
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4290
  return buf;
4291
}
4292

4293
typedef struct {
4294
  int32_t epoch;
4295
  int64_t topicUid;
4296
  char    name[TSDB_TOPIC_FNAME_LEN];
4297
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4298
} SMqTopicInfo;
4299

4300
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4301
  int32_t tlen = 0;
4302
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4303
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4304
  tlen += taosEncodeString(buf, pTopicInfo->name);
4305
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4306
  tlen += taosEncodeFixedI32(buf, sz);
4307
  for (int32_t i = 0; i < sz; i++) {
4308
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4309
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4310
  }
4311
  return tlen;
4312
}
4313

4314
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4315
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4316
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4317
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4318
  int32_t sz;
4319
  buf = taosDecodeFixedI32(buf, &sz);
4320
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4321
    return NULL;
4322
  }
4323
  for (int32_t i = 0; i < sz; i++) {
4324
    SMqReportVgInfo vgInfo;
4325
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4326
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4327
      return NULL;
4328
    }
4329
  }
4330
  return buf;
4331
}
4332

4333
typedef struct {
4334
  int32_t status;  // ask hb endpoint
4335
  int32_t epoch;
4336
  int64_t consumerId;
4337
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4338
} SMqReportReq;
4339

4340
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4341
  int32_t tlen = 0;
4342
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4343
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4344
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4345
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4346
  tlen += taosEncodeFixedI32(buf, sz);
4347
  for (int32_t i = 0; i < sz; i++) {
4348
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4349
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4350
  }
4351
  return tlen;
4352
}
4353

4354
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4355
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4356
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4357
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4358
  int32_t sz;
4359
  buf = taosDecodeFixedI32(buf, &sz);
4360
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4361
    return NULL;
4362
  }
4363
  for (int32_t i = 0; i < sz; i++) {
4364
    SMqTopicInfo topicInfo;
4365
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4366
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4367
      return NULL;
4368
    }
4369
  }
4370
  return buf;
4371
}
4372

4373
typedef struct {
4374
  SMsgHead head;
4375
  int64_t  leftForVer;
4376
  int32_t  vgId;
4377
  int64_t  consumerId;
4378
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4379
} SMqVDeleteReq;
4380

4381
typedef struct {
4382
  int8_t reserved;
4383
} SMqVDeleteRsp;
4384

4385
typedef struct {
4386
  char*   name;
4387
  int8_t  igNotExists;
4388
} SMDropStreamReq;
4389

4390
typedef struct {
4391
  int8_t reserved;
4392
} SMDropStreamRsp;
4393

4394
typedef struct {
4395
  SMsgHead head;
4396
  int64_t  resetRelHalt;  // reset related stream task halt status
4397
  int64_t  streamId;
4398
  int32_t  taskId;
4399
} SVDropStreamTaskReq;
4400

4401
typedef struct {
4402
  int8_t reserved;
4403
} SVDropStreamTaskRsp;
4404

4405
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4406
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4407
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4408

4409
typedef struct {
4410
  char*  name;
4411
  int8_t igNotExists;
4412
} SMPauseStreamReq;
4413

4414
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4415
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4416
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4417

4418
typedef struct {
4419
  char*  name;
4420
  int8_t igNotExists;
4421
  int8_t igUntreated;
4422
} SMResumeStreamReq;
4423

4424
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4425
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4426
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4427

4428
typedef struct {
4429
  char*       name;
4430
  int8_t      calcAll;
4431
  STimeWindow timeRange;
4432
} SMRecalcStreamReq;
4433

4434
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4435
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4436
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4437

4438
typedef struct SVndSetKeepVersionReq {
4439
  int64_t keepVersion;
4440
} SVndSetKeepVersionReq;
4441

4442
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4443
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4444

4445
typedef struct SVUpdateCheckpointInfoReq {
4446
  SMsgHead head;
4447
  int64_t  streamId;
4448
  int32_t  taskId;
4449
  int64_t  checkpointId;
4450
  int64_t  checkpointVer;
4451
  int64_t  checkpointTs;
4452
  int32_t  transId;
4453
  int64_t  hStreamId;  // add encode/decode
4454
  int64_t  hTaskId;
4455
  int8_t   dropRelHTask;
4456
} SVUpdateCheckpointInfoReq;
4457

4458
typedef struct {
4459
  int64_t leftForVer;
4460
  int32_t vgId;
4461
  int64_t oldConsumerId;
4462
  int64_t newConsumerId;
4463
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4464
  int8_t  subType;
4465
  int8_t  withMeta;
4466
  char*   qmsg;  // SubPlanToString
4467
  int64_t suid;
4468
} SMqRebVgReq;
4469

4470
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4471
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4472

4473
typedef struct {
4474
  char    topic[TSDB_TOPIC_FNAME_LEN];
4475
  int64_t ntbUid;
4476
  SArray* colIdList;  // SArray<int16_t>
4477
} STqCheckInfo;
4478

4479
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4480
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4481
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4482

4483
// tqOffset
4484
enum {
4485
  TMQ_OFFSET__RESET_NONE = -3,
4486
  TMQ_OFFSET__RESET_EARLIEST = -2,
4487
  TMQ_OFFSET__RESET_LATEST = -1,
4488
  TMQ_OFFSET__LOG = 1,
4489
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4490
  TMQ_OFFSET__SNAPSHOT_META = 3,
4491
};
4492

4493
enum {
4494
  WITH_DATA = 0,
4495
  WITH_META = 1,
4496
  ONLY_META = 2,
4497
};
4498

4499
#define TQ_OFFSET_VERSION 1
4500

4501
typedef struct {
4502
  int8_t type;
4503
  union {
4504
    // snapshot
4505
    struct {
4506
      int64_t uid;
4507
      int64_t ts;
4508
      SValue  primaryKey;
4509
    };
4510
    // log
4511
    struct {
4512
      int64_t version;
4513
    };
4514
  };
4515
} STqOffsetVal;
4516

4517
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4518
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,621,130✔
4519
  pOffsetVal->uid = uid;
1,621,046✔
4520
  pOffsetVal->ts = ts;
1,621,340✔
4521
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,621,493✔
4522
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4523
  }
4524
  pOffsetVal->primaryKey = primaryKey;
1,621,244✔
4525
}
1,620,929✔
4526

4527
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4528
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
6,818✔
4529
  pOffsetVal->uid = uid;
6,818✔
4530
}
6,818✔
4531

4532
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4533
  pOffsetVal->type = TMQ_OFFSET__LOG;
38,855,615✔
4534
  pOffsetVal->version = ver;
38,855,403✔
4535
}
38,854,892✔
4536

4537
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4538
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4539
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4540
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4541
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4542
void    tOffsetDestroy(void* pVal);
4543

4544
typedef struct {
4545
  STqOffsetVal val;
4546
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4547
} STqOffset;
4548

4549
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4550
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4551
void    tDeleteSTqOffset(void* val);
4552

4553
typedef struct SMqVgOffset {
4554
  int64_t   consumerId;
4555
  STqOffset offset;
4556
} SMqVgOffset;
4557

4558
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4559
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4560

4561
typedef struct {
4562
  char    name[TSDB_TABLE_FNAME_LEN];
4563
  char    stb[TSDB_TABLE_FNAME_LEN];
4564
  int8_t  igExists;
4565
  int8_t  intervalUnit;
4566
  int8_t  slidingUnit;
4567
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4568
  int32_t dstVgId;   // for stream
4569
  int64_t interval;
4570
  int64_t offset;
4571
  int64_t sliding;
4572
  int64_t maxDelay;
4573
  int64_t watermark;
4574
  int32_t exprLen;        // strlen + 1
4575
  int32_t tagsFilterLen;  // strlen + 1
4576
  int32_t sqlLen;         // strlen + 1
4577
  int32_t astLen;         // strlen + 1
4578
  char*   expr;
4579
  char*   tagsFilter;
4580
  char*   sql;
4581
  char*   ast;
4582
  int64_t deleteMark;
4583
  int64_t lastTs;
4584
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4585
  SArray* pVgroupVerList;
4586
  int8_t  recursiveTsma;
4587
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4588
  char*   createStreamReq;
4589
  int32_t streamReqLen;
4590
  char*   dropStreamReq;
4591
  int32_t dropStreamReqLen;
4592
  int64_t uid;
4593
} SMCreateSmaReq;
4594

4595
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4596
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4597
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4598

4599
typedef struct {
4600
  char   name[TSDB_TABLE_FNAME_LEN];
4601
  int8_t igNotExists;
4602
  char*   dropStreamReq;
4603
  int32_t dropStreamReqLen;
4604
} SMDropSmaReq;
4605

4606
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4607
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4608
void tFreeSMDropSmaReq(SMDropSmaReq *pReq);
4609

4610
typedef struct {
4611
  char name[TSDB_TABLE_NAME_LEN];
4612
  union {
4613
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4614
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4615
  };
4616
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4617
  union {
4618
    int8_t igExists;   // used by mnode
4619
    int8_t alterType;  // used by vnode
4620
  };
4621
  int8_t     intervalUnit;
4622
  int16_t    nFuncs;       // number of functions specified by user
4623
  col_id_t*  funcColIds;   // column ids specified by user
4624
  func_id_t* funcIds;      // function ids specified by user
4625
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4626
  int64_t    tbUid;
4627
  int64_t    uid;     // rsma uid
4628
  int32_t    sqlLen;  // strlen + 1
4629
  char*      sql;
4630
} SMCreateRsmaReq;
4631

4632
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4633
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4634
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4635

4636
typedef SMCreateRsmaReq SVCreateRsmaReq;
4637

4638
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4639
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4640
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4641

4642
typedef SMCreateRsmaReq SVAlterRsmaReq;
4643

4644
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4645
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4646
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4647

4648
typedef struct {
4649
  char       name[TSDB_TABLE_NAME_LEN];
4650
  int8_t     alterType;
4651
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4652
  int8_t     igNotExists;
4653
  int16_t    nFuncs;      // number of functions specified by user
4654
  col_id_t*  funcColIds;  // column ids specified by user
4655
  func_id_t* funcIds;     // function ids specified by user
4656
  int32_t    sqlLen;      // strlen + 1
4657
  char*      sql;
4658
} SMAlterRsmaReq;
4659

4660
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4661
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4662
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4663

4664
typedef struct {
4665
  int64_t    id;
4666
  char       name[TSDB_TABLE_NAME_LEN];
4667
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4668
  int32_t    code;
4669
  int32_t    version;
4670
  int8_t     tbType;
4671
  int8_t     intervalUnit;
4672
  col_id_t   nFuncs;
4673
  col_id_t   nColNames;
4674
  int64_t    interval[2];
4675
  col_id_t*  funcColIds;
4676
  func_id_t* funcIds;
4677
  SArray*    colNames;
4678
} SRsmaInfoRsp;
4679

4680
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4681
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4682
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4683

4684
typedef struct {
4685
  char   name[TSDB_TABLE_FNAME_LEN];
4686
  int8_t igNotExists;
4687
} SMDropRsmaReq;
4688

4689
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4690
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4691

4692
typedef struct {
4693
  char    name[TSDB_TABLE_NAME_LEN];
4694
  char    tbName[TSDB_TABLE_NAME_LEN];
4695
  int64_t uid;
4696
  int64_t tbUid;
4697
  int8_t  tbType;
4698
} SVDropRsmaReq;
4699

4700
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4701
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4702

4703
typedef struct {
4704
  char   dbFName[TSDB_DB_FNAME_LEN];
4705
  char   stbName[TSDB_TABLE_NAME_LEN];
4706
  char   colName[TSDB_COL_NAME_LEN];
4707
  char   idxName[TSDB_INDEX_FNAME_LEN];
4708
  int8_t idxType;
4709
} SCreateTagIndexReq;
4710

4711
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4712
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4713

4714
typedef SMDropSmaReq SDropTagIndexReq;
4715

4716
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4717
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4718

4719
typedef struct {
4720
  int8_t         version;       // for compatibility(default 0)
4721
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4722
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4723
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4724
  int32_t        dstVgId;
4725
  char           indexName[TSDB_INDEX_NAME_LEN];
4726
  int32_t        exprLen;
4727
  int32_t        tagsFilterLen;
4728
  int64_t        indexUid;
4729
  tb_uid_t       tableUid;  // super/child/common table uid
4730
  tb_uid_t       dstTbUid;  // for dstVgroup
4731
  int64_t        interval;
4732
  int64_t        offset;  // use unit by precision of DB
4733
  int64_t        sliding;
4734
  char*          dstTbName;  // for dstVgroup
4735
  char*          expr;       // sma expression
4736
  char*          tagsFilter;
4737
  SSchemaWrapper schemaRow;  // for dstVgroup
4738
  SSchemaWrapper schemaTag;  // for dstVgroup
4739
} STSma;                     // Time-range-wise SMA
4740

4741
typedef STSma SVCreateTSmaReq;
4742

4743
typedef struct {
4744
  int8_t  type;  // 0 status report, 1 update data
4745
  int64_t indexUid;
4746
  int64_t skey;  // start TS key of interval/sliding window
4747
} STSmaMsg;
4748

4749
typedef struct {
4750
  int64_t indexUid;
4751
  char    indexName[TSDB_INDEX_NAME_LEN];
4752
} SVDropTSmaReq;
4753

4754
typedef struct {
4755
  int tmp;  // TODO: to avoid compile error
4756
} SVCreateTSmaRsp, SVDropTSmaRsp;
4757

4758
#if 0
4759
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4760
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4761
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4762
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4763
#endif
4764

4765
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4766
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4767
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4768
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4769

4770
typedef struct {
4771
  int32_t number;
4772
  STSma*  tSma;
4773
} STSmaWrapper;
4774

4775
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4776
  if (pSma) {
×
4777
    taosMemoryFreeClear(pSma->dstTbName);
×
4778
    taosMemoryFreeClear(pSma->expr);
×
4779
    taosMemoryFreeClear(pSma->tagsFilter);
×
4780
  }
4781
}
×
4782

4783
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4784
  if (pSW) {
×
4785
    if (pSW->tSma) {
×
4786
      if (deepCopy) {
×
4787
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4788
          tDestroyTSma(pSW->tSma + i);
×
4789
        }
4790
      }
4791
      taosMemoryFreeClear(pSW->tSma);
×
4792
    }
4793
  }
4794
}
×
4795

4796
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4797
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4798
  taosMemoryFreeClear(pSW);
×
4799
  return NULL;
×
4800
}
4801

4802
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4803
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4804

4805
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4806
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4807

4808
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4809
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4810
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4811
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4812
  }
4813
  return 0;
×
4814
}
4815

4816
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4817
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4818
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4819
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4820
  }
4821
  return 0;
×
4822
}
4823

4824
typedef struct {
4825
  int idx;
4826
} SMCreateFullTextReq;
4827

4828
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4829
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4830
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4831

4832
typedef struct {
4833
  char   name[TSDB_TABLE_FNAME_LEN];
4834
  int8_t igNotExists;
4835
} SMDropFullTextReq;
4836

4837
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4838
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4839

4840
typedef struct {
4841
  char indexFName[TSDB_INDEX_FNAME_LEN];
4842
} SUserIndexReq;
4843

4844
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4845
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4846

4847
typedef struct {
4848
  char dbFName[TSDB_DB_FNAME_LEN];
4849
  char tblFName[TSDB_TABLE_FNAME_LEN];
4850
  char colName[TSDB_COL_NAME_LEN];
4851
  char indexType[TSDB_INDEX_TYPE_LEN];
4852
  char indexExts[TSDB_INDEX_EXTS_LEN];
4853
} SUserIndexRsp;
4854

4855
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4856
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4857

4858
typedef struct {
4859
  char tbFName[TSDB_TABLE_FNAME_LEN];
4860
} STableIndexReq;
4861

4862
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4863
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4864

4865
typedef struct {
4866
  int8_t  intervalUnit;
4867
  int8_t  slidingUnit;
4868
  int64_t interval;
4869
  int64_t offset;
4870
  int64_t sliding;
4871
  int64_t dstTbUid;
4872
  int32_t dstVgId;
4873
  SEpSet  epSet;
4874
  char*   expr;
4875
} STableIndexInfo;
4876

4877
typedef struct {
4878
  char     tbName[TSDB_TABLE_NAME_LEN];
4879
  char     dbFName[TSDB_DB_FNAME_LEN];
4880
  uint64_t suid;
4881
  int32_t  version;
4882
  int32_t  indexSize;
4883
  SArray*  pIndex;  // STableIndexInfo
4884
} STableIndexRsp;
4885

4886
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4887
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4888
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4889

4890
void tFreeSTableIndexInfo(void* pInfo);
4891

4892
typedef struct {
4893
  int8_t  mqMsgType;
4894
  int32_t code;
4895
  int32_t epoch;
4896
  int64_t consumerId;
4897
  int64_t walsver;
4898
  int64_t walever;
4899
} SMqRspHead;
4900

4901
typedef struct {
4902
  SMsgHead     head;
4903
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4904
  int8_t       withTbName;
4905
  int8_t       useSnapshot;
4906
  int32_t      epoch;
4907
  uint64_t     reqId;
4908
  int64_t      consumerId;
4909
  int64_t      timeout;
4910
  STqOffsetVal reqOffset;
4911
  int8_t       enableReplay;
4912
  int8_t       sourceExcluded;
4913
  int8_t       rawData;
4914
  int32_t      minPollRows;
4915
  int8_t       enableBatchMeta;
4916
  SHashObj*    uidHash;  // to find if uid is duplicated
4917
} SMqPollReq;
4918

4919
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4920
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4921
void    tDestroySMqPollReq(SMqPollReq* pReq);
4922

4923
typedef struct {
4924
  int32_t vgId;
4925
  int64_t offset;
4926
  SEpSet  epSet;
4927
} SMqSubVgEp;
4928

4929
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4930
  int32_t tlen = 0;
499,328✔
4931
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
499,328✔
4932
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
499,328✔
4933
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
499,328✔
4934
  return tlen;
499,328✔
4935
}
4936

4937
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4938
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
389,667✔
4939
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
389,667✔
4940
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
389,667✔
4941
  return buf;
389,667✔
4942
}
4943

4944
typedef struct {
4945
  char           topic[TSDB_TOPIC_FNAME_LEN];
4946
  char           db[TSDB_DB_FNAME_LEN];
4947
  SArray*        vgs;  // SArray<SMqSubVgEp>
4948
  SSchemaWrapper schema;
4949
} SMqSubTopicEp;
4950

4951
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4952
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4953
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4954

4955
typedef struct {
4956
  SMqRspHead   head;
4957
  STqOffsetVal rspOffset;
4958
  int16_t      resMsgType;
4959
  int32_t      metaRspLen;
4960
  void*        metaRsp;
4961
} SMqMetaRsp;
4962

4963
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4964
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4965
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4966

4967
#define MQ_DATA_RSP_VERSION 100
4968

4969
typedef struct {
4970
  SMqRspHead   head;
4971
  STqOffsetVal rspOffset;
4972
  STqOffsetVal reqOffset;
4973
  int32_t      blockNum;
4974
  int8_t       withTbName;
4975
  int8_t       withSchema;
4976
  SArray*      blockDataLen;
4977
  SArray*      blockData;
4978
  SArray*      blockTbName;
4979
  SArray*      blockSchema;
4980

4981
  union {
4982
    struct {
4983
      int64_t sleepTime;
4984
    };
4985
    struct {
4986
      int32_t createTableNum;
4987
      SArray* createTableLen;
4988
      SArray* createTableReq;
4989
    };
4990
    struct {
4991
      int32_t len;
4992
      void*   rawData;
4993
    };
4994
  };
4995
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4996
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4997
} SMqDataRsp;
4998

4999
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5000
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5001
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5002
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5003
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5004

5005
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5006
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5007
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5008

5009
typedef struct SMqBatchMetaRsp {
5010
  SMqRspHead   head;  // not serialize
5011
  STqOffsetVal rspOffset;
5012
  SArray*      batchMetaLen;
5013
  SArray*      batchMetaReq;
5014
  void*        pMetaBuff;    // not serialize
5015
  uint32_t     metaBuffLen;  // not serialize
5016
} SMqBatchMetaRsp;
5017

5018
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5019
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5020
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5021
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5022

5023
typedef struct {
5024
  SMqRspHead head;
5025
  char       cgroup[TSDB_CGROUP_LEN];
5026
  SArray*    topics;  // SArray<SMqSubTopicEp>
5027
} SMqAskEpRsp;
5028

5029
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5030
  int32_t tlen = 0;
1,209,598✔
5031
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5032
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,209,598✔
5033
  tlen += taosEncodeFixedI32(buf, sz);
1,209,598✔
5034
  for (int32_t i = 0; i < sz; i++) {
1,374,326✔
5035
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
164,932✔
5036
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
164,932✔
5037
  }
5038
  return tlen;
1,209,394✔
5039
}
5040

5041
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5042
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5043
  int32_t sz;
533,756✔
5044
  buf = taosDecodeFixedI32(buf, &sz);
814,070✔
5045
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
814,070✔
5046
  if (pRsp->topics == NULL) {
814,070✔
5047
    return NULL;
×
5048
  }
5049
  for (int32_t i = 0; i < sz; i++) {
977,009✔
5050
    SMqSubTopicEp topicEp;
82,259✔
5051
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
162,939✔
5052
    if (buf == NULL) {
162,939✔
5053
      return NULL;
×
5054
    }
5055
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
325,878✔
5056
      return NULL;
×
5057
    }
5058
  }
5059
  return buf;
814,070✔
5060
}
5061

5062
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5063
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,765,910✔
5064
}
1,765,910✔
5065

5066
typedef struct {
5067
  int32_t      vgId;
5068
  STqOffsetVal offset;
5069
  int64_t      rows;
5070
  int64_t      ever;
5071
} OffsetRows;
5072

5073
typedef struct {
5074
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5075
  SArray* offsetRows;
5076
} TopicOffsetRows;
5077

5078
typedef struct {
5079
  int64_t consumerId;
5080
  int32_t epoch;
5081
  SArray* topics;
5082
  int8_t  pollFlag;
5083
} SMqHbReq;
5084

5085
typedef struct {
5086
  char   topic[TSDB_TOPIC_FNAME_LEN];
5087
  int8_t noPrivilege;
5088
} STopicPrivilege;
5089

5090
typedef struct {
5091
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5092
  int32_t debugFlag;
5093
} SMqHbRsp;
5094

5095
typedef struct {
5096
  SMsgHead head;
5097
  int64_t  consumerId;
5098
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5099
} SMqSeekReq;
5100

5101
#define TD_AUTO_CREATE_TABLE 0x1
5102
typedef struct {
5103
  int64_t       suid;
5104
  int64_t       uid;
5105
  int32_t       sver;
5106
  uint32_t      nData;
5107
  uint8_t*      pData;
5108
  SVCreateTbReq cTbReq;
5109
} SVSubmitBlk;
5110

5111
typedef struct {
5112
  SMsgHead header;
5113
  uint64_t sId;
5114
  uint64_t queryId;
5115
  uint64_t clientId;
5116
  uint64_t taskId;
5117
  uint32_t sqlLen;
5118
  uint32_t phyLen;
5119
  char*    sql;
5120
  char*    msg;
5121
  int8_t   source;
5122
} SVDeleteReq;
5123

5124
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5125
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5126

5127
typedef struct {
5128
  int64_t affectedRows;
5129
} SVDeleteRsp;
5130

5131
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5132
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5133

5134
typedef struct SDeleteRes {
5135
  uint64_t suid;
5136
  SArray*  uidList;
5137
  int64_t  skey;
5138
  int64_t  ekey;
5139
  int64_t  affectedRows;
5140
  char     tableFName[TSDB_TABLE_NAME_LEN];
5141
  char     tsColName[TSDB_COL_NAME_LEN];
5142
  int64_t  ctimeMs;  // fill by vnode
5143
  int8_t   source;
5144
} SDeleteRes;
5145

5146
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5147
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5148

5149
typedef struct {
5150
  // int64_t uid;
5151
  char    tbname[TSDB_TABLE_NAME_LEN];
5152
  int64_t startTs;
5153
  int64_t endTs;
5154
} SSingleDeleteReq;
5155

5156
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5157
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5158

5159
typedef struct {
5160
  int64_t suid;
5161
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5162
  int64_t ctimeMs;     // fill by vnode
5163
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5164
} SBatchDeleteReq;
5165

5166
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5167
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5168
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5169

5170
typedef struct {
5171
  int32_t msgIdx;
5172
  int32_t msgType;
5173
  int32_t msgLen;
5174
  void*   msg;
5175
} SBatchMsg;
5176

5177
typedef struct {
5178
  SMsgHead header;
5179
  SArray*  pMsgs;  // SArray<SBatchMsg>
5180
} SBatchReq;
5181

5182
typedef struct {
5183
  int32_t reqType;
5184
  int32_t msgIdx;
5185
  int32_t msgLen;
5186
  int32_t rspCode;
5187
  void*   msg;
5188
} SBatchRspMsg;
5189

5190
typedef struct {
5191
  SArray* pRsps;  // SArray<SBatchRspMsg>
5192
} SBatchRsp;
5193

5194
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5195
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5196
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
91,889,206✔
5197
  if (NULL == msg) {
91,889,206✔
5198
    return;
×
5199
  }
5200
  SBatchMsg* pMsg = (SBatchMsg*)msg;
91,889,206✔
5201
  taosMemoryFree(pMsg->msg);
91,889,206✔
5202
}
5203

5204
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5205
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5206

5207
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
134,959,688✔
5208
  if (NULL == p) {
134,959,688✔
5209
    return;
×
5210
  }
5211

5212
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
134,959,688✔
5213
  taosMemoryFree(pRsp->msg);
134,959,688✔
5214
}
5215

5216
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5217
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5218
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5219
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5220
void    tDestroySMqHbReq(SMqHbReq* pReq);
5221

5222
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5223
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5224
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5225

5226
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5227
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5228

5229
#define TD_REQ_FROM_APP               0x0
5230
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5231
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5232
#define SUBMIT_REQ_FROM_FILE          0x4
5233
#define TD_REQ_FROM_TAOX              0x8
5234
#define TD_REQ_FROM_SML               0x10
5235
#define SUBMIT_REQUEST_VERSION        (2)
5236
#define SUBMIT_REQ_WITH_BLOB          0x10
5237
#define SUBMIT_REQ_SCHEMA_RES         0x20
5238
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5239

5240
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5241

5242
typedef struct {
5243
  int32_t        flags;
5244
  SVCreateTbReq* pCreateTbReq;
5245
  int64_t        suid;
5246
  int64_t        uid;
5247
  int32_t        sver;
5248
  union {
5249
    SArray* aRowP;
5250
    SArray* aCol;
5251
  };
5252
  int64_t    ctimeMs;
5253
  SBlobSet*  pBlobSet;
5254
} SSubmitTbData;
5255

5256
typedef struct {
5257
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5258
  SArray* aSubmitBlobData;
5259
  bool    raw;
5260
} SSubmitReq2;
5261

5262
typedef struct {
5263
  SMsgHead header;
5264
  int64_t  version;
5265
  char     data[];  // SSubmitReq2
5266
} SSubmitReq2Msg;
5267

5268
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5269
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5270
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5271
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5272
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5273

5274
typedef struct {
5275
  int32_t affectedRows;
5276
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5277
} SSubmitRsp2;
5278

5279
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5280
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5281
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5282

5283
#define TSDB_MSG_FLG_ENCODE 0x1
5284
#define TSDB_MSG_FLG_DECODE 0x2
5285
#define TSDB_MSG_FLG_CMPT   0x3
5286

5287
typedef struct {
5288
  union {
5289
    struct {
5290
      void*   msgStr;
5291
      int32_t msgLen;
5292
      int64_t ver;
5293
    };
5294
    void* pDataBlock;
5295
  };
5296
} SPackedData;
5297

5298
typedef struct {
5299
  char     fullname[TSDB_VIEW_FNAME_LEN];
5300
  char     name[TSDB_VIEW_NAME_LEN];
5301
  char     dbFName[TSDB_DB_FNAME_LEN];
5302
  char*    querySql;
5303
  char*    sql;
5304
  int8_t   orReplace;
5305
  int8_t   precision;
5306
  int32_t  numOfCols;
5307
  SSchema* pSchema;
5308
} SCMCreateViewReq;
5309

5310
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5311
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5312
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5313

5314
typedef struct {
5315
  char   fullname[TSDB_VIEW_FNAME_LEN];
5316
  char   name[TSDB_VIEW_NAME_LEN];
5317
  char   dbFName[TSDB_DB_FNAME_LEN];
5318
  char*  sql;
5319
  int8_t igNotExists;
5320
} SCMDropViewReq;
5321

5322
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5323
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5324
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5325

5326
typedef struct {
5327
  char fullname[TSDB_VIEW_FNAME_LEN];
5328
} SViewMetaReq;
5329
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5330
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5331

5332
typedef struct {
5333
  char     name[TSDB_VIEW_NAME_LEN];
5334
  char     dbFName[TSDB_DB_FNAME_LEN];
5335
  char*    user;
5336
  uint64_t dbId;
5337
  uint64_t viewId;
5338
  char*    querySql;
5339
  int8_t   precision;
5340
  int8_t   type;
5341
  int32_t  version;
5342
  int32_t  numOfCols;
5343
  SSchema* pSchema;
5344
} SViewMetaRsp;
5345
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5346
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5347
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5348
typedef struct {
5349
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5350
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5351
} STableTSMAInfoReq;
5352

5353
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5354
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5355

5356
typedef struct {
5357
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5358
  union {
5359
    uint8_t flags;
5360
    struct {
5361
      uint8_t withColName : 1;
5362
      uint8_t reserved : 7;
5363
    };
5364
  };
5365

5366
} SRsmaInfoReq;
5367

5368
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5369
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5370

5371
typedef struct {
5372
  int32_t  funcId;
5373
  col_id_t colId;
5374
} STableTSMAFuncInfo;
5375

5376
typedef struct {
5377
  char     name[TSDB_TABLE_NAME_LEN];
5378
  uint64_t tsmaId;
5379
  char     targetTb[TSDB_TABLE_NAME_LEN];
5380
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5381
  char     tb[TSDB_TABLE_NAME_LEN];
5382
  char     dbFName[TSDB_DB_FNAME_LEN];
5383
  uint64_t suid;
5384
  uint64_t destTbUid;
5385
  uint64_t dbId;
5386
  int32_t  version;
5387
  int64_t  interval;
5388
  int8_t   unit;
5389
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5390
  SArray*  pTags;      // SArray<SSchema>
5391
  SArray*  pUsedCols;  // SArray<SSchema>
5392
  char*    ast;
5393

5394
  int64_t streamUid;
5395
  int64_t reqTs;
5396
  int64_t rspTs;
5397
  int64_t delayDuration;  // ms
5398
  bool    fillHistoryFinished;
5399

5400
  void*   streamAddr;  // for stream task, the address of the stream task
5401
} STableTSMAInfo;
5402

5403
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5404
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5405
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5406
void    tFreeTableTSMAInfo(void* p);
5407
void    tFreeAndClearTableTSMAInfo(void* p);
5408
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5409

5410
#define STSMAHbRsp            STableTSMAInfoRsp
5411
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5412
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5413
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5414

5415
typedef struct SDropCtbWithTsmaSingleVgReq {
5416
  SVgroupInfo vgInfo;
5417
  SArray*     pTbs;  // SVDropTbReq
5418
} SMDropTbReqsOnSingleVg;
5419

5420
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5421
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5422
void    tFreeSMDropTbReqOnSingleVg(void* p);
5423

5424
typedef struct SDropTbsReq {
5425
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5426
} SMDropTbsReq;
5427

5428
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5429
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5430
void    tFreeSMDropTbsReq(void*);
5431

5432
typedef struct SVFetchTtlExpiredTbsRsp {
5433
  SArray* pExpiredTbs;  // SVDropTbReq
5434
  int32_t vgId;
5435
} SVFetchTtlExpiredTbsRsp;
5436

5437
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5438
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5439

5440
void tFreeFetchTtlExpiredTbsRsp(void* p);
5441

5442
void setDefaultOptionsForField(SFieldWithOptions* field);
5443
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5444

5445
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5446
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5447

5448
#ifdef USE_MOUNT
5449
typedef struct {
5450
  char     mountName[TSDB_MOUNT_NAME_LEN];
5451
  int8_t   ignoreExist;
5452
  int16_t  nMounts;
5453
  int32_t* dnodeIds;
5454
  char**   mountPaths;
5455
  int32_t  sqlLen;
5456
  char*    sql;
5457
} SCreateMountReq;
5458

5459
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5460
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5461
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5462

5463
typedef struct {
5464
  char    mountName[TSDB_MOUNT_NAME_LEN];
5465
  int8_t  ignoreNotExists;
5466
  int32_t sqlLen;
5467
  char*   sql;
5468
} SDropMountReq;
5469

5470
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5471
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5472
void    tFreeSDropMountReq(SDropMountReq* pReq);
5473

5474
typedef struct {
5475
  char     mountName[TSDB_MOUNT_NAME_LEN];
5476
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5477
  int64_t  mountUid;
5478
  int32_t  dnodeId;
5479
  uint32_t valLen;
5480
  int8_t   ignoreExist;
5481
  void*    pVal;
5482
} SRetrieveMountPathReq;
5483

5484
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5485
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5486

5487
typedef struct {
5488
  // path
5489
  int32_t diskPrimary;
5490
  // vgInfo
5491
  int32_t  vgId;
5492
  int32_t  cacheLastSize;
5493
  int32_t  szPage;
5494
  int32_t  szCache;
5495
  uint64_t szBuf;
5496
  int8_t   cacheLast;
5497
  int8_t   standby;
5498
  int8_t   hashMethod;
5499
  uint32_t hashBegin;
5500
  uint32_t hashEnd;
5501
  int16_t  hashPrefix;
5502
  int16_t  hashSuffix;
5503
  int16_t  sttTrigger;
5504
  // syncInfo
5505
  int32_t replications;
5506
  // tsdbInfo
5507
  int8_t  precision;
5508
  int8_t  compression;
5509
  int8_t  slLevel;
5510
  int32_t daysPerFile;
5511
  int32_t keep0;
5512
  int32_t keep1;
5513
  int32_t keep2;
5514
  int32_t keepTimeOffset;
5515
  int32_t minRows;
5516
  int32_t maxRows;
5517
  int32_t tsdbPageSize;
5518
  int32_t ssChunkSize;
5519
  int32_t ssKeepLocal;
5520
  int8_t  ssCompact;
5521
  // walInfo
5522
  int32_t walFsyncPeriod;      // millisecond
5523
  int32_t walRetentionPeriod;  // secs
5524
  int32_t walRollPeriod;       // secs
5525
  int64_t walRetentionSize;
5526
  int64_t walSegSize;
5527
  int32_t walLevel;
5528
  // encryptInfo
5529
  int32_t encryptAlgorithm;
5530
  // SVState
5531
  int64_t committed;
5532
  int64_t commitID;
5533
  int64_t commitTerm;
5534
  // stats
5535
  int64_t numOfSTables;
5536
  int64_t numOfCTables;
5537
  int64_t numOfNTables;
5538
  // dbInfo
5539
  uint64_t dbId;
5540
} SMountVgInfo;
5541

5542
typedef struct {
5543
  SMCreateStbReq req;
5544
  SArray*        pColExts;  // element: column id
5545
  SArray*        pTagExts;  // element: tag id
5546
} SMountStbInfo;
5547

5548
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5549
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5550

5551
typedef struct {
5552
  char     dbName[TSDB_DB_FNAME_LEN];
5553
  uint64_t dbId;
5554
  SArray*  pVgs;      // SMountVgInfo
5555
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5556
} SMountDbInfo;
5557

5558
typedef struct {
5559
  // common fields
5560
  char     mountName[TSDB_MOUNT_NAME_LEN];
5561
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5562
  int8_t   ignoreExist;
5563
  int64_t  mountUid;
5564
  int64_t  clusterId;
5565
  int32_t  dnodeId;
5566
  uint32_t valLen;
5567
  void*    pVal;
5568

5569
  // response fields
5570
  SArray* pDbs;  // SMountDbInfo
5571

5572
  // memory fields, no serialized
5573
  SArray*   pDisks[TFS_MAX_TIERS];
5574
  TdFilePtr pFile;
5575
} SMountInfo;
5576

5577
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5578
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5579
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5580

5581
typedef struct {
5582
  SCreateVnodeReq createReq;
5583
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5584
  char            mountName[TSDB_MOUNT_NAME_LEN];
5585
  int64_t         mountId;
5586
  int32_t         diskPrimary;
5587
  int32_t         mountVgId;
5588
  int64_t         committed;
5589
  int64_t         commitID;
5590
  int64_t         commitTerm;
5591
  int64_t         numOfSTables;
5592
  int64_t         numOfCTables;
5593
  int64_t         numOfNTables;
5594
} SMountVnodeReq;
5595

5596
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5597
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5598
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5599

5600
#endif  // USE_MOUNT
5601

5602
#pragma pack(pop)
5603

5604
typedef struct {
5605
  char        db[TSDB_DB_FNAME_LEN];
5606
  STimeWindow timeRange;
5607
  int32_t     sqlLen;
5608
  char*       sql;
5609
  SArray*     vgroupIds;
5610
} SScanDbReq;
5611

5612
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5613
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5614
void    tFreeSScanDbReq(SScanDbReq* pReq);
5615

5616
typedef struct {
5617
  int32_t scanId;
5618
  int8_t  bAccepted;
5619
} SScanDbRsp;
5620

5621
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5622
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5623

5624
typedef struct {
5625
  int32_t scanId;
5626
  int32_t sqlLen;
5627
  char*   sql;
5628
} SKillScanReq;
5629

5630
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5631
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5632
void    tFreeSKillScanReq(SKillScanReq* pReq);
5633

5634
typedef struct {
5635
  int32_t scanId;
5636
  int32_t vgId;
5637
  int32_t dnodeId;
5638
} SVKillScanReq;
5639

5640
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5641
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5642

5643
typedef struct {
5644
  int32_t scanId;
5645
  int32_t vgId;
5646
  int32_t dnodeId;
5647
  int32_t numberFileset;
5648
  int32_t finished;
5649
  int32_t progress;
5650
  int64_t remainingTime;
5651
} SQueryScanProgressRsp;
5652

5653
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5654
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5655

5656
typedef struct {
5657
  int32_t scanId;
5658
  int32_t vgId;
5659
  int32_t dnodeId;
5660
} SQueryScanProgressReq;
5661

5662
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5663
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5664

5665
typedef struct {
5666
  int64_t     dbUid;
5667
  char        db[TSDB_DB_FNAME_LEN];
5668
  int64_t     scanStartTime;
5669
  STimeWindow tw;
5670
  int32_t     scanId;
5671
} SScanVnodeReq;
5672

5673
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5674
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5675

5676
#ifdef __cplusplus
5677
}
5678
#endif
5679

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