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

taosdata / TDengine / #4848

12 Nov 2025 01:06AM UTC coverage: 63.27% (+0.6%) from 62.651%
#4848

push

travis-ci

web-flow
Merge f12882a7a into e27395247

33 of 36 new or added lines in 4 files covered. (91.67%)

2652 existing lines in 104 files now uncovered.

138980 of 219661 relevant lines covered (63.27%)

110230098.27 hits per line

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

84.31
/include/common/tmsg.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include "taosdef.h"
20
#include "taoserror.h"
21
#include "tarray.h"
22
#include "tcoding.h"
23
#include "tcol.h"
24
#include "tencode.h"
25
#include "thash.h"
26
#include "tlist.h"
27
#include "tname.h"
28
#include "trow.h"
29
#include "tuuid.h"
30

31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34

35
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
36

37
#define TD_MSG_NUMBER_
38
#undef TD_MSG_DICT_
39
#undef TD_MSG_INFO_
40
#undef TD_MSG_TYPE_INFO_
41
#undef TD_MSG_RANGE_CODE_
42
#undef TD_MSG_SEG_CODE_
43
#include "tmsgdef.h"
44

45
#undef TD_MSG_NUMBER_
46
#undef TD_MSG_DICT_
47
#undef TD_MSG_INFO_
48
#undef TD_MSG_TYPE_INFO_
49
#undef TD_MSG_RANGE_CODE_
50
#define TD_MSG_SEG_CODE_
51
#include "tmsgdef.h"
52

53
#undef TD_MSG_NUMBER_
54
#undef TD_MSG_DICT_
55
#undef TD_MSG_INFO_
56
#undef TD_MSG_TYPE_INFO_
57
#undef TD_MSG_SEG_CODE_
58
#undef TD_MSG_RANGE_CODE_
59
#include "tmsgdef.h"
60

61
extern char*   tMsgInfo[];
62
extern int32_t tMsgDict[];
63
extern int32_t tMsgRangeDict[];
64

65
typedef uint16_t tmsg_t;
66

67
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
68
#define TMSG_SEG_SEQ(TYPE)  ((TYPE)&0xff)
69
#define TMSG_INDEX(TYPE)    (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
70

71

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

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

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

98

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
  }
106
  return false;
217✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
688,664,126✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
649,846,573✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,338,510,699✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,840,569,219✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,840,569,219✔
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

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

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

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

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

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

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

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

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

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

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

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

654
typedef struct {
655
  int32_t contLen;
656
  int32_t vgId;
657
} SMsgHead;
658

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

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

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

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

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

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

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

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

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

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

742
typedef struct SVCTableMergeInfo {
743
  uint64_t uid;
744
  int32_t  numOfSrcTbls;
745
} SVCTableMergeInfo;
746

747
typedef struct {
748
  int32_t    nCols;
749
  SColRefEx* pColRefEx;
750
} SColRefExWrapper;
751

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

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

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

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

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

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

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

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

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

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

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

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

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

862
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
863

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

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

880
typedef struct {
881
  STypeMod typeMod;
882
} SExtSchema;
883

884
bool hasExtSchema(const SExtSchema* pExtSchema);
885

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

893
typedef struct {
894
  col_id_t id;
895
  uint32_t alg;
896
} SColCmpr;
897

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

904
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
905
  if (pRef->pColRef) {
430,936✔
906
    return TSDB_CODE_INVALID_PARA;
×
907
  }
908
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
430,936✔
909
  if (pRef->pColRef == NULL) {
430,936✔
910
    return terrno;
×
911
  }
912
  pRef->nCols = nCols;
430,936✔
913
  for (int32_t i = 0; i < nCols; i++) {
4,932,493✔
914
    pRef->pColRef[i].hasRef = false;
4,501,557✔
915
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4,501,557✔
916
  }
917
  return 0;
430,936✔
918
}
919

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

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

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

941
  return pDstWrapper;
942
}
943

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

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

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

977
  taosMemoryFreeClear(pWrapper->pColCmpr);
978
  taosMemoryFreeClear(pWrapper);
979
}
980
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
981
  if (pSchemaWrapper->pSchema == NULL) return NULL;
315,789,827✔
982

983
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
315,762,918✔
984
  if (pSW == NULL) {
315,774,008✔
985
    return NULL;
×
986
  }
987
  pSW->nCols = pSchemaWrapper->nCols;
315,774,008✔
988
  pSW->version = pSchemaWrapper->version;
315,771,782✔
989
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
315,826,897✔
990
  if (pSW->pSchema == NULL) {
315,706,463✔
991
    taosMemoryFree(pSW);
×
992
    return NULL;
×
993
  }
994

995
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
315,721,535✔
996
  return pSW;
315,810,225✔
997
}
998

999
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
78,474,493✔
1000
  if (pSchemaWrapper) {
847,661,521✔
1001
    taosMemoryFree(pSchemaWrapper->pSchema);
472,292,699✔
1002
    if(pSchemaWrapper->pRsma) {
472,250,643✔
1003
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
54,000✔
1004
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
54,000✔
1005
    }
1006
    taosMemoryFree(pSchemaWrapper);
472,271,707✔
1007
  }
1008
}
834,046,186✔
1009

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

1020
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
2,348,289✔
1021
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
2,348,289✔
1022
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
2,348,289✔
1023
  }
1024
}
2,348,289✔
1025

1026
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1027
  int32_t tlen = 0;
3,541,066✔
1028
  tlen += taosEncodeFixedI8(buf, pSchema->type);
3,553,222✔
1029
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
3,541,066✔
1030
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
3,541,066✔
1031
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
3,541,066✔
1032
  tlen += taosEncodeString(buf, pSchema->name);
3,541,066✔
1033
  return tlen;
3,541,066✔
1034
}
1035

1036
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1037
  buf = taosDecodeFixedI8(buf, &pSchema->type);
2,100,436✔
1038
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,825,820✔
1039
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,825,820✔
1040
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,825,820✔
1041
  buf = taosDecodeStringTo(buf, pSchema->name);
1,825,820✔
1042
  return (void*)buf;
1,825,820✔
1043
}
1044

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

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

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

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

1077
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1078
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
28,730,132✔
1079
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
28,730,132✔
1080
  if (pColRef->hasRef) {
14,365,066✔
1081
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
17,175,172✔
1082
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
17,175,172✔
1083
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
17,175,172✔
1084
  }
1085
  return 0;
14,365,066✔
1086
}
1087

1088
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1089
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
16,235,480✔
1090
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
16,235,480✔
1091
  if (pColRef->hasRef) {
8,117,740✔
1092
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
5,088,121✔
1093
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
5,088,121✔
1094
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
5,088,121✔
1095
  }
1096

1097
  return 0;
8,117,740✔
1098
}
1099

1100
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1101
  int32_t tlen = 0;
421,792✔
1102
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
421,792✔
1103
  tlen += taosEncodeVariantI32(buf, pSW->version);
421,792✔
1104
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,962,858✔
1105
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
7,082,132✔
1106
  }
1107
  return tlen;
421,792✔
1108
}
1109

1110
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1111
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
276,164✔
1112
  buf = taosDecodeVariantI32(buf, &pSW->version);
276,164✔
1113
  if (pSW->nCols > 0) {
276,164✔
1114
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
236,671✔
1115
    if (pSW->pSchema == NULL) {
236,671✔
1116
      return NULL;
×
1117
    }
1118

1119
    for (int32_t i = 0; i < pSW->nCols; i++) {
2,062,491✔
1120
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
3,651,640✔
1121
    }
1122
  } else {
1123
    pSW->pSchema = NULL;
39,493✔
1124
  }
1125
  return (void*)buf;
276,164✔
1126
}
1127

1128
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1129
  if (pSW == NULL) {
200,207,240✔
1130
    return TSDB_CODE_INVALID_PARA;
×
1131
  }
1132
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
400,380,578✔
1133
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
400,297,090✔
1134
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1135
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1136
  }
1137
  return 0;
200,284,887✔
1138
}
1139

1140
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1141
  if (pSW == NULL) {
57,587,599✔
1142
    return TSDB_CODE_INVALID_PARA;
×
1143
  }
1144
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
115,159,668✔
1145
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
115,166,559✔
1146

1147
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
57,594,490✔
1148
  if (pSW->pSchema == NULL) {
57,549,322✔
1149
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1150
  }
1151
  for (int32_t i = 0; i < pSW->nCols; i++) {
606,457,384✔
1152
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,097,675,320✔
1153
  }
1154

1155
  return 0;
57,606,952✔
1156
}
1157

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

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

1170
  return 0;
1,464,102,271✔
1171
}
1172

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

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

1210
typedef struct {
1211
  STableMetaRsp* pMeta;
1212
} SMCreateStbRsp;
1213

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

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

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

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

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

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

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

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

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

1275
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1276
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1277

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

1297
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1298
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1299

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

1311
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1312
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1313

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

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

1324
typedef struct SIpV4Range {
1325
  uint32_t ip;
1326
  uint32_t mask;
1327
} SIpV4Range;
1328

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

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

1342
typedef struct {
1343
  int32_t    num;
1344
  SIpV4Range pIpRange[];
1345
} SIpWhiteList;
1346

1347
typedef struct {
1348
  int32_t  num;
1349
  SIpRange pIpRanges[];
1350
} SIpWhiteListDual;
1351

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

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

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

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

1380
typedef struct {
1381
  int32_t dnodeId;
1382
  int64_t analVer;
1383
} SRetrieveAnalyticsAlgoReq;
1384

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

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

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

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

1428
typedef struct {
1429
  char user[TSDB_USER_LEN];
1430
} SGetUserAuthReq;
1431

1432
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1433
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1434

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

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

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

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

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

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

1487
typedef struct {
1488
  int64_t ipWhiteVer;
1489
} SRetrieveIpWhiteReq;
1490

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

1497
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1498
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1499

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

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

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

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

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

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

1540
typedef struct STimeWindow {
1541
  TSKEY skey;
1542
  TSKEY ekey;
1543
} STimeWindow;
1544

1545
typedef struct SQueryHint {
1546
  bool batchScan;
1547
} SQueryHint;
1548

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

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

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

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

1581
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1582

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

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

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

1615
typedef STableCfg STableCfgRsp;
1616

1617
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1618
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1619

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

1624
typedef struct {
1625
  SMsgHead header;
1626
  tb_uid_t suid;
1627
} SVSubTablesReq;
1628

1629
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1630
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1631

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

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

1641
typedef struct {
1642
  SMsgHead header;
1643
  tb_uid_t suid;
1644
} SVStbRefDbsReq;
1645

1646
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1647
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1648

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

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

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

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

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

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

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

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

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

1764
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1765
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1766

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

1772
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1773
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1774

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

1783
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1784
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1785

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

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

1812
typedef struct {
1813
  char db[TSDB_DB_FNAME_LEN];
1814
} SDbCfgReq;
1815

1816
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1817
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1818

1819
typedef struct {
1820
  char db[TSDB_DB_FNAME_LEN];
1821
} SSsMigrateDbReq;
1822

1823
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1824
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1825

1826
typedef struct {
1827
  int32_t ssMigrateId;
1828
  bool    bAccepted;
1829
} SSsMigrateDbRsp;
1830

1831
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1832
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1833

1834

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

1840
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1841
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1842

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

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

1853

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

1862
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1863
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1864

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

1872
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1873
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1874

1875

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

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

1894
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1895
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1896

1897

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

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

1909
// Request for TDMT_VND_KILL_SSMIGRATE
1910
typedef struct {
1911
  int32_t ssMigrateId;
1912
} SVnodeKillSsMigrateReq;
1913

1914
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1915
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
1916

1917

1918
typedef struct {
1919
  int32_t timestampSec;
1920
  int32_t ttlDropMaxCount;
1921
  int32_t nUids;
1922
  SArray* pTbUids;
1923
} SVDropTtlTableReq;
1924

1925
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1926
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1927

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

1982
typedef SDbCfgRsp SDbCfgInfo;
1983

1984
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1985
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1986
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1987
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1988
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1989

1990
typedef struct {
1991
  int32_t rowNum;
1992
} SQnodeListReq;
1993

1994
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1995
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1996

1997
typedef struct {
1998
  int32_t rowNum;
1999
} SDnodeListReq;
2000

2001
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2002

2003
typedef struct {
2004
  int32_t useless;  // useless
2005
} SServerVerReq;
2006

2007
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2008
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2009

2010
typedef struct {
2011
  char ver[TSDB_VERSION_LEN];
2012
} SServerVerRsp;
2013

2014
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2015
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2016

2017
typedef struct SQueryNodeAddr {
2018
  int32_t nodeId;  // vgId or qnodeId
2019
  SEpSet  epSet;
2020
} SQueryNodeAddr;
2021

2022
typedef struct {
2023
  SQueryNodeAddr addr;
2024
  uint64_t       load;
2025
} SQueryNodeLoad;
2026

2027
typedef struct {
2028
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2029
} SQnodeListRsp;
2030

2031
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2032
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2033
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2034

2035
typedef struct SDNodeAddr {
2036
  int32_t nodeId;  // dnodeId
2037
  SEpSet  epSet;
2038
} SDNodeAddr;
2039

2040
typedef struct {
2041
  SArray* dnodeList;  // SArray<SDNodeAddr>
2042
} SDnodeListRsp;
2043

2044
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2045
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2046
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2047

2048
typedef struct {
2049
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2050
} STableTSMAInfoRsp;
2051

2052
typedef struct {
2053
  SUseDbRsp*         useDbRsp;
2054
  SDbCfgRsp*         cfgRsp;
2055
  STableTSMAInfoRsp* pTsmaRsp;
2056
  int32_t            dbTsmaVersion;
2057
  char               db[TSDB_DB_FNAME_LEN];
2058
  int64_t            dbId;
2059
} SDbHbRsp;
2060

2061
typedef struct {
2062
  SArray* pArray;  // Array of SDbHbRsp
2063
} SDbHbBatchRsp;
2064

2065
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2066
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2067
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2068

2069
typedef struct {
2070
  SArray* pArray;  // Array of SGetUserAuthRsp
2071
} SUserAuthBatchRsp;
2072

2073
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2074
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2075
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2076

2077
typedef struct {
2078
  char        db[TSDB_DB_FNAME_LEN];
2079
  STimeWindow timeRange;
2080
  int32_t     sqlLen;
2081
  char*       sql;
2082
  SArray*     vgroupIds;
2083
  int32_t     compactId;
2084
  int8_t      metaOnly;
2085
  int8_t      force;
2086
} SCompactDbReq;
2087

2088
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2089
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2090
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2091

2092
typedef struct {
2093
  union {
2094
    int32_t compactId;
2095
    int32_t id;
2096
  };
2097
  int8_t bAccepted;
2098
} SCompactDbRsp;
2099

2100
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2101
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2102

2103
typedef struct {
2104
  union {
2105
    int32_t compactId;
2106
    int32_t id;
2107
  };
2108
  int32_t sqlLen;
2109
  char*   sql;
2110
} SKillCompactReq;
2111

2112
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2113
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2114
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2115

2116
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2117
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2118

2119
typedef struct {
2120
  char    name[TSDB_FUNC_NAME_LEN];
2121
  int8_t  igExists;
2122
  int8_t  funcType;
2123
  int8_t  scriptType;
2124
  int8_t  outputType;
2125
  int32_t outputLen;
2126
  int32_t bufSize;
2127
  int32_t codeLen;
2128
  int64_t signature;
2129
  char*   pComment;
2130
  char*   pCode;
2131
  int8_t  orReplace;
2132
} SCreateFuncReq;
2133

2134
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2135
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2136
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2137

2138
typedef struct {
2139
  char   name[TSDB_FUNC_NAME_LEN];
2140
  int8_t igNotExists;
2141
} SDropFuncReq;
2142

2143
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2144
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2145

2146
typedef struct {
2147
  int32_t numOfFuncs;
2148
  bool    ignoreCodeComment;
2149
  SArray* pFuncNames;
2150
} SRetrieveFuncReq;
2151

2152
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2153
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2154
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2155

2156
typedef struct {
2157
  char    name[TSDB_FUNC_NAME_LEN];
2158
  int8_t  funcType;
2159
  int8_t  scriptType;
2160
  int8_t  outputType;
2161
  int32_t outputLen;
2162
  int32_t bufSize;
2163
  int64_t signature;
2164
  int32_t commentSize;
2165
  int32_t codeSize;
2166
  char*   pComment;
2167
  char*   pCode;
2168
} SFuncInfo;
2169

2170
typedef struct {
2171
  int32_t funcVersion;
2172
  int64_t funcCreatedTime;
2173
} SFuncExtraInfo;
2174

2175
typedef struct {
2176
  int32_t numOfFuncs;
2177
  SArray* pFuncInfos;
2178
  SArray* pFuncExtraInfos;
2179
} SRetrieveFuncRsp;
2180

2181
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2182
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2183
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2184
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2185

2186
typedef struct {
2187
  int32_t       statusInterval;
2188
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2189
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2190
  char          locale[TD_LOCALE_LEN];      // tsLocale
2191
  char          charset[TD_LOCALE_LEN];     // tsCharset
2192
  int8_t        ttlChangeOnWrite;
2193
  int8_t        enableWhiteList;
2194
  int8_t        encryptionKeyStat;
2195
  uint32_t      encryptionKeyChksum;
2196
  SMonitorParas monitorParas;
2197
  int32_t       statusIntervalMs;
2198
} SClusterCfg;
2199

2200
typedef struct {
2201
  int32_t openVnodes;
2202
  int32_t dropVnodes;
2203
  int32_t totalVnodes;
2204
  int32_t masterNum;
2205
  int64_t numOfSelectReqs;
2206
  int64_t numOfInsertReqs;
2207
  int64_t numOfInsertSuccessReqs;
2208
  int64_t numOfBatchInsertReqs;
2209
  int64_t numOfBatchInsertSuccessReqs;
2210
  int64_t errors;
2211
} SVnodesStat;
2212

2213
typedef struct {
2214
  int32_t vgId;
2215
  int8_t  syncState;
2216
  int8_t  syncRestore;
2217
  int64_t syncTerm;
2218
  int64_t roleTimeMs;
2219
  int64_t startTimeMs;
2220
  int8_t  syncCanRead;
2221
  int64_t cacheUsage;
2222
  int64_t numOfTables;
2223
  int64_t numOfTimeSeries;
2224
  int64_t totalStorage;
2225
  int64_t compStorage;
2226
  int64_t pointsWritten;
2227
  int64_t numOfSelectReqs;
2228
  int64_t numOfInsertReqs;
2229
  int64_t numOfInsertSuccessReqs;
2230
  int64_t numOfBatchInsertReqs;
2231
  int64_t numOfBatchInsertSuccessReqs;
2232
  int32_t numOfCachedTables;
2233
  int32_t learnerProgress;  // use one reservered
2234
  int64_t syncAppliedIndex;
2235
  int64_t syncCommitIndex;
2236
  int64_t bufferSegmentUsed;
2237
  int64_t bufferSegmentSize;
2238
} SVnodeLoad;
2239

2240
typedef struct {
2241
  int64_t total_requests;
2242
  int64_t total_rows;
2243
  int64_t total_bytes;
2244
  double  write_size;
2245
  double  cache_hit_ratio;
2246
  int64_t rpc_queue_wait;
2247
  int64_t preprocess_time;
2248

2249
  int64_t memory_table_size;
2250
  int64_t commit_count;
2251
  int64_t merge_count;
2252
  double  commit_time;
2253
  double  merge_time;
2254
  int64_t block_commit_time;
2255
  int64_t memtable_wait_time;
2256
} SVnodeMetrics;
2257

2258
typedef struct {
2259
  int32_t     vgId;
2260
  int64_t     numOfTables;
2261
  int64_t     memSize;
2262
  int64_t     l1Size;
2263
  int64_t     l2Size;
2264
  int64_t     l3Size;
2265
  int64_t     cacheSize;
2266
  int64_t     walSize;
2267
  int64_t     metaSize;
2268
  int64_t     rawDataSize;
2269
  int64_t     ssSize;
2270
  const char* dbname;
2271
  int8_t      estimateRawData;
2272
} SDbSizeStatisInfo;
2273

2274
typedef struct {
2275
  int32_t vgId;
2276
  int64_t nTimeSeries;
2277
} SVnodeLoadLite;
2278

2279
typedef struct {
2280
  int8_t  syncState;
2281
  int64_t syncTerm;
2282
  int8_t  syncRestore;
2283
  int64_t roleTimeMs;
2284
} SMnodeLoad;
2285

2286
typedef struct {
2287
  int32_t dnodeId;
2288
  int64_t numOfProcessedQuery;
2289
  int64_t numOfProcessedCQuery;
2290
  int64_t numOfProcessedFetch;
2291
  int64_t numOfProcessedDrop;
2292
  int64_t numOfProcessedNotify;
2293
  int64_t numOfProcessedHb;
2294
  int64_t numOfProcessedDelete;
2295
  int64_t cacheDataSize;
2296
  int64_t numOfQueryInQueue;
2297
  int64_t numOfFetchInQueue;
2298
  int64_t timeInQueryQueue;
2299
  int64_t timeInFetchQueue;
2300
} SQnodeLoad;
2301

2302
typedef struct {
2303
  int32_t     sver;      // software version
2304
  int64_t     dnodeVer;  // dnode table version in sdb
2305
  int32_t     dnodeId;
2306
  int64_t     clusterId;
2307
  int64_t     rebootTime;
2308
  int64_t     updateTime;
2309
  float       numOfCores;
2310
  int32_t     numOfSupportVnodes;
2311
  int32_t     numOfDiskCfg;
2312
  int64_t     memTotal;
2313
  int64_t     memAvail;
2314
  char        dnodeEp[TSDB_EP_LEN];
2315
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2316
  SMnodeLoad  mload;
2317
  SQnodeLoad  qload;
2318
  SClusterCfg clusterCfg;
2319
  SArray*     pVloads;  // array of SVnodeLoad
2320
  int32_t     statusSeq;
2321
  int64_t     ipWhiteVer;
2322
  int64_t     analVer;
2323
  int64_t     timestamp;
2324
} SStatusReq;
2325

2326
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2327
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2328
void    tFreeSStatusReq(SStatusReq* pReq);
2329

2330
typedef struct {
2331
  int32_t forceReadConfig;
2332
  int32_t cver;
2333
  SArray* array;
2334
} SConfigReq;
2335

2336
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2337
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2338
void    tFreeSConfigReq(SConfigReq* pReq);
2339

2340
typedef struct {
2341
  int32_t dnodeId;
2342
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2343
} SDnodeInfoReq;
2344

2345
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2346
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2347

2348
typedef enum {
2349
  MONITOR_TYPE_COUNTER = 0,
2350
  MONITOR_TYPE_SLOW_LOG = 1,
2351
} MONITOR_TYPE;
2352

2353
typedef struct {
2354
  int32_t      contLen;
2355
  char*        pCont;
2356
  MONITOR_TYPE type;
2357
} SStatisReq;
2358

2359
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2360
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2361
void    tFreeSStatisReq(SStatisReq* pReq);
2362

2363
typedef struct {
2364
  char    db[TSDB_DB_FNAME_LEN];
2365
  char    table[TSDB_TABLE_NAME_LEN];
2366
  char    operation[AUDIT_OPERATION_LEN];
2367
  int32_t sqlLen;
2368
  char*   pSql;
2369
} SAuditReq;
2370
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2371
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2372
void    tFreeSAuditReq(SAuditReq* pReq);
2373

2374
typedef struct {
2375
  int32_t dnodeId;
2376
  int64_t clusterId;
2377
  SArray* pVloads;
2378
} SNotifyReq;
2379

2380
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2381
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2382
void    tFreeSNotifyReq(SNotifyReq* pReq);
2383

2384
typedef struct {
2385
  int32_t dnodeId;
2386
  int64_t clusterId;
2387
} SDnodeCfg;
2388

2389
typedef struct {
2390
  int32_t id;
2391
  int8_t  isMnode;
2392
  SEp     ep;
2393
} SDnodeEp;
2394

2395
typedef struct {
2396
  int32_t id;
2397
  int8_t  isMnode;
2398
  int8_t  offlineReason;
2399
  SEp     ep;
2400
  char    active[TSDB_ACTIVE_KEY_LEN];
2401
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2402
} SDnodeInfo;
2403

2404
typedef struct {
2405
  int64_t   dnodeVer;
2406
  SDnodeCfg dnodeCfg;
2407
  SArray*   pDnodeEps;  // Array of SDnodeEp
2408
  int32_t   statusSeq;
2409
  int64_t   ipWhiteVer;
2410
  int64_t   analVer;
2411
} SStatusRsp;
2412

2413
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2414
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2415
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2416

2417
typedef struct {
2418
  int32_t forceReadConfig;
2419
  int32_t isConifgVerified;
2420
  int32_t isVersionVerified;
2421
  int32_t cver;
2422
  SArray* array;
2423
} SConfigRsp;
2424

2425
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2426
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2427
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2428

2429
typedef struct {
2430
  int32_t reserved;
2431
} SMTimerReq;
2432

2433
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2434
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2435

2436
typedef struct SOrphanTask {
2437
  int64_t streamId;
2438
  int32_t taskId;
2439
  int32_t nodeId;
2440
} SOrphanTask;
2441

2442
typedef struct SMStreamDropOrphanMsg {
2443
  SArray* pList;  // SArray<SOrphanTask>
2444
} SMStreamDropOrphanMsg;
2445

2446
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2447
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2448
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2449

2450
typedef struct {
2451
  int32_t  id;
2452
  uint16_t port;                 // node sync Port
2453
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2454
} SReplica;
2455

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

2508
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2509
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2510
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2511

2512
typedef struct {
2513
  union {
2514
    int32_t compactId;
2515
    int32_t id;
2516
  };
2517
  int32_t vgId;
2518
  int32_t dnodeId;
2519
} SQueryCompactProgressReq;
2520

2521
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2522
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2523

2524
typedef struct {
2525
  union {
2526
    int32_t compactId;
2527
    int32_t id;
2528
  };
2529
  int32_t vgId;
2530
  int32_t dnodeId;
2531
  int32_t numberFileset;
2532
  int32_t finished;
2533
  int32_t progress;
2534
  int64_t remainingTime;
2535
} SQueryCompactProgressRsp;
2536

2537
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2538
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2539

2540
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2541
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2542

2543
typedef struct {
2544
  int32_t vgId;
2545
  int32_t dnodeId;
2546
  int64_t dbUid;
2547
  char    db[TSDB_DB_FNAME_LEN];
2548
  int64_t reserved[8];
2549
} SDropVnodeReq;
2550

2551
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2552
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2553

2554
typedef struct {
2555
  char    colName[TSDB_COL_NAME_LEN];
2556
  char    stb[TSDB_TABLE_FNAME_LEN];
2557
  int64_t stbUid;
2558
  int64_t dbUid;
2559
  int64_t reserved[8];
2560
} SDropIndexReq;
2561

2562
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2563
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2564

2565
typedef struct {
2566
  int64_t dbUid;
2567
  char    db[TSDB_DB_FNAME_LEN];
2568
  union {
2569
    int64_t compactStartTime;
2570
    int64_t startTime;
2571
  };
2572

2573
  STimeWindow tw;
2574
  union {
2575
    int32_t compactId;
2576
    int32_t id;
2577
  };
2578
  int8_t metaOnly;
2579
  union {
2580
    uint16_t flags;
2581
    struct {
2582
      uint16_t optrType : 3;     // ETsdbOpType
2583
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2584
      uint16_t reserved : 12;
2585
    };
2586
  };
2587
  int8_t force;  // force compact
2588
} SCompactVnodeReq;
2589

2590
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2591
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2592

2593
typedef struct {
2594
  union {
2595
    int32_t compactId;
2596
    int32_t taskId;
2597
  };
2598
  int32_t vgId;
2599
  int32_t dnodeId;
2600
} SVKillCompactReq;
2601

2602
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2603
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2604

2605
typedef SVKillCompactReq SVKillRetentionReq;
2606

2607
typedef struct {
2608
  char        db[TSDB_DB_FNAME_LEN];
2609
  int32_t     maxSpeed;
2610
  int32_t     sqlLen;
2611
  char*       sql;
2612
  SArray*     vgroupIds;
2613
  STimeWindow tw;  // unit is second
2614
  union {
2615
    uint32_t flags;
2616
    struct {
2617
      uint32_t optrType : 3;     // ETsdbOpType
2618
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2619
      uint32_t reserved : 28;
2620
    };
2621
  };
2622
} STrimDbReq;
2623

2624
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2625
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2626
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2627

2628
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2629

2630
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2631
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2632

2633
typedef struct {
2634
  int32_t vgVersion;
2635
  int32_t buffer;
2636
  int32_t pageSize;
2637
  int32_t pages;
2638
  int32_t cacheLastSize;
2639
  int32_t daysPerFile;
2640
  int32_t daysToKeep0;
2641
  int32_t daysToKeep1;
2642
  int32_t daysToKeep2;
2643
  int32_t keepTimeOffset;
2644
  int32_t walFsyncPeriod;
2645
  int8_t  walLevel;
2646
  int8_t  strict;
2647
  int8_t  cacheLast;
2648
  int64_t reserved[7];
2649
  // 1st modification
2650
  int16_t sttTrigger;
2651
  int32_t minRows;
2652
  // 2nd modification
2653
  int32_t walRetentionPeriod;
2654
  int32_t walRetentionSize;
2655
  int32_t ssKeepLocal;
2656
  int8_t  ssCompact;
2657
} SAlterVnodeConfigReq;
2658

2659
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2660
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2661

2662
typedef struct {
2663
  int32_t  vgId;
2664
  int8_t   strict;
2665
  int8_t   selfIndex;
2666
  int8_t   replica;
2667
  SReplica replicas[TSDB_MAX_REPLICA];
2668
  int64_t  reserved[8];
2669
  int8_t   learnerSelfIndex;
2670
  int8_t   learnerReplica;
2671
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2672
  int32_t  changeVersion;
2673
  int32_t  electBaseLine;
2674
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2675

2676
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2677
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2678

2679
typedef struct {
2680
  int32_t vgId;
2681
  int8_t  disable;
2682
} SDisableVnodeWriteReq;
2683

2684
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2685
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2686

2687
typedef struct {
2688
  int32_t  srcVgId;
2689
  int32_t  dstVgId;
2690
  uint32_t hashBegin;
2691
  uint32_t hashEnd;
2692
  int32_t  changeVersion;
2693
  int32_t  reserved;
2694
} SAlterVnodeHashRangeReq;
2695

2696
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2697
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2698

2699
#define REQ_OPT_TBNAME 0x0
2700
#define REQ_OPT_TBUID  0x01
2701
typedef struct {
2702
  SMsgHead header;
2703
  char     dbFName[TSDB_DB_FNAME_LEN];
2704
  char     tbName[TSDB_TABLE_NAME_LEN];
2705
  uint8_t  option;
2706
  uint8_t  autoCreateCtb;
2707
} STableInfoReq;
2708

2709
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2710
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2711

2712
typedef struct {
2713
  int8_t  metaClone;  // create local clone of the cached table meta
2714
  int32_t numOfVgroups;
2715
  int32_t numOfTables;
2716
  int32_t numOfUdfs;
2717
  char    tableNames[];
2718
} SMultiTableInfoReq;
2719

2720
// todo refactor
2721
typedef struct SVgroupInfo {
2722
  int32_t  vgId;
2723
  uint32_t hashBegin;
2724
  uint32_t hashEnd;
2725
  SEpSet   epSet;
2726
  union {
2727
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2728
    int32_t taskId;      // used in stream
2729
  };
2730
} SVgroupInfo;
2731

2732
typedef struct {
2733
  int32_t     numOfVgroups;
2734
  SVgroupInfo vgroups[];
2735
} SVgroupsInfo;
2736

2737
typedef struct {
2738
  STableMetaRsp* pMeta;
2739
} SMAlterStbRsp;
2740

2741
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2742
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2743
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2744

2745
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2746
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2747
void    tFreeSTableMetaRsp(void* pRsp);
2748
void    tFreeSTableIndexRsp(void* info);
2749

2750
typedef struct {
2751
  SArray* pMetaRsp;   // Array of STableMetaRsp
2752
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2753
} SSTbHbRsp;
2754

2755
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2756
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2757
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2758

2759
typedef struct {
2760
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2761
} SViewHbRsp;
2762

2763
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2764
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2765
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2766

2767
typedef struct {
2768
  int32_t numOfTables;
2769
  int32_t numOfVgroup;
2770
  int32_t numOfUdf;
2771
  int32_t contLen;
2772
  int8_t  compressed;  // denote if compressed or not
2773
  int32_t rawLen;      // size before compress
2774
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2775
  char    meta[];
2776
} SMultiTableMeta;
2777

2778
typedef struct {
2779
  int32_t dataLen;
2780
  char    name[TSDB_TABLE_FNAME_LEN];
2781
  char*   data;
2782
} STagData;
2783

2784
typedef struct {
2785
  int32_t  opType;
2786
  uint32_t valLen;
2787
  char*    val;
2788
} SShowVariablesReq;
2789

2790
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2791
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2792
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2793

2794
typedef struct {
2795
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2796
  char value[TSDB_CONFIG_PATH_LEN + 1];
2797
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2798
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2799
  char info[TSDB_CONFIG_INFO_LEN + 1];
2800
} SVariablesInfo;
2801

2802
typedef struct {
2803
  SArray* variables;  // SArray<SVariablesInfo>
2804
} SShowVariablesRsp;
2805

2806
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2807
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2808

2809
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2810

2811
/*
2812
 * sql: show tables like '%a_%'
2813
 * payload is the query condition, e.g., '%a_%'
2814
 * payloadLen is the length of payload
2815
 */
2816
typedef struct {
2817
  int32_t type;
2818
  char    db[TSDB_DB_FNAME_LEN];
2819
  int32_t payloadLen;
2820
  char*   payload;
2821
} SShowReq;
2822

2823
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2824
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2825
void tFreeSShowReq(SShowReq* pReq);
2826

2827
typedef struct {
2828
  int64_t       showId;
2829
  STableMetaRsp tableMeta;
2830
} SShowRsp, SVShowTablesRsp;
2831

2832
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2833
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2834
// void    tFreeSShowRsp(SShowRsp* pRsp);
2835

2836
typedef struct {
2837
  char    db[TSDB_DB_FNAME_LEN];
2838
  char    tb[TSDB_TABLE_NAME_LEN];
2839
  char    user[TSDB_USER_LEN];
2840
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2841
  int64_t showId;
2842
  int64_t compactId;  // for compact
2843
  bool    withFull;   // for show users full
2844
} SRetrieveTableReq;
2845

2846
typedef struct SSysTableSchema {
2847
  int8_t   type;
2848
  col_id_t colId;
2849
  int32_t  bytes;
2850
} SSysTableSchema;
2851

2852
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2853
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2854

2855
#define RETRIEVE_TABLE_RSP_VERSION         0
2856
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2857
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2858

2859
typedef struct {
2860
  int64_t useconds;
2861
  int8_t  completed;  // all results are returned to client
2862
  int8_t  precision;
2863
  int8_t  compressed;
2864
  int8_t  streamBlockType;
2865
  int32_t payloadLen;
2866
  int32_t compLen;
2867
  int32_t numOfBlocks;
2868
  int64_t numOfRows;  // from int32_t change to int64_t
2869
  int64_t numOfCols;
2870
  int64_t skey;
2871
  int64_t ekey;
2872
  int64_t version;                         // for stream
2873
  TSKEY   watermark;                       // for stream
2874
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2875
  char    data[];
2876
} SRetrieveTableRsp;
2877

2878
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2879

2880
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2881
  do {                                          \
2882
    ((int32_t*)(_p))[0] = (_compLen);           \
2883
    ((int32_t*)(_p))[1] = (_fullLen);           \
2884
  } while (0);
2885

2886
typedef struct {
2887
  int64_t version;
2888
  int64_t numOfRows;
2889
  int8_t  compressed;
2890
  int8_t  precision;
2891
  char    data[];
2892
} SRetrieveTableRspForTmq;
2893

2894
typedef struct {
2895
  int64_t handle;
2896
  int64_t useconds;
2897
  int8_t  completed;  // all results are returned to client
2898
  int8_t  precision;
2899
  int8_t  compressed;
2900
  int32_t compLen;
2901
  int32_t numOfRows;
2902
  int32_t fullLen;
2903
  char    data[];
2904
} SRetrieveMetaTableRsp;
2905

2906
typedef struct SExplainExecInfo {
2907
  double   startupCost;
2908
  double   totalCost;
2909
  uint64_t numOfRows;
2910
  uint32_t verboseLen;
2911
  void*    verboseInfo;
2912
} SExplainExecInfo;
2913

2914
typedef struct {
2915
  int32_t           numOfPlans;
2916
  SExplainExecInfo* subplanInfo;
2917
} SExplainRsp;
2918

2919
typedef struct {
2920
  SExplainRsp rsp;
2921
  uint64_t    qId;
2922
  uint64_t    cId;
2923
  uint64_t    tId;
2924
  int64_t     rId;
2925
  int32_t     eId;
2926
} SExplainLocalRsp;
2927

2928
typedef struct STableScanAnalyzeInfo {
2929
  uint64_t totalRows;
2930
  uint64_t totalCheckedRows;
2931
  uint32_t totalBlocks;
2932
  uint32_t loadBlocks;
2933
  uint32_t loadBlockStatis;
2934
  uint32_t skipBlocks;
2935
  uint32_t filterOutBlocks;
2936
  double   elapsedTime;
2937
  double   filterTime;
2938
} STableScanAnalyzeInfo;
2939

2940
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2941
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2942
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2943

2944
typedef struct {
2945
  char    config[TSDB_DNODE_CONFIG_LEN];
2946
  char    value[TSDB_CLUSTER_VALUE_LEN];
2947
  int32_t sqlLen;
2948
  char*   sql;
2949
} SMCfgClusterReq;
2950

2951
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2952
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2953
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2954

2955
typedef struct {
2956
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2957
  int32_t port;
2958
  int32_t sqlLen;
2959
  char*   sql;
2960
} SCreateDnodeReq;
2961

2962
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2963
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2964
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2965

2966
typedef struct {
2967
  int32_t dnodeId;
2968
  char    fqdn[TSDB_FQDN_LEN];
2969
  int32_t port;
2970
  int8_t  force;
2971
  int8_t  unsafe;
2972
  int32_t sqlLen;
2973
  char*   sql;
2974
} SDropDnodeReq;
2975

2976
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2977
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2978
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2979

2980
enum {
2981
  RESTORE_TYPE__ALL = 1,
2982
  RESTORE_TYPE__MNODE,
2983
  RESTORE_TYPE__VNODE,
2984
  RESTORE_TYPE__QNODE,
2985
};
2986

2987
typedef struct {
2988
  int32_t dnodeId;
2989
  int8_t  restoreType;
2990
  int32_t sqlLen;
2991
  char*   sql;
2992
} SRestoreDnodeReq;
2993

2994
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2995
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2996
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2997

2998
typedef struct {
2999
  int32_t dnodeId;
3000
  char    config[TSDB_DNODE_CONFIG_LEN];
3001
  char    value[TSDB_DNODE_VALUE_LEN];
3002
  int32_t sqlLen;
3003
  char*   sql;
3004
} SMCfgDnodeReq;
3005

3006
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3007
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3008
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3009

3010
typedef struct {
3011
  char    config[TSDB_DNODE_CONFIG_LEN];
3012
  char    value[TSDB_DNODE_VALUE_LEN];
3013
  int32_t version;
3014
} SDCfgDnodeReq;
3015

3016
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3017
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3018

3019
typedef struct {
3020
  int32_t dnodeId;
3021
  int32_t sqlLen;
3022
  char*   sql;
3023
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3024
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
3025

3026

3027
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3028
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3029

3030

3031
typedef struct {
3032
  int32_t nodeId;
3033
  SEpSet  epSet;
3034
} SNodeEpSet;
3035

3036

3037
typedef struct {
3038
  int32_t    snodeId;
3039
  SNodeEpSet leaders[2];
3040
  SNodeEpSet replica;
3041
  int32_t    sqlLen;
3042
  char*      sql;
3043
} SDCreateSnodeReq;
3044

3045
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3046
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
3047
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
3048

3049

3050
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3051
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3052
typedef struct {
3053
  int8_t   replica;
3054
  SReplica replicas[TSDB_MAX_REPLICA];
3055
  int8_t   learnerReplica;
3056
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3057
  int64_t  lastIndex;
3058
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3059

3060
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3061
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3062

3063
typedef struct {
3064
  int32_t urlLen;
3065
  int32_t sqlLen;
3066
  char*   url;
3067
  char*   sql;
3068
} SMCreateAnodeReq;
3069

3070
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3071
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3072
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3073

3074
typedef struct {
3075
  int32_t anodeId;
3076
  int32_t sqlLen;
3077
  char*   sql;
3078
} SMDropAnodeReq, SMUpdateAnodeReq;
3079

3080
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3081
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3082
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3083
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3084
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3085
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3086

3087
typedef struct {
3088
  int32_t dnodeId;
3089
  int32_t bnodeProto;
3090
  int32_t sqlLen;
3091
  char*   sql;
3092
} SMCreateBnodeReq, SDCreateBnodeReq;
3093

3094
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3095
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3096
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3097

3098
typedef struct {
3099
  int32_t dnodeId;
3100
  int32_t sqlLen;
3101
  char*   sql;
3102
} SMDropBnodeReq, SDDropBnodeReq;
3103

3104
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3105
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3106
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3107

3108
typedef struct {
3109
  int32_t vgId;
3110
  int32_t hbSeq;
3111
} SVArbHbReqMember;
3112

3113
typedef struct {
3114
  int32_t dnodeId;
3115
  char*   arbToken;
3116
  int64_t arbTerm;
3117
  SArray* hbMembers;  // SVArbHbReqMember
3118
} SVArbHeartBeatReq;
3119

3120
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3121
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3122
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3123

3124
typedef struct {
3125
  int32_t vgId;
3126
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3127
  int32_t hbSeq;
3128
} SVArbHbRspMember;
3129

3130
typedef struct {
3131
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3132
  int32_t dnodeId;
3133
  SArray* hbMembers;  // SVArbHbRspMember
3134
} SVArbHeartBeatRsp;
3135

3136
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3137
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3138
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3139

3140
typedef struct {
3141
  char*   arbToken;
3142
  int64_t arbTerm;
3143
  char*   member0Token;
3144
  char*   member1Token;
3145
} SVArbCheckSyncReq;
3146

3147
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3148
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3149
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3150

3151
typedef struct {
3152
  char*   arbToken;
3153
  char*   member0Token;
3154
  char*   member1Token;
3155
  int32_t vgId;
3156
  int32_t errCode;
3157
} SVArbCheckSyncRsp;
3158

3159
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3160
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3161
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3162

3163
typedef struct {
3164
  char*   arbToken;
3165
  int64_t arbTerm;
3166
  char*   memberToken;
3167
  int8_t  force;
3168
} SVArbSetAssignedLeaderReq;
3169

3170
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3171
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3172
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3173

3174
typedef struct {
3175
  char*   arbToken;
3176
  char*   memberToken;
3177
  int32_t vgId;
3178
} SVArbSetAssignedLeaderRsp;
3179

3180
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3181
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3182
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3183

3184
typedef struct {
3185
  int32_t dnodeId;
3186
  char*   token;
3187
} SMArbUpdateGroupMember;
3188

3189
typedef struct {
3190
  int32_t dnodeId;
3191
  char*   token;
3192
  int8_t  acked;
3193
} SMArbUpdateGroupAssigned;
3194

3195
typedef struct {
3196
  int32_t                  vgId;
3197
  int64_t                  dbUid;
3198
  SMArbUpdateGroupMember   members[2];
3199
  int8_t                   isSync;
3200
  int8_t                   assignedAcked;
3201
  SMArbUpdateGroupAssigned assignedLeader;
3202
  int64_t                  version;
3203
  int32_t                  code;
3204
  int64_t                  updateTimeMs;
3205
} SMArbUpdateGroup;
3206

3207
typedef struct {
3208
  SArray* updateArray;  // SMArbUpdateGroup
3209
} SMArbUpdateGroupBatchReq;
3210

3211
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3212
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3213
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3214

3215
typedef struct {
3216
  char queryStrId[TSDB_QUERY_ID_LEN];
3217
} SKillQueryReq;
3218

3219
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3220
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3221

3222
typedef struct {
3223
  uint32_t connId;
3224
} SKillConnReq;
3225

3226
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3227
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3228

3229
typedef struct {
3230
  int32_t transId;
3231
} SKillTransReq;
3232

3233
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3234
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3235

3236
typedef struct {
3237
  int32_t useless;  // useless
3238
  int32_t sqlLen;
3239
  char*   sql;
3240
} SBalanceVgroupReq;
3241

3242
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3243
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3244
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3245

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

3252
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3253
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3254
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3255
typedef struct {
3256
  int32_t vgId1;
3257
  int32_t vgId2;
3258
} SMergeVgroupReq;
3259

3260
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3261
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3262

3263
typedef struct {
3264
  int32_t vgId;
3265
  int32_t dnodeId1;
3266
  int32_t dnodeId2;
3267
  int32_t dnodeId3;
3268
  int32_t sqlLen;
3269
  char*   sql;
3270
} SRedistributeVgroupReq;
3271

3272
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3273
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3274
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3275

3276
typedef struct {
3277
  int32_t reserved;
3278
  int32_t vgId;
3279
  int32_t sqlLen;
3280
  char*   sql;
3281
  char    db[TSDB_DB_FNAME_LEN];
3282
} SBalanceVgroupLeaderReq;
3283

3284
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3285
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3286
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3287

3288
typedef struct {
3289
  int32_t vgId;
3290
} SForceBecomeFollowerReq;
3291

3292
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3293
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3294

3295
typedef struct {
3296
  int32_t vgId;
3297
  bool    force;
3298
} SSplitVgroupReq;
3299

3300
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3301
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3302

3303
typedef struct {
3304
  char user[TSDB_USER_LEN];
3305
  char spi;
3306
  char encrypt;
3307
  char secret[TSDB_PASSWORD_LEN];
3308
  char ckey[TSDB_PASSWORD_LEN];
3309
} SAuthReq, SAuthRsp;
3310

3311
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3312
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3313

3314
typedef struct {
3315
  int32_t statusCode;
3316
  char    details[1024];
3317
} SServerStatusRsp;
3318

3319
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3320
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3321

3322
/**
3323
 * The layout of the query message payload is as following:
3324
 * +--------------------+---------------------------------+
3325
 * |Sql statement       | Physical plan                   |
3326
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3327
 * +--------------------+---------------------------------+
3328
 */
3329
typedef struct SSubQueryMsg {
3330
  SMsgHead header;
3331
  uint64_t sId;
3332
  uint64_t queryId;
3333
  uint64_t clientId;
3334
  uint64_t taskId;
3335
  int64_t  refId;
3336
  int32_t  execId;
3337
  int32_t  msgMask;
3338
  int8_t   taskType;
3339
  int8_t   explain;
3340
  int8_t   needFetch;
3341
  int8_t   compress;
3342
  uint32_t sqlLen;
3343
  char*    sql;
3344
  uint32_t msgLen;
3345
  char*    msg;
3346
} SSubQueryMsg;
3347

3348
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3349
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3350
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3351

3352
typedef struct {
3353
  SMsgHead header;
3354
  uint64_t sId;
3355
  uint64_t queryId;
3356
  uint64_t taskId;
3357
} SSinkDataReq;
3358

3359
typedef struct {
3360
  SMsgHead header;
3361
  uint64_t sId;
3362
  uint64_t queryId;
3363
  uint64_t clientId;
3364
  uint64_t taskId;
3365
  int32_t  execId;
3366
} SQueryContinueReq;
3367

3368
typedef struct {
3369
  SMsgHead header;
3370
  uint64_t sId;
3371
  uint64_t queryId;
3372
  uint64_t taskId;
3373
} SResReadyReq;
3374

3375
typedef struct {
3376
  int32_t code;
3377
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3378
  int32_t sversion;
3379
  int32_t tversion;
3380
} SResReadyRsp;
3381

3382
typedef struct SOperatorParam {
3383
  int32_t opType;
3384
  int32_t downstreamIdx;
3385
  void*   value;
3386
  SArray* pChildren;  // SArray<SOperatorParam*>
3387
  bool    reUse;
3388
} SOperatorParam;
3389

3390
typedef struct SColIdNameKV {
3391
  col_id_t colId;
3392
  char     colName[TSDB_COL_NAME_LEN];
3393
} SColIdNameKV;
3394

3395
typedef struct SColIdPair {
3396
  col_id_t vtbColId;
3397
  col_id_t orgColId;
3398
} SColIdPair;
3399

3400
typedef struct SOrgTbInfo {
3401
  int32_t vgId;
3402
  char    tbName[TSDB_TABLE_FNAME_LEN];
3403
  SArray* colMap;  // SArray<SColIdNameKV>
3404
} SOrgTbInfo;
3405

3406
typedef struct STableScanOperatorParam {
3407
  bool        tableSeq;
3408
  SArray*     pUidList;
3409
  SOrgTbInfo* pOrgTbInfo;
3410
  STimeWindow window;
3411
} STableScanOperatorParam;
3412

3413
typedef struct STagScanOperatorParam {
3414
  tb_uid_t       vcUid;
3415
} STagScanOperatorParam;
3416

3417
typedef struct SSysScanOperatorParam {
3418
  bool           isVstb;
3419
  tb_uid_t       uid;
3420
  int64_t        version;
3421
} SSysScanOperatorParam;
3422

3423
typedef struct SVTableScanOperatorParam {
3424
  uint64_t        uid;
3425
  SOperatorParam* pTagScanOp;
3426
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3427
} SVTableScanOperatorParam;
3428

3429
struct SStreamRuntimeFuncInfo;
3430
typedef struct {
3431
  SMsgHead                       header;
3432
  uint64_t                       sId;
3433
  uint64_t                       queryId;
3434
  uint64_t                       clientId;
3435
  uint64_t                       taskId;
3436
  int32_t                        execId;
3437
  SOperatorParam*                pOpParam;
3438

3439
  // used for new-stream
3440
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3441
  bool                           reset;
3442
  bool                           dynTbname;
3443
  // used for new-stream
3444
} SResFetchReq;
3445

3446
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3447
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3448
void    tDestroySResFetchReq(SResFetchReq* pReq);
3449
typedef struct {
3450
  SMsgHead header;
3451
  uint64_t clientId;
3452
} SSchTasksStatusReq;
3453

3454
typedef struct {
3455
  uint64_t queryId;
3456
  uint64_t clientId;
3457
  uint64_t taskId;
3458
  int64_t  refId;
3459
  int32_t  execId;
3460
  int8_t   status;
3461
} STaskStatus;
3462

3463
typedef struct {
3464
  int64_t refId;
3465
  SArray* taskStatus;  // SArray<STaskStatus>
3466
} SSchedulerStatusRsp;
3467

3468
typedef struct {
3469
  uint64_t queryId;
3470
  uint64_t taskId;
3471
  int8_t   action;
3472
} STaskAction;
3473

3474
typedef struct SQueryNodeEpId {
3475
  int32_t nodeId;  // vgId or qnodeId
3476
  SEp     ep;
3477
} SQueryNodeEpId;
3478

3479
typedef struct {
3480
  SMsgHead       header;
3481
  uint64_t       clientId;
3482
  SQueryNodeEpId epId;
3483
  SArray*        taskAction;  // SArray<STaskAction>
3484
} SSchedulerHbReq;
3485

3486
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3487
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3488
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3489

3490
typedef struct {
3491
  SQueryNodeEpId epId;
3492
  SArray*        taskStatus;  // SArray<STaskStatus>
3493
} SSchedulerHbRsp;
3494

3495
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3496
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3497
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3498

3499
typedef struct {
3500
  SMsgHead header;
3501
  uint64_t sId;
3502
  uint64_t queryId;
3503
  uint64_t clientId;
3504
  uint64_t taskId;
3505
  int64_t  refId;
3506
  int32_t  execId;
3507
} STaskCancelReq;
3508

3509
typedef struct {
3510
  int32_t code;
3511
} STaskCancelRsp;
3512

3513
typedef struct {
3514
  SMsgHead header;
3515
  uint64_t sId;
3516
  uint64_t queryId;
3517
  uint64_t clientId;
3518
  uint64_t taskId;
3519
  int64_t  refId;
3520
  int32_t  execId;
3521
} STaskDropReq;
3522

3523
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3524
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3525

3526
typedef enum {
3527
  TASK_NOTIFY_FINISHED = 1,
3528
} ETaskNotifyType;
3529

3530
typedef struct {
3531
  SMsgHead        header;
3532
  uint64_t        sId;
3533
  uint64_t        queryId;
3534
  uint64_t        clientId;
3535
  uint64_t        taskId;
3536
  int64_t         refId;
3537
  int32_t         execId;
3538
  ETaskNotifyType type;
3539
} STaskNotifyReq;
3540

3541
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3542
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3543

3544
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3545
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3546

3547
typedef struct {
3548
  int32_t code;
3549
} STaskDropRsp;
3550

3551
#define STREAM_TRIGGER_AT_ONCE                 1
3552
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3553
#define STREAM_TRIGGER_MAX_DELAY               3
3554
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3555
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3556

3557
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3558
#define STREAM_FILL_HISTORY_ON        1
3559
#define STREAM_FILL_HISTORY_OFF       0
3560
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3561
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3562
#define STREAM_CREATE_STABLE_TRUE     1
3563
#define STREAM_CREATE_STABLE_FALSE    0
3564

3565
typedef struct SVgroupVer {
3566
  int32_t vgId;
3567
  int64_t ver;
3568
} SVgroupVer;
3569

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

3586
enum {
3587
  TOPIC_SUB_TYPE__DB = 1,
3588
  TOPIC_SUB_TYPE__TABLE,
3589
  TOPIC_SUB_TYPE__COLUMN,
3590
};
3591

3592
#define DEFAULT_MAX_POLL_INTERVAL  300000
3593
#define DEFAULT_SESSION_TIMEOUT    12000
3594
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3595
#define DEFAULT_MIN_POLL_ROWS      4096
3596

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

3608
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3609
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3610
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3611

3612
typedef struct {
3613
  int64_t consumerId;
3614
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3615

3616
typedef struct {
3617
  int64_t consumerId;
3618
  char    cgroup[TSDB_CGROUP_LEN];
3619
  char    clientId[TSDB_CLIENT_ID_LEN];
3620
  char    user[TSDB_USER_LEN];
3621
  char    fqdn[TSDB_FQDN_LEN];
3622
  SArray* topicNames;  // SArray<char**>
3623

3624
  int8_t  withTbName;
3625
  int8_t  autoCommit;
3626
  int32_t autoCommitInterval;
3627
  int8_t  resetOffsetCfg;
3628
  int8_t  enableReplay;
3629
  int8_t  enableBatchMeta;
491,548✔
3630
  int32_t sessionTimeoutMs;
491,548✔
3631
  int32_t maxPollIntervalMs;
491,548✔
3632
} SCMSubscribeReq;
491,548✔
3633

3634
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
491,548✔
3635
  int32_t tlen = 0;
491,548✔
3636
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
3637
  tlen += taosEncodeString(buf, pReq->cgroup);
700,570✔
3638
  tlen += taosEncodeString(buf, pReq->clientId);
418,044✔
3639

3640
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
3641
  tlen += taosEncodeFixedI32(buf, topicNum);
491,548✔
3642

491,548✔
3643
  for (int32_t i = 0; i < topicNum; i++) {
491,548✔
3644
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
491,548✔
3645
  }
491,548✔
3646

491,548✔
3647
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
491,548✔
3648
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
491,548✔
3649
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
491,548✔
3650
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
491,548✔
3651
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
3652
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
491,548✔
3653
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
3654
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
3655
  tlen += taosEncodeString(buf, pReq->user);
3656
  tlen += taosEncodeString(buf, pReq->fqdn);
123,548✔
3657

123,548✔
3658
  return tlen;
123,548✔
3659
}
123,548✔
3660

3661
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
123,548✔
3662
  void* start = buf;
123,548✔
3663
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
3664
  buf = taosDecodeStringTo(buf, pReq->cgroup);
123,548✔
3665
  buf = taosDecodeStringTo(buf, pReq->clientId);
123,548✔
UNCOV
3666

×
3667
  int32_t topicNum = 0;
3668
  buf = taosDecodeFixedI32(buf, &topicNum);
175,938✔
3669

52,390✔
3670
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
52,390✔
3671
  if (pReq->topicNames == NULL) {
104,780✔
3672
    return terrno;
×
3673
  }
3674
  for (int32_t i = 0; i < topicNum; i++) {
3675
    char* name = NULL;
3676
    buf = taosDecodeString(buf, &name);
123,548✔
3677
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
123,548✔
3678
      return terrno;
123,548✔
3679
    }
123,548✔
3680
  }
123,548✔
3681

123,548✔
3682
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
123,548✔
3683
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
123,548✔
3684
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
123,548✔
3685
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
123,548✔
3686
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
247,096✔
3687
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
UNCOV
3688
  if ((char*)buf - (char*)start < len) {
×
UNCOV
3689
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
×
3690
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
3691
    buf = taosDecodeStringTo(buf, pReq->user);
3692
    buf = taosDecodeStringTo(buf, pReq->fqdn);
123,548✔
3693
  } else {
3694
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
3695
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
3696
  }
3697

3698
  return 0;
3699
}
3700

3701
typedef struct {
3702
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
91,659✔
3703
  SArray* removedConsumers;  // SArray<int64_t>
91,659✔
UNCOV
3704
  SArray* newConsumers;      // SArray<int64_t>
×
3705
} SMqRebInfo;
3706

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

3729
typedef struct {
3730
  int64_t streamId;
3731
  int64_t checkpointId;
3732
  char    streamName[TSDB_STREAM_FNAME_LEN];
3733
} SMStreamDoCheckpointMsg;
3734

3735
typedef struct {
3736
  int64_t status;
3737
} SMVSubscribeRsp;
3738

3739
typedef struct {
3740
  char    name[TSDB_TOPIC_FNAME_LEN];
3741
  int8_t  igNotExists;
3742
  int32_t sqlLen;
3743
  char*   sql;
3744
  int8_t  force;
3745
} SMDropTopicReq;
3746

3747
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3748
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3749
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3750

3751
typedef struct {
3752
  char   topic[TSDB_TOPIC_FNAME_LEN];
3753
  char   cgroup[TSDB_CGROUP_LEN];
3754
  int8_t igNotExists;
3755
  int8_t force;
3756
} SMDropCgroupReq;
3757

3758
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3759
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3760

3761
typedef struct {
3762
  int8_t reserved;
3763
} SMDropCgroupRsp;
3764

3765
typedef struct {
3766
  char    name[TSDB_TABLE_FNAME_LEN];
3767
  int8_t  alterType;
3768
  SSchema schema;
3769
} SAlterTopicReq;
3770

3771
typedef struct {
3772
  SMsgHead head;
3773
  char     name[TSDB_TABLE_FNAME_LEN];
3774
  int64_t  tuid;
3775
  int32_t  sverson;
3776
  int32_t  execLen;
3777
  char*    executor;
3778
  int32_t  sqlLen;
3779
  char*    sql;
3780
} SDCreateTopicReq;
3781

3782
typedef struct {
3783
  SMsgHead head;
3784
  char     name[TSDB_TABLE_FNAME_LEN];
3785
  int64_t  tuid;
3786
} SDDropTopicReq;
3787

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

3798
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3799
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3800

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

3819
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3820
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3821

3822
// TDMT_VND_DROP_STB ==============
3823
typedef struct SVDropStbReq {
3824
  char*    name;
3825
  tb_uid_t suid;
3826
} SVDropStbReq;
3827

3828
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3829
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3830

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

3863
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
2,147,483,647✔
3864
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
2,101,302,271✔
3865
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3866
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
3867

70,008,929✔
3868
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
70,006,359✔
3869
  if (NULL == req) {
70,012,691✔
3870
    return;
70,011,803✔
3871
  }
67,403,929✔
3872

67,391,999✔
3873
  taosMemoryFreeClear(req->sql);
67,407,367✔
3874
  taosMemoryFreeClear(req->name);
67,390,255✔
3875
  taosMemoryFreeClear(req->comment);
2,607,457✔
3876
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,607,457✔
3877
    taosMemoryFreeClear(req->ctb.pTag);
3878
    taosMemoryFreeClear(req->ctb.stbName);
70,002,797✔
3879
    taosArrayDestroy(req->ctb.tagName);
70,010,070✔
3880
    req->ctb.tagName = NULL;
70,009,134✔
3881
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
3882
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
3883
  }
3884
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
3885
  taosMemoryFreeClear(req->pExtSchemas);
3886
  taosMemoryFreeClear(req->colRef.pColRef);
3887
}
3888

3889
typedef struct {
3890
  int32_t nReqs;
3891
  union {
3892
    SVCreateTbReq* pReqs;
3893
    SArray*        pArray;
3894
  };
3895
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3896
} SVCreateTbBatchReq;
3897

3898
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3899
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3900
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3901

3902
typedef struct {
3903
  int32_t        code;
3904
  STableMetaRsp* pMeta;
3905
} SVCreateTbRsp, SVUpdateTbRsp;
3906

3907
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3908
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3909
void tFreeSVCreateTbRsp(void* param);
3910

3911
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3912
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3913

3914
typedef struct {
3915
  int32_t nRsps;
3916
  union {
3917
    SVCreateTbRsp* pRsps;
3918
    SArray*        pArray;
3919
  };
3920
} SVCreateTbBatchRsp;
3921

3922
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3923
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3924

3925
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3926
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3927

3928
// TDMT_VND_DROP_TABLE =================
3929
typedef struct {
3930
  char*    name;
3931
  uint64_t suid;  // for tmq in wal format
3932
  int64_t  uid;
3933
  int8_t   igNotExists;
3934
  int8_t   isVirtual;
3935
} SVDropTbReq;
3936

3937
typedef struct {
3938
  int32_t code;
3939
} SVDropTbRsp;
3940

3941
typedef struct {
3942
  int32_t nReqs;
3943
  union {
3944
    SVDropTbReq* pReqs;
3945
    SArray*      pArray;
3946
  };
3947
} SVDropTbBatchReq;
3948

3949
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3950
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3951

3952
typedef struct {
3953
  int32_t nRsps;
3954
  union {
3955
    SVDropTbRsp* pRsps;
3956
    SArray*      pArray;
3957
  };
3958
} SVDropTbBatchRsp;
3959

3960
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3961
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3962

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

4013
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4014
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4015
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4016
void    tfreeMultiTagUpateVal(void* pMultiTag);
4017

4018
typedef struct {
4019
  int32_t        code;
4020
  STableMetaRsp* pMeta;
4021
} SVAlterTbRsp;
4022

4023
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4024
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4025
// ======================
4026

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

4041
typedef struct {
4042
  SMsgHead head;
4043
} SUpdateTagValRsp;
4044

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

4049
typedef struct {
4050
  SMsgHead head;
4051
  int32_t  id;
4052
} SVShowTablesFetchReq;
4053

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

4064
typedef struct {
4065
  int64_t consumerId;
4066
  int32_t epoch;
4067
  char    cgroup[TSDB_CGROUP_LEN];
4068
} SMqAskEpReq;
4069

4070
typedef struct {
4071
  int32_t key;
4072
  int32_t valueLen;
4073
  void*   value;
4074
} SKv;
4075

4076
typedef struct {
4077
  int64_t tscRid;
4078
  int8_t  connType;
4079
} SClientHbKey;
4080

4081
typedef struct {
4082
  int64_t tid;
4083
  char    status[TSDB_JOB_STATUS_LEN];
4084
} SQuerySubDesc;
4085

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

4099
typedef struct {
4100
  uint32_t connId;
4101
  SArray*  queryDesc;  // SArray<SQueryDesc>
4102
} SQueryHbReqBasic;
4103

4104
typedef struct {
4105
  uint32_t connId;
4106
  uint64_t killRid;
4107
  int32_t  totalDnodes;
4108
  int32_t  onlineDnodes;
4109
  int8_t   killConnection;
4110
  int8_t   align[3];
4111
  SEpSet   epSet;
4112
  SArray*  pQnodeList;
4113
} SQueryHbRspBasic;
4114

4115
typedef struct SAppClusterSummary {
4116
  uint64_t numOfInsertsReq;
4117
  uint64_t numOfInsertRows;
4118
  uint64_t insertElapsedTime;
4119
  uint64_t insertBytes;  // submit to tsdb since launched.
4120

4121
  uint64_t fetchBytes;
4122
  uint64_t numOfQueryReq;
4123
  uint64_t queryElapsedTime;
4124
  uint64_t numOfSlowQueries;
4125
  uint64_t totalRequests;
4126
  uint64_t currentRequests;  // the number of SRequestObj
4127
} SAppClusterSummary;
4128

4129
typedef struct {
4130
  int64_t            appId;
4131
  int32_t            pid;
4132
  char               name[TSDB_APP_NAME_LEN];
4133
  int64_t            startTime;
4134
  SAppClusterSummary summary;
4135
} SAppHbReq;
4136

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

4150
typedef struct {
4151
  int64_t reqId;
4152
  SArray* reqs;  // SArray<SClientHbReq>
4153
  int64_t ipWhiteListVer;
4154
} SClientHbBatchReq;
4155

4156
typedef struct {
4157
  SClientHbKey      connKey;
4158
  int32_t           status;
4159
  SQueryHbRspBasic* query;
4160
  SArray*           info;  // Array<Skv>
4161
} SClientHbRsp;
4162

4163
typedef struct {
4164
  int64_t       reqId;
4165
  int64_t       rspId;
4166
  int32_t       svrTimestamp;
4167
  SArray*       rsps;  // SArray<SClientHbRsp>
65,337,835✔
4168
  SMonitorParas monitorParas;
4169
  int8_t        enableAuditDelete;
4170
  int8_t        enableStrongPass;
40,881,674✔
4171
} SClientHbBatchRsp;
91,407,451✔
4172

50,525,363✔
4173
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
50,525,363✔
4174

50,525,076✔
4175
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4176
  void* pIter = taosHashIterate(info, NULL);
40,882,088✔
4177
  while (pIter != NULL) {
4178
    SKv* kv = (SKv*)pIter;
25,133,199✔
4179
    taosMemoryFreeClear(kv->value);
25,133,199✔
4180
    pIter = taosHashIterate(info, pIter);
25,133,199✔
4181
  }
21,589,078✔
4182
}
21,588,568✔
4183

4184
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
25,133,011✔
4185
  SQueryDesc* desc = (SQueryDesc*)pDesc;
4186
  if (desc->subDesc) {
49,005,691✔
4187
    taosArrayDestroy(desc->subDesc);
52,551,362✔
4188
    desc->subDesc = NULL;
52,551,362✔
4189
  }
42,217,499✔
4190
}
20,603,655✔
4191

4192
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
42,216,887✔
4193
  SClientHbReq* req = (SClientHbReq*)pReq;
4194
  if (req->query) {
4195
    if (req->query->queryDesc) {
52,551,108✔
4196
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
40,880,634✔
4197
    }
40,882,088✔
4198
    taosMemoryFreeClear(req->query);
40,882,088✔
4199
  }
4200

26,410,361✔
4201
  if (req->info) {
4202
    tFreeReqKvHash(req->info);
4203
    taosHashCleanup(req->info);
4204
    req->info = NULL;
4205
  }
4206
}
23,103,510✔
4207

23,103,510✔
4208
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
23,103,510✔
4209
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
23,103,510✔
4210

4211
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4212
  if (pReq == NULL) return;
19,233,931✔
4213
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
19,233,931✔
4214
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
19,233,931✔
4215
  taosMemoryFree(pReq);
19,233,931✔
4216
}
4217

19,233,931✔
4218
static FORCE_INLINE void tFreeClientKv(void* pKv) {
4219
  SKv* kv = (SKv*)pKv;
48,342,802✔
4220
  if (kv) {
48,342,802✔
4221
    taosMemoryFreeClear(kv->value);
48,342,802✔
4222
  }
41,586,037✔
4223
}
41,585,908✔
4224

4225
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
48,343,427✔
4226
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
25,480,250✔
4227
  if (rsp->query) {
4228
    taosArrayDestroy(rsp->query->pQnodeList);
4229
    taosMemoryFreeClear(rsp->query);
42,973,930✔
4230
  }
42,973,930✔
4231
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
42,975,119✔
4232
}
4233

4234
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4235
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
4236
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
4237
}
4238

150,211,806✔
4239
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
150,212,109✔
4240
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
150,212,109✔
4241
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
75,105,529✔
4242

4243
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4244
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
4245
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
69,241,632✔
4246
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
69,241,276✔
4247
  return 0;
34,620,460✔
4248
}
34,620,799✔
UNCOV
4249

×
4250
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4251
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
34,620,799✔
4252
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
34,620,412✔
4253
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
4254
  if (pKv->value == NULL) {
4255
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
4256
  }
203,183,912✔
4257
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
203,182,561✔
4258
  return 0;
101,591,302✔
4259
}
4260

4261
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4262
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
100,257,772✔
4263
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
100,257,272✔
4264
  return 0;
50,128,847✔
4265
}
4266

4267
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4268
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
4269
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
4270
  return 0;
4271
}
4272

4273
typedef struct {
4274
  int32_t vgId;
4275
  // TODO stas
4276
} SMqReportVgInfo;
4277

4278
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4279
  int32_t tlen = 0;
4280
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4281
  return tlen;
4282
}
4283

4284
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4285
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4286
  return buf;
4287
}
4288

4289
typedef struct {
4290
  int32_t epoch;
4291
  int64_t topicUid;
4292
  char    name[TSDB_TOPIC_FNAME_LEN];
4293
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4294
} SMqTopicInfo;
4295

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

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

4329
typedef struct {
4330
  int32_t status;  // ask hb endpoint
4331
  int32_t epoch;
4332
  int64_t consumerId;
4333
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4334
} SMqReportReq;
4335

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

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

4369
typedef struct {
4370
  SMsgHead head;
4371
  int64_t  leftForVer;
4372
  int32_t  vgId;
4373
  int64_t  consumerId;
4374
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4375
} SMqVDeleteReq;
4376

4377
typedef struct {
4378
  int8_t reserved;
4379
} SMqVDeleteRsp;
4380

4381
typedef struct {
4382
  char*   name;
4383
  int8_t  igNotExists;
4384
} SMDropStreamReq;
4385

4386
typedef struct {
4387
  int8_t reserved;
4388
} SMDropStreamRsp;
4389

4390
typedef struct {
4391
  SMsgHead head;
4392
  int64_t  resetRelHalt;  // reset related stream task halt status
4393
  int64_t  streamId;
4394
  int32_t  taskId;
4395
} SVDropStreamTaskReq;
4396

4397
typedef struct {
4398
  int8_t reserved;
4399
} SVDropStreamTaskRsp;
4400

4401
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4402
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4403
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4404

4405
typedef struct {
4406
  char*  name;
4407
  int8_t igNotExists;
4408
} SMPauseStreamReq;
4409

4410
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4411
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4412
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4413

4414
typedef struct {
4415
  char*  name;
4416
  int8_t igNotExists;
4417
  int8_t igUntreated;
4418
} SMResumeStreamReq;
4419

4420
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4421
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4422
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4423

4424
typedef struct {
4425
  char*       name;
4426
  int8_t      calcAll;
4427
  STimeWindow timeRange;
4428
} SMRecalcStreamReq;
4429

4430
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4431
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4432
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4433

4434
typedef struct SVUpdateCheckpointInfoReq {
4435
  SMsgHead head;
4436
  int64_t  streamId;
4437
  int32_t  taskId;
4438
  int64_t  checkpointId;
4439
  int64_t  checkpointVer;
4440
  int64_t  checkpointTs;
4441
  int32_t  transId;
4442
  int64_t  hStreamId;  // add encode/decode
4443
  int64_t  hTaskId;
4444
  int8_t   dropRelHTask;
4445
} SVUpdateCheckpointInfoReq;
4446

4447
typedef struct {
4448
  int64_t leftForVer;
4449
  int32_t vgId;
4450
  int64_t oldConsumerId;
4451
  int64_t newConsumerId;
4452
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4453
  int8_t  subType;
4454
  int8_t  withMeta;
4455
  char*   qmsg;  // SubPlanToString
4456
  int64_t suid;
4457
} SMqRebVgReq;
4458

4459
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4460
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4461

4462
typedef struct {
4463
  char    topic[TSDB_TOPIC_FNAME_LEN];
4464
  int64_t ntbUid;
4465
  SArray* colIdList;  // SArray<int16_t>
4466
} STqCheckInfo;
4467

4468
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4469
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4470
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4471

4472
// tqOffset
4473
enum {
4474
  TMQ_OFFSET__RESET_NONE = -3,
4475
  TMQ_OFFSET__RESET_EARLIEST = -2,
4476
  TMQ_OFFSET__RESET_LATEST = -1,
4477
  TMQ_OFFSET__LOG = 1,
4478
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4479
  TMQ_OFFSET__SNAPSHOT_META = 3,
4480
};
4481

4482
enum {
4483
  WITH_DATA = 0,
4484
  WITH_META = 1,
4485
  ONLY_META = 2,
4486
};
4487

4488
#define TQ_OFFSET_VERSION 1
4489

4490
typedef struct {
4491
  int8_t type;
4492
  union {
4493
    // snapshot
4494
    struct {
4495
      int64_t uid;
4496
      int64_t ts;
4497
      SValue  primaryKey;
4498
    };
4499
    // log
4500
    struct {
4501
      int64_t version;
1,618,176✔
4502
    };
1,618,405✔
4503
  };
1,618,675✔
4504
} STqOffsetVal;
1,618,690✔
UNCOV
4505

×
4506
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4507
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,618,889✔
4508
  pOffsetVal->uid = uid;
1,618,260✔
4509
  pOffsetVal->ts = ts;
4510
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
4511
    taosMemoryFree(pOffsetVal->primaryKey.pData);
6,621✔
4512
  }
6,593✔
4513
  pOffsetVal->primaryKey = primaryKey;
6,685✔
4514
}
4515

4516
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
39,158,335✔
4517
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
39,158,297✔
4518
  pOffsetVal->uid = uid;
39,157,456✔
4519
}
4520

4521
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4522
  pOffsetVal->type = TMQ_OFFSET__LOG;
4523
  pOffsetVal->version = ver;
4524
}
4525

4526
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4527
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4528
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4529
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4530
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4531
void    tOffsetDestroy(void* pVal);
4532

4533
typedef struct {
4534
  STqOffsetVal val;
4535
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4536
} STqOffset;
4537

4538
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4539
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4540
void    tDeleteSTqOffset(void* val);
4541

4542
typedef struct SMqVgOffset {
4543
  int64_t   consumerId;
4544
  STqOffset offset;
4545
} SMqVgOffset;
4546

4547
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4548
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4549

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

4584
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4585
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4586
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4587

4588
typedef struct {
4589
  char   name[TSDB_TABLE_FNAME_LEN];
4590
  int8_t igNotExists;
4591
  char*   dropStreamReq;
4592
  int32_t dropStreamReqLen;
4593
} SMDropSmaReq;
4594

4595
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4596
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4597
void tFreeSMDropSmaReq(SMDropSmaReq *pReq);
4598

4599
typedef struct {
4600
  char name[TSDB_TABLE_NAME_LEN];
4601
  union {
4602
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4603
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4604
  };
4605
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4606
  union {
4607
    int8_t igExists;   // used by mnode
4608
    int8_t alterType;  // used by vnode
4609
  };
4610
  int8_t     intervalUnit;
4611
  int16_t    nFuncs;       // number of functions specified by user
4612
  col_id_t*  funcColIds;   // column ids specified by user
4613
  func_id_t* funcIds;      // function ids specified by user
4614
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4615
  int64_t    tbUid;
4616
  int64_t    uid;     // rsma uid
4617
  int32_t    sqlLen;  // strlen + 1
4618
  char*      sql;
4619
} SMCreateRsmaReq;
4620

4621
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4622
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4623
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4624

4625
typedef SMCreateRsmaReq SVCreateRsmaReq;
4626

4627
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4628
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4629
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4630

4631
typedef SMCreateRsmaReq SVAlterRsmaReq;
4632

4633
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4634
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4635
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4636

4637
typedef struct {
4638
  char       name[TSDB_TABLE_NAME_LEN];
4639
  int8_t     alterType;
4640
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4641
  int8_t     igNotExists;
4642
  int16_t    nFuncs;      // number of functions specified by user
4643
  col_id_t*  funcColIds;  // column ids specified by user
4644
  func_id_t* funcIds;     // function ids specified by user
4645
  int32_t    sqlLen;      // strlen + 1
4646
  char*      sql;
4647
} SMAlterRsmaReq;
4648

4649
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4650
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4651
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4652

4653
typedef struct {
4654
  int64_t    id;
4655
  char       name[TSDB_TABLE_NAME_LEN];
4656
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4657
  int32_t    code;
4658
  int32_t    version;
4659
  int8_t     tbType;
4660
  int8_t     intervalUnit;
4661
  col_id_t   nFuncs;
4662
  col_id_t   nColNames;
4663
  int64_t    interval[2];
4664
  col_id_t*  funcColIds;
4665
  func_id_t* funcIds;
4666
  SArray*    colNames;
4667
} SRsmaInfoRsp;
4668

4669
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4670
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4671
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4672

4673
typedef struct {
4674
  char   name[TSDB_TABLE_FNAME_LEN];
4675
  int8_t igNotExists;
4676
} SMDropRsmaReq;
4677

4678
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4679
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4680

4681
typedef struct {
4682
  char    name[TSDB_TABLE_NAME_LEN];
4683
  char    tbName[TSDB_TABLE_NAME_LEN];
4684
  int64_t uid;
4685
  int64_t tbUid;
4686
  int8_t  tbType;
4687
} SVDropRsmaReq;
4688

4689
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4690
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4691

4692
typedef struct {
4693
  char   dbFName[TSDB_DB_FNAME_LEN];
4694
  char   stbName[TSDB_TABLE_NAME_LEN];
4695
  char   colName[TSDB_COL_NAME_LEN];
4696
  char   idxName[TSDB_INDEX_FNAME_LEN];
4697
  int8_t idxType;
4698
} SCreateTagIndexReq;
4699

4700
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4701
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4702

4703
typedef SMDropSmaReq SDropTagIndexReq;
4704

4705
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4706
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4707

4708
typedef struct {
4709
  int8_t         version;       // for compatibility(default 0)
4710
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4711
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4712
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4713
  int32_t        dstVgId;
4714
  char           indexName[TSDB_INDEX_NAME_LEN];
4715
  int32_t        exprLen;
4716
  int32_t        tagsFilterLen;
4717
  int64_t        indexUid;
4718
  tb_uid_t       tableUid;  // super/child/common table uid
4719
  tb_uid_t       dstTbUid;  // for dstVgroup
4720
  int64_t        interval;
4721
  int64_t        offset;  // use unit by precision of DB
4722
  int64_t        sliding;
4723
  char*          dstTbName;  // for dstVgroup
4724
  char*          expr;       // sma expression
4725
  char*          tagsFilter;
4726
  SSchemaWrapper schemaRow;  // for dstVgroup
4727
  SSchemaWrapper schemaTag;  // for dstVgroup
4728
} STSma;                     // Time-range-wise SMA
4729

4730
typedef STSma SVCreateTSmaReq;
4731

4732
typedef struct {
4733
  int8_t  type;  // 0 status report, 1 update data
4734
  int64_t indexUid;
4735
  int64_t skey;  // start TS key of interval/sliding window
4736
} STSmaMsg;
4737

4738
typedef struct {
4739
  int64_t indexUid;
4740
  char    indexName[TSDB_INDEX_NAME_LEN];
4741
} SVDropTSmaReq;
4742

4743
typedef struct {
4744
  int tmp;  // TODO: to avoid compile error
4745
} SVCreateTSmaRsp, SVDropTSmaRsp;
4746

4747
#if 0
4748
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4749
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4750
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4751
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4752
#endif
4753

4754
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4755
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4756
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4757
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4758

UNCOV
4759
typedef struct {
×
UNCOV
4760
  int32_t number;
×
UNCOV
4761
  STSma*  tSma;
×
UNCOV
4762
} STSmaWrapper;
×
4763

UNCOV
4764
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
×
4765
  if (pSma) {
4766
    taosMemoryFreeClear(pSma->dstTbName);
4767
    taosMemoryFreeClear(pSma->expr);
×
4768
    taosMemoryFreeClear(pSma->tagsFilter);
×
UNCOV
4769
  }
×
4770
}
×
UNCOV
4771

×
4772
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4773
  if (pSW) {
4774
    if (pSW->tSma) {
×
4775
      if (deepCopy) {
4776
        for (uint32_t i = 0; i < pSW->number; ++i) {
4777
          tDestroyTSma(pSW->tSma + i);
×
4778
        }
4779
      }
4780
      taosMemoryFreeClear(pSW->tSma);
×
UNCOV
4781
    }
×
UNCOV
4782
  }
×
4783
}
4784

4785
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4786
  tDestroyTSmaWrapper(pSW, deepCopy);
4787
  taosMemoryFreeClear(pSW);
4788
  return NULL;
4789
}
4790

UNCOV
4791
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
×
UNCOV
4792
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
×
UNCOV
4793

×
UNCOV
4794
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
×
4795
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
UNCOV
4796

×
4797
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
4798
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
4799
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4800
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
UNCOV
4801
  }
×
4802
  return 0;
×
4803
}
UNCOV
4804

×
4805
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
4806
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
4807
  for (int32_t i = 0; i < pReq->number; ++i) {
4808
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
4809
  }
4810
  return 0;
4811
}
4812

4813
typedef struct {
4814
  int idx;
4815
} SMCreateFullTextReq;
4816

4817
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4818
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4819
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4820

4821
typedef struct {
4822
  char   name[TSDB_TABLE_FNAME_LEN];
4823
  int8_t igNotExists;
4824
} SMDropFullTextReq;
4825

4826
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4827
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4828

4829
typedef struct {
4830
  char indexFName[TSDB_INDEX_FNAME_LEN];
4831
} SUserIndexReq;
4832

4833
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4834
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4835

4836
typedef struct {
4837
  char dbFName[TSDB_DB_FNAME_LEN];
4838
  char tblFName[TSDB_TABLE_FNAME_LEN];
4839
  char colName[TSDB_COL_NAME_LEN];
4840
  char indexType[TSDB_INDEX_TYPE_LEN];
4841
  char indexExts[TSDB_INDEX_EXTS_LEN];
4842
} SUserIndexRsp;
4843

4844
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4845
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4846

4847
typedef struct {
4848
  char tbFName[TSDB_TABLE_FNAME_LEN];
4849
} STableIndexReq;
4850

4851
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4852
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4853

4854
typedef struct {
4855
  int8_t  intervalUnit;
4856
  int8_t  slidingUnit;
4857
  int64_t interval;
4858
  int64_t offset;
4859
  int64_t sliding;
4860
  int64_t dstTbUid;
4861
  int32_t dstVgId;
4862
  SEpSet  epSet;
4863
  char*   expr;
4864
} STableIndexInfo;
4865

4866
typedef struct {
4867
  char     tbName[TSDB_TABLE_NAME_LEN];
4868
  char     dbFName[TSDB_DB_FNAME_LEN];
4869
  uint64_t suid;
4870
  int32_t  version;
4871
  int32_t  indexSize;
4872
  SArray*  pIndex;  // STableIndexInfo
4873
} STableIndexRsp;
4874

4875
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4876
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4877
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4878

4879
void tFreeSTableIndexInfo(void* pInfo);
4880

4881
typedef struct {
4882
  int8_t  mqMsgType;
4883
  int32_t code;
4884
  int32_t epoch;
4885
  int64_t consumerId;
4886
  int64_t walsver;
4887
  int64_t walever;
4888
} SMqRspHead;
4889

4890
typedef struct {
4891
  SMsgHead     head;
4892
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4893
  int8_t       withTbName;
4894
  int8_t       useSnapshot;
4895
  int32_t      epoch;
4896
  uint64_t     reqId;
4897
  int64_t      consumerId;
4898
  int64_t      timeout;
4899
  STqOffsetVal reqOffset;
4900
  int8_t       enableReplay;
4901
  int8_t       sourceExcluded;
4902
  int8_t       rawData;
4903
  int32_t      minPollRows;
4904
  int8_t       enableBatchMeta;
4905
  SHashObj*    uidHash;  // to find if uid is duplicated
4906
} SMqPollReq;
4907

4908
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4909
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4910
void    tDestroySMqPollReq(SMqPollReq* pReq);
4911

4912
typedef struct {
4913
  int32_t vgId;
512,088✔
4914
  int64_t offset;
512,088✔
4915
  SEpSet  epSet;
512,088✔
4916
} SMqSubVgEp;
512,088✔
4917

512,088✔
4918
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4919
  int32_t tlen = 0;
4920
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
4921
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
401,363✔
4922
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
401,363✔
4923
  return tlen;
401,363✔
4924
}
401,363✔
4925

4926
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4927
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4928
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4929
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4930
  return buf;
4931
}
4932

4933
typedef struct {
4934
  char           topic[TSDB_TOPIC_FNAME_LEN];
4935
  char           db[TSDB_DB_FNAME_LEN];
4936
  SArray*        vgs;  // SArray<SMqSubVgEp>
4937
  SSchemaWrapper schema;
4938
} SMqSubTopicEp;
4939

4940
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4941
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4942
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4943

4944
typedef struct {
4945
  SMqRspHead   head;
4946
  STqOffsetVal rspOffset;
4947
  int16_t      resMsgType;
4948
  int32_t      metaRspLen;
4949
  void*        metaRsp;
4950
} SMqMetaRsp;
4951

4952
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4953
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4954
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4955

4956
#define MQ_DATA_RSP_VERSION 100
4957

4958
typedef struct {
4959
  SMqRspHead   head;
4960
  STqOffsetVal rspOffset;
4961
  STqOffsetVal reqOffset;
4962
  int32_t      blockNum;
4963
  int8_t       withTbName;
4964
  int8_t       withSchema;
4965
  SArray*      blockDataLen;
4966
  SArray*      blockData;
4967
  SArray*      blockTbName;
4968
  SArray*      blockSchema;
4969

4970
  union {
4971
    struct {
4972
      int64_t sleepTime;
4973
    };
4974
    struct {
4975
      int32_t createTableNum;
4976
      SArray* createTableLen;
4977
      SArray* createTableReq;
4978
    };
4979
    struct {
4980
      int32_t len;
4981
      void*   rawData;
4982
    };
4983
  };
4984
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4985
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4986
} SMqDataRsp;
4987

4988
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4989
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4990
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4991
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4992
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4993

4994
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4995
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4996
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4997

4998
typedef struct SMqBatchMetaRsp {
4999
  SMqRspHead   head;  // not serialize
5000
  STqOffsetVal rspOffset;
5001
  SArray*      batchMetaLen;
5002
  SArray*      batchMetaReq;
5003
  void*        pMetaBuff;    // not serialize
5004
  uint32_t     metaBuffLen;  // not serialize
5005
} SMqBatchMetaRsp;
5006

5007
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5008
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5009
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5010
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5011

5012
typedef struct {
5013
  SMqRspHead head;
1,228,992✔
5014
  char       cgroup[TSDB_CGROUP_LEN];
5015
  SArray*    topics;  // SArray<SMqSubTopicEp>
1,228,992✔
5016
} SMqAskEpRsp;
1,229,152✔
5017

1,410,384✔
5018
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
181,232✔
5019
  int32_t tlen = 0;
181,232✔
5020
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5021
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,229,152✔
5022
  tlen += taosEncodeFixedI32(buf, sz);
5023
  for (int32_t i = 0; i < sz; i++) {
5024
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
5025
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
5026
  }
542,256✔
5027
  return tlen;
832,067✔
5028
}
832,067✔
5029

832,067✔
UNCOV
5030
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
×
5031
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5032
  int32_t sz;
1,005,936✔
5033
  buf = taosDecodeFixedI32(buf, &sz);
90,449✔
5034
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
173,869✔
5035
  if (pRsp->topics == NULL) {
173,670✔
5036
    return NULL;
×
5037
  }
5038
  for (int32_t i = 0; i < sz; i++) {
347,539✔
UNCOV
5039
    SMqSubTopicEp topicEp;
×
5040
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
5041
    if (buf == NULL) {
5042
      return NULL;
832,067✔
5043
    }
5044
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
5045
      return NULL;
5046
    }
1,840,436✔
5047
  }
1,840,276✔
5048
  return buf;
5049
}
5050

5051
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5052
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
5053
}
5054

5055
typedef struct {
5056
  int32_t      vgId;
5057
  STqOffsetVal offset;
5058
  int64_t      rows;
5059
  int64_t      ever;
5060
} OffsetRows;
5061

5062
typedef struct {
5063
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5064
  SArray* offsetRows;
5065
} TopicOffsetRows;
5066

5067
typedef struct {
5068
  int64_t consumerId;
5069
  int32_t epoch;
5070
  SArray* topics;
5071
  int8_t  pollFlag;
5072
} SMqHbReq;
5073

5074
typedef struct {
5075
  char   topic[TSDB_TOPIC_FNAME_LEN];
5076
  int8_t noPrivilege;
5077
} STopicPrivilege;
5078

5079
typedef struct {
5080
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5081
  int32_t debugFlag;
5082
} SMqHbRsp;
5083

5084
typedef struct {
5085
  SMsgHead head;
5086
  int64_t  consumerId;
5087
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5088
} SMqSeekReq;
5089

5090
#define TD_AUTO_CREATE_TABLE 0x1
5091
typedef struct {
5092
  int64_t       suid;
5093
  int64_t       uid;
5094
  int32_t       sver;
5095
  uint32_t      nData;
5096
  uint8_t*      pData;
5097
  SVCreateTbReq cTbReq;
5098
} SVSubmitBlk;
5099

5100
typedef struct {
5101
  SMsgHead header;
5102
  uint64_t sId;
5103
  uint64_t queryId;
5104
  uint64_t clientId;
5105
  uint64_t taskId;
5106
  uint32_t sqlLen;
5107
  uint32_t phyLen;
5108
  char*    sql;
5109
  char*    msg;
5110
  int8_t   source;
5111
} SVDeleteReq;
5112

5113
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5114
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5115

5116
typedef struct {
5117
  int64_t affectedRows;
5118
} SVDeleteRsp;
5119

5120
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5121
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5122

5123
typedef struct SDeleteRes {
5124
  uint64_t suid;
5125
  SArray*  uidList;
5126
  int64_t  skey;
5127
  int64_t  ekey;
5128
  int64_t  affectedRows;
5129
  char     tableFName[TSDB_TABLE_NAME_LEN];
5130
  char     tsColName[TSDB_COL_NAME_LEN];
5131
  int64_t  ctimeMs;  // fill by vnode
5132
  int8_t   source;
5133
} SDeleteRes;
5134

5135
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5136
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5137

5138
typedef struct {
5139
  // int64_t uid;
5140
  char    tbname[TSDB_TABLE_NAME_LEN];
5141
  int64_t startTs;
5142
  int64_t endTs;
5143
} SSingleDeleteReq;
5144

5145
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5146
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5147

5148
typedef struct {
5149
  int64_t suid;
5150
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5151
  int64_t ctimeMs;     // fill by vnode
5152
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5153
} SBatchDeleteReq;
5154

5155
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5156
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5157
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5158

5159
typedef struct {
5160
  int32_t msgIdx;
5161
  int32_t msgType;
5162
  int32_t msgLen;
5163
  void*   msg;
5164
} SBatchMsg;
5165

5166
typedef struct {
5167
  SMsgHead header;
5168
  SArray*  pMsgs;  // SArray<SBatchMsg>
5169
} SBatchReq;
5170

5171
typedef struct {
5172
  int32_t reqType;
5173
  int32_t msgIdx;
5174
  int32_t msgLen;
5175
  int32_t rspCode;
5176
  void*   msg;
5177
} SBatchRspMsg;
5178

5179
typedef struct {
91,587,571✔
5180
  SArray* pRsps;  // SArray<SBatchRspMsg>
91,587,571✔
UNCOV
5181
} SBatchRsp;
×
5182

5183
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
91,587,571✔
5184
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
91,587,571✔
5185
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
5186
  if (NULL == msg) {
5187
    return;
5188
  }
5189
  SBatchMsg* pMsg = (SBatchMsg*)msg;
5190
  taosMemoryFree(pMsg->msg);
138,702,115✔
5191
}
138,702,115✔
UNCOV
5192

×
5193
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5194
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5195

138,702,115✔
5196
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
138,702,115✔
5197
  if (NULL == p) {
5198
    return;
5199
  }
5200

5201
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
5202
  taosMemoryFree(pRsp->msg);
5203
}
5204

5205
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5206
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5207
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5208
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5209
void    tDestroySMqHbReq(SMqHbReq* pReq);
5210

5211
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5212
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5213
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5214

5215
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5216
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5217

5218
#define TD_REQ_FROM_APP               0x0
5219
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5220
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5221
#define SUBMIT_REQ_FROM_FILE          0x4
5222
#define TD_REQ_FROM_TAOX              0x8
5223
#define TD_REQ_FROM_SML               0x10
5224
#define SUBMIT_REQUEST_VERSION        (2)
5225
#define SUBMIT_REQ_WITH_BLOB          0x10
5226
#define SUBMIT_REQ_SCHEMA_RES         0x20
5227
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5228

5229
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5230

5231
typedef struct {
5232
  int32_t        flags;
5233
  SVCreateTbReq* pCreateTbReq;
5234
  int64_t        suid;
5235
  int64_t        uid;
5236
  int32_t        sver;
5237
  union {
5238
    SArray* aRowP;
5239
    SArray* aCol;
5240
  };
5241
  int64_t    ctimeMs;
5242
  SBlobSet*  pBlobSet;
5243
} SSubmitTbData;
5244

5245
typedef struct {
5246
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5247
  SArray* aSubmitBlobData;
5248
  bool    raw;
5249
} SSubmitReq2;
5250

5251
typedef struct {
5252
  SMsgHead header;
5253
  int64_t  version;
5254
  char     data[];  // SSubmitReq2
5255
} SSubmitReq2Msg;
5256

5257
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5258
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5259
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5260
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5261
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5262

5263
typedef struct {
5264
  int32_t affectedRows;
5265
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5266
} SSubmitRsp2;
5267

5268
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5269
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5270
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5271

5272
#define TSDB_MSG_FLG_ENCODE 0x1
5273
#define TSDB_MSG_FLG_DECODE 0x2
5274
#define TSDB_MSG_FLG_CMPT   0x3
5275

5276
typedef struct {
5277
  union {
5278
    struct {
5279
      void*   msgStr;
5280
      int32_t msgLen;
5281
      int64_t ver;
5282
    };
5283
    void* pDataBlock;
5284
  };
5285
} SPackedData;
5286

5287
typedef struct {
5288
  char     fullname[TSDB_VIEW_FNAME_LEN];
5289
  char     name[TSDB_VIEW_NAME_LEN];
5290
  char     dbFName[TSDB_DB_FNAME_LEN];
5291
  char*    querySql;
5292
  char*    sql;
5293
  int8_t   orReplace;
5294
  int8_t   precision;
5295
  int32_t  numOfCols;
5296
  SSchema* pSchema;
5297
} SCMCreateViewReq;
5298

5299
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5300
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5301
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5302

5303
typedef struct {
5304
  char   fullname[TSDB_VIEW_FNAME_LEN];
5305
  char   name[TSDB_VIEW_NAME_LEN];
5306
  char   dbFName[TSDB_DB_FNAME_LEN];
5307
  char*  sql;
5308
  int8_t igNotExists;
5309
} SCMDropViewReq;
5310

5311
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5312
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5313
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5314

5315
typedef struct {
5316
  char fullname[TSDB_VIEW_FNAME_LEN];
5317
} SViewMetaReq;
5318
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5319
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5320

5321
typedef struct {
5322
  char     name[TSDB_VIEW_NAME_LEN];
5323
  char     dbFName[TSDB_DB_FNAME_LEN];
5324
  char*    user;
5325
  uint64_t dbId;
5326
  uint64_t viewId;
5327
  char*    querySql;
5328
  int8_t   precision;
5329
  int8_t   type;
5330
  int32_t  version;
5331
  int32_t  numOfCols;
5332
  SSchema* pSchema;
5333
} SViewMetaRsp;
5334
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5335
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5336
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5337
typedef struct {
5338
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5339
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5340
} STableTSMAInfoReq;
5341

5342
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5343
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5344

5345
typedef struct {
5346
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5347
  union {
5348
    uint8_t flags;
5349
    struct {
5350
      uint8_t withColName : 1;
5351
      uint8_t reserved : 7;
5352
    };
5353
  };
5354

5355
} SRsmaInfoReq;
5356

5357
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5358
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5359

5360
typedef struct {
5361
  int32_t  funcId;
5362
  col_id_t colId;
5363
} STableTSMAFuncInfo;
5364

5365
typedef struct {
5366
  char     name[TSDB_TABLE_NAME_LEN];
5367
  uint64_t tsmaId;
5368
  char     targetTb[TSDB_TABLE_NAME_LEN];
5369
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5370
  char     tb[TSDB_TABLE_NAME_LEN];
5371
  char     dbFName[TSDB_DB_FNAME_LEN];
5372
  uint64_t suid;
5373
  uint64_t destTbUid;
5374
  uint64_t dbId;
5375
  int32_t  version;
5376
  int64_t  interval;
5377
  int8_t   unit;
5378
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5379
  SArray*  pTags;      // SArray<SSchema>
5380
  SArray*  pUsedCols;  // SArray<SSchema>
5381
  char*    ast;
5382

5383
  int64_t streamUid;
5384
  int64_t reqTs;
5385
  int64_t rspTs;
5386
  int64_t delayDuration;  // ms
5387
  bool    fillHistoryFinished;
5388

5389
  void*   streamAddr;  // for stream task, the address of the stream task
5390
} STableTSMAInfo;
5391

5392
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5393
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5394
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5395
void    tFreeTableTSMAInfo(void* p);
5396
void    tFreeAndClearTableTSMAInfo(void* p);
5397
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5398

5399
#define STSMAHbRsp            STableTSMAInfoRsp
5400
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5401
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5402
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5403

5404
typedef struct SDropCtbWithTsmaSingleVgReq {
5405
  SVgroupInfo vgInfo;
5406
  SArray*     pTbs;  // SVDropTbReq
5407
} SMDropTbReqsOnSingleVg;
5408

5409
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5410
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5411
void    tFreeSMDropTbReqOnSingleVg(void* p);
5412

5413
typedef struct SDropTbsReq {
5414
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5415
} SMDropTbsReq;
5416

5417
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5418
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5419
void    tFreeSMDropTbsReq(void*);
5420

5421
typedef struct SVFetchTtlExpiredTbsRsp {
5422
  SArray* pExpiredTbs;  // SVDropTbReq
5423
  int32_t vgId;
5424
} SVFetchTtlExpiredTbsRsp;
5425

5426
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5427
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5428

5429
void tFreeFetchTtlExpiredTbsRsp(void* p);
5430

5431
void setDefaultOptionsForField(SFieldWithOptions* field);
5432
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5433

5434
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5435
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5436

5437
#ifdef USE_MOUNT
5438
typedef struct {
5439
  char     mountName[TSDB_MOUNT_NAME_LEN];
5440
  int8_t   ignoreExist;
5441
  int16_t  nMounts;
5442
  int32_t* dnodeIds;
5443
  char**   mountPaths;
5444
  int32_t  sqlLen;
5445
  char*    sql;
5446
} SCreateMountReq;
5447

5448
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5449
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5450
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5451

5452
typedef struct {
5453
  char    mountName[TSDB_MOUNT_NAME_LEN];
5454
  int8_t  ignoreNotExists;
5455
  int32_t sqlLen;
5456
  char*   sql;
5457
} SDropMountReq;
5458

5459
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5460
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5461
void    tFreeSDropMountReq(SDropMountReq* pReq);
5462

5463
typedef struct {
5464
  char     mountName[TSDB_MOUNT_NAME_LEN];
5465
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5466
  int64_t  mountUid;
5467
  int32_t  dnodeId;
5468
  uint32_t valLen;
5469
  int8_t   ignoreExist;
5470
  void*    pVal;
5471
} SRetrieveMountPathReq;
5472

5473
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5474
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5475

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

5531
typedef struct {
5532
  SMCreateStbReq req;
5533
  SArray*        pColExts;  // element: column id
5534
  SArray*        pTagExts;  // element: tag id
5535
} SMountStbInfo;
5536

5537
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5538
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5539

5540
typedef struct {
5541
  char     dbName[TSDB_DB_FNAME_LEN];
5542
  uint64_t dbId;
5543
  SArray*  pVgs;      // SMountVgInfo
5544
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5545
} SMountDbInfo;
5546

5547
typedef struct {
5548
  // common fields
5549
  char     mountName[TSDB_MOUNT_NAME_LEN];
5550
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5551
  int8_t   ignoreExist;
5552
  int64_t  mountUid;
5553
  int64_t  clusterId;
5554
  int32_t  dnodeId;
5555
  uint32_t valLen;
5556
  void*    pVal;
5557

5558
  // response fields
5559
  SArray* pDbs;  // SMountDbInfo
5560

5561
  // memory fields, no serialized
5562
  SArray*   pDisks[TFS_MAX_TIERS];
5563
  TdFilePtr pFile;
5564
} SMountInfo;
5565

5566
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5567
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5568
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5569

5570
typedef struct {
5571
  SCreateVnodeReq createReq;
5572
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5573
  char            mountName[TSDB_MOUNT_NAME_LEN];
5574
  int64_t         mountId;
5575
  int32_t         diskPrimary;
5576
  int32_t         mountVgId;
5577
  int64_t         committed;
5578
  int64_t         commitID;
5579
  int64_t         commitTerm;
5580
  int64_t         numOfSTables;
5581
  int64_t         numOfCTables;
5582
  int64_t         numOfNTables;
5583
} SMountVnodeReq;
5584

5585
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5586
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5587
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5588

5589
#endif  // USE_MOUNT
5590

5591
#pragma pack(pop)
5592

5593
typedef struct {
5594
  char        db[TSDB_DB_FNAME_LEN];
5595
  STimeWindow timeRange;
5596
  int32_t     sqlLen;
5597
  char*       sql;
5598
  SArray*     vgroupIds;
5599
} SScanDbReq;
5600

5601
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5602
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5603
void    tFreeSScanDbReq(SScanDbReq* pReq);
5604

5605
typedef struct {
5606
  int32_t scanId;
5607
  int8_t  bAccepted;
5608
} SScanDbRsp;
5609

5610
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5611
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5612

5613
typedef struct {
5614
  int32_t scanId;
5615
  int32_t sqlLen;
5616
  char*   sql;
5617
} SKillScanReq;
5618

5619
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5620
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5621
void    tFreeSKillScanReq(SKillScanReq* pReq);
5622

5623
typedef struct {
5624
  int32_t scanId;
5625
  int32_t vgId;
5626
  int32_t dnodeId;
5627
} SVKillScanReq;
5628

5629
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5630
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5631

5632
typedef struct {
5633
  int32_t scanId;
5634
  int32_t vgId;
5635
  int32_t dnodeId;
5636
  int32_t numberFileset;
5637
  int32_t finished;
5638
  int32_t progress;
5639
  int64_t remainingTime;
5640
} SQueryScanProgressRsp;
5641

5642
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5643
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5644

5645
typedef struct {
5646
  int32_t scanId;
5647
  int32_t vgId;
5648
  int32_t dnodeId;
5649
} SQueryScanProgressReq;
5650

5651
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5652
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5653

5654
typedef struct {
5655
  int64_t     dbUid;
5656
  char        db[TSDB_DB_FNAME_LEN];
5657
  int64_t     scanStartTime;
5658
  STimeWindow tw;
5659
  int32_t     scanId;
5660
} SScanVnodeReq;
5661

5662
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5663
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5664

5665
#ifdef __cplusplus
5666
}
5667
#endif
5668

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