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

taosdata / TDengine / #4874

04 Dec 2025 01:55AM UTC coverage: 64.623% (+0.07%) from 64.558%
#4874

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

865 of 2219 new or added lines in 36 files covered. (38.98%)

6317 existing lines in 143 files now uncovered.

159543 of 246882 relevant lines covered (64.62%)

106415537.4 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

65
typedef uint16_t tmsg_t;
66

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

71

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

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

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

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

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

110
static inline bool vnodeIsMsgBlock(tmsg_t type) {
739,422,487✔
111
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
697,198,613✔
112
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,436,621,100✔
113
         (type == TDMT_SYNC_CONFIG_CHANGE);
114
}
115

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

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

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

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

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

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

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

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

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

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

258
#define TSDB_ALTER_RSMA_FUNCTION        0x1
259

260
#define TSDB_KILL_MSG_LEN 30
261

262
#define TSDB_TABLE_NUM_UNIT 100000
263

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

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

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

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

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

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

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

460
  // show statement nodes
461
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
462
  QUERY_NODE_SHOW_DNODES_STMT = 400,
463
  QUERY_NODE_SHOW_MNODES_STMT,
464
  QUERY_NODE_SHOW_MODULES_STMT,
465
  QUERY_NODE_SHOW_QNODES_STMT,
466
  QUERY_NODE_SHOW_SNODES_STMT,
467
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
468
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
469
  QUERY_NODE_SHOW_CLUSTER_STMT,
470
  QUERY_NODE_SHOW_DATABASES_STMT,
471
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
472
  QUERY_NODE_SHOW_INDEXES_STMT,
473
  QUERY_NODE_SHOW_STABLES_STMT,
474
  QUERY_NODE_SHOW_STREAMS_STMT,
475
  QUERY_NODE_SHOW_TABLES_STMT,
476
  QUERY_NODE_SHOW_TAGS_STMT,
477
  QUERY_NODE_SHOW_USERS_STMT,
478
  QUERY_NODE_SHOW_USERS_FULL_STMT,
479
  QUERY_NODE_SHOW_LICENCES_STMT,
480
  QUERY_NODE_SHOW_VGROUPS_STMT,
481
  QUERY_NODE_SHOW_TOPICS_STMT,
482
  QUERY_NODE_SHOW_CONSUMERS_STMT,
483
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
484
  QUERY_NODE_SHOW_QUERIES_STMT,
485
  QUERY_NODE_SHOW_APPS_STMT,
486
  QUERY_NODE_SHOW_VARIABLES_STMT,
487
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
488
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
489
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
490
  QUERY_NODE_SHOW_VNODES_STMT,
491
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
492
  QUERY_NODE_SHOW_VIEWS_STMT,
493
  QUERY_NODE_SHOW_COMPACTS_STMT,
494
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
495
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
496
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
497
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
498
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
499
  QUERY_NODE_SHOW_TSMAS_STMT,
500
  QUERY_NODE_SHOW_ANODES_STMT,
501
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
502
  QUERY_NODE_SHOW_USAGE_STMT,
503
  QUERY_NODE_SHOW_FILESETS_STMT,
504
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
505
  QUERY_NODE_SHOW_VTABLES_STMT,
506
  QUERY_NODE_SHOW_BNODES_STMT,
507
  QUERY_NODE_SHOW_MOUNTS_STMT,
508
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
509
  QUERY_NODE_SHOW_SCANS_STMT,
510
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
511
  QUERY_NODE_SHOW_RSMAS_STMT,
512
  QUERY_NODE_SHOW_RETENTIONS_STMT,
513
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
514
  QUERY_NODE_SHOW_INSTANCES_STMT,
515
  // logic plan node
516
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
517
  QUERY_NODE_LOGIC_PLAN_JOIN,
518
  QUERY_NODE_LOGIC_PLAN_AGG,
519
  QUERY_NODE_LOGIC_PLAN_PROJECT,
520
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
521
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
522
  QUERY_NODE_LOGIC_PLAN_MERGE,
523
  QUERY_NODE_LOGIC_PLAN_WINDOW,
524
  QUERY_NODE_LOGIC_PLAN_FILL,
525
  QUERY_NODE_LOGIC_PLAN_SORT,
526
  QUERY_NODE_LOGIC_PLAN_PARTITION,
527
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
528
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
529
  QUERY_NODE_LOGIC_SUBPLAN,
530
  QUERY_NODE_LOGIC_PLAN,
531
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
532
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
533
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
534
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
535
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
536

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

886
bool hasExtSchema(const SExtSchema* pExtSchema);
887

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

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

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

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

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

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

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

943
  return pDstWrapper;
944
}
945

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

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

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

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

985
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
293,796,404✔
986
  if (pSW == NULL) {
293,760,418✔
987
    return NULL;
×
988
  }
989
  pSW->nCols = pSchemaWrapper->nCols;
293,760,418✔
990
  pSW->version = pSchemaWrapper->version;
293,732,612✔
991
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
293,722,539✔
992
  if (pSW->pSchema == NULL) {
293,653,580✔
993
    taosMemoryFree(pSW);
×
994
    return NULL;
×
995
  }
996

997
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
293,652,583✔
998
  return pSW;
293,853,497✔
999
}
1000

1001
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
73,865,788✔
1002
  if (pSchemaWrapper) {
765,139,901✔
1003
    taosMemoryFree(pSchemaWrapper->pSchema);
433,365,399✔
1004
    if(pSchemaWrapper->pRsma) {
433,325,060✔
1005
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
56,664✔
1006
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
56,664✔
1007
    }
1008
    taosMemoryFree(pSchemaWrapper);
433,236,054✔
1009
  }
1010
}
749,194,599✔
1011

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

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

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

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

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

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

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

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

1079
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1080
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
22,550,148✔
1081
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
22,550,148✔
1082
  if (pColRef->hasRef) {
11,275,074✔
1083
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
12,438,872✔
1084
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
12,438,872✔
1085
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
12,438,872✔
1086
  }
1087
  return 0;
11,275,074✔
1088
}
1089

1090
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1091
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
12,807,360✔
1092
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
12,807,360✔
1093
  if (pColRef->hasRef) {
6,403,680✔
1094
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
3,753,181✔
1095
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
3,753,181✔
1096
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
3,753,181✔
1097
  }
1098

1099
  return 0;
6,403,680✔
1100
}
1101

1102
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1103
  int32_t tlen = 0;
347,432✔
1104
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
347,432✔
1105
  tlen += taosEncodeVariantI32(buf, pSW->version);
347,432✔
1106
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,227,962✔
1107
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,761,060✔
1108
  }
1109
  return tlen;
347,432✔
1110
}
1111

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

1121
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,703,686✔
1122
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,979,194✔
1123
    }
1124
  } else {
1125
    pSW->pSchema = NULL;
21,140✔
1126
  }
1127
  return (void*)buf;
235,229✔
1128
}
1129

1130
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1131
  if (pSW == NULL) {
197,416,036✔
1132
    return TSDB_CODE_INVALID_PARA;
×
1133
  }
1134
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
394,808,742✔
1135
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
394,690,358✔
1136
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1137
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1138
  }
1139
  return 0;
197,563,341✔
1140
}
1141

1142
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1143
  if (pSW == NULL) {
58,310,949✔
1144
    return TSDB_CODE_INVALID_PARA;
×
1145
  }
1146
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
116,618,591✔
1147
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
116,637,548✔
1148

1149
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
58,329,906✔
1150
  if (pSW->pSchema == NULL) {
58,290,616✔
1151
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1152
  }
1153
  for (int32_t i = 0; i < pSW->nCols; i++) {
622,075,941✔
1154
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,127,418,033✔
1155
  }
1156

1157
  return 0;
58,348,960✔
1158
}
1159

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

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

1172
  return 0;
1,428,889,068✔
1173
}
1174

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1617
typedef STableCfg STableCfgRsp;
1618

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1836

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

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

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

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

1855

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

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

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

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

1877

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

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

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

1899

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

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

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

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

1919

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

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

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

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

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

1992
typedef SDbCfgRsp SDbCfgInfo;
1993

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2550
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2551
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2552

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

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

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

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

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

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

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

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

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

2615
typedef SVKillCompactReq SVKillRetentionReq;
2616

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2819
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2820

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3036

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

3040

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

3046

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

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

3059

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3435
typedef struct SMergeOperatorParam {
3436
  int32_t         winNum;
3437
} SMergeOperatorParam;
3438

3439
typedef struct SExternalWindowOperatorParam {
3440
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3441
} SExternalWindowOperatorParam;
3442

3443
typedef struct SDynQueryCtrlOperatorParam {
3444
  STimeWindow    window;
3445
} SDynQueryCtrlOperatorParam;
3446

3447
struct SStreamRuntimeFuncInfo;
3448
typedef struct {
3449
  SMsgHead                       header;
3450
  uint64_t                       sId;
3451
  uint64_t                       queryId;
3452
  uint64_t                       clientId;
3453
  uint64_t                       taskId;
3454
  int32_t                        execId;
3455
  SOperatorParam*                pOpParam;
3456

3457
  // used for new-stream
3458
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3459
  bool                           reset;
3460
  bool                           dynTbname;
3461
  // used for new-stream
3462
} SResFetchReq;
3463

3464
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3465
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3466
void    tDestroySResFetchReq(SResFetchReq* pReq);
3467
typedef struct {
3468
  SMsgHead header;
3469
  uint64_t clientId;
3470
} SSchTasksStatusReq;
3471

3472
typedef struct {
3473
  uint64_t queryId;
3474
  uint64_t clientId;
3475
  uint64_t taskId;
3476
  int64_t  refId;
3477
  int32_t  execId;
3478
  int8_t   status;
3479
} STaskStatus;
3480

3481
typedef struct {
3482
  int64_t refId;
3483
  SArray* taskStatus;  // SArray<STaskStatus>
3484
} SSchedulerStatusRsp;
3485

3486
typedef struct {
3487
  uint64_t queryId;
3488
  uint64_t taskId;
3489
  int8_t   action;
3490
} STaskAction;
3491

3492
typedef struct SQueryNodeEpId {
3493
  int32_t nodeId;  // vgId or qnodeId
3494
  SEp     ep;
3495
} SQueryNodeEpId;
3496

3497
typedef struct {
3498
  SMsgHead       header;
3499
  uint64_t       clientId;
3500
  SQueryNodeEpId epId;
3501
  SArray*        taskAction;  // SArray<STaskAction>
3502
} SSchedulerHbReq;
3503

3504
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3505
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3506
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3507

3508
typedef struct {
3509
  SQueryNodeEpId epId;
3510
  SArray*        taskStatus;  // SArray<STaskStatus>
3511
} SSchedulerHbRsp;
3512

3513
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3514
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3515
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3516

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

3527
typedef struct {
3528
  int32_t code;
3529
} STaskCancelRsp;
3530

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

3541
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3542
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3543

3544
typedef enum {
3545
  TASK_NOTIFY_FINISHED = 1,
3546
} ETaskNotifyType;
3547

3548
typedef struct {
3549
  SMsgHead        header;
3550
  uint64_t        sId;
3551
  uint64_t        queryId;
3552
  uint64_t        clientId;
3553
  uint64_t        taskId;
3554
  int64_t         refId;
3555
  int32_t         execId;
3556
  ETaskNotifyType type;
3557
} STaskNotifyReq;
3558

3559
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3560
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3561

3562
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3563
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3564

3565
typedef struct {
3566
  int32_t code;
3567
} STaskDropRsp;
3568

3569
#define STREAM_TRIGGER_AT_ONCE                 1
3570
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3571
#define STREAM_TRIGGER_MAX_DELAY               3
3572
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3573
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3574

3575
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3576
#define STREAM_FILL_HISTORY_ON        1
3577
#define STREAM_FILL_HISTORY_OFF       0
3578
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3579
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3580
#define STREAM_CREATE_STABLE_TRUE     1
3581
#define STREAM_CREATE_STABLE_FALSE    0
3582

3583
typedef struct SVgroupVer {
3584
  int32_t vgId;
3585
  int64_t ver;
3586
} SVgroupVer;
3587

3588
typedef struct STaskNotifyEventStat {
3589
  int64_t notifyEventAddTimes;     // call times of add function
3590
  int64_t notifyEventAddElems;     // elements added by add function
3591
  double  notifyEventAddCostSec;   // time cost of add function
3592
  int64_t notifyEventPushTimes;    // call times of push function
3593
  int64_t notifyEventPushElems;    // elements pushed by push function
3594
  double  notifyEventPushCostSec;  // time cost of push function
3595
  int64_t notifyEventPackTimes;    // call times of pack function
3596
  int64_t notifyEventPackElems;    // elements packed by pack function
3597
  double  notifyEventPackCostSec;  // time cost of pack function
3598
  int64_t notifyEventSendTimes;    // call times of send function
3599
  int64_t notifyEventSendElems;    // elements sent by send function
3600
  double  notifyEventSendCostSec;  // time cost of send function
3601
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3602
} STaskNotifyEventStat;
3603

3604
enum {
3605
  TOPIC_SUB_TYPE__DB = 1,
3606
  TOPIC_SUB_TYPE__TABLE,
3607
  TOPIC_SUB_TYPE__COLUMN,
3608
};
3609

3610
#define DEFAULT_MAX_POLL_INTERVAL  300000
3611
#define DEFAULT_SESSION_TIMEOUT    12000
3612
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3613
#define DEFAULT_MIN_POLL_ROWS      4096
3614

3615
typedef struct {
3616
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3617
  int8_t igExists;
3618
  int8_t subType;
3619
  int8_t withMeta;
3620
  char*  sql;
3621
  char   subDbName[TSDB_DB_FNAME_LEN];
3622
  char*  ast;
3623
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3624
} SCMCreateTopicReq;
3625

3626
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3627
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3628
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3629

3630
typedef struct {
3631
  int64_t consumerId;
3632
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3633

3634
typedef struct {
3635
  int64_t consumerId;
3636
  char    cgroup[TSDB_CGROUP_LEN];
3637
  char    clientId[TSDB_CLIENT_ID_LEN];
3638
  char    user[TSDB_USER_LEN];
3639
  char    fqdn[TSDB_FQDN_LEN];
3640
  SArray* topicNames;  // SArray<char**>
3641

3642
  int8_t  withTbName;
3643
  int8_t  autoCommit;
3644
  int32_t autoCommitInterval;
3645
  int8_t  resetOffsetCfg;
3646
  int8_t  enableReplay;
3647
  int8_t  enableBatchMeta;
3648
  int32_t sessionTimeoutMs;
3649
  int32_t maxPollIntervalMs;
3650
} SCMSubscribeReq;
3651

3652
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3653
  int32_t tlen = 0;
475,714✔
3654
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
475,714✔
3655
  tlen += taosEncodeString(buf, pReq->cgroup);
475,714✔
3656
  tlen += taosEncodeString(buf, pReq->clientId);
475,714✔
3657

3658
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
475,714✔
3659
  tlen += taosEncodeFixedI32(buf, topicNum);
475,714✔
3660

3661
  for (int32_t i = 0; i < topicNum; i++) {
679,134✔
3662
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
406,840✔
3663
  }
3664

3665
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
475,714✔
3666
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
475,714✔
3667
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
475,714✔
3668
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
475,714✔
3669
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
475,714✔
3670
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
475,714✔
3671
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
475,714✔
3672
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
475,714✔
3673
  tlen += taosEncodeString(buf, pReq->user);
475,714✔
3674
  tlen += taosEncodeString(buf, pReq->fqdn);
475,714✔
3675

3676
  return tlen;
475,714✔
3677
}
3678

3679
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3680
  void* start = buf;
133,068✔
3681
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
133,068✔
3682
  buf = taosDecodeStringTo(buf, pReq->cgroup);
133,068✔
3683
  buf = taosDecodeStringTo(buf, pReq->clientId);
133,068✔
3684

3685
  int32_t topicNum = 0;
133,068✔
3686
  buf = taosDecodeFixedI32(buf, &topicNum);
133,068✔
3687

3688
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
133,068✔
3689
  if (pReq->topicNames == NULL) {
133,068✔
UNCOV
3690
    return terrno;
×
3691
  }
3692
  for (int32_t i = 0; i < topicNum; i++) {
190,427✔
3693
    char* name = NULL;
57,359✔
3694
    buf = taosDecodeString(buf, &name);
57,359✔
3695
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
114,718✔
UNCOV
3696
      return terrno;
×
3697
    }
3698
  }
3699

3700
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
133,068✔
3701
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
133,068✔
3702
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
133,068✔
3703
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
133,068✔
3704
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
133,068✔
3705
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
133,068✔
3706
  if ((char*)buf - (char*)start < len) {
133,068✔
3707
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
133,068✔
3708
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
133,068✔
3709
    buf = taosDecodeStringTo(buf, pReq->user);
133,068✔
3710
    buf = taosDecodeStringTo(buf, pReq->fqdn);
266,136✔
3711
  } else {
UNCOV
3712
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
3713
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3714
  }
3715

3716
  return 0;
133,068✔
3717
}
3718

3719
typedef struct {
3720
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3721
  SArray* removedConsumers;  // SArray<int64_t>
3722
  SArray* newConsumers;      // SArray<int64_t>
3723
} SMqRebInfo;
3724

3725
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3726
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
100,903✔
3727
  if (pRebInfo == NULL) {
100,903✔
UNCOV
3728
    return NULL;
×
3729
  }
3730
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
100,903✔
3731
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
100,903✔
3732
  if (pRebInfo->removedConsumers == NULL) {
100,903✔
UNCOV
3733
    goto _err;
×
3734
  }
3735
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
100,903✔
3736
  if (pRebInfo->newConsumers == NULL) {
100,903✔
UNCOV
3737
    goto _err;
×
3738
  }
3739
  return pRebInfo;
100,903✔
UNCOV
3740
_err:
×
UNCOV
3741
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3742
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3743
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
3744
  return NULL;
×
3745
}
3746

3747
typedef struct {
3748
  int64_t streamId;
3749
  int64_t checkpointId;
3750
  char    streamName[TSDB_STREAM_FNAME_LEN];
3751
} SMStreamDoCheckpointMsg;
3752

3753
typedef struct {
3754
  int64_t status;
3755
} SMVSubscribeRsp;
3756

3757
typedef struct {
3758
  char    name[TSDB_TOPIC_FNAME_LEN];
3759
  int8_t  igNotExists;
3760
  int32_t sqlLen;
3761
  char*   sql;
3762
  int8_t  force;
3763
} SMDropTopicReq;
3764

3765
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3766
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3767
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3768

3769
typedef struct {
3770
  char   topic[TSDB_TOPIC_FNAME_LEN];
3771
  char   cgroup[TSDB_CGROUP_LEN];
3772
  int8_t igNotExists;
3773
  int8_t force;
3774
} SMDropCgroupReq;
3775

3776
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3777
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3778

3779
typedef struct {
3780
  int8_t reserved;
3781
} SMDropCgroupRsp;
3782

3783
typedef struct {
3784
  char    name[TSDB_TABLE_FNAME_LEN];
3785
  int8_t  alterType;
3786
  SSchema schema;
3787
} SAlterTopicReq;
3788

3789
typedef struct {
3790
  SMsgHead head;
3791
  char     name[TSDB_TABLE_FNAME_LEN];
3792
  int64_t  tuid;
3793
  int32_t  sverson;
3794
  int32_t  execLen;
3795
  char*    executor;
3796
  int32_t  sqlLen;
3797
  char*    sql;
3798
} SDCreateTopicReq;
3799

3800
typedef struct {
3801
  SMsgHead head;
3802
  char     name[TSDB_TABLE_FNAME_LEN];
3803
  int64_t  tuid;
3804
} SDDropTopicReq;
3805

3806
typedef struct {
3807
  char*      name;
3808
  int64_t    uid;
3809
  int64_t    interval[2];
3810
  int8_t     intervalUnit;
3811
  int16_t    nFuncs;
3812
  col_id_t*  funcColIds;  // column ids specified by user
3813
  func_id_t* funcIds;     // function ids specified by user
3814
} SRSmaParam;
3815

3816
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3817
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3818

3819
// TDMT_VND_CREATE_STB ==============
3820
typedef struct SVCreateStbReq {
3821
  char*           name;
3822
  tb_uid_t        suid;
3823
  int8_t          rollup;
3824
  SSchemaWrapper  schemaRow;
3825
  SSchemaWrapper  schemaTag;
3826
  SRSmaParam      rsmaParam;
3827
  int32_t         alterOriDataLen;
3828
  void*           alterOriData;
3829
  int8_t          source;
3830
  int8_t          colCmpred;
3831
  SColCmprWrapper colCmpr;
3832
  int64_t         keep;
3833
  SExtSchema*     pExtSchemas;
3834
  int8_t          virtualStb;
3835
} SVCreateStbReq;
3836

3837
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3838
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3839

3840
// TDMT_VND_DROP_STB ==============
3841
typedef struct SVDropStbReq {
3842
  char*    name;
3843
  tb_uid_t suid;
3844
} SVDropStbReq;
3845

3846
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3847
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3848

3849
// TDMT_VND_CREATE_TABLE ==============
3850
#define TD_CREATE_IF_NOT_EXISTS       0x1
3851
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
3852
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
3853
typedef struct SVCreateTbReq {
3854
  int32_t  flags;
3855
  char*    name;
3856
  tb_uid_t uid;
3857
  int64_t  btime;
3858
  int32_t  ttl;
3859
  int32_t  commentLen;
3860
  char*    comment;
3861
  int8_t   type;
3862
  union {
3863
    struct {
3864
      char*    stbName;  // super table name
3865
      uint8_t  tagNum;
3866
      tb_uid_t suid;
3867
      SArray*  tagName;
3868
      uint8_t* pTag;
3869
    } ctb;
3870
    struct {
3871
      SSchemaWrapper schemaRow;
3872
    } ntb;
3873
  };
3874
  int32_t         sqlLen;
3875
  char*           sql;
3876
  SColCmprWrapper colCmpr;
3877
  SExtSchema*     pExtSchemas;
3878
  SColRefWrapper  colRef;  // col reference for virtual table
3879
} SVCreateTbReq;
3880

3881
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3882
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3883
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3884
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
3885

3886
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3887
  if (NULL == req) {
2,099,993,651✔
3888
    return;
2,032,467,733✔
3889
  }
3890

3891
  taosMemoryFreeClear(req->sql);
67,526,172✔
3892
  taosMemoryFreeClear(req->name);
67,526,248✔
3893
  taosMemoryFreeClear(req->comment);
67,537,339✔
3894
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
67,525,385✔
3895
    taosMemoryFreeClear(req->ctb.pTag);
65,190,101✔
3896
    taosMemoryFreeClear(req->ctb.stbName);
65,176,905✔
3897
    taosArrayDestroy(req->ctb.tagName);
65,185,405✔
3898
    req->ctb.tagName = NULL;
65,162,498✔
3899
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,333,647✔
3900
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,333,647✔
3901
  }
3902
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
67,519,381✔
3903
  taosMemoryFreeClear(req->pExtSchemas);
67,536,130✔
3904
  taosMemoryFreeClear(req->colRef.pColRef);
67,537,402✔
3905
}
3906

3907
typedef struct {
3908
  int32_t nReqs;
3909
  union {
3910
    SVCreateTbReq* pReqs;
3911
    SArray*        pArray;
3912
  };
3913
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3914
} SVCreateTbBatchReq;
3915

3916
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3917
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3918
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3919

3920
typedef struct {
3921
  int32_t        code;
3922
  STableMetaRsp* pMeta;
3923
} SVCreateTbRsp, SVUpdateTbRsp;
3924

3925
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3926
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3927
void tFreeSVCreateTbRsp(void* param);
3928

3929
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3930
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3931

3932
typedef struct {
3933
  int32_t nRsps;
3934
  union {
3935
    SVCreateTbRsp* pRsps;
3936
    SArray*        pArray;
3937
  };
3938
} SVCreateTbBatchRsp;
3939

3940
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3941
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3942

3943
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3944
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3945

3946
// TDMT_VND_DROP_TABLE =================
3947
typedef struct {
3948
  char*    name;
3949
  uint64_t suid;  // for tmq in wal format
3950
  int64_t  uid;
3951
  int8_t   igNotExists;
3952
  int8_t   isVirtual;
3953
} SVDropTbReq;
3954

3955
typedef struct {
3956
  int32_t code;
3957
} SVDropTbRsp;
3958

3959
typedef struct {
3960
  int32_t nReqs;
3961
  union {
3962
    SVDropTbReq* pReqs;
3963
    SArray*      pArray;
3964
  };
3965
} SVDropTbBatchReq;
3966

3967
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3968
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3969

3970
typedef struct {
3971
  int32_t nRsps;
3972
  union {
3973
    SVDropTbRsp* pRsps;
3974
    SArray*      pArray;
3975
  };
3976
} SVDropTbBatchRsp;
3977

3978
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3979
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3980

3981
// TDMT_VND_ALTER_TABLE =====================
3982
typedef struct SMultiTagUpateVal {
3983
  char*    tagName;
3984
  int32_t  colId;
3985
  int8_t   tagType;
3986
  int8_t   tagFree;
3987
  uint32_t nTagVal;
3988
  uint8_t* pTagVal;
3989
  int8_t   isNull;
3990
  SArray*  pTagArray;
3991
} SMultiTagUpateVal;
3992
typedef struct SVAlterTbReq {
3993
  char*   tbName;
3994
  int8_t  action;
3995
  char*   colName;
3996
  int32_t colId;
3997
  // TSDB_ALTER_TABLE_ADD_COLUMN
3998
  int8_t  type;
3999
  int8_t  flags;
4000
  int32_t bytes;
4001
  // TSDB_ALTER_TABLE_DROP_COLUMN
4002
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4003
  int8_t   colModType;
4004
  int32_t  colModBytes;
4005
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4006
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4007
  int8_t   isNull;
4008
  int8_t   tagType;
4009
  int8_t   tagFree;
4010
  uint32_t nTagVal;
4011
  uint8_t* pTagVal;
4012
  SArray*  pTagArray;
4013
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4014
  int8_t   updateTTL;
4015
  int32_t  newTTL;
4016
  int32_t  newCommentLen;
4017
  char*    newComment;
4018
  int64_t  ctimeMs;    // fill by vnode
4019
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4020
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4021
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4022
  // for Add column
4023
  STypeMod typeMod;
4024
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4025
  char* refDbName;
4026
  char* refTbName;
4027
  char* refColName;
4028
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4029
} SVAlterTbReq;
4030

4031
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4032
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4033
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4034
void    tfreeMultiTagUpateVal(void* pMultiTag);
4035

4036
typedef struct {
4037
  int32_t        code;
4038
  STableMetaRsp* pMeta;
4039
} SVAlterTbRsp;
4040

4041
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4042
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4043
// ======================
4044

4045
typedef struct {
4046
  SMsgHead head;
4047
  int64_t  uid;
4048
  int32_t  tid;
4049
  int16_t  tversion;
4050
  int16_t  colId;
4051
  int8_t   type;
4052
  int16_t  bytes;
4053
  int32_t  tagValLen;
4054
  int16_t  numOfTags;
4055
  int32_t  schemaLen;
4056
  char     data[];
4057
} SUpdateTagValReq;
4058

4059
typedef struct {
4060
  SMsgHead head;
4061
} SUpdateTagValRsp;
4062

4063
typedef struct {
4064
  SMsgHead head;
4065
} SVShowTablesReq;
4066

4067
typedef struct {
4068
  SMsgHead head;
4069
  int32_t  id;
4070
} SVShowTablesFetchReq;
4071

4072
typedef struct {
4073
  int64_t useconds;
4074
  int8_t  completed;  // all results are returned to client
4075
  int8_t  precision;
4076
  int8_t  compressed;
4077
  int32_t compLen;
4078
  int32_t numOfRows;
4079
  char    data[];
4080
} SVShowTablesFetchRsp;
4081

4082
typedef struct {
4083
  int64_t consumerId;
4084
  int32_t epoch;
4085
  char    cgroup[TSDB_CGROUP_LEN];
4086
} SMqAskEpReq;
4087

4088
typedef struct {
4089
  int32_t key;
4090
  int32_t valueLen;
4091
  void*   value;
4092
} SKv;
4093

4094
typedef struct {
4095
  int64_t tscRid;
4096
  int8_t  connType;
4097
} SClientHbKey;
4098

4099
typedef struct {
4100
  int64_t tid;
4101
  char    status[TSDB_JOB_STATUS_LEN];
4102
} SQuerySubDesc;
4103

4104
typedef struct {
4105
  char     sql[TSDB_SHOW_SQL_LEN];
4106
  uint64_t queryId;
4107
  int64_t  useconds;
4108
  int64_t  stime;  // timestamp precision ms
4109
  int64_t  reqRid;
4110
  bool     stableQuery;
4111
  bool     isSubQuery;
4112
  char     fqdn[TSDB_FQDN_LEN];
4113
  int32_t  subPlanNum;
4114
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4115
} SQueryDesc;
4116

4117
typedef struct {
4118
  uint32_t connId;
4119
  SArray*  queryDesc;  // SArray<SQueryDesc>
4120
} SQueryHbReqBasic;
4121

4122
typedef struct {
4123
  uint32_t connId;
4124
  uint64_t killRid;
4125
  int32_t  totalDnodes;
4126
  int32_t  onlineDnodes;
4127
  int8_t   killConnection;
4128
  int8_t   align[3];
4129
  SEpSet   epSet;
4130
  SArray*  pQnodeList;
4131
} SQueryHbRspBasic;
4132

4133
typedef struct SAppClusterSummary {
4134
  uint64_t numOfInsertsReq;
4135
  uint64_t numOfInsertRows;
4136
  uint64_t insertElapsedTime;
4137
  uint64_t insertBytes;  // submit to tsdb since launched.
4138

4139
  uint64_t fetchBytes;
4140
  uint64_t numOfQueryReq;
4141
  uint64_t queryElapsedTime;
4142
  uint64_t numOfSlowQueries;
4143
  uint64_t totalRequests;
4144
  uint64_t currentRequests;  // the number of SRequestObj
4145
} SAppClusterSummary;
4146

4147
typedef struct {
4148
  int64_t            appId;
4149
  int32_t            pid;
4150
  char               name[TSDB_APP_NAME_LEN];
4151
  int64_t            startTime;
4152
  SAppClusterSummary summary;
4153
} SAppHbReq;
4154

4155
typedef struct {
4156
  SClientHbKey      connKey;
4157
  int64_t           clusterId;
4158
  SAppHbReq         app;
4159
  SQueryHbReqBasic* query;
4160
  SHashObj*         info;  // hash<Skv.key, Skv>
4161
  char              userApp[TSDB_APP_NAME_LEN];
4162
  uint32_t          userIp;
4163
  SIpRange          userDualIp;
4164
  char              sVer[TSDB_VERSION_LEN];
4165
  char              cInfo[CONNECTOR_INFO_LEN];
4166
} SClientHbReq;
4167

4168
typedef struct {
4169
  int64_t reqId;
4170
  SArray* reqs;  // SArray<SClientHbReq>
4171
  int64_t ipWhiteListVer;
4172
} SClientHbBatchReq;
4173

4174
typedef struct {
4175
  SClientHbKey      connKey;
4176
  int32_t           status;
4177
  SQueryHbRspBasic* query;
4178
  SArray*           info;  // Array<Skv>
4179
} SClientHbRsp;
4180

4181
typedef struct {
4182
  int64_t       reqId;
4183
  int64_t       rspId;
4184
  int32_t       svrTimestamp;
4185
  SArray*       rsps;  // SArray<SClientHbRsp>
4186
  SMonitorParas monitorParas;
4187
  int8_t        enableAuditDelete;
4188
  int8_t        enableStrongPass;
4189
} SClientHbBatchRsp;
4190

4191
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
57,034,905✔
4192

4193
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4194
  void* pIter = taosHashIterate(info, NULL);
36,677,890✔
4195
  while (pIter != NULL) {
81,319,562✔
4196
    SKv* kv = (SKv*)pIter;
44,640,950✔
4197
    taosMemoryFreeClear(kv->value);
44,640,950✔
4198
    pIter = taosHashIterate(info, pIter);
44,640,950✔
4199
  }
4200
}
36,678,612✔
4201

4202
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
21,078,930✔
4203
  SQueryDesc* desc = (SQueryDesc*)pDesc;
21,078,930✔
4204
  if (desc->subDesc) {
21,078,930✔
4205
    taosArrayDestroy(desc->subDesc);
18,996,530✔
4206
    desc->subDesc = NULL;
18,996,119✔
4207
  }
4208
}
21,078,732✔
4209

4210
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
43,972,388✔
4211
  SClientHbReq* req = (SClientHbReq*)pReq;
47,100,366✔
4212
  if (req->query) {
47,100,366✔
4213
    if (req->query->queryDesc) {
40,051,736✔
4214
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
19,189,879✔
4215
    }
4216
    taosMemoryFreeClear(req->query);
40,051,747✔
4217
  }
4218

4219
  if (req->info) {
47,099,953✔
4220
    tFreeReqKvHash(req->info);
36,677,877✔
4221
    taosHashCleanup(req->info);
36,678,612✔
4222
    req->info = NULL;
36,678,099✔
4223
  }
4224
}
23,960,290✔
4225

4226
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4227
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4228

4229
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4230
  if (pReq == NULL) return;
19,460,523✔
4231
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
19,460,523✔
4232
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
19,460,523✔
4233
  taosMemoryFree(pReq);
19,460,523✔
4234
}
4235

4236
static FORCE_INLINE void tFreeClientKv(void* pKv) {
16,443,100✔
4237
  SKv* kv = (SKv*)pKv;
16,443,100✔
4238
  if (kv) {
16,443,100✔
4239
    taosMemoryFreeClear(kv->value);
16,443,100✔
4240
  }
4241
}
16,443,100✔
4242

4243
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
43,363,947✔
4244
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
43,363,947✔
4245
  if (rsp->query) {
43,363,947✔
4246
    taosArrayDestroy(rsp->query->pQnodeList);
39,468,737✔
4247
    taosMemoryFreeClear(rsp->query);
39,464,016✔
4248
  }
4249
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
43,363,791✔
4250
}
22,533,866✔
4251

4252
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4253
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
36,738,469✔
4254
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
36,738,469✔
4255
}
36,742,563✔
4256

4257
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4258
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4259
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4260

4261
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4262
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
124,281,785✔
4263
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
124,282,232✔
4264
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
124,281,616✔
4265
  return 0;
62,140,500✔
4266
}
4267

4268
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4269
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
57,381,338✔
4270
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
57,381,420✔
4271
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
28,690,710✔
4272
  if (pKv->value == NULL) {
28,690,710✔
UNCOV
4273
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4274
  }
4275
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
28,690,710✔
4276
  return 0;
28,690,704✔
4277
}
4278

4279
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4280
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
171,884,320✔
4281
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
171,881,356✔
4282
  return 0;
85,940,694✔
4283
}
4284

4285
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4286
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
84,728,947✔
4287
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
84,728,549✔
4288
  return 0;
42,365,039✔
4289
}
4290

4291
typedef struct {
4292
  int32_t vgId;
4293
  // TODO stas
4294
} SMqReportVgInfo;
4295

4296
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4297
  int32_t tlen = 0;
4298
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4299
  return tlen;
4300
}
4301

4302
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4303
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4304
  return buf;
4305
}
4306

4307
typedef struct {
4308
  int32_t epoch;
4309
  int64_t topicUid;
4310
  char    name[TSDB_TOPIC_FNAME_LEN];
4311
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4312
} SMqTopicInfo;
4313

4314
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4315
  int32_t tlen = 0;
4316
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4317
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4318
  tlen += taosEncodeString(buf, pTopicInfo->name);
4319
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4320
  tlen += taosEncodeFixedI32(buf, sz);
4321
  for (int32_t i = 0; i < sz; i++) {
4322
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4323
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4324
  }
4325
  return tlen;
4326
}
4327

4328
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4329
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4330
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4331
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4332
  int32_t sz;
4333
  buf = taosDecodeFixedI32(buf, &sz);
4334
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4335
    return NULL;
4336
  }
4337
  for (int32_t i = 0; i < sz; i++) {
4338
    SMqReportVgInfo vgInfo;
4339
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4340
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4341
      return NULL;
4342
    }
4343
  }
4344
  return buf;
4345
}
4346

4347
typedef struct {
4348
  int32_t status;  // ask hb endpoint
4349
  int32_t epoch;
4350
  int64_t consumerId;
4351
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4352
} SMqReportReq;
4353

4354
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4355
  int32_t tlen = 0;
4356
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4357
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4358
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4359
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4360
  tlen += taosEncodeFixedI32(buf, sz);
4361
  for (int32_t i = 0; i < sz; i++) {
4362
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4363
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4364
  }
4365
  return tlen;
4366
}
4367

4368
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4369
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4370
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4371
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4372
  int32_t sz;
4373
  buf = taosDecodeFixedI32(buf, &sz);
4374
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4375
    return NULL;
4376
  }
4377
  for (int32_t i = 0; i < sz; i++) {
4378
    SMqTopicInfo topicInfo;
4379
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4380
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4381
      return NULL;
4382
    }
4383
  }
4384
  return buf;
4385
}
4386

4387
typedef struct {
4388
  SMsgHead head;
4389
  int64_t  leftForVer;
4390
  int32_t  vgId;
4391
  int64_t  consumerId;
4392
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4393
} SMqVDeleteReq;
4394

4395
typedef struct {
4396
  int8_t reserved;
4397
} SMqVDeleteRsp;
4398

4399
typedef struct {
4400
  char*   name;
4401
  int8_t  igNotExists;
4402
} SMDropStreamReq;
4403

4404
typedef struct {
4405
  int8_t reserved;
4406
} SMDropStreamRsp;
4407

4408
typedef struct {
4409
  SMsgHead head;
4410
  int64_t  resetRelHalt;  // reset related stream task halt status
4411
  int64_t  streamId;
4412
  int32_t  taskId;
4413
} SVDropStreamTaskReq;
4414

4415
typedef struct {
4416
  int8_t reserved;
4417
} SVDropStreamTaskRsp;
4418

4419
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4420
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4421
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4422

4423
typedef struct {
4424
  char*  name;
4425
  int8_t igNotExists;
4426
} SMPauseStreamReq;
4427

4428
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4429
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4430
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4431

4432
typedef struct {
4433
  char*  name;
4434
  int8_t igNotExists;
4435
  int8_t igUntreated;
4436
} SMResumeStreamReq;
4437

4438
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4439
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4440
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4441

4442
typedef struct {
4443
  char*       name;
4444
  int8_t      calcAll;
4445
  STimeWindow timeRange;
4446
} SMRecalcStreamReq;
4447

4448
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4449
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4450
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4451

4452
typedef struct SVndSetKeepVersionReq {
4453
  int64_t keepVersion;
4454
} SVndSetKeepVersionReq;
4455

4456
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4457
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4458

4459
typedef struct SVUpdateCheckpointInfoReq {
4460
  SMsgHead head;
4461
  int64_t  streamId;
4462
  int32_t  taskId;
4463
  int64_t  checkpointId;
4464
  int64_t  checkpointVer;
4465
  int64_t  checkpointTs;
4466
  int32_t  transId;
4467
  int64_t  hStreamId;  // add encode/decode
4468
  int64_t  hTaskId;
4469
  int8_t   dropRelHTask;
4470
} SVUpdateCheckpointInfoReq;
4471

4472
typedef struct {
4473
  int64_t leftForVer;
4474
  int32_t vgId;
4475
  int64_t oldConsumerId;
4476
  int64_t newConsumerId;
4477
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4478
  int8_t  subType;
4479
  int8_t  withMeta;
4480
  char*   qmsg;  // SubPlanToString
4481
  int64_t suid;
4482
} SMqRebVgReq;
4483

4484
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4485
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4486

4487
typedef struct {
4488
  char    topic[TSDB_TOPIC_FNAME_LEN];
4489
  int64_t ntbUid;
4490
  SArray* colIdList;  // SArray<int16_t>
4491
} STqCheckInfo;
4492

4493
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4494
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4495
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4496

4497
// tqOffset
4498
enum {
4499
  TMQ_OFFSET__RESET_NONE = -3,
4500
  TMQ_OFFSET__RESET_EARLIEST = -2,
4501
  TMQ_OFFSET__RESET_LATEST = -1,
4502
  TMQ_OFFSET__LOG = 1,
4503
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4504
  TMQ_OFFSET__SNAPSHOT_META = 3,
4505
};
4506

4507
enum {
4508
  WITH_DATA = 0,
4509
  WITH_META = 1,
4510
  ONLY_META = 2,
4511
};
4512

4513
#define TQ_OFFSET_VERSION 1
4514

4515
typedef struct {
4516
  int8_t type;
4517
  union {
4518
    // snapshot
4519
    struct {
4520
      int64_t uid;
4521
      int64_t ts;
4522
      SValue  primaryKey;
4523
    };
4524
    // log
4525
    struct {
4526
      int64_t version;
4527
    };
4528
  };
4529
} STqOffsetVal;
4530

4531
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4532
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,662,076✔
4533
  pOffsetVal->uid = uid;
1,661,696✔
4534
  pOffsetVal->ts = ts;
1,661,768✔
4535
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,661,932✔
UNCOV
4536
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4537
  }
4538
  pOffsetVal->primaryKey = primaryKey;
1,661,500✔
4539
}
1,661,756✔
4540

4541
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4542
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
5,731✔
4543
  pOffsetVal->uid = uid;
5,731✔
4544
}
5,731✔
4545

4546
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4547
  pOffsetVal->type = TMQ_OFFSET__LOG;
37,116,841✔
4548
  pOffsetVal->version = ver;
37,116,309✔
4549
}
37,115,313✔
4550

4551
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4552
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4553
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4554
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4555
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4556
void    tOffsetDestroy(void* pVal);
4557

4558
typedef struct {
4559
  STqOffsetVal val;
4560
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4561
} STqOffset;
4562

4563
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4564
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4565
void    tDeleteSTqOffset(void* val);
4566

4567
typedef struct SMqVgOffset {
4568
  int64_t   consumerId;
4569
  STqOffset offset;
4570
} SMqVgOffset;
4571

4572
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4573
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4574

4575
typedef struct {
4576
  char    name[TSDB_TABLE_FNAME_LEN];
4577
  char    stb[TSDB_TABLE_FNAME_LEN];
4578
  int8_t  igExists;
4579
  int8_t  intervalUnit;
4580
  int8_t  slidingUnit;
4581
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4582
  int32_t dstVgId;   // for stream
4583
  int64_t interval;
4584
  int64_t offset;
4585
  int64_t sliding;
4586
  int64_t maxDelay;
4587
  int64_t watermark;
4588
  int32_t exprLen;        // strlen + 1
4589
  int32_t tagsFilterLen;  // strlen + 1
4590
  int32_t sqlLen;         // strlen + 1
4591
  int32_t astLen;         // strlen + 1
4592
  char*   expr;
4593
  char*   tagsFilter;
4594
  char*   sql;
4595
  char*   ast;
4596
  int64_t deleteMark;
4597
  int64_t lastTs;
4598
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4599
  SArray* pVgroupVerList;
4600
  int8_t  recursiveTsma;
4601
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4602
  char*   createStreamReq;
4603
  int32_t streamReqLen;
4604
  char*   dropStreamReq;
4605
  int32_t dropStreamReqLen;
4606
  int64_t uid;
4607
} SMCreateSmaReq;
4608

4609
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4610
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4611
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4612

4613
typedef struct {
4614
  char   name[TSDB_TABLE_FNAME_LEN];
4615
  int8_t igNotExists;
4616
  char*   dropStreamReq;
4617
  int32_t dropStreamReqLen;
4618
} SMDropSmaReq;
4619

4620
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4621
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4622
void tFreeSMDropSmaReq(SMDropSmaReq *pReq);
4623

4624
typedef struct {
4625
  char name[TSDB_TABLE_NAME_LEN];
4626
  union {
4627
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4628
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4629
  };
4630
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4631
  union {
4632
    int8_t igExists;   // used by mnode
4633
    int8_t alterType;  // used by vnode
4634
  };
4635
  int8_t     intervalUnit;
4636
  int16_t    nFuncs;       // number of functions specified by user
4637
  col_id_t*  funcColIds;   // column ids specified by user
4638
  func_id_t* funcIds;      // function ids specified by user
4639
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4640
  int64_t    tbUid;
4641
  int64_t    uid;     // rsma uid
4642
  int32_t    sqlLen;  // strlen + 1
4643
  char*      sql;
4644
} SMCreateRsmaReq;
4645

4646
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4647
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4648
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4649

4650
typedef SMCreateRsmaReq SVCreateRsmaReq;
4651

4652
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4653
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4654
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4655

4656
typedef SMCreateRsmaReq SVAlterRsmaReq;
4657

4658
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4659
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4660
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4661

4662
typedef struct {
4663
  char       name[TSDB_TABLE_NAME_LEN];
4664
  int8_t     alterType;
4665
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4666
  int8_t     igNotExists;
4667
  int16_t    nFuncs;      // number of functions specified by user
4668
  col_id_t*  funcColIds;  // column ids specified by user
4669
  func_id_t* funcIds;     // function ids specified by user
4670
  int32_t    sqlLen;      // strlen + 1
4671
  char*      sql;
4672
} SMAlterRsmaReq;
4673

4674
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4675
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4676
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4677

4678
typedef struct {
4679
  int64_t    id;
4680
  char       name[TSDB_TABLE_NAME_LEN];
4681
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4682
  int32_t    code;
4683
  int32_t    version;
4684
  int8_t     tbType;
4685
  int8_t     intervalUnit;
4686
  col_id_t   nFuncs;
4687
  col_id_t   nColNames;
4688
  int64_t    interval[2];
4689
  col_id_t*  funcColIds;
4690
  func_id_t* funcIds;
4691
  SArray*    colNames;
4692
} SRsmaInfoRsp;
4693

4694
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4695
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4696
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4697

4698
typedef struct {
4699
  char   name[TSDB_TABLE_FNAME_LEN];
4700
  int8_t igNotExists;
4701
} SMDropRsmaReq;
4702

4703
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4704
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4705

4706
typedef struct {
4707
  char    name[TSDB_TABLE_NAME_LEN];
4708
  char    tbName[TSDB_TABLE_NAME_LEN];
4709
  int64_t uid;
4710
  int64_t tbUid;
4711
  int8_t  tbType;
4712
} SVDropRsmaReq;
4713

4714
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4715
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4716

4717
typedef struct {
4718
  char   dbFName[TSDB_DB_FNAME_LEN];
4719
  char   stbName[TSDB_TABLE_NAME_LEN];
4720
  char   colName[TSDB_COL_NAME_LEN];
4721
  char   idxName[TSDB_INDEX_FNAME_LEN];
4722
  int8_t idxType;
4723
} SCreateTagIndexReq;
4724

4725
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4726
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4727

4728
typedef SMDropSmaReq SDropTagIndexReq;
4729

4730
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4731
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4732

4733
typedef struct {
4734
  int8_t         version;       // for compatibility(default 0)
4735
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4736
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4737
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4738
  int32_t        dstVgId;
4739
  char           indexName[TSDB_INDEX_NAME_LEN];
4740
  int32_t        exprLen;
4741
  int32_t        tagsFilterLen;
4742
  int64_t        indexUid;
4743
  tb_uid_t       tableUid;  // super/child/common table uid
4744
  tb_uid_t       dstTbUid;  // for dstVgroup
4745
  int64_t        interval;
4746
  int64_t        offset;  // use unit by precision of DB
4747
  int64_t        sliding;
4748
  char*          dstTbName;  // for dstVgroup
4749
  char*          expr;       // sma expression
4750
  char*          tagsFilter;
4751
  SSchemaWrapper schemaRow;  // for dstVgroup
4752
  SSchemaWrapper schemaTag;  // for dstVgroup
4753
} STSma;                     // Time-range-wise SMA
4754

4755
typedef STSma SVCreateTSmaReq;
4756

4757
typedef struct {
4758
  int8_t  type;  // 0 status report, 1 update data
4759
  int64_t indexUid;
4760
  int64_t skey;  // start TS key of interval/sliding window
4761
} STSmaMsg;
4762

4763
typedef struct {
4764
  int64_t indexUid;
4765
  char    indexName[TSDB_INDEX_NAME_LEN];
4766
} SVDropTSmaReq;
4767

4768
typedef struct {
4769
  int tmp;  // TODO: to avoid compile error
4770
} SVCreateTSmaRsp, SVDropTSmaRsp;
4771

4772
#if 0
4773
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4774
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4775
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4776
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4777
#endif
4778

4779
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4780
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4781
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4782
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4783

4784
typedef struct {
4785
  int32_t number;
4786
  STSma*  tSma;
4787
} STSmaWrapper;
4788

4789
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
4790
  if (pSma) {
×
UNCOV
4791
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
4792
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
4793
    taosMemoryFreeClear(pSma->tagsFilter);
×
4794
  }
UNCOV
4795
}
×
4796

4797
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4798
  if (pSW) {
×
UNCOV
4799
    if (pSW->tSma) {
×
UNCOV
4800
      if (deepCopy) {
×
UNCOV
4801
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
4802
          tDestroyTSma(pSW->tSma + i);
×
4803
        }
4804
      }
4805
      taosMemoryFreeClear(pSW->tSma);
×
4806
    }
4807
  }
UNCOV
4808
}
×
4809

4810
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4811
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4812
  taosMemoryFreeClear(pSW);
×
4813
  return NULL;
×
4814
}
4815

4816
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4817
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4818

4819
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4820
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4821

4822
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
4823
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
4824
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4825
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4826
  }
4827
  return 0;
×
4828
}
4829

UNCOV
4830
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
4831
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
4832
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
4833
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4834
  }
UNCOV
4835
  return 0;
×
4836
}
4837

4838
typedef struct {
4839
  int idx;
4840
} SMCreateFullTextReq;
4841

4842
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4843
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4844
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4845

4846
typedef struct {
4847
  char   name[TSDB_TABLE_FNAME_LEN];
4848
  int8_t igNotExists;
4849
} SMDropFullTextReq;
4850

4851
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4852
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4853

4854
typedef struct {
4855
  char indexFName[TSDB_INDEX_FNAME_LEN];
4856
} SUserIndexReq;
4857

4858
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4859
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4860

4861
typedef struct {
4862
  char dbFName[TSDB_DB_FNAME_LEN];
4863
  char tblFName[TSDB_TABLE_FNAME_LEN];
4864
  char colName[TSDB_COL_NAME_LEN];
4865
  char indexType[TSDB_INDEX_TYPE_LEN];
4866
  char indexExts[TSDB_INDEX_EXTS_LEN];
4867
} SUserIndexRsp;
4868

4869
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4870
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4871

4872
typedef struct {
4873
  char tbFName[TSDB_TABLE_FNAME_LEN];
4874
} STableIndexReq;
4875

4876
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4877
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4878

4879
typedef struct {
4880
  int8_t  intervalUnit;
4881
  int8_t  slidingUnit;
4882
  int64_t interval;
4883
  int64_t offset;
4884
  int64_t sliding;
4885
  int64_t dstTbUid;
4886
  int32_t dstVgId;
4887
  SEpSet  epSet;
4888
  char*   expr;
4889
} STableIndexInfo;
4890

4891
typedef struct {
4892
  char     tbName[TSDB_TABLE_NAME_LEN];
4893
  char     dbFName[TSDB_DB_FNAME_LEN];
4894
  uint64_t suid;
4895
  int32_t  version;
4896
  int32_t  indexSize;
4897
  SArray*  pIndex;  // STableIndexInfo
4898
} STableIndexRsp;
4899

4900
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4901
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4902
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4903

4904
void tFreeSTableIndexInfo(void* pInfo);
4905

4906
typedef struct {
4907
  int8_t  mqMsgType;
4908
  int32_t code;
4909
  int32_t epoch;
4910
  int64_t consumerId;
4911
  int64_t walsver;
4912
  int64_t walever;
4913
} SMqRspHead;
4914

4915
typedef struct {
4916
  SMsgHead     head;
4917
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4918
  int8_t       withTbName;
4919
  int8_t       useSnapshot;
4920
  int32_t      epoch;
4921
  uint64_t     reqId;
4922
  int64_t      consumerId;
4923
  int64_t      timeout;
4924
  STqOffsetVal reqOffset;
4925
  int8_t       enableReplay;
4926
  int8_t       sourceExcluded;
4927
  int8_t       rawData;
4928
  int32_t      minPollRows;
4929
  int8_t       enableBatchMeta;
4930
  SHashObj*    uidHash;  // to find if uid is duplicated
4931
} SMqPollReq;
4932

4933
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4934
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4935
void    tDestroySMqPollReq(SMqPollReq* pReq);
4936

4937
typedef struct {
4938
  int32_t vgId;
4939
  int64_t offset;
4940
  SEpSet  epSet;
4941
} SMqSubVgEp;
4942

4943
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4944
  int32_t tlen = 0;
407,796✔
4945
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
407,796✔
4946
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
407,796✔
4947
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
407,796✔
4948
  return tlen;
407,796✔
4949
}
4950

4951
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4952
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
348,040✔
4953
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
348,040✔
4954
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
348,040✔
4955
  return buf;
348,040✔
4956
}
4957

4958
typedef struct {
4959
  char           topic[TSDB_TOPIC_FNAME_LEN];
4960
  char           db[TSDB_DB_FNAME_LEN];
4961
  SArray*        vgs;  // SArray<SMqSubVgEp>
4962
  SSchemaWrapper schema;
4963
} SMqSubTopicEp;
4964

4965
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4966
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4967
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4968

4969
typedef struct {
4970
  SMqRspHead   head;
4971
  STqOffsetVal rspOffset;
4972
  int16_t      resMsgType;
4973
  int32_t      metaRspLen;
4974
  void*        metaRsp;
4975
} SMqMetaRsp;
4976

4977
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4978
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4979
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4980

4981
#define MQ_DATA_RSP_VERSION 100
4982

4983
typedef struct {
4984
  SMqRspHead   head;
4985
  STqOffsetVal rspOffset;
4986
  STqOffsetVal reqOffset;
4987
  int32_t      blockNum;
4988
  int8_t       withTbName;
4989
  int8_t       withSchema;
4990
  SArray*      blockDataLen;
4991
  SArray*      blockData;
4992
  SArray*      blockTbName;
4993
  SArray*      blockSchema;
4994

4995
  union {
4996
    struct {
4997
      int64_t sleepTime;
4998
    };
4999
    struct {
5000
      int32_t createTableNum;
5001
      SArray* createTableLen;
5002
      SArray* createTableReq;
5003
    };
5004
    struct {
5005
      int32_t len;
5006
      void*   rawData;
5007
    };
5008
  };
5009
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5010
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5011
} SMqDataRsp;
5012

5013
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5014
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5015
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5016
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5017
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5018

5019
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5020
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5021
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5022

5023
typedef struct SMqBatchMetaRsp {
5024
  SMqRspHead   head;  // not serialize
5025
  STqOffsetVal rspOffset;
5026
  SArray*      batchMetaLen;
5027
  SArray*      batchMetaReq;
5028
  void*        pMetaBuff;    // not serialize
5029
  uint32_t     metaBuffLen;  // not serialize
5030
} SMqBatchMetaRsp;
5031

5032
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5033
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5034
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5035
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5036

5037
typedef struct {
5038
  SMqRspHead head;
5039
  char       cgroup[TSDB_CGROUP_LEN];
5040
  SArray*    topics;  // SArray<SMqSubTopicEp>
5041
} SMqAskEpRsp;
5042

5043
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5044
  int32_t tlen = 0;
1,317,851✔
5045
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5046
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,317,851✔
5047
  tlen += taosEncodeFixedI32(buf, sz);
1,317,851✔
5048
  for (int32_t i = 0; i < sz; i++) {
1,531,165✔
5049
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
213,314✔
5050
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
213,314✔
5051
  }
5052
  return tlen;
1,317,851✔
5053
}
5054

5055
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5056
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5057
  int32_t sz;
504,150✔
5058
  buf = taosDecodeFixedI32(buf, &sz);
782,626✔
5059
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
782,626✔
5060
  if (pRsp->topics == NULL) {
782,626✔
UNCOV
5061
    return NULL;
×
5062
  }
5063
  for (int32_t i = 0; i < sz; i++) {
942,879✔
5064
    SMqSubTopicEp topicEp;
76,794✔
5065
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
160,449✔
5066
    if (buf == NULL) {
160,449✔
UNCOV
5067
      return NULL;
×
5068
    }
5069
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
320,702✔
UNCOV
5070
      return NULL;
×
5071
    }
5072
  }
5073
  return buf;
782,430✔
5074
}
5075

5076
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5077
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,818,818✔
5078
}
1,818,702✔
5079

5080
typedef struct {
5081
  int32_t      vgId;
5082
  STqOffsetVal offset;
5083
  int64_t      rows;
5084
  int64_t      ever;
5085
} OffsetRows;
5086

5087
typedef struct {
5088
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5089
  SArray* offsetRows;
5090
} TopicOffsetRows;
5091

5092
typedef struct {
5093
  int64_t consumerId;
5094
  int32_t epoch;
5095
  SArray* topics;
5096
  int8_t  pollFlag;
5097
} SMqHbReq;
5098

5099
typedef struct {
5100
  char   topic[TSDB_TOPIC_FNAME_LEN];
5101
  int8_t noPrivilege;
5102
} STopicPrivilege;
5103

5104
typedef struct {
5105
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5106
  int32_t debugFlag;
5107
} SMqHbRsp;
5108

5109
typedef struct {
5110
  SMsgHead head;
5111
  int64_t  consumerId;
5112
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5113
} SMqSeekReq;
5114

5115
#define TD_AUTO_CREATE_TABLE 0x1
5116
typedef struct {
5117
  int64_t       suid;
5118
  int64_t       uid;
5119
  int32_t       sver;
5120
  uint32_t      nData;
5121
  uint8_t*      pData;
5122
  SVCreateTbReq cTbReq;
5123
} SVSubmitBlk;
5124

5125
typedef struct {
5126
  SMsgHead header;
5127
  uint64_t sId;
5128
  uint64_t queryId;
5129
  uint64_t clientId;
5130
  uint64_t taskId;
5131
  uint32_t sqlLen;
5132
  uint32_t phyLen;
5133
  char*    sql;
5134
  char*    msg;
5135
  int8_t   source;
5136
} SVDeleteReq;
5137

5138
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5139
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5140

5141
typedef struct {
5142
  int64_t affectedRows;
5143
} SVDeleteRsp;
5144

5145
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5146
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5147

5148
typedef struct SDeleteRes {
5149
  uint64_t suid;
5150
  SArray*  uidList;
5151
  int64_t  skey;
5152
  int64_t  ekey;
5153
  int64_t  affectedRows;
5154
  char     tableFName[TSDB_TABLE_NAME_LEN];
5155
  char     tsColName[TSDB_COL_NAME_LEN];
5156
  int64_t  ctimeMs;  // fill by vnode
5157
  int8_t   source;
5158
} SDeleteRes;
5159

5160
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5161
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5162

5163
typedef struct {
5164
  // int64_t uid;
5165
  char    tbname[TSDB_TABLE_NAME_LEN];
5166
  int64_t startTs;
5167
  int64_t endTs;
5168
} SSingleDeleteReq;
5169

5170
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5171
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5172

5173
typedef struct {
5174
  int64_t suid;
5175
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5176
  int64_t ctimeMs;     // fill by vnode
5177
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5178
} SBatchDeleteReq;
5179

5180
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5181
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5182
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5183

5184
typedef struct {
5185
  int32_t msgIdx;
5186
  int32_t msgType;
5187
  int32_t msgLen;
5188
  void*   msg;
5189
} SBatchMsg;
5190

5191
typedef struct {
5192
  SMsgHead header;
5193
  SArray*  pMsgs;  // SArray<SBatchMsg>
5194
} SBatchReq;
5195

5196
typedef struct {
5197
  int32_t reqType;
5198
  int32_t msgIdx;
5199
  int32_t msgLen;
5200
  int32_t rspCode;
5201
  void*   msg;
5202
} SBatchRspMsg;
5203

5204
typedef struct {
5205
  SArray* pRsps;  // SArray<SBatchRspMsg>
5206
} SBatchRsp;
5207

5208
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5209
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5210
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
88,701,104✔
5211
  if (NULL == msg) {
88,701,104✔
UNCOV
5212
    return;
×
5213
  }
5214
  SBatchMsg* pMsg = (SBatchMsg*)msg;
88,701,104✔
5215
  taosMemoryFree(pMsg->msg);
88,701,104✔
5216
}
5217

5218
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5219
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5220

5221
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
125,899,900✔
5222
  if (NULL == p) {
125,899,900✔
UNCOV
5223
    return;
×
5224
  }
5225

5226
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
125,899,900✔
5227
  taosMemoryFree(pRsp->msg);
125,899,900✔
5228
}
5229

5230
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5231
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5232
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5233
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5234
void    tDestroySMqHbReq(SMqHbReq* pReq);
5235

5236
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5237
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5238
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5239

5240
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5241
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5242

5243
#define TD_REQ_FROM_APP               0x0
5244
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5245
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5246
#define SUBMIT_REQ_FROM_FILE          0x4
5247
#define TD_REQ_FROM_TAOX              0x8
5248
#define TD_REQ_FROM_SML               0x10
5249
#define SUBMIT_REQUEST_VERSION        (2)
5250
#define SUBMIT_REQ_WITH_BLOB          0x10
5251
#define SUBMIT_REQ_SCHEMA_RES         0x20
5252
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5253

5254
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5255

5256
typedef struct {
5257
  int32_t        flags;
5258
  SVCreateTbReq* pCreateTbReq;
5259
  int64_t        suid;
5260
  int64_t        uid;
5261
  int32_t        sver;
5262
  union {
5263
    SArray* aRowP;
5264
    SArray* aCol;
5265
  };
5266
  int64_t    ctimeMs;
5267
  SBlobSet*  pBlobSet;
5268
} SSubmitTbData;
5269

5270
typedef struct {
5271
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5272
  SArray* aSubmitBlobData;
5273
  bool    raw;
5274
} SSubmitReq2;
5275

5276
typedef struct {
5277
  SMsgHead header;
5278
  int64_t  version;
5279
  char     data[];  // SSubmitReq2
5280
} SSubmitReq2Msg;
5281

5282
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5283
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5284
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5285
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5286
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5287

5288
typedef struct {
5289
  int32_t affectedRows;
5290
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5291
} SSubmitRsp2;
5292

5293
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5294
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5295
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5296

5297
#define TSDB_MSG_FLG_ENCODE 0x1
5298
#define TSDB_MSG_FLG_DECODE 0x2
5299
#define TSDB_MSG_FLG_CMPT   0x3
5300

5301
typedef struct {
5302
  union {
5303
    struct {
5304
      void*   msgStr;
5305
      int32_t msgLen;
5306
      int64_t ver;
5307
    };
5308
    void* pDataBlock;
5309
  };
5310
} SPackedData;
5311

5312
typedef struct {
5313
  char     fullname[TSDB_VIEW_FNAME_LEN];
5314
  char     name[TSDB_VIEW_NAME_LEN];
5315
  char     dbFName[TSDB_DB_FNAME_LEN];
5316
  char*    querySql;
5317
  char*    sql;
5318
  int8_t   orReplace;
5319
  int8_t   precision;
5320
  int32_t  numOfCols;
5321
  SSchema* pSchema;
5322
} SCMCreateViewReq;
5323

5324
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5325
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5326
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5327

5328
typedef struct {
5329
  char   fullname[TSDB_VIEW_FNAME_LEN];
5330
  char   name[TSDB_VIEW_NAME_LEN];
5331
  char   dbFName[TSDB_DB_FNAME_LEN];
5332
  char*  sql;
5333
  int8_t igNotExists;
5334
} SCMDropViewReq;
5335

5336
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5337
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5338
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5339

5340
typedef struct {
5341
  char fullname[TSDB_VIEW_FNAME_LEN];
5342
} SViewMetaReq;
5343
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5344
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5345

5346
typedef struct {
5347
  char     name[TSDB_VIEW_NAME_LEN];
5348
  char     dbFName[TSDB_DB_FNAME_LEN];
5349
  char*    user;
5350
  uint64_t dbId;
5351
  uint64_t viewId;
5352
  char*    querySql;
5353
  int8_t   precision;
5354
  int8_t   type;
5355
  int32_t  version;
5356
  int32_t  numOfCols;
5357
  SSchema* pSchema;
5358
} SViewMetaRsp;
5359
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5360
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5361
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5362
typedef struct {
5363
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5364
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5365
} STableTSMAInfoReq;
5366

5367
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5368
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5369

5370
typedef struct {
5371
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5372
  union {
5373
    uint8_t flags;
5374
    struct {
5375
      uint8_t withColName : 1;
5376
      uint8_t reserved : 7;
5377
    };
5378
  };
5379

5380
} SRsmaInfoReq;
5381

5382
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5383
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5384

5385
typedef struct {
5386
  int32_t  funcId;
5387
  col_id_t colId;
5388
} STableTSMAFuncInfo;
5389

5390
typedef struct {
5391
  char     name[TSDB_TABLE_NAME_LEN];
5392
  uint64_t tsmaId;
5393
  char     targetTb[TSDB_TABLE_NAME_LEN];
5394
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5395
  char     tb[TSDB_TABLE_NAME_LEN];
5396
  char     dbFName[TSDB_DB_FNAME_LEN];
5397
  uint64_t suid;
5398
  uint64_t destTbUid;
5399
  uint64_t dbId;
5400
  int32_t  version;
5401
  int64_t  interval;
5402
  int8_t   unit;
5403
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5404
  SArray*  pTags;      // SArray<SSchema>
5405
  SArray*  pUsedCols;  // SArray<SSchema>
5406
  char*    ast;
5407

5408
  int64_t streamUid;
5409
  int64_t reqTs;
5410
  int64_t rspTs;
5411
  int64_t delayDuration;  // ms
5412
  bool    fillHistoryFinished;
5413

5414
  void*   streamAddr;  // for stream task, the address of the stream task
5415
} STableTSMAInfo;
5416

5417
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5418
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5419
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5420
void    tFreeTableTSMAInfo(void* p);
5421
void    tFreeAndClearTableTSMAInfo(void* p);
5422
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5423

5424
#define STSMAHbRsp            STableTSMAInfoRsp
5425
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5426
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5427
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5428

5429
typedef struct SDropCtbWithTsmaSingleVgReq {
5430
  SVgroupInfo vgInfo;
5431
  SArray*     pTbs;  // SVDropTbReq
5432
} SMDropTbReqsOnSingleVg;
5433

5434
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5435
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5436
void    tFreeSMDropTbReqOnSingleVg(void* p);
5437

5438
typedef struct SDropTbsReq {
5439
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5440
} SMDropTbsReq;
5441

5442
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5443
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5444
void    tFreeSMDropTbsReq(void*);
5445

5446
typedef struct SVFetchTtlExpiredTbsRsp {
5447
  SArray* pExpiredTbs;  // SVDropTbReq
5448
  int32_t vgId;
5449
} SVFetchTtlExpiredTbsRsp;
5450

5451
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5452
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5453

5454
void tFreeFetchTtlExpiredTbsRsp(void* p);
5455

5456
void setDefaultOptionsForField(SFieldWithOptions* field);
5457
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5458

5459
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5460
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5461

5462
typedef struct {
5463
  char    id[TSDB_INSTANCE_ID_LEN];
5464
  char    type[TSDB_INSTANCE_TYPE_LEN];
5465
  char    desc[TSDB_INSTANCE_DESC_LEN];
5466
  int32_t expire;
5467
} SInstanceRegisterReq;
5468

5469
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5470
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5471

5472
typedef struct {
5473
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5474
} SInstanceListReq;
5475

5476
typedef struct {
5477
  int32_t count;
5478
  char**  ids;  // Array of instance IDs
5479
} SInstanceListRsp;
5480

5481
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5482
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5483
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5484
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5485

5486
#ifdef USE_MOUNT
5487
typedef struct {
5488
  char     mountName[TSDB_MOUNT_NAME_LEN];
5489
  int8_t   ignoreExist;
5490
  int16_t  nMounts;
5491
  int32_t* dnodeIds;
5492
  char**   mountPaths;
5493
  int32_t  sqlLen;
5494
  char*    sql;
5495
} SCreateMountReq;
5496

5497
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5498
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5499
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5500

5501
typedef struct {
5502
  char    mountName[TSDB_MOUNT_NAME_LEN];
5503
  int8_t  ignoreNotExists;
5504
  int32_t sqlLen;
5505
  char*   sql;
5506
} SDropMountReq;
5507

5508
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5509
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5510
void    tFreeSDropMountReq(SDropMountReq* pReq);
5511

5512
typedef struct {
5513
  char     mountName[TSDB_MOUNT_NAME_LEN];
5514
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5515
  int64_t  mountUid;
5516
  int32_t  dnodeId;
5517
  uint32_t valLen;
5518
  int8_t   ignoreExist;
5519
  void*    pVal;
5520
} SRetrieveMountPathReq;
5521

5522
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5523
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5524

5525
typedef struct {
5526
  // path
5527
  int32_t diskPrimary;
5528
  // vgInfo
5529
  int32_t  vgId;
5530
  int32_t  cacheLastSize;
5531
  int32_t  szPage;
5532
  int32_t  szCache;
5533
  uint64_t szBuf;
5534
  int8_t   cacheLast;
5535
  int8_t   standby;
5536
  int8_t   hashMethod;
5537
  uint32_t hashBegin;
5538
  uint32_t hashEnd;
5539
  int16_t  hashPrefix;
5540
  int16_t  hashSuffix;
5541
  int16_t  sttTrigger;
5542
  // syncInfo
5543
  int32_t replications;
5544
  // tsdbInfo
5545
  int8_t  precision;
5546
  int8_t  compression;
5547
  int8_t  slLevel;
5548
  int32_t daysPerFile;
5549
  int32_t keep0;
5550
  int32_t keep1;
5551
  int32_t keep2;
5552
  int32_t keepTimeOffset;
5553
  int32_t minRows;
5554
  int32_t maxRows;
5555
  int32_t tsdbPageSize;
5556
  int32_t ssChunkSize;
5557
  int32_t ssKeepLocal;
5558
  int8_t  ssCompact;
5559
  // walInfo
5560
  int32_t walFsyncPeriod;      // millisecond
5561
  int32_t walRetentionPeriod;  // secs
5562
  int32_t walRollPeriod;       // secs
5563
  int64_t walRetentionSize;
5564
  int64_t walSegSize;
5565
  int32_t walLevel;
5566
  // encryptInfo
5567
  int32_t encryptAlgorithm;
5568
  // SVState
5569
  int64_t committed;
5570
  int64_t commitID;
5571
  int64_t commitTerm;
5572
  // stats
5573
  int64_t numOfSTables;
5574
  int64_t numOfCTables;
5575
  int64_t numOfNTables;
5576
  // dbInfo
5577
  uint64_t dbId;
5578
} SMountVgInfo;
5579

5580
typedef struct {
5581
  SMCreateStbReq req;
5582
  SArray*        pColExts;  // element: column id
5583
  SArray*        pTagExts;  // element: tag id
5584
} SMountStbInfo;
5585

5586
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5587
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5588

5589
typedef struct {
5590
  char     dbName[TSDB_DB_FNAME_LEN];
5591
  uint64_t dbId;
5592
  SArray*  pVgs;      // SMountVgInfo
5593
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5594
} SMountDbInfo;
5595

5596
typedef struct {
5597
  // common fields
5598
  char     mountName[TSDB_MOUNT_NAME_LEN];
5599
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5600
  int8_t   ignoreExist;
5601
  int64_t  mountUid;
5602
  int64_t  clusterId;
5603
  int32_t  dnodeId;
5604
  uint32_t valLen;
5605
  void*    pVal;
5606

5607
  // response fields
5608
  SArray* pDbs;  // SMountDbInfo
5609

5610
  // memory fields, no serialized
5611
  SArray*   pDisks[TFS_MAX_TIERS];
5612
  TdFilePtr pFile;
5613
} SMountInfo;
5614

5615
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5616
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5617
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5618

5619
typedef struct {
5620
  SCreateVnodeReq createReq;
5621
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5622
  char            mountName[TSDB_MOUNT_NAME_LEN];
5623
  int64_t         mountId;
5624
  int32_t         diskPrimary;
5625
  int32_t         mountVgId;
5626
  int64_t         committed;
5627
  int64_t         commitID;
5628
  int64_t         commitTerm;
5629
  int64_t         numOfSTables;
5630
  int64_t         numOfCTables;
5631
  int64_t         numOfNTables;
5632
} SMountVnodeReq;
5633

5634
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5635
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5636
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5637

5638
#endif  // USE_MOUNT
5639

5640
#pragma pack(pop)
5641

5642
typedef struct {
5643
  char        db[TSDB_DB_FNAME_LEN];
5644
  STimeWindow timeRange;
5645
  int32_t     sqlLen;
5646
  char*       sql;
5647
  SArray*     vgroupIds;
5648
} SScanDbReq;
5649

5650
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5651
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5652
void    tFreeSScanDbReq(SScanDbReq* pReq);
5653

5654
typedef struct {
5655
  int32_t scanId;
5656
  int8_t  bAccepted;
5657
} SScanDbRsp;
5658

5659
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5660
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5661

5662
typedef struct {
5663
  int32_t scanId;
5664
  int32_t sqlLen;
5665
  char*   sql;
5666
} SKillScanReq;
5667

5668
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5669
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5670
void    tFreeSKillScanReq(SKillScanReq* pReq);
5671

5672
typedef struct {
5673
  int32_t scanId;
5674
  int32_t vgId;
5675
  int32_t dnodeId;
5676
} SVKillScanReq;
5677

5678
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5679
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5680

5681
typedef struct {
5682
  int32_t scanId;
5683
  int32_t vgId;
5684
  int32_t dnodeId;
5685
  int32_t numberFileset;
5686
  int32_t finished;
5687
  int32_t progress;
5688
  int64_t remainingTime;
5689
} SQueryScanProgressRsp;
5690

5691
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5692
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5693

5694
typedef struct {
5695
  int32_t scanId;
5696
  int32_t vgId;
5697
  int32_t dnodeId;
5698
} SQueryScanProgressReq;
5699

5700
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5701
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5702

5703
typedef struct {
5704
  int64_t     dbUid;
5705
  char        db[TSDB_DB_FNAME_LEN];
5706
  int64_t     scanStartTime;
5707
  STimeWindow tw;
5708
  int32_t     scanId;
5709
} SScanVnodeReq;
5710

5711
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5712
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5713

5714
#ifdef __cplusplus
5715
}
5716
#endif
5717

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