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

taosdata / TDengine / #4738

15 Sep 2025 08:54AM UTC coverage: 59.028% (+0.08%) from 58.953%
#4738

push

travis-ci

web-flow
test: submit stream case test_idmp_privilege.py (#32954)

135961 of 292975 branches covered (46.41%)

Branch coverage included in aggregate %.

204958 of 284577 relevant lines covered (72.02%)

25560812.11 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

65
typedef uint16_t tmsg_t;
66

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

71

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

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

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

98

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
15,281,832✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
15,192,739!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
30,474,571✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
69,361,102✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
69,361,102✔
119
}
120

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

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

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

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

203
#define TSDB_ALTER_TABLE_ADD_TAG                         1
204
#define TSDB_ALTER_TABLE_DROP_TAG                        2
205
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
206
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
207
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
208
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
209
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
210
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
211
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
212
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
213
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
214
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
215
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
216
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
217
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
218
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
219
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
220
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
221

222
#define TSDB_FILL_NONE        0
223
#define TSDB_FILL_NULL        1
224
#define TSDB_FILL_NULL_F      2
225
#define TSDB_FILL_SET_VALUE   3
226
#define TSDB_FILL_SET_VALUE_F 4
227
#define TSDB_FILL_LINEAR      5
228
#define TSDB_FILL_PREV        6
229
#define TSDB_FILL_NEXT        7
230
#define TSDB_FILL_NEAR        8
231

232
#define TSDB_ALTER_USER_PASSWD          0x1
233
#define TSDB_ALTER_USER_SUPERUSER       0x2
234
#define TSDB_ALTER_USER_ENABLE          0x3
235
#define TSDB_ALTER_USER_SYSINFO         0x4
236
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
237
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
238
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
239
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
240
#define TSDB_ALTER_USER_CREATEDB        0x9
241

242
#define TSDB_KILL_MSG_LEN 30
243

244
#define TSDB_TABLE_NUM_UNIT 100000
245

246
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
247
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
248
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
249

250
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
251
#define TSDB_COL_TAG    0x1u  // the tag column type
252
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
253
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
254
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
255

256
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
257
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
258
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
259
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
260

261
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
262
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
263
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
264
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
265
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
266

267
typedef enum ENodeType {
268
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
269
  // VALUE, OPERATOR, FUNCTION and so on.
270
  QUERY_NODE_COLUMN = 1,
271
  QUERY_NODE_VALUE,
272
  QUERY_NODE_OPERATOR,
273
  QUERY_NODE_LOGIC_CONDITION,
274
  QUERY_NODE_FUNCTION,
275
  QUERY_NODE_REAL_TABLE,
276
  QUERY_NODE_TEMP_TABLE,
277
  QUERY_NODE_JOIN_TABLE,
278
  QUERY_NODE_GROUPING_SET,
279
  QUERY_NODE_ORDER_BY_EXPR,
280
  QUERY_NODE_LIMIT,
281
  QUERY_NODE_STATE_WINDOW,
282
  QUERY_NODE_SESSION_WINDOW,
283
  QUERY_NODE_INTERVAL_WINDOW,
284
  QUERY_NODE_NODE_LIST,
285
  QUERY_NODE_FILL,
286
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
287
  QUERY_NODE_TARGET,
288
  QUERY_NODE_DATABLOCK_DESC,
289
  QUERY_NODE_SLOT_DESC,
290
  QUERY_NODE_COLUMN_DEF,
291
  QUERY_NODE_DOWNSTREAM_SOURCE,
292
  QUERY_NODE_DATABASE_OPTIONS,
293
  QUERY_NODE_TABLE_OPTIONS,
294
  QUERY_NODE_INDEX_OPTIONS,
295
  QUERY_NODE_EXPLAIN_OPTIONS,
296
  QUERY_NODE_LEFT_VALUE,
297
  QUERY_NODE_COLUMN_REF,
298
  QUERY_NODE_WHEN_THEN,
299
  QUERY_NODE_CASE_WHEN,
300
  QUERY_NODE_EVENT_WINDOW,
301
  QUERY_NODE_HINT,
302
  QUERY_NODE_VIEW,
303
  QUERY_NODE_WINDOW_OFFSET,
304
  QUERY_NODE_COUNT_WINDOW,
305
  QUERY_NODE_COLUMN_OPTIONS,
306
  QUERY_NODE_TSMA_OPTIONS,
307
  QUERY_NODE_ANOMALY_WINDOW,
308
  QUERY_NODE_RANGE_AROUND,
309
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
310
  QUERY_NODE_VIRTUAL_TABLE,
311
  QUERY_NODE_SLIDING_WINDOW,
312
  QUERY_NODE_PERIOD_WINDOW,
313
  QUERY_NODE_STREAM_TRIGGER,
314
  QUERY_NODE_STREAM,
315
  QUERY_NODE_STREAM_TAG_DEF,
316
  QUERY_NODE_EXTERNAL_WINDOW,
317
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
318
  QUERY_NODE_PLACE_HOLDER_TABLE,
319
  QUERY_NODE_TIME_RANGE,
320
  QUERY_NODE_STREAM_OUT_TABLE,
321
  QUERY_NODE_STREAM_CALC_RANGE,
322
  QUERY_NODE_COUNT_WINDOW_ARGS,
323
  QUERY_NODE_BNODE_OPTIONS,
324

325
  // Statement nodes are used in parser and planner module.
326
  QUERY_NODE_SET_OPERATOR = 100,
327
  QUERY_NODE_SELECT_STMT,
328
  QUERY_NODE_VNODE_MODIFY_STMT,
329
  QUERY_NODE_CREATE_DATABASE_STMT,
330
  QUERY_NODE_DROP_DATABASE_STMT,
331
  QUERY_NODE_ALTER_DATABASE_STMT,
332
  QUERY_NODE_FLUSH_DATABASE_STMT,
333
  QUERY_NODE_TRIM_DATABASE_STMT,
334
  QUERY_NODE_CREATE_TABLE_STMT,
335
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
336
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
337
  QUERY_NODE_DROP_TABLE_CLAUSE,
338
  QUERY_NODE_DROP_TABLE_STMT,
339
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
340
  QUERY_NODE_ALTER_TABLE_STMT,
341
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
342
  QUERY_NODE_CREATE_USER_STMT,
343
  QUERY_NODE_ALTER_USER_STMT,
344
  QUERY_NODE_DROP_USER_STMT,
345
  QUERY_NODE_USE_DATABASE_STMT,
346
  QUERY_NODE_CREATE_DNODE_STMT,
347
  QUERY_NODE_DROP_DNODE_STMT,
348
  QUERY_NODE_ALTER_DNODE_STMT,
349
  QUERY_NODE_CREATE_INDEX_STMT,
350
  QUERY_NODE_DROP_INDEX_STMT,
351
  QUERY_NODE_CREATE_QNODE_STMT,
352
  QUERY_NODE_DROP_QNODE_STMT,
353
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
354
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
355
  QUERY_NODE_CREATE_SNODE_STMT,
356
  QUERY_NODE_DROP_SNODE_STMT,
357
  QUERY_NODE_CREATE_MNODE_STMT,
358
  QUERY_NODE_DROP_MNODE_STMT,
359
  QUERY_NODE_CREATE_TOPIC_STMT,
360
  QUERY_NODE_DROP_TOPIC_STMT,
361
  QUERY_NODE_DROP_CGROUP_STMT,
362
  QUERY_NODE_ALTER_LOCAL_STMT,
363
  QUERY_NODE_EXPLAIN_STMT,
364
  QUERY_NODE_DESCRIBE_STMT,
365
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
366
  QUERY_NODE_COMPACT_DATABASE_STMT,
367
  QUERY_NODE_COMPACT_VGROUPS_STMT,
368
  QUERY_NODE_CREATE_FUNCTION_STMT,
369
  QUERY_NODE_DROP_FUNCTION_STMT,
370
  QUERY_NODE_CREATE_STREAM_STMT,
371
  QUERY_NODE_DROP_STREAM_STMT,
372
  QUERY_NODE_BALANCE_VGROUP_STMT,
373
  QUERY_NODE_MERGE_VGROUP_STMT,
374
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
375
  QUERY_NODE_SPLIT_VGROUP_STMT,
376
  QUERY_NODE_SYNCDB_STMT,
377
  QUERY_NODE_GRANT_STMT,
378
  QUERY_NODE_REVOKE_STMT,
379
  QUERY_NODE_ALTER_CLUSTER_STMT,
380
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
381
  QUERY_NODE_CREATE_TSMA_STMT,
382
  QUERY_NODE_DROP_TSMA_STMT,
383
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
384
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
385
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
386
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
387
  QUERY_NODE_CREATE_MOUNT_STMT,
388
  QUERY_NODE_DROP_MOUNT_STMT,
389

390
  // placeholder for [154, 180]
391
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
392
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
393
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
394
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
395
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
396
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
397
  QUERY_NODE_SHOW_SCORES_STMT,
398
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
399
  QUERY_NODE_KILL_CONNECTION_STMT,
400
  QUERY_NODE_KILL_QUERY_STMT,
401
  QUERY_NODE_KILL_TRANSACTION_STMT,
402
  QUERY_NODE_KILL_COMPACT_STMT,
403
  QUERY_NODE_DELETE_STMT,
404
  QUERY_NODE_INSERT_STMT,
405
  QUERY_NODE_QUERY,
406
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
407
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
408
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
409
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
410
  QUERY_NODE_RESTORE_DNODE_STMT,
411
  QUERY_NODE_RESTORE_QNODE_STMT,
412
  QUERY_NODE_RESTORE_MNODE_STMT,
413
  QUERY_NODE_RESTORE_VNODE_STMT,
414
  QUERY_NODE_PAUSE_STREAM_STMT,
415
  QUERY_NODE_RESUME_STREAM_STMT,
416
  QUERY_NODE_CREATE_VIEW_STMT,
417
  QUERY_NODE_DROP_VIEW_STMT,
418
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
419
  QUERY_NODE_CREATE_ANODE_STMT,
420
  QUERY_NODE_DROP_ANODE_STMT,
421
  QUERY_NODE_UPDATE_ANODE_STMT,
422
  QUERY_NODE_ASSIGN_LEADER_STMT,
423
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
424
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
425
  QUERY_NODE_RECALCULATE_STREAM_STMT,
426
  QUERY_NODE_CREATE_BNODE_STMT,
427
  QUERY_NODE_DROP_BNODE_STMT,
428

429
  // show statement nodes
430
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
431
  QUERY_NODE_SHOW_DNODES_STMT = 400,
432
  QUERY_NODE_SHOW_MNODES_STMT,
433
  QUERY_NODE_SHOW_MODULES_STMT,
434
  QUERY_NODE_SHOW_QNODES_STMT,
435
  QUERY_NODE_SHOW_SNODES_STMT,
436
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
437
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
438
  QUERY_NODE_SHOW_CLUSTER_STMT,
439
  QUERY_NODE_SHOW_DATABASES_STMT,
440
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
441
  QUERY_NODE_SHOW_INDEXES_STMT,
442
  QUERY_NODE_SHOW_STABLES_STMT,
443
  QUERY_NODE_SHOW_STREAMS_STMT,
444
  QUERY_NODE_SHOW_TABLES_STMT,
445
  QUERY_NODE_SHOW_TAGS_STMT,
446
  QUERY_NODE_SHOW_USERS_STMT,
447
  QUERY_NODE_SHOW_USERS_FULL_STMT,
448
  QUERY_NODE_SHOW_LICENCES_STMT,
449
  QUERY_NODE_SHOW_VGROUPS_STMT,
450
  QUERY_NODE_SHOW_TOPICS_STMT,
451
  QUERY_NODE_SHOW_CONSUMERS_STMT,
452
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
453
  QUERY_NODE_SHOW_QUERIES_STMT,
454
  QUERY_NODE_SHOW_APPS_STMT,
455
  QUERY_NODE_SHOW_VARIABLES_STMT,
456
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
457
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
458
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
459
  QUERY_NODE_SHOW_VNODES_STMT,
460
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
461
  QUERY_NODE_SHOW_VIEWS_STMT,
462
  QUERY_NODE_SHOW_COMPACTS_STMT,
463
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
464
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
465
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
466
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
467
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
468
  QUERY_NODE_SHOW_TSMAS_STMT,
469
  QUERY_NODE_SHOW_ANODES_STMT,
470
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
471
  QUERY_NODE_SHOW_USAGE_STMT,
472
  QUERY_NODE_SHOW_FILESETS_STMT,
473
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
474
  QUERY_NODE_SHOW_VTABLES_STMT,
475
  QUERY_NODE_SHOW_BNODES_STMT,
476
  QUERY_NODE_SHOW_MOUNTS_STMT,
477

478
  // logic plan node
479
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
480
  QUERY_NODE_LOGIC_PLAN_JOIN,
481
  QUERY_NODE_LOGIC_PLAN_AGG,
482
  QUERY_NODE_LOGIC_PLAN_PROJECT,
483
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
484
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
485
  QUERY_NODE_LOGIC_PLAN_MERGE,
486
  QUERY_NODE_LOGIC_PLAN_WINDOW,
487
  QUERY_NODE_LOGIC_PLAN_FILL,
488
  QUERY_NODE_LOGIC_PLAN_SORT,
489
  QUERY_NODE_LOGIC_PLAN_PARTITION,
490
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
491
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
492
  QUERY_NODE_LOGIC_SUBPLAN,
493
  QUERY_NODE_LOGIC_PLAN,
494
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
495
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
496
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
497
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
498
  QUERY_NODE_LOGIC_PLAN_IMPUTATION_FUNC,
499

500
  // physical plan node
501
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
502
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
503
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
504
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
505
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
506
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
507
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
508
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
509
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
510
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
511
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
512
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
513
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
514
  QUERY_NODE_PHYSICAL_PLAN_SORT,
515
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
516
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
517
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
518
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
519
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
520
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
521
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
522
  QUERY_NODE_PHYSICAL_PLAN_FILL,
523
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
524
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
525
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
526
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
527
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
528
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
529
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
530
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
531
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
532
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
533
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
534
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
535
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
536
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
537
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
538
  QUERY_NODE_PHYSICAL_SUBPLAN,
539
  QUERY_NODE_PHYSICAL_PLAN,
540
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
541
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
542
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
543
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
544
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
545
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
546
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
547
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
548
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
549
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
550
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
551
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
552
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
553
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
554
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
555
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
556
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
557
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
558
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
559
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
560
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
561
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
562
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
563
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
564
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
565
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
566
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
567
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
568
  QUERY_NODE_PHYSICAL_PLAN_IMPUTATION_FUNC,
569
} ENodeType;
570

571
typedef struct {
572
  int32_t     vgId;
573
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
574
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
575
  const char* dbFName;
576
  const char* tbName;
577
} SBuildTableInput;
578

579
typedef struct {
580
  char    db[TSDB_DB_FNAME_LEN];
581
  int64_t dbId;
582
  int32_t vgVersion;
583
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
584
  int64_t stateTs;
585
} SBuildUseDBInput;
586

587
typedef struct SField {
588
  char    name[TSDB_COL_NAME_LEN];
589
  uint8_t type;
590
  int8_t  flags;
591
  int32_t bytes;
592
} SField;
593

594
typedef struct SFieldWithOptions {
595
  char     name[TSDB_COL_NAME_LEN];
596
  uint8_t  type;
597
  int8_t   flags;
598
  int32_t  bytes;
599
  uint32_t compress;
600
  STypeMod typeMod;
601
} SFieldWithOptions;
602

603
typedef struct SRetention {
604
  int64_t freq;
605
  int64_t keep;
606
  int8_t  freqUnit;
607
  int8_t  keepUnit;
608
} SRetention;
609

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

612
#pragma pack(push, 1)
613
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
614
typedef struct SEp {
615
  char     fqdn[TSDB_FQDN_LEN];
616
  uint16_t port;
617
} SEp;
618

619
typedef struct {
620
  int32_t contLen;
621
  int32_t vgId;
622
} SMsgHead;
623

624
// Submit message for one table
625
typedef struct SSubmitBlk {
626
  int64_t uid;        // table unique id
627
  int64_t suid;       // stable id
628
  int32_t sversion;   // data schema version
629
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
630
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
631
  int32_t numOfRows;  // total number of rows in current submit block
632
  char    data[];
633
} SSubmitBlk;
634

635
// Submit message for this TSDB
636
typedef struct {
637
  SMsgHead header;
638
  int64_t  version;
639
  int32_t  length;
640
  int32_t  numOfBlocks;
641
  char     blocks[];
642
} SSubmitReq;
643

644
typedef struct {
645
  int32_t totalLen;
646
  int32_t len;
647
  STSRow* row;
648
} SSubmitBlkIter;
649

650
typedef struct {
651
  int32_t totalLen;
652
  int32_t len;
653
  // head of SSubmitBlk
654
  int64_t uid;        // table unique id
655
  int64_t suid;       // stable id
656
  int32_t sversion;   // data schema version
657
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
658
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
659
  int32_t numOfRows;  // total number of rows in current submit block
660
  // head of SSubmitBlk
661
  int32_t     numOfBlocks;
662
  const void* pMsg;
663
} SSubmitMsgIter;
664

665
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
666
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
667
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
668
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
669
// for debug
670
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
671

672
typedef struct {
673
  bool     hasRef;
674
  col_id_t id;
675
  char     refDbName[TSDB_DB_NAME_LEN];
676
  char     refTableName[TSDB_TABLE_NAME_LEN];
677
  char     refColName[TSDB_COL_NAME_LEN];
678
} SColRef;
679

680
typedef struct {
681
  int32_t  nCols;
682
  int32_t  version;
683
  SColRef* pColRef;
684
} SColRefWrapper;
685

686
int32_t tEncodeSColRefWrapper(SEncoder *pCoder, const SColRefWrapper *pWrapper);
687
int32_t tDecodeSColRefWrapperEx(SDecoder *pDecoder, SColRefWrapper *pWrapper, bool decoderMalloc);
688
typedef struct {
689
  int32_t vgId;
690
  SColRef colRef;
691
} SColRefEx;
692

693
typedef struct {
694
  int16_t colId;
695
  char    refDbName[TSDB_DB_NAME_LEN];
696
  char    refTableName[TSDB_TABLE_NAME_LEN];
697
  char    refColName[TSDB_COL_NAME_LEN];
698
} SRefColInfo;
699

700
typedef struct SVCTableRefCols {
701
  uint64_t     uid;
702
  int32_t      numOfSrcTbls;
703
  int32_t      numOfColRefs;
704
  SRefColInfo* refCols;
705
} SVCTableRefCols;
706

707
typedef struct SVCTableMergeInfo {
708
  uint64_t uid;
709
  int32_t  numOfSrcTbls;
710
} SVCTableMergeInfo;
711

712
typedef struct {
713
  int32_t    nCols;
714
  SColRefEx* pColRefEx;
715
} SColRefExWrapper;
716

717
struct SSchema {
718
  int8_t   type;
719
  int8_t   flags;
720
  col_id_t colId;
721
  int32_t  bytes;
722
  char     name[TSDB_COL_NAME_LEN];
723
};
724
struct SSchemaExt {
725
  col_id_t colId;
726
  uint32_t compress;
727
  STypeMod typeMod;
728
};
729

730
//
731

732
struct SSchema2 {
733
  int8_t   type;
734
  int8_t   flags;
735
  col_id_t colId;
736
  int32_t  bytes;
737
  char     name[TSDB_COL_NAME_LEN];
738
  uint32_t compress;
739
};
740

741
typedef struct {
742
  char        tbName[TSDB_TABLE_NAME_LEN];
743
  char        stbName[TSDB_TABLE_NAME_LEN];
744
  char        dbFName[TSDB_DB_FNAME_LEN];
745
  int64_t     dbId;
746
  int32_t     numOfTags;
747
  int32_t     numOfColumns;
748
  int8_t      precision;
749
  int8_t      tableType;
750
  int32_t     sversion;
751
  int32_t     tversion;
752
  int32_t     rversion;
753
  uint64_t    suid;
754
  uint64_t    tuid;
755
  int32_t     vgId;
756
  int8_t      sysInfo;
757
  SSchema*    pSchemas;
758
  SSchemaExt* pSchemaExt;
759
  int8_t      virtualStb;
760
  int32_t     numOfColRefs;
761
  SColRef*    pColRefs;
762
} STableMetaRsp;
763

764
typedef struct {
765
  int32_t        code;
766
  int64_t        uid;
767
  char*          tblFName;
768
  int32_t        numOfRows;
769
  int32_t        affectedRows;
770
  int64_t        sver;
771
  STableMetaRsp* pMeta;
772
} SSubmitBlkRsp;
773

774
typedef struct {
775
  int32_t numOfRows;
776
  int32_t affectedRows;
777
  int32_t nBlocks;
778
  union {
779
    SArray*        pArray;
780
    SSubmitBlkRsp* pBlocks;
781
  };
782
} SSubmitRsp;
783

784
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
785
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
786
// void    tFreeSSubmitBlkRsp(void* param);
787
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
788

789
#define COL_SMA_ON       ((int8_t)0x1)
790
#define COL_IDX_ON       ((int8_t)0x2)
791
#define COL_IS_KEY       ((int8_t)0x4)
792
#define COL_SET_NULL     ((int8_t)0x10)
793
#define COL_SET_VAL      ((int8_t)0x20)
794
#define COL_IS_SYSINFO   ((int8_t)0x40)
795
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
796
#define COL_REF_BY_STM   ((int8_t)0x08)
797

798
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
799
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
800

801
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
802
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
803
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
804

805
#define SSCHMEA_SET_IDX_ON(s) \
806
  do {                        \
807
    (s)->flags |= COL_IDX_ON; \
808
  } while (0)
809

810
#define SSCHMEA_SET_IDX_OFF(s)   \
811
  do {                           \
812
    (s)->flags &= (~COL_IDX_ON); \
813
  } while (0)
814

815
#define SSCHEMA_SET_TYPE_MOD(s)     \
816
  do {                              \
817
    (s)->flags |= COL_HAS_TYPE_MOD; \
818
  } while (0)
819

820
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
821

822
#define SSCHMEA_TYPE(s)  ((s)->type)
823
#define SSCHMEA_FLAGS(s) ((s)->flags)
824
#define SSCHMEA_COLID(s) ((s)->colId)
825
#define SSCHMEA_BYTES(s) ((s)->bytes)
826
#define SSCHMEA_NAME(s)  ((s)->name)
827

828
typedef struct {
829
  bool    tsEnableMonitor;
830
  int32_t tsMonitorInterval;
831
  int32_t tsSlowLogThreshold;
832
  int32_t tsSlowLogMaxLen;
833
  int32_t tsSlowLogScope;
834
  int32_t tsSlowLogThresholdTest;  // Obsolete
835
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
836
} SMonitorParas;
837

838
typedef struct {
839
  STypeMod typeMod;
840
} SExtSchema;
841

842
bool hasExtSchema(const SExtSchema* pExtSchema);
843

844
typedef struct {
845
  int32_t  nCols;
846
  int32_t  version;
847
  SSchema* pSchema;
848
} SSchemaWrapper;
849

850
typedef struct {
851
  col_id_t id;
852
  uint32_t alg;
853
} SColCmpr;
854

855
typedef struct {
856
  int32_t   nCols;
857
  int32_t   version;
858
  SColCmpr* pColCmpr;
859
} SColCmprWrapper;
860

861
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
862
  if (pRef->pColRef) {
822!
863
    return TSDB_CODE_INVALID_PARA;
×
864
  }
865
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
822!
866
  if (pRef->pColRef == NULL) {
822!
867
    return terrno;
×
868
  }
869
  pRef->nCols = nCols;
822✔
870
  for (int32_t i = 0; i < nCols; i++) {
8,070✔
871
    pRef->pColRef[i].hasRef = false;
7,248✔
872
    pRef->pColRef[i].id = (col_id_t)(i + 1);
7,248✔
873
  }
874
  return 0;
822✔
875
}
876

877
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
878
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
879
    terrno = TSDB_CODE_INVALID_PARA;
880
    return NULL;
881
  }
882

883
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
884
  if (pDstWrapper == NULL) {
885
    return NULL;
886
  }
887
  pDstWrapper->nCols = pSrcWrapper->nCols;
888
  pDstWrapper->version = pSrcWrapper->version;
889

890
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
891
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
892
  if (pDstWrapper->pColCmpr == NULL) {
893
    taosMemoryFree(pDstWrapper);
894
    return NULL;
895
  }
896
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
897

898
  return pDstWrapper;
899
}
900

901
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
902
  if (!(!pCmpr->pColCmpr)) {
581!
903
    return TSDB_CODE_INVALID_PARA;
×
904
  }
905
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
581!
906
  if (pCmpr->pColCmpr == NULL) {
581!
907
    return terrno;
×
908
  }
909
  pCmpr->nCols = nCols;
581✔
910
  return 0;
581✔
911
}
912

913
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
914
  pCmpr->nCols = pSchema->nCols;
915
  if (!(!pCmpr->pColCmpr)) {
916
    return TSDB_CODE_INVALID_PARA;
917
  }
918
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
919
  if (pCmpr->pColCmpr == NULL) {
920
    return terrno;
921
  }
922
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
923
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
924
    SSchema*  pColSchema = &pSchema->pSchema[i];
925
    pColCmpr->id = pColSchema->colId;
926
    pColCmpr->alg = 0;
927
  }
928
  return 0;
929
}
930

931
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
932
  if (pWrapper == NULL) return;
933

934
  taosMemoryFreeClear(pWrapper->pColCmpr);
935
  taosMemoryFreeClear(pWrapper);
936
}
937
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
938
  if (pSchemaWrapper->pSchema == NULL) return NULL;
19,763,232!
939

940
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
19,763,232!
941
  if (pSW == NULL) {
19,770,298!
942
    return NULL;
×
943
  }
944
  pSW->nCols = pSchemaWrapper->nCols;
19,770,298✔
945
  pSW->version = pSchemaWrapper->version;
19,770,298✔
946
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
19,770,298!
947
  if (pSW->pSchema == NULL) {
19,764,114!
948
    taosMemoryFree(pSW);
×
949
    return NULL;
×
950
  }
951

952
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
19,764,114✔
953
  return pSW;
19,764,114✔
954
}
955

956
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
156,066✔
957
  if (pSchemaWrapper) {
45,678,887!
958
    taosMemoryFree(pSchemaWrapper->pSchema);
16,920,295!
959
    taosMemoryFree(pSchemaWrapper);
16,920,697!
960
  }
961
}
45,600,256✔
962

963
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
3,153,887✔
964
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
3,153,887!
965
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
3,154,204!
966
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
3,154,703!
967
  }
968
}
3,153,738✔
969

970
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
971
  int32_t tlen = 0;
46,278✔
972
  tlen += taosEncodeFixedI8(buf, pSchema->type);
92,556✔
973
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
46,278!
974
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
46,278!
975
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
46,278!
976
  tlen += taosEncodeString(buf, pSchema->name);
46,278✔
977
  return tlen;
46,278✔
978
}
979

980
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
981
  buf = taosDecodeFixedI8(buf, &pSchema->type);
8,806✔
982
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
4,403✔
983
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
4,403!
984
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
4,403!
985
  buf = taosDecodeStringTo(buf, pSchema->name);
4,403✔
986
  return (void*)buf;
4,403✔
987
}
988

989
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
990
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
1,307,788,914!
991
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
1,358,637,238!
992
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
1,358,637,238!
993
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
1,358,637,238!
994
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
1,358,637,238!
995
  return 0;
679,318,619✔
996
}
997

998
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
999
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
1,290,150,858!
1000
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647!
1001
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647!
1002
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647!
1003
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
1,279,987,299!
1004
  return 0;
1,378,135,401✔
1005
}
1006

1007
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1008
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
788,519,452!
1009
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
788,519,452!
1010
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
788,519,452!
1011
  return 0;
394,259,726✔
1012
}
1013

1014
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1015
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
1,144,624!
1016
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
1,144,619!
1017
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
1,144,603!
1018
  return 0;
572,295✔
1019
}
1020

1021
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1022
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
35,060!
1023
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
35,060!
1024
  if (pColRef->hasRef) {
17,530✔
1025
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
21,012!
1026
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
21,012!
1027
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
21,012!
1028
  }
1029
  return 0;
17,530✔
1030
}
1031

1032
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1033
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
16,592!
1034
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
16,592!
1035
  if (pColRef->hasRef) {
8,296✔
1036
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
7,238!
1037
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
7,238!
1038
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
7,238!
1039
  }
1040

1041
  return 0;
8,296✔
1042
}
1043

1044
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1045
  int32_t tlen = 0;
6,574✔
1046
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
6,574✔
1047
  tlen += taosEncodeVariantI32(buf, pSW->version);
6,574✔
1048
  for (int32_t i = 0; i < pSW->nCols; i++) {
52,852✔
1049
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
92,556!
1050
  }
1051
  return tlen;
6,574✔
1052
}
1053

1054
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1055
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
643✔
1056
  buf = taosDecodeVariantI32(buf, &pSW->version);
643✔
1057
  if (pSW->nCols > 0) {
643✔
1058
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
596!
1059
    if (pSW->pSchema == NULL) {
596!
1060
      return NULL;
×
1061
    }
1062

1063
    for (int32_t i = 0; i < pSW->nCols; i++) {
4,999✔
1064
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
8,806✔
1065
    }
1066
  } else {
1067
    pSW->pSchema = NULL;
47✔
1068
  }
1069
  return (void*)buf;
643✔
1070
}
1071

1072
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1073
  if (pSW == NULL) {
699,856!
1074
    return TSDB_CODE_INVALID_PARA;
×
1075
  }
1076
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,399,712!
1077
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,399,712!
1078
  for (int32_t i = 0; i < pSW->nCols; i++) {
51,548,180!
1079
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
101,696,648!
1080
  }
1081
  return 0;
699,856✔
1082
}
1083

1084
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1085
  if (pSW == NULL) {
308,505!
1086
    return TSDB_CODE_INVALID_PARA;
×
1087
  }
1088
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
616,992!
1089
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
616,966!
1090

1091
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
308,479!
1092
  if (pSW->pSchema == NULL) {
308,477!
1093
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1094
  }
1095
  for (int32_t i = 0; i < pSW->nCols; i++) {
5,668,614✔
1096
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
10,720,507!
1097
  }
1098

1099
  return 0;
308,244✔
1100
}
1101

1102
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1103
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
145,260,639!
1104
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
149,093,060!
1105

1106
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
74,536,854!
1107
  if (pSW->pSchema == NULL) {
75,018,801!
1108
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1109
  }
1110
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,446,963,430!
1111
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647!
1112
  }
1113

1114
  return 0;
70,374,799✔
1115
}
1116

1117
typedef struct {
1118
  char     name[TSDB_TABLE_FNAME_LEN];
1119
  int8_t   igExists;
1120
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1121
  int8_t   reserved[6];
1122
  tb_uid_t suid;
1123
  int64_t  delay1;
1124
  int64_t  delay2;
1125
  int64_t  watermark1;
1126
  int64_t  watermark2;
1127
  int32_t  ttl;
1128
  int32_t  colVer;
1129
  int32_t  tagVer;
1130
  int32_t  numOfColumns;
1131
  int32_t  numOfTags;
1132
  int32_t  numOfFuncs;
1133
  int32_t  commentLen;
1134
  int32_t  ast1Len;
1135
  int32_t  ast2Len;
1136
  SArray*  pColumns;  // array of SFieldWithOptions
1137
  SArray*  pTags;     // array of SField
1138
  SArray*  pFuncs;
1139
  char*    pComment;
1140
  char*    pAst1;
1141
  char*    pAst2;
1142
  int64_t  deleteMark1;
1143
  int64_t  deleteMark2;
1144
  int32_t  sqlLen;
1145
  char*    sql;
1146
  int64_t  keep;
1147
  int8_t   virtualStb;
1148
} SMCreateStbReq;
1149

1150
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1151
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1152
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1153

1154
typedef struct {
1155
  STableMetaRsp* pMeta;
1156
} SMCreateStbRsp;
1157

1158
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1159
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1160
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1161

1162
typedef struct {
1163
  char     name[TSDB_TABLE_FNAME_LEN];
1164
  int8_t   igNotExists;
1165
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1166
  int8_t   reserved[6];
1167
  tb_uid_t suid;
1168
  int32_t  sqlLen;
1169
  char*    sql;
1170
} SMDropStbReq;
1171

1172
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1173
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1174
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1175

1176
typedef struct {
1177
  char    name[TSDB_TABLE_FNAME_LEN];
1178
  int8_t  alterType;
1179
  int32_t numOfFields;
1180
  SArray* pFields;
1181
  int32_t ttl;
1182
  int32_t commentLen;
1183
  char*   comment;
1184
  int32_t sqlLen;
1185
  char*   sql;
1186
  int64_t keep;
1187
  SArray* pTypeMods;
1188
} SMAlterStbReq;
1189

1190
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1191
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1192
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1193

1194
typedef struct SEpSet {
1195
  int8_t inUse;
1196
  int8_t numOfEps;
1197
  SEp    eps[TSDB_MAX_REPLICA];
1198
} SEpSet;
1199

1200
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1201
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1202
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1203
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1204

1205
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1206
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1207

1208
typedef struct {
1209
  int8_t  connType;
1210
  int32_t pid;
1211
  char    app[TSDB_APP_NAME_LEN];
1212
  char    db[TSDB_DB_NAME_LEN];
1213
  char    user[TSDB_USER_LEN];
1214
  char    passwd[TSDB_PASSWORD_LEN];
1215
  int64_t startTime;
1216
  char    sVer[TSDB_VERSION_LEN];
1217
} SConnectReq;
1218

1219
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1220
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1221

1222
typedef struct {
1223
  int32_t       acctId;
1224
  int64_t       clusterId;
1225
  uint32_t      connId;
1226
  int32_t       dnodeNum;
1227
  int8_t        superUser;
1228
  int8_t        sysInfo;
1229
  int8_t        connType;
1230
  SEpSet        epSet;
1231
  int32_t       svrTimestamp;
1232
  int32_t       passVer;
1233
  int32_t       authVer;
1234
  char          sVer[TSDB_VERSION_LEN];
1235
  char          sDetailVer[128];
1236
  int64_t       whiteListVer;
1237
  SMonitorParas monitorParas;
1238
  int8_t        enableAuditDelete;
1239
} SConnectRsp;
1240

1241
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1242
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1243

1244
typedef struct {
1245
  char    user[TSDB_USER_LEN];
1246
  char    pass[TSDB_PASSWORD_LEN];
1247
  int32_t maxUsers;
1248
  int32_t maxDbs;
1249
  int32_t maxTimeSeries;
1250
  int32_t maxStreams;
1251
  int32_t accessState;  // Configured only by command
1252
  int64_t maxStorage;
1253
} SCreateAcctReq, SAlterAcctReq;
1254

1255
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1256
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1257

1258
typedef struct {
1259
  char    user[TSDB_USER_LEN];
1260
  int32_t sqlLen;
1261
  char*   sql;
1262
} SDropUserReq, SDropAcctReq;
1263

1264
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1265
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1266
void    tFreeSDropUserReq(SDropUserReq* pReq);
1267

1268
typedef struct SIpV4Range {
1269
  uint32_t ip;
1270
  uint32_t mask;
1271
} SIpV4Range;
1272

1273
typedef struct SIpv6Range {
1274
  uint64_t addr[2];
1275
  uint32_t mask;
1276
} SIpV6Range;
1277

1278
typedef struct {
1279
  int8_t type;
1280
  union {
1281
    SIpV4Range ipV4;
1282
    SIpV6Range ipV6;
1283
  };
1284
} SIpRange;
1285

1286
typedef struct {
1287
  int32_t    num;
1288
  SIpV4Range pIpRange[];
1289
} SIpWhiteList;
1290

1291
typedef struct {
1292
  int32_t  num;
1293
  SIpRange pIpRanges[];
1294
} SIpWhiteListDual;
1295

1296
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1297
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1298
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1299
int32_t           createDefaultIp6Range(SIpRange* pRange);
1300
int32_t           createDefaultIp4Range(SIpRange* pRange);
1301

1302
typedef struct {
1303
  int8_t  createType;
1304
  int8_t  superUser;  // denote if it is a super user or not
1305
  int8_t  sysInfo;
1306
  int8_t  enable;
1307
  char    user[TSDB_USER_LEN];
1308
  char    pass[TSDB_USET_PASSWORD_LEN];
1309
  int32_t numIpRanges;
1310

1311
  SIpV4Range* pIpRanges;
1312
  int32_t     sqlLen;
1313
  char*       sql;
1314
  int8_t      isImport;
1315
  int8_t      createDb;
1316
  int8_t      passIsMd5;
1317
  SIpRange*   pIpDualRanges;
1318
} SCreateUserReq;
1319

1320
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1321
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1322
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1323

1324
typedef struct {
1325
  int32_t dnodeId;
1326
  int64_t analVer;
1327
} SRetrieveAnalyticsAlgoReq;
1328

1329
typedef struct {
1330
  int64_t   ver;
1331
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1332
} SRetrieveAnalyticAlgoRsp;
1333

1334
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1335
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1336
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1337
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1338
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1339

1340
typedef struct {
1341
  int8_t alterType;
1342
  int8_t superUser;
1343
  int8_t sysInfo;
1344
  int8_t enable;
1345
  int8_t isView;
1346
  union {
1347
    uint8_t flag;
1348
    struct {
1349
      uint8_t createdb : 1;
1350
      uint8_t reserve : 7;
1351
    };
1352
  };
1353
  char        user[TSDB_USER_LEN];
1354
  char        pass[TSDB_USET_PASSWORD_LEN];
1355
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1356
  char        tabName[TSDB_TABLE_NAME_LEN];
1357
  char*       tagCond;
1358
  int32_t     tagCondLen;
1359
  int32_t     numIpRanges;
1360
  SIpV4Range* pIpRanges;
1361
  int64_t     privileges;
1362
  int32_t     sqlLen;
1363
  char*       sql;
1364
  int8_t      passIsMd5;
1365
  SIpRange*   pIpDualRanges;
1366
} SAlterUserReq;
1367

1368
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1369
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1370
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1371

1372
typedef struct {
1373
  char user[TSDB_USER_LEN];
1374
} SGetUserAuthReq;
1375

1376
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1377
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1378

1379
typedef struct {
1380
  char      user[TSDB_USER_LEN];
1381
  int32_t   version;
1382
  int32_t   passVer;
1383
  int8_t    superAuth;
1384
  int8_t    sysInfo;
1385
  int8_t    enable;
1386
  int8_t    dropped;
1387
  SHashObj* createdDbs;
1388
  SHashObj* readDbs;
1389
  SHashObj* writeDbs;
1390
  SHashObj* readTbs;
1391
  SHashObj* writeTbs;
1392
  SHashObj* alterTbs;
1393
  SHashObj* readViews;
1394
  SHashObj* writeViews;
1395
  SHashObj* alterViews;
1396
  SHashObj* useDbs;
1397
  int64_t   whiteListVer;
1398
} SGetUserAuthRsp;
1399

1400
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1401
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1402
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1403

1404
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1405
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1406
typedef struct {
1407
  int64_t ver;
1408
  char    user[TSDB_USER_LEN];
1409
  int32_t numOfRange;
1410
  union {
1411
    SIpV4Range* pIpRanges;
1412
    SIpRange*   pIpDualRanges;
1413
  };
1414
} SUpdateUserIpWhite;
1415

1416
typedef struct {
1417
  int64_t             ver;
1418
  int                 numOfUser;
1419
  SUpdateUserIpWhite* pUserIpWhite;
1420
} SUpdateIpWhite;
1421

1422
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1423
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1424
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1425
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1426

1427
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1428
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1429
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1430

1431
typedef struct {
1432
  int64_t ipWhiteVer;
1433
} SRetrieveIpWhiteReq;
1434

1435
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1436
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1437
typedef struct {
1438
  char user[TSDB_USER_LEN];
1439
} SGetUserWhiteListReq;
1440

1441
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1442
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1443

1444
typedef struct {
1445
  char    user[TSDB_USER_LEN];
1446
  int32_t numWhiteLists;
1447
  union {
1448
    SIpV4Range* pWhiteLists;
1449
    SIpRange*   pWhiteListsDual;
1450
  };
1451
} SGetUserWhiteListRsp;
1452

1453
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1454
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1455
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1456
void    tIpRangeSetDefaultMask(SIpRange* range);
1457

1458
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1459
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1460
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1461

1462
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1463
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1464
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1465

1466
/*
1467
 * for client side struct, only column id, type, bytes are necessary
1468
 * But for data in vnode side, we need all the following information.
1469
 */
1470
typedef struct {
1471
  union {
1472
    col_id_t colId;
1473
    int16_t  slotId;
1474
  };
1475

1476
  uint8_t precision;
1477
  uint8_t scale;
1478
  int32_t bytes;
1479
  int8_t  type;
1480
  uint8_t pk;
1481
  bool    noData;
1482
} SColumnInfo;
1483

1484
typedef struct STimeWindow {
1485
  TSKEY skey;
1486
  TSKEY ekey;
1487
} STimeWindow;
1488

1489
typedef struct SQueryHint {
1490
  bool batchScan;
1491
} SQueryHint;
1492

1493
typedef struct {
1494
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1495
  int32_t tsLen;          // total length of ts comp block
1496
  int32_t tsNumOfBlocks;  // ts comp block numbers
1497
  int32_t tsOrder;        // ts comp block order
1498
} STsBufInfo;
1499

1500
typedef struct {
1501
  void*       timezone;
1502
  char        intervalUnit;
1503
  char        slidingUnit;
1504
  char        offsetUnit;
1505
  int8_t      precision;
1506
  int64_t     interval;
1507
  int64_t     sliding;
1508
  int64_t     offset;
1509
  STimeWindow timeRange;
1510
} SInterval;
1511

1512
typedef struct STbVerInfo {
1513
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1514
  int32_t sversion;
1515
  int32_t tversion;
1516
  int32_t rversion;  // virtual table's column ref's version
1517
} STbVerInfo;
1518

1519
typedef struct {
1520
  int32_t code;
1521
  int64_t affectedRows;
1522
  SArray* tbVerInfo;  // STbVerInfo
1523
} SQueryTableRsp;
1524

1525
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1526

1527
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1528

1529
typedef struct {
1530
  SMsgHead header;
1531
  char     dbFName[TSDB_DB_FNAME_LEN];
1532
  char     tbName[TSDB_TABLE_NAME_LEN];
1533
} STableCfgReq;
1534

1535
typedef struct {
1536
  char        tbName[TSDB_TABLE_NAME_LEN];
1537
  char        stbName[TSDB_TABLE_NAME_LEN];
1538
  char        dbFName[TSDB_DB_FNAME_LEN];
1539
  int32_t     numOfTags;
1540
  int32_t     numOfColumns;
1541
  int8_t      tableType;
1542
  int64_t     delay1;
1543
  int64_t     delay2;
1544
  int64_t     watermark1;
1545
  int64_t     watermark2;
1546
  int32_t     ttl;
1547
  int32_t     keep;
1548
  SArray*     pFuncs;
1549
  int32_t     commentLen;
1550
  char*       pComment;
1551
  SSchema*    pSchemas;
1552
  int32_t     tagsLen;
1553
  char*       pTags;
1554
  SSchemaExt* pSchemaExt;
1555
  int8_t      virtualStb;
1556
  SColRef*    pColRefs;
1557
} STableCfg;
1558

1559
typedef STableCfg STableCfgRsp;
1560

1561
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1562
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1563

1564
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1565
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1566
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1567

1568
typedef struct {
1569
  SMsgHead header;
1570
  tb_uid_t suid;
1571
} SVSubTablesReq;
1572

1573
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1574
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1575

1576
typedef struct {
1577
  int32_t vgId;
1578
  SArray* pTables;  // SArray<SVCTableRefCols*>
1579
} SVSubTablesRsp;
1580

1581
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1582
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1583
void    tDestroySVSubTablesRsp(void* rsp);
1584

1585
typedef struct {
1586
  SMsgHead header;
1587
  tb_uid_t suid;
1588
} SVStbRefDbsReq;
1589

1590
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1591
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1592

1593
typedef struct {
1594
  int32_t vgId;
1595
  SArray* pDbs;  // SArray<char* (db name)>
1596
} SVStbRefDbsRsp;
1597

1598
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1599
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1600
void    tDestroySVStbRefDbsRsp(void* rsp);
1601

1602
typedef struct {
1603
  char    db[TSDB_DB_FNAME_LEN];
1604
  int32_t numOfVgroups;
1605
  int32_t numOfStables;  // single_stable
1606
  int32_t buffer;        // MB
1607
  int32_t pageSize;
1608
  int32_t pages;
1609
  int32_t cacheLastSize;
1610
  int32_t daysPerFile;
1611
  int32_t daysToKeep0;
1612
  int32_t daysToKeep1;
1613
  int32_t daysToKeep2;
1614
  int32_t keepTimeOffset;
1615
  int32_t minRows;
1616
  int32_t maxRows;
1617
  int32_t walFsyncPeriod;
1618
  int8_t  walLevel;
1619
  int8_t  precision;  // time resolution
1620
  int8_t  compression;
1621
  int8_t  replications;
1622
  int8_t  strict;
1623
  int8_t  cacheLast;
1624
  int8_t  schemaless;
1625
  int8_t  ignoreExist;
1626
  int32_t numOfRetensions;
1627
  SArray* pRetensions;  // SRetention
1628
  int32_t walRetentionPeriod;
1629
  int64_t walRetentionSize;
1630
  int32_t walRollPeriod;
1631
  int64_t walSegmentSize;
1632
  int32_t sstTrigger;
1633
  int16_t hashPrefix;
1634
  int16_t hashSuffix;
1635
  int32_t ssChunkSize;
1636
  int32_t ssKeepLocal;
1637
  int8_t  ssCompact;
1638
  int32_t tsdbPageSize;
1639
  int32_t sqlLen;
1640
  char*   sql;
1641
  int8_t  withArbitrator;
1642
  int8_t  encryptAlgorithm;
1643
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1644
  // 1. add auto-compact parameters
1645
  int32_t compactInterval;    // minutes
1646
  int32_t compactStartTime;   // minutes
1647
  int32_t compactEndTime;     // minutes
1648
  int8_t  compactTimeOffset;  // hour
1649
} SCreateDbReq;
1650

1651
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1652
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1653
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1654

1655
typedef struct {
1656
  char    db[TSDB_DB_FNAME_LEN];
1657
  int32_t buffer;
1658
  int32_t pageSize;
1659
  int32_t pages;
1660
  int32_t cacheLastSize;
1661
  int32_t daysPerFile;
1662
  int32_t daysToKeep0;
1663
  int32_t daysToKeep1;
1664
  int32_t daysToKeep2;
1665
  int32_t keepTimeOffset;
1666
  int32_t walFsyncPeriod;
1667
  int8_t  walLevel;
1668
  int8_t  strict;
1669
  int8_t  cacheLast;
1670
  int8_t  replications;
1671
  int32_t sstTrigger;
1672
  int32_t minRows;
1673
  int32_t walRetentionPeriod;
1674
  int32_t walRetentionSize;
1675
  int32_t ssKeepLocal;
1676
  int8_t  ssCompact;
1677
  int32_t sqlLen;
1678
  char*   sql;
1679
  int8_t  withArbitrator;
1680
  // 1. add auto-compact parameters
1681
  int32_t compactInterval;
1682
  int32_t compactStartTime;
1683
  int32_t compactEndTime;
1684
  int8_t  compactTimeOffset;
1685
} SAlterDbReq;
1686

1687
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1688
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1689
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1690

1691
typedef struct {
1692
  char    db[TSDB_DB_FNAME_LEN];
1693
  int8_t  ignoreNotExists;
1694
  int8_t  force;
1695
  int32_t sqlLen;
1696
  char*   sql;
1697
} SDropDbReq;
1698

1699
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1700
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1701
void    tFreeSDropDbReq(SDropDbReq* pReq);
1702

1703
typedef struct {
1704
  char    db[TSDB_DB_FNAME_LEN];
1705
  int64_t uid;
1706
} SDropDbRsp;
1707

1708
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1709
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1710

1711
typedef struct {
1712
  char    name[TSDB_MOUNT_NAME_LEN];
1713
  int64_t uid;
1714
} SDropMountRsp;
1715

1716
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1717
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1718

1719
typedef struct {
1720
  char    db[TSDB_DB_FNAME_LEN];
1721
  int64_t dbId;
1722
  int32_t vgVersion;
1723
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1724
  int64_t stateTs;     // ms
1725
} SUseDbReq;
1726

1727
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1728
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1729

1730
typedef struct {
1731
  char    db[TSDB_DB_FNAME_LEN];
1732
  int64_t uid;
1733
  int32_t vgVersion;
1734
  int32_t vgNum;
1735
  int16_t hashPrefix;
1736
  int16_t hashSuffix;
1737
  int8_t  hashMethod;
1738
  union {
1739
    uint8_t flags;
1740
    struct {
1741
      uint8_t isMount : 1;  // TS-5868
1742
      uint8_t padding : 7;
1743
    };
1744
  };
1745
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1746
  int32_t errCode;
1747
  int64_t stateTs;  // ms
1748
} SUseDbRsp;
1749

1750
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1751
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1752
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1753
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1754
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1755

1756
typedef struct {
1757
  char db[TSDB_DB_FNAME_LEN];
1758
} SDbCfgReq;
1759

1760
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1761
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1762

1763
typedef struct {
1764
  char    db[TSDB_DB_FNAME_LEN];
1765
  int32_t maxSpeed;
1766
} STrimDbReq;
1767

1768
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1769
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1770

1771
typedef struct {
1772
  int32_t timestamp;
1773
} SVTrimDbReq;
1774

1775
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1776
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1777

1778
typedef struct {
1779
  char db[TSDB_DB_FNAME_LEN];
1780
} SSsMigrateDbReq;
1781

1782
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1783
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1784

1785
typedef struct {
1786
  int32_t ssMigrateId;
1787
  bool    bAccepted;
1788
} SSsMigrateDbRsp;
1789

1790
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1791
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1792

1793

1794
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
1795
typedef struct {
1796
  int32_t ssMigrateId;
1797
} SListSsMigrateFileSetsReq;
1798

1799
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1800
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1801

1802
typedef struct {
1803
  int32_t ssMigrateId;
1804
  int32_t vgId;   // vgroup id
1805
  SArray* pFileSets; // SArray<int32_t>
1806
} SListSsMigrateFileSetsRsp;
1807

1808
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1809
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
1810
void tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
1811

1812

1813
// Request and response for TDMT_VND_SSMIGRATE_FILESET
1814
typedef struct {
1815
  int32_t ssMigrateId;
1816
  int32_t nodeId; // node id of the leader vnode, filled by vnode
1817
  int32_t fid;
1818
  int64_t startTimeSec;
1819
} SSsMigrateFileSetReq;
1820

1821
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1822
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1823

1824
typedef struct {
1825
  int32_t ssMigrateId;
1826
  int32_t nodeId; // node id of the leader vnode
1827
  int32_t vgId;
1828
  int32_t fid;
1829
} SSsMigrateFileSetRsp;
1830

1831
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1832
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1833

1834

1835
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS  0
1836
#define SSMIGRATE_FILESET_STATE_SUCCEEDED    1
1837
#define SSMIGRATE_FILESET_STATE_COMPACT      2
1838
#define SSMIGRATE_FILESET_STATE_SKIPPED      3
1839
#define SSMIGRATE_FILESET_STATE_FAILED       4
1840

1841
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
1842
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
1843
// while as a request, the 'state' field is not used.
1844
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
1845
typedef struct {
1846
  int32_t ssMigrateId; // ss migrate id
1847
  int32_t nodeId;      // node id of the leader vnode
1848
  int32_t vgId;        // vgroup id
1849
  int32_t fid;         // file set id
1850
  int32_t state;       // SSMIGRATE_FILESET_STATE_*
1851
} SSsMigrateProgress;
1852

1853
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1854
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1855

1856

1857
typedef struct {
1858
  int32_t timestampSec;
1859
  int32_t ttlDropMaxCount;
1860
  int32_t nUids;
1861
  SArray* pTbUids;
1862
} SVDropTtlTableReq;
1863

1864
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1865
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1866

1867
typedef struct {
1868
  char    db[TSDB_DB_FNAME_LEN];
1869
  int64_t dbId;
1870
  int32_t cfgVersion;
1871
  int32_t numOfVgroups;
1872
  int32_t numOfStables;
1873
  int32_t buffer;
1874
  int32_t cacheSize;
1875
  int32_t pageSize;
1876
  int32_t pages;
1877
  int32_t daysPerFile;
1878
  int32_t daysToKeep0;
1879
  int32_t daysToKeep1;
1880
  int32_t daysToKeep2;
1881
  int32_t keepTimeOffset;
1882
  int32_t minRows;
1883
  int32_t maxRows;
1884
  int32_t walFsyncPeriod;
1885
  int16_t hashPrefix;
1886
  int16_t hashSuffix;
1887
  int8_t  hashMethod;
1888
  int8_t  walLevel;
1889
  int8_t  precision;
1890
  int8_t  compression;
1891
  int8_t  replications;
1892
  int8_t  strict;
1893
  int8_t  cacheLast;
1894
  int8_t  encryptAlgorithm;
1895
  int32_t ssChunkSize;
1896
  int32_t ssKeepLocal;
1897
  int8_t  ssCompact;
1898
  union {
1899
    uint8_t flags;
1900
    struct {
1901
      uint8_t isMount : 1;  // TS-5868
1902
      uint8_t padding : 7;
1903
    };
1904
  };
1905
  int8_t  compactTimeOffset;
1906
  int32_t compactInterval;
1907
  int32_t compactStartTime;
1908
  int32_t compactEndTime;
1909
  int32_t tsdbPageSize;
1910
  int32_t walRetentionPeriod;
1911
  int32_t walRollPeriod;
1912
  int64_t walRetentionSize;
1913
  int64_t walSegmentSize;
1914
  int32_t numOfRetensions;
1915
  SArray* pRetensions;
1916
  int8_t  schemaless;
1917
  int16_t sstTrigger;
1918
  int8_t  withArbitrator;
1919
} SDbCfgRsp;
1920

1921
typedef SDbCfgRsp SDbCfgInfo;
1922

1923
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1924
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1925
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1926
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1927
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1928

1929
typedef struct {
1930
  int32_t rowNum;
1931
} SQnodeListReq;
1932

1933
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1934
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1935

1936
typedef struct {
1937
  int32_t rowNum;
1938
} SDnodeListReq;
1939

1940
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1941

1942
typedef struct {
1943
  int32_t useless;  // useless
1944
} SServerVerReq;
1945

1946
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1947
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1948

1949
typedef struct {
1950
  char ver[TSDB_VERSION_LEN];
1951
} SServerVerRsp;
1952

1953
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1954
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1955

1956
typedef struct SQueryNodeAddr {
1957
  int32_t nodeId;  // vgId or qnodeId
1958
  SEpSet  epSet;
1959
} SQueryNodeAddr;
1960

1961
typedef struct {
1962
  SQueryNodeAddr addr;
1963
  uint64_t       load;
1964
} SQueryNodeLoad;
1965

1966
typedef struct {
1967
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1968
} SQnodeListRsp;
1969

1970
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1971
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1972
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1973

1974
typedef struct SDNodeAddr {
1975
  int32_t nodeId;  // dnodeId
1976
  SEpSet  epSet;
1977
} SDNodeAddr;
1978

1979
typedef struct {
1980
  SArray* dnodeList;  // SArray<SDNodeAddr>
1981
} SDnodeListRsp;
1982

1983
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1984
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1985
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1986

1987
typedef struct {
1988
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1989
} STableTSMAInfoRsp;
1990

1991
typedef struct {
1992
  SUseDbRsp*         useDbRsp;
1993
  SDbCfgRsp*         cfgRsp;
1994
  STableTSMAInfoRsp* pTsmaRsp;
1995
  int32_t            dbTsmaVersion;
1996
  char               db[TSDB_DB_FNAME_LEN];
1997
  int64_t            dbId;
1998
} SDbHbRsp;
1999

2000
typedef struct {
2001
  SArray* pArray;  // Array of SDbHbRsp
2002
} SDbHbBatchRsp;
2003

2004
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2005
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2006
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2007

2008
typedef struct {
2009
  SArray* pArray;  // Array of SGetUserAuthRsp
2010
} SUserAuthBatchRsp;
2011

2012
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2013
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2014
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2015

2016
typedef struct {
2017
  char        db[TSDB_DB_FNAME_LEN];
2018
  STimeWindow timeRange;
2019
  int32_t     sqlLen;
2020
  char*       sql;
2021
  SArray*     vgroupIds;
2022
  int8_t      metaOnly;
2023
} SCompactDbReq;
2024

2025
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2026
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2027
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2028

2029
typedef struct {
2030
  int32_t compactId;
2031
  int8_t  bAccepted;
2032
} SCompactDbRsp;
2033

2034
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2035
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2036

2037
typedef struct {
2038
  int32_t compactId;
2039
  int32_t sqlLen;
2040
  char*   sql;
2041
} SKillCompactReq;
2042

2043
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2044
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2045
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2046

2047
typedef struct {
2048
  char    name[TSDB_FUNC_NAME_LEN];
2049
  int8_t  igExists;
2050
  int8_t  funcType;
2051
  int8_t  scriptType;
2052
  int8_t  outputType;
2053
  int32_t outputLen;
2054
  int32_t bufSize;
2055
  int32_t codeLen;
2056
  int64_t signature;
2057
  char*   pComment;
2058
  char*   pCode;
2059
  int8_t  orReplace;
2060
} SCreateFuncReq;
2061

2062
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2063
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2064
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2065

2066
typedef struct {
2067
  char   name[TSDB_FUNC_NAME_LEN];
2068
  int8_t igNotExists;
2069
} SDropFuncReq;
2070

2071
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2072
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2073

2074
typedef struct {
2075
  int32_t numOfFuncs;
2076
  bool    ignoreCodeComment;
2077
  SArray* pFuncNames;
2078
} SRetrieveFuncReq;
2079

2080
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2081
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2082
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2083

2084
typedef struct {
2085
  char    name[TSDB_FUNC_NAME_LEN];
2086
  int8_t  funcType;
2087
  int8_t  scriptType;
2088
  int8_t  outputType;
2089
  int32_t outputLen;
2090
  int32_t bufSize;
2091
  int64_t signature;
2092
  int32_t commentSize;
2093
  int32_t codeSize;
2094
  char*   pComment;
2095
  char*   pCode;
2096
} SFuncInfo;
2097

2098
typedef struct {
2099
  int32_t funcVersion;
2100
  int64_t funcCreatedTime;
2101
} SFuncExtraInfo;
2102

2103
typedef struct {
2104
  int32_t numOfFuncs;
2105
  SArray* pFuncInfos;
2106
  SArray* pFuncExtraInfos;
2107
} SRetrieveFuncRsp;
2108

2109
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2110
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2111
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2112
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2113

2114
typedef struct {
2115
  int32_t       statusInterval;
2116
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2117
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2118
  char          locale[TD_LOCALE_LEN];      // tsLocale
2119
  char          charset[TD_LOCALE_LEN];     // tsCharset
2120
  int8_t        ttlChangeOnWrite;
2121
  int8_t        enableWhiteList;
2122
  int8_t        encryptionKeyStat;
2123
  uint32_t      encryptionKeyChksum;
2124
  SMonitorParas monitorParas;
2125
  int32_t       statusIntervalMs;
2126
} SClusterCfg;
2127

2128
typedef struct {
2129
  int32_t openVnodes;
2130
  int32_t dropVnodes;
2131
  int32_t totalVnodes;
2132
  int32_t masterNum;
2133
  int64_t numOfSelectReqs;
2134
  int64_t numOfInsertReqs;
2135
  int64_t numOfInsertSuccessReqs;
2136
  int64_t numOfBatchInsertReqs;
2137
  int64_t numOfBatchInsertSuccessReqs;
2138
  int64_t errors;
2139
} SVnodesStat;
2140

2141
typedef struct {
2142
  int32_t vgId;
2143
  int8_t  syncState;
2144
  int8_t  syncRestore;
2145
  int64_t syncTerm;
2146
  int64_t roleTimeMs;
2147
  int64_t startTimeMs;
2148
  int8_t  syncCanRead;
2149
  int64_t cacheUsage;
2150
  int64_t numOfTables;
2151
  int64_t numOfTimeSeries;
2152
  int64_t totalStorage;
2153
  int64_t compStorage;
2154
  int64_t pointsWritten;
2155
  int64_t numOfSelectReqs;
2156
  int64_t numOfInsertReqs;
2157
  int64_t numOfInsertSuccessReqs;
2158
  int64_t numOfBatchInsertReqs;
2159
  int64_t numOfBatchInsertSuccessReqs;
2160
  int32_t numOfCachedTables;
2161
  int32_t learnerProgress;  // use one reservered
2162
  int64_t syncAppliedIndex;
2163
  int64_t syncCommitIndex;
2164
  int64_t bufferSegmentUsed;
2165
  int64_t bufferSegmentSize;
2166
} SVnodeLoad;
2167

2168
typedef struct {
2169
  int64_t total_requests;
2170
  int64_t total_rows;
2171
  int64_t total_bytes;
2172
  double  write_size;
2173
  double  cache_hit_ratio;
2174
  int64_t rpc_queue_wait;
2175
  int64_t preprocess_time;
2176

2177
  int64_t memory_table_size;
2178
  int64_t commit_count;
2179
  int64_t merge_count;
2180
  double  commit_time;
2181
  double  merge_time;
2182
  int64_t block_commit_time;
2183
  int64_t memtable_wait_time;
2184
} SVnodeMetrics;
2185

2186
typedef struct {
2187
  int32_t     vgId;
2188
  int64_t     numOfTables;
2189
  int64_t     memSize;
2190
  int64_t     l1Size;
2191
  int64_t     l2Size;
2192
  int64_t     l3Size;
2193
  int64_t     cacheSize;
2194
  int64_t     walSize;
2195
  int64_t     metaSize;
2196
  int64_t     rawDataSize;
2197
  int64_t     ssSize;
2198
  const char* dbname;
2199
  int8_t      estimateRawData;
2200
} SDbSizeStatisInfo;
2201

2202
typedef struct {
2203
  int32_t vgId;
2204
  int64_t nTimeSeries;
2205
} SVnodeLoadLite;
2206

2207
typedef struct {
2208
  int8_t  syncState;
2209
  int64_t syncTerm;
2210
  int8_t  syncRestore;
2211
  int64_t roleTimeMs;
2212
} SMnodeLoad;
2213

2214
typedef struct {
2215
  int32_t dnodeId;
2216
  int64_t numOfProcessedQuery;
2217
  int64_t numOfProcessedCQuery;
2218
  int64_t numOfProcessedFetch;
2219
  int64_t numOfProcessedDrop;
2220
  int64_t numOfProcessedNotify;
2221
  int64_t numOfProcessedHb;
2222
  int64_t numOfProcessedDelete;
2223
  int64_t cacheDataSize;
2224
  int64_t numOfQueryInQueue;
2225
  int64_t numOfFetchInQueue;
2226
  int64_t timeInQueryQueue;
2227
  int64_t timeInFetchQueue;
2228
} SQnodeLoad;
2229

2230
typedef struct {
2231
  int32_t     sver;      // software version
2232
  int64_t     dnodeVer;  // dnode table version in sdb
2233
  int32_t     dnodeId;
2234
  int64_t     clusterId;
2235
  int64_t     rebootTime;
2236
  int64_t     updateTime;
2237
  float       numOfCores;
2238
  int32_t     numOfSupportVnodes;
2239
  int32_t     numOfDiskCfg;
2240
  int64_t     memTotal;
2241
  int64_t     memAvail;
2242
  char        dnodeEp[TSDB_EP_LEN];
2243
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2244
  SMnodeLoad  mload;
2245
  SQnodeLoad  qload;
2246
  SClusterCfg clusterCfg;
2247
  SArray*     pVloads;  // array of SVnodeLoad
2248
  int32_t     statusSeq;
2249
  int64_t     ipWhiteVer;
2250
  int64_t     analVer;
2251
  int64_t     timestamp;
2252
} SStatusReq;
2253

2254
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2255
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2256
void    tFreeSStatusReq(SStatusReq* pReq);
2257

2258
typedef struct {
2259
  int32_t forceReadConfig;
2260
  int32_t cver;
2261
  SArray* array;
2262
} SConfigReq;
2263

2264
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2265
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2266
void    tFreeSConfigReq(SConfigReq* pReq);
2267

2268
typedef struct {
2269
  int32_t dnodeId;
2270
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2271
} SDnodeInfoReq;
2272

2273
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2274
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2275

2276
typedef enum {
2277
  MONITOR_TYPE_COUNTER = 0,
2278
  MONITOR_TYPE_SLOW_LOG = 1,
2279
} MONITOR_TYPE;
2280

2281
typedef struct {
2282
  int32_t      contLen;
2283
  char*        pCont;
2284
  MONITOR_TYPE type;
2285
} SStatisReq;
2286

2287
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2288
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2289
void    tFreeSStatisReq(SStatisReq* pReq);
2290

2291
typedef struct {
2292
  char    db[TSDB_DB_FNAME_LEN];
2293
  char    table[TSDB_TABLE_NAME_LEN];
2294
  char    operation[AUDIT_OPERATION_LEN];
2295
  int32_t sqlLen;
2296
  char*   pSql;
2297
} SAuditReq;
2298
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2299
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2300
void    tFreeSAuditReq(SAuditReq* pReq);
2301

2302
typedef struct {
2303
  int32_t dnodeId;
2304
  int64_t clusterId;
2305
  SArray* pVloads;
2306
} SNotifyReq;
2307

2308
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2309
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2310
void    tFreeSNotifyReq(SNotifyReq* pReq);
2311

2312
typedef struct {
2313
  int32_t dnodeId;
2314
  int64_t clusterId;
2315
} SDnodeCfg;
2316

2317
typedef struct {
2318
  int32_t id;
2319
  int8_t  isMnode;
2320
  SEp     ep;
2321
} SDnodeEp;
2322

2323
typedef struct {
2324
  int32_t id;
2325
  int8_t  isMnode;
2326
  int8_t  offlineReason;
2327
  SEp     ep;
2328
  char    active[TSDB_ACTIVE_KEY_LEN];
2329
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2330
} SDnodeInfo;
2331

2332
typedef struct {
2333
  int64_t   dnodeVer;
2334
  SDnodeCfg dnodeCfg;
2335
  SArray*   pDnodeEps;  // Array of SDnodeEp
2336
  int32_t   statusSeq;
2337
  int64_t   ipWhiteVer;
2338
  int64_t   analVer;
2339
} SStatusRsp;
2340

2341
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2342
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2343
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2344

2345
typedef struct {
2346
  int32_t forceReadConfig;
2347
  int32_t isConifgVerified;
2348
  int32_t isVersionVerified;
2349
  int32_t cver;
2350
  SArray* array;
2351
} SConfigRsp;
2352

2353
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2354
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2355
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2356

2357
typedef struct {
2358
  int32_t reserved;
2359
} SMTimerReq;
2360

2361
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2362
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2363

2364
typedef struct SOrphanTask {
2365
  int64_t streamId;
2366
  int32_t taskId;
2367
  int32_t nodeId;
2368
} SOrphanTask;
2369

2370
typedef struct SMStreamDropOrphanMsg {
2371
  SArray* pList;  // SArray<SOrphanTask>
2372
} SMStreamDropOrphanMsg;
2373

2374
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2375
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2376
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2377

2378
typedef struct {
2379
  int32_t  id;
2380
  uint16_t port;                 // node sync Port
2381
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2382
} SReplica;
2383

2384
typedef struct {
2385
  int32_t  vgId;
2386
  char     db[TSDB_DB_FNAME_LEN];
2387
  int64_t  dbUid;
2388
  int32_t  vgVersion;
2389
  int32_t  numOfStables;
2390
  int32_t  buffer;
2391
  int32_t  pageSize;
2392
  int32_t  pages;
2393
  int32_t  cacheLastSize;
2394
  int32_t  daysPerFile;
2395
  int32_t  daysToKeep0;
2396
  int32_t  daysToKeep1;
2397
  int32_t  daysToKeep2;
2398
  int32_t  keepTimeOffset;
2399
  int32_t  minRows;
2400
  int32_t  maxRows;
2401
  int32_t  walFsyncPeriod;
2402
  uint32_t hashBegin;
2403
  uint32_t hashEnd;
2404
  int8_t   hashMethod;
2405
  int8_t   walLevel;
2406
  int8_t   precision;
2407
  int8_t   compression;
2408
  int8_t   strict;
2409
  int8_t   cacheLast;
2410
  int8_t   isTsma;
2411
  int8_t   replica;
2412
  int8_t   selfIndex;
2413
  SReplica replicas[TSDB_MAX_REPLICA];
2414
  int32_t  numOfRetensions;
2415
  SArray*  pRetensions;  // SRetention
2416
  void*    pTsma;
2417
  int32_t  walRetentionPeriod;
2418
  int64_t  walRetentionSize;
2419
  int32_t  walRollPeriod;
2420
  int64_t  walSegmentSize;
2421
  int16_t  sstTrigger;
2422
  int16_t  hashPrefix;
2423
  int16_t  hashSuffix;
2424
  int32_t  tsdbPageSize;
2425
  int32_t  ssChunkSize;
2426
  int32_t  ssKeepLocal;
2427
  int8_t   ssCompact;
2428
  int64_t  reserved[6];
2429
  int8_t   learnerReplica;
2430
  int8_t   learnerSelfIndex;
2431
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2432
  int32_t  changeVersion;
2433
  int8_t   encryptAlgorithm;
2434
} SCreateVnodeReq;
2435

2436
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2437
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2438
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2439

2440
typedef struct {
2441
  int32_t compactId;
2442
  int32_t vgId;
2443
  int32_t dnodeId;
2444
} SQueryCompactProgressReq;
2445

2446
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2447
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2448

2449
typedef struct {
2450
  int32_t compactId;
2451
  int32_t vgId;
2452
  int32_t dnodeId;
2453
  int32_t numberFileset;
2454
  int32_t finished;
2455
  int32_t progress;
2456
  int64_t remainingTime;
2457
} SQueryCompactProgressRsp;
2458

2459
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2460
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2461

2462
typedef struct {
2463
  int32_t vgId;
2464
  int32_t dnodeId;
2465
  int64_t dbUid;
2466
  char    db[TSDB_DB_FNAME_LEN];
2467
  int64_t reserved[8];
2468
} SDropVnodeReq;
2469

2470
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2471
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2472

2473
typedef struct {
2474
  char    colName[TSDB_COL_NAME_LEN];
2475
  char    stb[TSDB_TABLE_FNAME_LEN];
2476
  int64_t stbUid;
2477
  int64_t dbUid;
2478
  int64_t reserved[8];
2479
} SDropIndexReq;
2480

2481
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2482
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2483

2484
typedef struct {
2485
  int64_t     dbUid;
2486
  char        db[TSDB_DB_FNAME_LEN];
2487
  int64_t     compactStartTime;
2488
  STimeWindow tw;
2489
  int32_t     compactId;
2490
  int8_t      metaOnly;
2491
} SCompactVnodeReq;
2492

2493
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2494
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2495

2496
typedef struct {
2497
  int32_t compactId;
2498
  int32_t vgId;
2499
  int32_t dnodeId;
2500
} SVKillCompactReq;
2501

2502
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2503
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2504

2505
typedef struct {
2506
  int32_t vgVersion;
2507
  int32_t buffer;
2508
  int32_t pageSize;
2509
  int32_t pages;
2510
  int32_t cacheLastSize;
2511
  int32_t daysPerFile;
2512
  int32_t daysToKeep0;
2513
  int32_t daysToKeep1;
2514
  int32_t daysToKeep2;
2515
  int32_t keepTimeOffset;
2516
  int32_t walFsyncPeriod;
2517
  int8_t  walLevel;
2518
  int8_t  strict;
2519
  int8_t  cacheLast;
2520
  int64_t reserved[7];
2521
  // 1st modification
2522
  int16_t sttTrigger;
2523
  int32_t minRows;
2524
  // 2nd modification
2525
  int32_t walRetentionPeriod;
2526
  int32_t walRetentionSize;
2527
  int32_t ssKeepLocal;
2528
  int8_t  ssCompact;
2529
} SAlterVnodeConfigReq;
2530

2531
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2532
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2533

2534
typedef struct {
2535
  int32_t  vgId;
2536
  int8_t   strict;
2537
  int8_t   selfIndex;
2538
  int8_t   replica;
2539
  SReplica replicas[TSDB_MAX_REPLICA];
2540
  int64_t  reserved[8];
2541
  int8_t   learnerSelfIndex;
2542
  int8_t   learnerReplica;
2543
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2544
  int32_t  changeVersion;
2545
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2546

2547
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2548
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2549

2550
typedef struct {
2551
  int32_t vgId;
2552
  int8_t  disable;
2553
} SDisableVnodeWriteReq;
2554

2555
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2556
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2557

2558
typedef struct {
2559
  int32_t  srcVgId;
2560
  int32_t  dstVgId;
2561
  uint32_t hashBegin;
2562
  uint32_t hashEnd;
2563
  int32_t  changeVersion;
2564
  int32_t  reserved;
2565
} SAlterVnodeHashRangeReq;
2566

2567
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2568
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2569

2570
#define REQ_OPT_TBNAME 0x0
2571
#define REQ_OPT_TBUID  0x01
2572
typedef struct {
2573
  SMsgHead header;
2574
  char     dbFName[TSDB_DB_FNAME_LEN];
2575
  char     tbName[TSDB_TABLE_NAME_LEN];
2576
  uint8_t  option;
2577
  uint8_t  autoCreateCtb;
2578
} STableInfoReq;
2579

2580
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2581
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2582

2583
typedef struct {
2584
  int8_t  metaClone;  // create local clone of the cached table meta
2585
  int32_t numOfVgroups;
2586
  int32_t numOfTables;
2587
  int32_t numOfUdfs;
2588
  char    tableNames[];
2589
} SMultiTableInfoReq;
2590

2591
// todo refactor
2592
typedef struct SVgroupInfo {
2593
  int32_t  vgId;
2594
  uint32_t hashBegin;
2595
  uint32_t hashEnd;
2596
  SEpSet   epSet;
2597
  union {
2598
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2599
    int32_t taskId;      // used in stream
2600
  };
2601
} SVgroupInfo;
2602

2603
typedef struct {
2604
  int32_t     numOfVgroups;
2605
  SVgroupInfo vgroups[];
2606
} SVgroupsInfo;
2607

2608
typedef struct {
2609
  STableMetaRsp* pMeta;
2610
} SMAlterStbRsp;
2611

2612
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2613
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2614
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2615

2616
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2617
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2618
void    tFreeSTableMetaRsp(void* pRsp);
2619
void    tFreeSTableIndexRsp(void* info);
2620

2621
typedef struct {
2622
  SArray* pMetaRsp;   // Array of STableMetaRsp
2623
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2624
} SSTbHbRsp;
2625

2626
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2627
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2628
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2629

2630
typedef struct {
2631
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2632
} SViewHbRsp;
2633

2634
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2635
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2636
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2637

2638
typedef struct {
2639
  int32_t numOfTables;
2640
  int32_t numOfVgroup;
2641
  int32_t numOfUdf;
2642
  int32_t contLen;
2643
  int8_t  compressed;  // denote if compressed or not
2644
  int32_t rawLen;      // size before compress
2645
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2646
  char    meta[];
2647
} SMultiTableMeta;
2648

2649
typedef struct {
2650
  int32_t dataLen;
2651
  char    name[TSDB_TABLE_FNAME_LEN];
2652
  char*   data;
2653
} STagData;
2654

2655
typedef struct {
2656
  int32_t  opType;
2657
  uint32_t valLen;
2658
  char*    val;
2659
} SShowVariablesReq;
2660

2661
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2662
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2663
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2664

2665
typedef struct {
2666
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2667
  char value[TSDB_CONFIG_PATH_LEN + 1];
2668
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2669
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2670
  char info[TSDB_CONFIG_INFO_LEN + 1];
2671
} SVariablesInfo;
2672

2673
typedef struct {
2674
  SArray* variables;  // SArray<SVariablesInfo>
2675
} SShowVariablesRsp;
2676

2677
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2678
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2679

2680
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2681

2682
/*
2683
 * sql: show tables like '%a_%'
2684
 * payload is the query condition, e.g., '%a_%'
2685
 * payloadLen is the length of payload
2686
 */
2687
typedef struct {
2688
  int32_t type;
2689
  char    db[TSDB_DB_FNAME_LEN];
2690
  int32_t payloadLen;
2691
  char*   payload;
2692
} SShowReq;
2693

2694
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2695
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2696
void tFreeSShowReq(SShowReq* pReq);
2697

2698
typedef struct {
2699
  int64_t       showId;
2700
  STableMetaRsp tableMeta;
2701
} SShowRsp, SVShowTablesRsp;
2702

2703
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2704
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2705
// void    tFreeSShowRsp(SShowRsp* pRsp);
2706

2707
typedef struct {
2708
  char    db[TSDB_DB_FNAME_LEN];
2709
  char    tb[TSDB_TABLE_NAME_LEN];
2710
  char    user[TSDB_USER_LEN];
2711
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2712
  int64_t showId;
2713
  int64_t compactId;  // for compact
2714
  bool    withFull;   // for show users full
2715
} SRetrieveTableReq;
2716

2717
typedef struct SSysTableSchema {
2718
  int8_t   type;
2719
  col_id_t colId;
2720
  int32_t  bytes;
2721
} SSysTableSchema;
2722

2723
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2724
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2725

2726
#define RETRIEVE_TABLE_RSP_VERSION         0
2727
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2728
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2729

2730
typedef struct {
2731
  int64_t useconds;
2732
  int8_t  completed;  // all results are returned to client
2733
  int8_t  precision;
2734
  int8_t  compressed;
2735
  int8_t  streamBlockType;
2736
  int32_t payloadLen;
2737
  int32_t compLen;
2738
  int32_t numOfBlocks;
2739
  int64_t numOfRows;  // from int32_t change to int64_t
2740
  int64_t numOfCols;
2741
  int64_t skey;
2742
  int64_t ekey;
2743
  int64_t version;                         // for stream
2744
  TSKEY   watermark;                       // for stream
2745
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2746
  char    data[];
2747
} SRetrieveTableRsp;
2748

2749
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2750

2751
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2752
  do {                                          \
2753
    ((int32_t*)(_p))[0] = (_compLen);           \
2754
    ((int32_t*)(_p))[1] = (_fullLen);           \
2755
  } while (0);
2756

2757
typedef struct {
2758
  int64_t version;
2759
  int64_t numOfRows;
2760
  int8_t  compressed;
2761
  int8_t  precision;
2762
  char    data[];
2763
} SRetrieveTableRspForTmq;
2764

2765
typedef struct {
2766
  int64_t handle;
2767
  int64_t useconds;
2768
  int8_t  completed;  // all results are returned to client
2769
  int8_t  precision;
2770
  int8_t  compressed;
2771
  int32_t compLen;
2772
  int32_t numOfRows;
2773
  int32_t fullLen;
2774
  char    data[];
2775
} SRetrieveMetaTableRsp;
2776

2777
typedef struct SExplainExecInfo {
2778
  double   startupCost;
2779
  double   totalCost;
2780
  uint64_t numOfRows;
2781
  uint32_t verboseLen;
2782
  void*    verboseInfo;
2783
} SExplainExecInfo;
2784

2785
typedef struct {
2786
  int32_t           numOfPlans;
2787
  SExplainExecInfo* subplanInfo;
2788
} SExplainRsp;
2789

2790
typedef struct {
2791
  SExplainRsp rsp;
2792
  uint64_t    qId;
2793
  uint64_t    cId;
2794
  uint64_t    tId;
2795
  int64_t     rId;
2796
  int32_t     eId;
2797
} SExplainLocalRsp;
2798

2799
typedef struct STableScanAnalyzeInfo {
2800
  uint64_t totalRows;
2801
  uint64_t totalCheckedRows;
2802
  uint32_t totalBlocks;
2803
  uint32_t loadBlocks;
2804
  uint32_t loadBlockStatis;
2805
  uint32_t skipBlocks;
2806
  uint32_t filterOutBlocks;
2807
  double   elapsedTime;
2808
  double   filterTime;
2809
} STableScanAnalyzeInfo;
2810

2811
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2812
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2813
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2814

2815
typedef struct {
2816
  char    config[TSDB_DNODE_CONFIG_LEN];
2817
  char    value[TSDB_CLUSTER_VALUE_LEN];
2818
  int32_t sqlLen;
2819
  char*   sql;
2820
} SMCfgClusterReq;
2821

2822
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2823
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2824
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2825

2826
typedef struct {
2827
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2828
  int32_t port;
2829
  int32_t sqlLen;
2830
  char*   sql;
2831
} SCreateDnodeReq;
2832

2833
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2834
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2835
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2836

2837
typedef struct {
2838
  int32_t dnodeId;
2839
  char    fqdn[TSDB_FQDN_LEN];
2840
  int32_t port;
2841
  int8_t  force;
2842
  int8_t  unsafe;
2843
  int32_t sqlLen;
2844
  char*   sql;
2845
} SDropDnodeReq;
2846

2847
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2848
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2849
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2850

2851
enum {
2852
  RESTORE_TYPE__ALL = 1,
2853
  RESTORE_TYPE__MNODE,
2854
  RESTORE_TYPE__VNODE,
2855
  RESTORE_TYPE__QNODE,
2856
};
2857

2858
typedef struct {
2859
  int32_t dnodeId;
2860
  int8_t  restoreType;
2861
  int32_t sqlLen;
2862
  char*   sql;
2863
} SRestoreDnodeReq;
2864

2865
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2866
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2867
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2868

2869
typedef struct {
2870
  int32_t dnodeId;
2871
  char    config[TSDB_DNODE_CONFIG_LEN];
2872
  char    value[TSDB_DNODE_VALUE_LEN];
2873
  int32_t sqlLen;
2874
  char*   sql;
2875
} SMCfgDnodeReq;
2876

2877
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2878
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2879
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2880

2881
typedef struct {
2882
  char    config[TSDB_DNODE_CONFIG_LEN];
2883
  char    value[TSDB_DNODE_VALUE_LEN];
2884
  int32_t version;
2885
} SDCfgDnodeReq;
2886

2887
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2888
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2889

2890
typedef struct {
2891
  int32_t dnodeId;
2892
  int32_t sqlLen;
2893
  char*   sql;
2894
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2895
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
2896

2897

2898
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2899
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2900

2901

2902
typedef struct {
2903
  int32_t nodeId;
2904
  SEpSet  epSet;
2905
} SNodeEpSet;
2906

2907

2908
typedef struct {
2909
  int32_t    snodeId;
2910
  SNodeEpSet leaders[2];
2911
  SNodeEpSet replica;
2912
  int32_t    sqlLen;
2913
  char*      sql;
2914
} SDCreateSnodeReq;
2915

2916
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
2917
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
2918
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
2919

2920

2921
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2922
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2923
typedef struct {
2924
  int8_t   replica;
2925
  SReplica replicas[TSDB_MAX_REPLICA];
2926
  int8_t   learnerReplica;
2927
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2928
  int64_t  lastIndex;
2929
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2930

2931
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2932
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2933

2934
typedef struct {
2935
  int32_t urlLen;
2936
  int32_t sqlLen;
2937
  char*   url;
2938
  char*   sql;
2939
} SMCreateAnodeReq;
2940

2941
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2942
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2943
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2944

2945
typedef struct {
2946
  int32_t anodeId;
2947
  int32_t sqlLen;
2948
  char*   sql;
2949
} SMDropAnodeReq, SMUpdateAnodeReq;
2950

2951
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2952
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2953
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2954
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2955
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2956
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2957

2958
typedef struct {
2959
  int32_t dnodeId;
2960
  int32_t bnodeProto;
2961
  int32_t sqlLen;
2962
  char*   sql;
2963
} SMCreateBnodeReq, SDCreateBnodeReq;
2964

2965
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2966
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2967
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
2968

2969
typedef struct {
2970
  int32_t dnodeId;
2971
  int32_t sqlLen;
2972
  char*   sql;
2973
} SMDropBnodeReq, SDDropBnodeReq;
2974

2975
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2976
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2977
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
2978

2979
typedef struct {
2980
  int32_t vgId;
2981
  int32_t hbSeq;
2982
} SVArbHbReqMember;
2983

2984
typedef struct {
2985
  int32_t dnodeId;
2986
  char*   arbToken;
2987
  int64_t arbTerm;
2988
  SArray* hbMembers;  // SVArbHbReqMember
2989
} SVArbHeartBeatReq;
2990

2991
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2992
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2993
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2994

2995
typedef struct {
2996
  int32_t vgId;
2997
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2998
  int32_t hbSeq;
2999
} SVArbHbRspMember;
3000

3001
typedef struct {
3002
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3003
  int32_t dnodeId;
3004
  SArray* hbMembers;  // SVArbHbRspMember
3005
} SVArbHeartBeatRsp;
3006

3007
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3008
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3009
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3010

3011
typedef struct {
3012
  char*   arbToken;
3013
  int64_t arbTerm;
3014
  char*   member0Token;
3015
  char*   member1Token;
3016
} SVArbCheckSyncReq;
3017

3018
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3019
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3020
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3021

3022
typedef struct {
3023
  char*   arbToken;
3024
  char*   member0Token;
3025
  char*   member1Token;
3026
  int32_t vgId;
3027
  int32_t errCode;
3028
} SVArbCheckSyncRsp;
3029

3030
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3031
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3032
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3033

3034
typedef struct {
3035
  char*   arbToken;
3036
  int64_t arbTerm;
3037
  char*   memberToken;
3038
  int8_t  force;
3039
} SVArbSetAssignedLeaderReq;
3040

3041
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3042
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3043
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3044

3045
typedef struct {
3046
  char*   arbToken;
3047
  char*   memberToken;
3048
  int32_t vgId;
3049
} SVArbSetAssignedLeaderRsp;
3050

3051
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3052
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3053
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3054

3055
typedef struct {
3056
  int32_t dnodeId;
3057
  char*   token;
3058
} SMArbUpdateGroupMember;
3059

3060
typedef struct {
3061
  int32_t dnodeId;
3062
  char*   token;
3063
  int8_t  acked;
3064
} SMArbUpdateGroupAssigned;
3065

3066
typedef struct {
3067
  int32_t                  vgId;
3068
  int64_t                  dbUid;
3069
  SMArbUpdateGroupMember   members[2];
3070
  int8_t                   isSync;
3071
  int8_t                   assignedAcked;
3072
  SMArbUpdateGroupAssigned assignedLeader;
3073
  int64_t                  version;
3074
  int32_t                  code;
3075
  int64_t                  updateTimeMs;
3076
} SMArbUpdateGroup;
3077

3078
typedef struct {
3079
  SArray* updateArray;  // SMArbUpdateGroup
3080
} SMArbUpdateGroupBatchReq;
3081

3082
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3083
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3084
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3085

3086
typedef struct {
3087
  char queryStrId[TSDB_QUERY_ID_LEN];
3088
} SKillQueryReq;
3089

3090
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3091
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3092

3093
typedef struct {
3094
  uint32_t connId;
3095
} SKillConnReq;
3096

3097
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3098
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3099

3100
typedef struct {
3101
  int32_t transId;
3102
} SKillTransReq;
3103

3104
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3105
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3106

3107
typedef struct {
3108
  int32_t useless;  // useless
3109
  int32_t sqlLen;
3110
  char*   sql;
3111
} SBalanceVgroupReq;
3112

3113
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3114
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3115
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3116

3117
typedef struct {
3118
  int32_t useless;  // useless
3119
  int32_t sqlLen;
3120
  char*   sql;
3121
} SAssignLeaderReq;
3122

3123
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3124
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3125
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3126
typedef struct {
3127
  int32_t vgId1;
3128
  int32_t vgId2;
3129
} SMergeVgroupReq;
3130

3131
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3132
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3133

3134
typedef struct {
3135
  int32_t vgId;
3136
  int32_t dnodeId1;
3137
  int32_t dnodeId2;
3138
  int32_t dnodeId3;
3139
  int32_t sqlLen;
3140
  char*   sql;
3141
} SRedistributeVgroupReq;
3142

3143
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3144
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3145
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3146

3147
typedef struct {
3148
  int32_t reserved;
3149
  int32_t vgId;
3150
  int32_t sqlLen;
3151
  char*   sql;
3152
  char    db[TSDB_DB_FNAME_LEN];
3153
} SBalanceVgroupLeaderReq;
3154

3155
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3156
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3157
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3158

3159
typedef struct {
3160
  int32_t vgId;
3161
} SForceBecomeFollowerReq;
3162

3163
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3164
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3165

3166
typedef struct {
3167
  int32_t vgId;
3168
  bool    force;
3169
} SSplitVgroupReq;
3170

3171
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3172
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3173

3174
typedef struct {
3175
  char user[TSDB_USER_LEN];
3176
  char spi;
3177
  char encrypt;
3178
  char secret[TSDB_PASSWORD_LEN];
3179
  char ckey[TSDB_PASSWORD_LEN];
3180
} SAuthReq, SAuthRsp;
3181

3182
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3183
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3184

3185
typedef struct {
3186
  int32_t statusCode;
3187
  char    details[1024];
3188
} SServerStatusRsp;
3189

3190
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3191
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3192

3193
/**
3194
 * The layout of the query message payload is as following:
3195
 * +--------------------+---------------------------------+
3196
 * |Sql statement       | Physical plan                   |
3197
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3198
 * +--------------------+---------------------------------+
3199
 */
3200
typedef struct SSubQueryMsg {
3201
  SMsgHead header;
3202
  uint64_t sId;
3203
  uint64_t queryId;
3204
  uint64_t clientId;
3205
  uint64_t taskId;
3206
  int64_t  refId;
3207
  int32_t  execId;
3208
  int32_t  msgMask;
3209
  int8_t   taskType;
3210
  int8_t   explain;
3211
  int8_t   needFetch;
3212
  int8_t   compress;
3213
  uint32_t sqlLen;
3214
  char*    sql;
3215
  uint32_t msgLen;
3216
  char*    msg;
3217
} SSubQueryMsg;
3218

3219
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3220
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3221
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3222

3223
typedef struct {
3224
  SMsgHead header;
3225
  uint64_t sId;
3226
  uint64_t queryId;
3227
  uint64_t taskId;
3228
} SSinkDataReq;
3229

3230
typedef struct {
3231
  SMsgHead header;
3232
  uint64_t sId;
3233
  uint64_t queryId;
3234
  uint64_t clientId;
3235
  uint64_t taskId;
3236
  int32_t  execId;
3237
} SQueryContinueReq;
3238

3239
typedef struct {
3240
  SMsgHead header;
3241
  uint64_t sId;
3242
  uint64_t queryId;
3243
  uint64_t taskId;
3244
} SResReadyReq;
3245

3246
typedef struct {
3247
  int32_t code;
3248
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3249
  int32_t sversion;
3250
  int32_t tversion;
3251
} SResReadyRsp;
3252

3253
typedef struct SOperatorParam {
3254
  int32_t opType;
3255
  int32_t downstreamIdx;
3256
  void*   value;
3257
  SArray* pChildren;  // SArray<SOperatorParam*>
3258
  bool    reUse;
3259
} SOperatorParam;
3260

3261
typedef struct SColIdNameKV {
3262
  col_id_t colId;
3263
  char     colName[TSDB_COL_NAME_LEN];
3264
} SColIdNameKV;
3265

3266
typedef struct SColIdPair {
3267
  col_id_t vtbColId;
3268
  col_id_t orgColId;
3269
} SColIdPair;
3270

3271
typedef struct SOrgTbInfo {
3272
  int32_t vgId;
3273
  char    tbName[TSDB_TABLE_FNAME_LEN];
3274
  SArray* colMap;  // SArray<SColIdNameKV>
3275
} SOrgTbInfo;
3276

3277
typedef struct STableScanOperatorParam {
3278
  bool        tableSeq;
3279
  SArray*     pUidList;
3280
  SOrgTbInfo* pOrgTbInfo;
3281
  STimeWindow window;
3282
} STableScanOperatorParam;
3283

3284
typedef struct STagScanOperatorParam {
3285
  tb_uid_t       vcUid;
3286
} STagScanOperatorParam;
3287

3288
typedef struct SVTableScanOperatorParam {
3289
  uint64_t        uid;
3290
  SOperatorParam* pTagScanOp;
3291
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3292
} SVTableScanOperatorParam;
3293

3294
struct SStreamRuntimeFuncInfo;
3295
typedef struct {
3296
  SMsgHead                       header;
3297
  uint64_t                       sId;
3298
  uint64_t                       queryId;
3299
  uint64_t                       clientId;
3300
  uint64_t                       taskId;
3301
  int32_t                        execId;
3302
  SOperatorParam*                pOpParam;
3303

3304
  // used for new-stream
3305
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3306
  bool                           reset;
3307
  bool                           dynTbname;
3308
  // used for new-stream
3309
} SResFetchReq;
3310

3311
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3312
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3313
void    tDestroySResFetchReq(SResFetchReq* pReq);
3314
typedef struct {
3315
  SMsgHead header;
3316
  uint64_t clientId;
3317
} SSchTasksStatusReq;
3318

3319
typedef struct {
3320
  uint64_t queryId;
3321
  uint64_t clientId;
3322
  uint64_t taskId;
3323
  int64_t  refId;
3324
  int32_t  execId;
3325
  int8_t   status;
3326
} STaskStatus;
3327

3328
typedef struct {
3329
  int64_t refId;
3330
  SArray* taskStatus;  // SArray<STaskStatus>
3331
} SSchedulerStatusRsp;
3332

3333
typedef struct {
3334
  uint64_t queryId;
3335
  uint64_t taskId;
3336
  int8_t   action;
3337
} STaskAction;
3338

3339
typedef struct SQueryNodeEpId {
3340
  int32_t nodeId;  // vgId or qnodeId
3341
  SEp     ep;
3342
} SQueryNodeEpId;
3343

3344
typedef struct {
3345
  SMsgHead       header;
3346
  uint64_t       clientId;
3347
  SQueryNodeEpId epId;
3348
  SArray*        taskAction;  // SArray<STaskAction>
3349
} SSchedulerHbReq;
3350

3351
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3352
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3353
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3354

3355
typedef struct {
3356
  SQueryNodeEpId epId;
3357
  SArray*        taskStatus;  // SArray<STaskStatus>
3358
} SSchedulerHbRsp;
3359

3360
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3361
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3362
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3363

3364
typedef struct {
3365
  SMsgHead header;
3366
  uint64_t sId;
3367
  uint64_t queryId;
3368
  uint64_t clientId;
3369
  uint64_t taskId;
3370
  int64_t  refId;
3371
  int32_t  execId;
3372
} STaskCancelReq;
3373

3374
typedef struct {
3375
  int32_t code;
3376
} STaskCancelRsp;
3377

3378
typedef struct {
3379
  SMsgHead header;
3380
  uint64_t sId;
3381
  uint64_t queryId;
3382
  uint64_t clientId;
3383
  uint64_t taskId;
3384
  int64_t  refId;
3385
  int32_t  execId;
3386
} STaskDropReq;
3387

3388
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3389
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3390

3391
typedef enum {
3392
  TASK_NOTIFY_FINISHED = 1,
3393
} ETaskNotifyType;
3394

3395
typedef struct {
3396
  SMsgHead        header;
3397
  uint64_t        sId;
3398
  uint64_t        queryId;
3399
  uint64_t        clientId;
3400
  uint64_t        taskId;
3401
  int64_t         refId;
3402
  int32_t         execId;
3403
  ETaskNotifyType type;
3404
} STaskNotifyReq;
3405

3406
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3407
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3408

3409
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3410
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3411

3412
typedef struct {
3413
  int32_t code;
3414
} STaskDropRsp;
3415

3416
#define STREAM_TRIGGER_AT_ONCE                 1
3417
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3418
#define STREAM_TRIGGER_MAX_DELAY               3
3419
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3420
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3421

3422
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3423
#define STREAM_FILL_HISTORY_ON        1
3424
#define STREAM_FILL_HISTORY_OFF       0
3425
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3426
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3427
#define STREAM_CREATE_STABLE_TRUE     1
3428
#define STREAM_CREATE_STABLE_FALSE    0
3429

3430
typedef struct SVgroupVer {
3431
  int32_t vgId;
3432
  int64_t ver;
3433
} SVgroupVer;
3434

3435
typedef struct STaskNotifyEventStat {
3436
  int64_t notifyEventAddTimes;     // call times of add function
3437
  int64_t notifyEventAddElems;     // elements added by add function
3438
  double  notifyEventAddCostSec;   // time cost of add function
3439
  int64_t notifyEventPushTimes;    // call times of push function
3440
  int64_t notifyEventPushElems;    // elements pushed by push function
3441
  double  notifyEventPushCostSec;  // time cost of push function
3442
  int64_t notifyEventPackTimes;    // call times of pack function
3443
  int64_t notifyEventPackElems;    // elements packed by pack function
3444
  double  notifyEventPackCostSec;  // time cost of pack function
3445
  int64_t notifyEventSendTimes;    // call times of send function
3446
  int64_t notifyEventSendElems;    // elements sent by send function
3447
  double  notifyEventSendCostSec;  // time cost of send function
3448
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3449
} STaskNotifyEventStat;
3450

3451
enum {
3452
  TOPIC_SUB_TYPE__DB = 1,
3453
  TOPIC_SUB_TYPE__TABLE,
3454
  TOPIC_SUB_TYPE__COLUMN,
3455
};
3456

3457
#define DEFAULT_MAX_POLL_INTERVAL  300000
3458
#define DEFAULT_SESSION_TIMEOUT    12000
3459
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3460
#define DEFAULT_MIN_POLL_ROWS      4096
3461

3462
typedef struct {
3463
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3464
  int8_t igExists;
3465
  int8_t subType;
3466
  int8_t withMeta;
3467
  char*  sql;
3468
  char   subDbName[TSDB_DB_FNAME_LEN];
3469
  char*  ast;
3470
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3471
} SCMCreateTopicReq;
3472

3473
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3474
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3475
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3476

3477
typedef struct {
3478
  int64_t consumerId;
3479
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3480

3481
typedef struct {
3482
  int64_t consumerId;
3483
  char    cgroup[TSDB_CGROUP_LEN];
3484
  char    clientId[TSDB_CLIENT_ID_LEN];
3485
  char    user[TSDB_USER_LEN];
3486
  char    fqdn[TSDB_FQDN_LEN];
3487
  SArray* topicNames;  // SArray<char**>
3488

3489
  int8_t  withTbName;
3490
  int8_t  autoCommit;
3491
  int32_t autoCommitInterval;
3492
  int8_t  resetOffsetCfg;
3493
  int8_t  enableReplay;
3494
  int8_t  enableBatchMeta;
3495
  int32_t sessionTimeoutMs;
3496
  int32_t maxPollIntervalMs;
3497
} SCMSubscribeReq;
3498

3499
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3500
  int32_t tlen = 0;
314✔
3501
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
314!
3502
  tlen += taosEncodeString(buf, pReq->cgroup);
314✔
3503
  tlen += taosEncodeString(buf, pReq->clientId);
314✔
3504

3505
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
314!
3506
  tlen += taosEncodeFixedI32(buf, topicNum);
314✔
3507

3508
  for (int32_t i = 0; i < topicNum; i++) {
480✔
3509
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
332✔
3510
  }
3511

3512
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
314!
3513
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
314!
3514
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
314!
3515
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
314!
3516
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
314!
3517
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
314!
3518
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
314!
3519
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
314!
3520
  tlen += taosEncodeString(buf, pReq->user);
314✔
3521
  tlen += taosEncodeString(buf, pReq->fqdn);
314✔
3522

3523
  return tlen;
314✔
3524
}
3525

3526
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3527
  void* start = buf;
979✔
3528
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
979!
3529
  buf = taosDecodeStringTo(buf, pReq->cgroup);
979✔
3530
  buf = taosDecodeStringTo(buf, pReq->clientId);
979✔
3531

3532
  int32_t topicNum = 0;
979!
3533
  buf = taosDecodeFixedI32(buf, &topicNum);
979✔
3534

3535
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
979✔
3536
  if (pReq->topicNames == NULL) {
979!
3537
    return terrno;
×
3538
  }
3539
  for (int32_t i = 0; i < topicNum; i++) {
1,425✔
3540
    char* name = NULL;
446✔
3541
    buf = taosDecodeString(buf, &name);
446✔
3542
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
892!
3543
      return terrno;
×
3544
    }
3545
  }
3546

3547
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
979✔
3548
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
979✔
3549
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
979!
3550
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
979✔
3551
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
979✔
3552
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
979✔
3553
  if ((char*)buf - (char*)start < len) {
979!
3554
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
979!
3555
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
979!
3556
    buf = taosDecodeStringTo(buf, pReq->user);
979✔
3557
    buf = taosDecodeStringTo(buf, pReq->fqdn);
1,958✔
3558
  } else {
3559
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3560
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3561
  }
3562

3563
  return 0;
979✔
3564
}
3565

3566
typedef struct {
3567
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3568
  SArray* removedConsumers;  // SArray<int64_t>
3569
  SArray* newConsumers;      // SArray<int64_t>
3570
} SMqRebInfo;
3571

3572
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3573
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
913!
3574
  if (pRebInfo == NULL) {
913!
3575
    return NULL;
×
3576
  }
3577
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
913✔
3578
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
913✔
3579
  if (pRebInfo->removedConsumers == NULL) {
913!
3580
    goto _err;
×
3581
  }
3582
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
913✔
3583
  if (pRebInfo->newConsumers == NULL) {
913!
3584
    goto _err;
×
3585
  }
3586
  return pRebInfo;
913✔
3587
_err:
×
3588
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3589
  taosArrayDestroy(pRebInfo->newConsumers);
×
3590
  taosMemoryFreeClear(pRebInfo);
×
3591
  return NULL;
×
3592
}
3593

3594
typedef struct {
3595
  int64_t streamId;
3596
  int64_t checkpointId;
3597
  char    streamName[TSDB_STREAM_FNAME_LEN];
3598
} SMStreamDoCheckpointMsg;
3599

3600
typedef struct {
3601
  int64_t status;
3602
} SMVSubscribeRsp;
3603

3604
typedef struct {
3605
  char    name[TSDB_TOPIC_FNAME_LEN];
3606
  int8_t  igNotExists;
3607
  int32_t sqlLen;
3608
  char*   sql;
3609
  int8_t  force;
3610
} SMDropTopicReq;
3611

3612
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3613
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3614
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3615

3616
typedef struct {
3617
  char   topic[TSDB_TOPIC_FNAME_LEN];
3618
  char   cgroup[TSDB_CGROUP_LEN];
3619
  int8_t igNotExists;
3620
  int8_t force;
3621
} SMDropCgroupReq;
3622

3623
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3624
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3625

3626
typedef struct {
3627
  int8_t reserved;
3628
} SMDropCgroupRsp;
3629

3630
typedef struct {
3631
  char    name[TSDB_TABLE_FNAME_LEN];
3632
  int8_t  alterType;
3633
  SSchema schema;
3634
} SAlterTopicReq;
3635

3636
typedef struct {
3637
  SMsgHead head;
3638
  char     name[TSDB_TABLE_FNAME_LEN];
3639
  int64_t  tuid;
3640
  int32_t  sverson;
3641
  int32_t  execLen;
3642
  char*    executor;
3643
  int32_t  sqlLen;
3644
  char*    sql;
3645
} SDCreateTopicReq;
3646

3647
typedef struct {
3648
  SMsgHead head;
3649
  char     name[TSDB_TABLE_FNAME_LEN];
3650
  int64_t  tuid;
3651
} SDDropTopicReq;
3652

3653
typedef struct {
3654
  int64_t maxdelay[2];
3655
  int64_t watermark[2];
3656
  int64_t deleteMark[2];
3657
  int32_t qmsgLen[2];
3658
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3659
} SRSmaParam;
3660

3661
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3662
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3663

3664
// TDMT_VND_CREATE_STB ==============
3665
typedef struct SVCreateStbReq {
3666
  char*           name;
3667
  tb_uid_t        suid;
3668
  int8_t          rollup;
3669
  SSchemaWrapper  schemaRow;
3670
  SSchemaWrapper  schemaTag;
3671
  SRSmaParam      rsmaParam;
3672
  int32_t         alterOriDataLen;
3673
  void*           alterOriData;
3674
  int8_t          source;
3675
  int8_t          colCmpred;
3676
  SColCmprWrapper colCmpr;
3677
  int64_t         keep;
3678
  SExtSchema*     pExtSchemas;
3679
  int8_t          virtualStb;
3680
} SVCreateStbReq;
3681

3682
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3683
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3684

3685
// TDMT_VND_DROP_STB ==============
3686
typedef struct SVDropStbReq {
3687
  char*    name;
3688
  tb_uid_t suid;
3689
} SVDropStbReq;
3690

3691
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3692
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3693

3694
// TDMT_VND_CREATE_TABLE ==============
3695
#define TD_CREATE_IF_NOT_EXISTS       0x1
3696
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
3697
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
3698
typedef struct SVCreateTbReq {
3699
  int32_t  flags;
3700
  char*    name;
3701
  tb_uid_t uid;
3702
  int64_t  btime;
3703
  int32_t  ttl;
3704
  int32_t  commentLen;
3705
  char*    comment;
3706
  int8_t   type;
3707
  union {
3708
    struct {
3709
      char*    stbName;  // super table name
3710
      uint8_t  tagNum;
3711
      tb_uid_t suid;
3712
      SArray*  tagName;
3713
      uint8_t* pTag;
3714
    } ctb;
3715
    struct {
3716
      SSchemaWrapper schemaRow;
3717
    } ntb;
3718
  };
3719
  int32_t         sqlLen;
3720
  char*           sql;
3721
  SColCmprWrapper colCmpr;
3722
  SExtSchema*     pExtSchemas;
3723
  SColRefWrapper  colRef;  // col reference for virtual table
3724
} SVCreateTbReq;
3725

3726
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3727
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3728
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3729
void tDestroySVSubmitCreateTbReq(SVCreateTbReq *pReq, int32_t flags);
3730

3731
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3732
  if (NULL == req) {
32,056,058!
3733
    return;
31,945,661✔
3734
  }
3735

3736
  taosMemoryFreeClear(req->sql);
110,397!
3737
  taosMemoryFreeClear(req->name);
110,397!
3738
  taosMemoryFreeClear(req->comment);
110,436!
3739
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
110,436!
3740
    taosMemoryFreeClear(req->ctb.pTag);
109,608!
3741
    taosMemoryFreeClear(req->ctb.stbName);
109,622!
3742
    taosArrayDestroy(req->ctb.tagName);
109,627✔
3743
    req->ctb.tagName = NULL;
109,598✔
3744
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
828!
3745
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
828!
3746
  }
3747
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
110,426!
3748
  taosMemoryFreeClear(req->pExtSchemas);
110,426!
3749
  taosMemoryFreeClear(req->colRef.pColRef);
110,426!
3750
}
3751

3752
typedef struct {
3753
  int32_t nReqs;
3754
  union {
3755
    SVCreateTbReq* pReqs;
3756
    SArray*        pArray;
3757
  };
3758
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3759
} SVCreateTbBatchReq;
3760

3761
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3762
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3763
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3764

3765
typedef struct {
3766
  int32_t        code;
3767
  STableMetaRsp* pMeta;
3768
} SVCreateTbRsp, SVUpdateTbRsp;
3769

3770
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3771
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3772
void tFreeSVCreateTbRsp(void* param);
3773

3774
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3775
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3776

3777
typedef struct {
3778
  int32_t nRsps;
3779
  union {
3780
    SVCreateTbRsp* pRsps;
3781
    SArray*        pArray;
3782
  };
3783
} SVCreateTbBatchRsp;
3784

3785
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3786
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3787

3788
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3789
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3790

3791
// TDMT_VND_DROP_TABLE =================
3792
typedef struct {
3793
  char*    name;
3794
  uint64_t suid;  // for tmq in wal format
3795
  int64_t  uid;
3796
  int8_t   igNotExists;
3797
  int8_t   isVirtual;
3798
} SVDropTbReq;
3799

3800
typedef struct {
3801
  int32_t code;
3802
} SVDropTbRsp;
3803

3804
typedef struct {
3805
  int32_t nReqs;
3806
  union {
3807
    SVDropTbReq* pReqs;
3808
    SArray*      pArray;
3809
  };
3810
} SVDropTbBatchReq;
3811

3812
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3813
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3814

3815
typedef struct {
3816
  int32_t nRsps;
3817
  union {
3818
    SVDropTbRsp* pRsps;
3819
    SArray*      pArray;
3820
  };
3821
} SVDropTbBatchRsp;
3822

3823
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3824
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3825

3826
// TDMT_VND_ALTER_TABLE =====================
3827
typedef struct SMultiTagUpateVal {
3828
  char*    tagName;
3829
  int32_t  colId;
3830
  int8_t   tagType;
3831
  int8_t   tagFree;
3832
  uint32_t nTagVal;
3833
  uint8_t* pTagVal;
3834
  int8_t   isNull;
3835
  SArray*  pTagArray;
3836
} SMultiTagUpateVal;
3837
typedef struct SVAlterTbReq {
3838
  char*   tbName;
3839
  int8_t  action;
3840
  char*   colName;
3841
  int32_t colId;
3842
  // TSDB_ALTER_TABLE_ADD_COLUMN
3843
  int8_t  type;
3844
  int8_t  flags;
3845
  int32_t bytes;
3846
  // TSDB_ALTER_TABLE_DROP_COLUMN
3847
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3848
  int8_t   colModType;
3849
  int32_t  colModBytes;
3850
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3851
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3852
  int8_t   isNull;
3853
  int8_t   tagType;
3854
  int8_t   tagFree;
3855
  uint32_t nTagVal;
3856
  uint8_t* pTagVal;
3857
  SArray*  pTagArray;
3858
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3859
  int8_t   updateTTL;
3860
  int32_t  newTTL;
3861
  int32_t  newCommentLen;
3862
  char*    newComment;
3863
  int64_t  ctimeMs;    // fill by vnode
3864
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3865
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3866
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3867
  // for Add column
3868
  STypeMod typeMod;
3869
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3870
  char* refDbName;
3871
  char* refTbName;
3872
  char* refColName;
3873
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3874
} SVAlterTbReq;
3875

3876
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3877
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3878
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3879
void    tfreeMultiTagUpateVal(void* pMultiTag);
3880

3881
typedef struct {
3882
  int32_t        code;
3883
  STableMetaRsp* pMeta;
3884
} SVAlterTbRsp;
3885

3886
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3887
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3888
// ======================
3889

3890
typedef struct {
3891
  SMsgHead head;
3892
  int64_t  uid;
3893
  int32_t  tid;
3894
  int16_t  tversion;
3895
  int16_t  colId;
3896
  int8_t   type;
3897
  int16_t  bytes;
3898
  int32_t  tagValLen;
3899
  int16_t  numOfTags;
3900
  int32_t  schemaLen;
3901
  char     data[];
3902
} SUpdateTagValReq;
3903

3904
typedef struct {
3905
  SMsgHead head;
3906
} SUpdateTagValRsp;
3907

3908
typedef struct {
3909
  SMsgHead head;
3910
} SVShowTablesReq;
3911

3912
typedef struct {
3913
  SMsgHead head;
3914
  int32_t  id;
3915
} SVShowTablesFetchReq;
3916

3917
typedef struct {
3918
  int64_t useconds;
3919
  int8_t  completed;  // all results are returned to client
3920
  int8_t  precision;
3921
  int8_t  compressed;
3922
  int32_t compLen;
3923
  int32_t numOfRows;
3924
  char    data[];
3925
} SVShowTablesFetchRsp;
3926

3927
typedef struct {
3928
  int64_t consumerId;
3929
  int32_t epoch;
3930
  char    cgroup[TSDB_CGROUP_LEN];
3931
} SMqAskEpReq;
3932

3933
typedef struct {
3934
  int32_t key;
3935
  int32_t valueLen;
3936
  void*   value;
3937
} SKv;
3938

3939
typedef struct {
3940
  int64_t tscRid;
3941
  int8_t  connType;
3942
} SClientHbKey;
3943

3944
typedef struct {
3945
  int64_t tid;
3946
  char    status[TSDB_JOB_STATUS_LEN];
3947
} SQuerySubDesc;
3948

3949
typedef struct {
3950
  char     sql[TSDB_SHOW_SQL_LEN];
3951
  uint64_t queryId;
3952
  int64_t  useconds;
3953
  int64_t  stime;  // timestamp precision ms
3954
  int64_t  reqRid;
3955
  bool     stableQuery;
3956
  bool     isSubQuery;
3957
  char     fqdn[TSDB_FQDN_LEN];
3958
  int32_t  subPlanNum;
3959
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3960
} SQueryDesc;
3961

3962
typedef struct {
3963
  uint32_t connId;
3964
  SArray*  queryDesc;  // SArray<SQueryDesc>
3965
} SQueryHbReqBasic;
3966

3967
typedef struct {
3968
  uint32_t connId;
3969
  uint64_t killRid;
3970
  int32_t  totalDnodes;
3971
  int32_t  onlineDnodes;
3972
  int8_t   killConnection;
3973
  int8_t   align[3];
3974
  SEpSet   epSet;
3975
  SArray*  pQnodeList;
3976
} SQueryHbRspBasic;
3977

3978
typedef struct SAppClusterSummary {
3979
  uint64_t numOfInsertsReq;
3980
  uint64_t numOfInsertRows;
3981
  uint64_t insertElapsedTime;
3982
  uint64_t insertBytes;  // submit to tsdb since launched.
3983

3984
  uint64_t fetchBytes;
3985
  uint64_t numOfQueryReq;
3986
  uint64_t queryElapsedTime;
3987
  uint64_t numOfSlowQueries;
3988
  uint64_t totalRequests;
3989
  uint64_t currentRequests;  // the number of SRequestObj
3990
} SAppClusterSummary;
3991

3992
typedef struct {
3993
  int64_t            appId;
3994
  int32_t            pid;
3995
  char               name[TSDB_APP_NAME_LEN];
3996
  int64_t            startTime;
3997
  SAppClusterSummary summary;
3998
} SAppHbReq;
3999

4000
typedef struct {
4001
  SClientHbKey      connKey;
4002
  int64_t           clusterId;
4003
  SAppHbReq         app;
4004
  SQueryHbReqBasic* query;
4005
  SHashObj*         info;  // hash<Skv.key, Skv>
4006
  char              userApp[TSDB_APP_NAME_LEN];
4007
  uint32_t          userIp;
4008
  SIpRange          userDualIp;
4009
} SClientHbReq;
4010

4011
typedef struct {
4012
  int64_t reqId;
4013
  SArray* reqs;  // SArray<SClientHbReq>
4014
  int64_t ipWhiteListVer;
4015
} SClientHbBatchReq;
4016

4017
typedef struct {
4018
  SClientHbKey      connKey;
4019
  int32_t           status;
4020
  SQueryHbRspBasic* query;
4021
  SArray*           info;  // Array<Skv>
4022
} SClientHbRsp;
4023

4024
typedef struct {
4025
  int64_t       reqId;
4026
  int64_t       rspId;
4027
  int32_t       svrTimestamp;
4028
  SArray*       rsps;  // SArray<SClientHbRsp>
4029
  SMonitorParas monitorParas;
4030
  int8_t        enableAuditDelete;
4031
  int8_t        enableStrongPass;
4032
} SClientHbBatchRsp;
4033

4034
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
144,127✔
4035

4036
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4037
  void* pIter = taosHashIterate(info, NULL);
562,086✔
4038
  while (pIter != NULL) {
939,343!
4039
    SKv* kv = (SKv*)pIter;
377,212✔
4040
    taosMemoryFreeClear(kv->value);
377,212!
4041
    pIter = taosHashIterate(info, pIter);
377,211✔
4042
  }
4043
}
562,131✔
4044

4045
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
493,542✔
4046
  SQueryDesc* desc = (SQueryDesc*)pDesc;
493,542✔
4047
  if (desc->subDesc) {
493,542✔
4048
    taosArrayDestroy(desc->subDesc);
492,144✔
4049
    desc->subDesc = NULL;
492,143✔
4050
  }
4051
}
493,541✔
4052

4053
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
633,304✔
4054
  SClientHbReq* req = (SClientHbReq*)pReq;
646,514✔
4055
  if (req->query) {
646,514!
4056
    if (req->query->queryDesc) {
625,881!
4057
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
30,304✔
4058
    }
4059
    taosMemoryFreeClear(req->query);
625,881!
4060
  }
4061

4062
  if (req->info) {
646,551!
4063
    tFreeReqKvHash(req->info);
562,086✔
4064
    taosHashCleanup(req->info);
562,131✔
4065
    req->info = NULL;
562,103✔
4066
  }
4067
}
565,227✔
4068

4069
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4070
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4071

4072
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4073
  if (pReq == NULL) return;
10,827!
4074
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
10,827✔
4075
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
10,827✔
4076
  taosMemoryFree(pReq);
10,827!
4077
}
4078

4079
static FORCE_INLINE void tFreeClientKv(void* pKv) {
142,326✔
4080
  SKv* kv = (SKv*)pKv;
142,326✔
4081
  if (kv) {
142,326!
4082
    taosMemoryFreeClear(kv->value);
142,326!
4083
  }
4084
}
142,324✔
4085

4086
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
633,185✔
4087
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
633,185✔
4088
  if (rsp->query) {
633,185✔
4089
    taosArrayDestroy(rsp->query->pQnodeList);
625,823✔
4090
    taosMemoryFreeClear(rsp->query);
625,856!
4091
  }
4092
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
633,243!
4093
}
81,302✔
4094

4095
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4096
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
415,307✔
4097
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
415,307✔
4098
}
415,380✔
4099

4100
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4101
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4102
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4103

4104
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4105
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
608,686!
4106
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
608,686!
4107
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
608,686!
4108
  return 0;
304,343✔
4109
}
4110

4111
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4112
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
735,867!
4113
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
735,871!
4114
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
367,936!
4115
  if (pKv->value == NULL) {
367,937!
4116
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4117
  }
4118
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
367,937!
4119
  return 0;
367,935✔
4120
}
4121

4122
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4123
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,532,818!
4124
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,532,818!
4125
  return 0;
1,266,409✔
4126
}
4127

4128
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4129
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,267,411!
4130
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,267,416!
4131
  return 0;
633,706✔
4132
}
4133

4134
typedef struct {
4135
  int32_t vgId;
4136
  // TODO stas
4137
} SMqReportVgInfo;
4138

4139
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4140
  int32_t tlen = 0;
4141
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4142
  return tlen;
4143
}
4144

4145
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4146
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4147
  return buf;
4148
}
4149

4150
typedef struct {
4151
  int32_t epoch;
4152
  int64_t topicUid;
4153
  char    name[TSDB_TOPIC_FNAME_LEN];
4154
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4155
} SMqTopicInfo;
4156

4157
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4158
  int32_t tlen = 0;
4159
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4160
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4161
  tlen += taosEncodeString(buf, pTopicInfo->name);
4162
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4163
  tlen += taosEncodeFixedI32(buf, sz);
4164
  for (int32_t i = 0; i < sz; i++) {
4165
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4166
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4167
  }
4168
  return tlen;
4169
}
4170

4171
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4172
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4173
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4174
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4175
  int32_t sz;
4176
  buf = taosDecodeFixedI32(buf, &sz);
4177
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4178
    return NULL;
4179
  }
4180
  for (int32_t i = 0; i < sz; i++) {
4181
    SMqReportVgInfo vgInfo;
4182
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4183
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4184
      return NULL;
4185
    }
4186
  }
4187
  return buf;
4188
}
4189

4190
typedef struct {
4191
  int32_t status;  // ask hb endpoint
4192
  int32_t epoch;
4193
  int64_t consumerId;
4194
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4195
} SMqReportReq;
4196

4197
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4198
  int32_t tlen = 0;
4199
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4200
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4201
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4202
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4203
  tlen += taosEncodeFixedI32(buf, sz);
4204
  for (int32_t i = 0; i < sz; i++) {
4205
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4206
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4207
  }
4208
  return tlen;
4209
}
4210

4211
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4212
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4213
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4214
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4215
  int32_t sz;
4216
  buf = taosDecodeFixedI32(buf, &sz);
4217
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4218
    return NULL;
4219
  }
4220
  for (int32_t i = 0; i < sz; i++) {
4221
    SMqTopicInfo topicInfo;
4222
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4223
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4224
      return NULL;
4225
    }
4226
  }
4227
  return buf;
4228
}
4229

4230
typedef struct {
4231
  SMsgHead head;
4232
  int64_t  leftForVer;
4233
  int32_t  vgId;
4234
  int64_t  consumerId;
4235
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4236
} SMqVDeleteReq;
4237

4238
typedef struct {
4239
  int8_t reserved;
4240
} SMqVDeleteRsp;
4241

4242
typedef struct {
4243
  char*   name;
4244
  int8_t  igNotExists;
4245
} SMDropStreamReq;
4246

4247
typedef struct {
4248
  int8_t reserved;
4249
} SMDropStreamRsp;
4250

4251
typedef struct {
4252
  SMsgHead head;
4253
  int64_t  resetRelHalt;  // reset related stream task halt status
4254
  int64_t  streamId;
4255
  int32_t  taskId;
4256
} SVDropStreamTaskReq;
4257

4258
typedef struct {
4259
  int8_t reserved;
4260
} SVDropStreamTaskRsp;
4261

4262
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4263
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4264
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4265

4266
typedef struct {
4267
  char*  name;
4268
  int8_t igNotExists;
4269
} SMPauseStreamReq;
4270

4271
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4272
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4273
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4274

4275
typedef struct {
4276
  char*  name;
4277
  int8_t igNotExists;
4278
  int8_t igUntreated;
4279
} SMResumeStreamReq;
4280

4281
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4282
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4283
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4284

4285
typedef struct {
4286
  char*       name;
4287
  int8_t      calcAll;
4288
  STimeWindow timeRange;
4289
} SMRecalcStreamReq;
4290

4291
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4292
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4293
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4294

4295
typedef struct SVUpdateCheckpointInfoReq {
4296
  SMsgHead head;
4297
  int64_t  streamId;
4298
  int32_t  taskId;
4299
  int64_t  checkpointId;
4300
  int64_t  checkpointVer;
4301
  int64_t  checkpointTs;
4302
  int32_t  transId;
4303
  int64_t  hStreamId;  // add encode/decode
4304
  int64_t  hTaskId;
4305
  int8_t   dropRelHTask;
4306
} SVUpdateCheckpointInfoReq;
4307

4308
typedef struct {
4309
  int64_t leftForVer;
4310
  int32_t vgId;
4311
  int64_t oldConsumerId;
4312
  int64_t newConsumerId;
4313
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4314
  int8_t  subType;
4315
  int8_t  withMeta;
4316
  char*   qmsg;  // SubPlanToString
4317
  int64_t suid;
4318
} SMqRebVgReq;
4319

4320
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4321
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4322

4323
typedef struct {
4324
  char    topic[TSDB_TOPIC_FNAME_LEN];
4325
  int64_t ntbUid;
4326
  SArray* colIdList;  // SArray<int16_t>
4327
} STqCheckInfo;
4328

4329
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4330
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4331
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4332

4333
// tqOffset
4334
enum {
4335
  TMQ_OFFSET__RESET_NONE = -3,
4336
  TMQ_OFFSET__RESET_EARLIEST = -2,
4337
  TMQ_OFFSET__RESET_LATEST = -1,
4338
  TMQ_OFFSET__LOG = 1,
4339
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4340
  TMQ_OFFSET__SNAPSHOT_META = 3,
4341
};
4342

4343
enum {
4344
  WITH_DATA = 0,
4345
  WITH_META = 1,
4346
  ONLY_META = 2,
4347
};
4348

4349
#define TQ_OFFSET_VERSION 1
4350

4351
typedef struct {
4352
  int8_t type;
4353
  union {
4354
    // snapshot
4355
    struct {
4356
      int64_t uid;
4357
      int64_t ts;
4358
      SValue  primaryKey;
4359
    };
4360
    // log
4361
    struct {
4362
      int64_t version;
4363
    };
4364
  };
4365
} STqOffsetVal;
4366

4367
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4368
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
24,907✔
4369
  pOffsetVal->uid = uid;
24,907✔
4370
  pOffsetVal->ts = ts;
24,907✔
4371
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
24,907!
4372
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4373
  }
4374
  pOffsetVal->primaryKey = primaryKey;
24,909✔
4375
}
24,909✔
4376

4377
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4378
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
4379
  pOffsetVal->uid = uid;
149✔
4380
}
149✔
4381

4382
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4383
  pOffsetVal->type = TMQ_OFFSET__LOG;
188,285✔
4384
  pOffsetVal->version = ver;
188,285✔
4385
}
188,285✔
4386

4387
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4388
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4389
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4390
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4391
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4392
void    tOffsetDestroy(void* pVal);
4393

4394
typedef struct {
4395
  STqOffsetVal val;
4396
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4397
} STqOffset;
4398

4399
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4400
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4401
void    tDeleteSTqOffset(void* val);
4402

4403
typedef struct SMqVgOffset {
4404
  int64_t   consumerId;
4405
  STqOffset offset;
4406
} SMqVgOffset;
4407

4408
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4409
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4410

4411
typedef struct {
4412
  char    name[TSDB_TABLE_FNAME_LEN];
4413
  char    stb[TSDB_TABLE_FNAME_LEN];
4414
  int8_t  igExists;
4415
  int8_t  intervalUnit;
4416
  int8_t  slidingUnit;
4417
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4418
  int32_t dstVgId;   // for stream
4419
  int64_t interval;
4420
  int64_t offset;
4421
  int64_t sliding;
4422
  int64_t maxDelay;
4423
  int64_t watermark;
4424
  int32_t exprLen;        // strlen + 1
4425
  int32_t tagsFilterLen;  // strlen + 1
4426
  int32_t sqlLen;         // strlen + 1
4427
  int32_t astLen;         // strlen + 1
4428
  char*   expr;
4429
  char*   tagsFilter;
4430
  char*   sql;
4431
  char*   ast;
4432
  int64_t deleteMark;
4433
  int64_t lastTs;
4434
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4435
  SArray* pVgroupVerList;
4436
  int8_t  recursiveTsma;
4437
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4438
  char*   createStreamReq;
4439
  int32_t streamReqLen;
4440
  char*   dropStreamReq;
4441
  int32_t dropStreamReqLen;
4442
  int64_t uid;
4443
} SMCreateSmaReq;
4444

4445
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4446
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4447
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4448

4449
typedef struct {
4450
  char   name[TSDB_TABLE_FNAME_LEN];
4451
  int8_t igNotExists;
4452
  char*   dropStreamReq;
4453
  int32_t dropStreamReqLen;
4454
} SMDropSmaReq;
4455

4456
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4457
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4458

4459
typedef struct {
4460
  char   dbFName[TSDB_DB_FNAME_LEN];
4461
  char   stbName[TSDB_TABLE_NAME_LEN];
4462
  char   colName[TSDB_COL_NAME_LEN];
4463
  char   idxName[TSDB_INDEX_FNAME_LEN];
4464
  int8_t idxType;
4465
} SCreateTagIndexReq;
4466

4467
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4468
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4469

4470
typedef SMDropSmaReq SDropTagIndexReq;
4471

4472
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4473
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4474

4475
typedef struct {
4476
  int8_t         version;       // for compatibility(default 0)
4477
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4478
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4479
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4480
  int32_t        dstVgId;
4481
  char           indexName[TSDB_INDEX_NAME_LEN];
4482
  int32_t        exprLen;
4483
  int32_t        tagsFilterLen;
4484
  int64_t        indexUid;
4485
  tb_uid_t       tableUid;  // super/child/common table uid
4486
  tb_uid_t       dstTbUid;  // for dstVgroup
4487
  int64_t        interval;
4488
  int64_t        offset;  // use unit by precision of DB
4489
  int64_t        sliding;
4490
  char*          dstTbName;  // for dstVgroup
4491
  char*          expr;       // sma expression
4492
  char*          tagsFilter;
4493
  SSchemaWrapper schemaRow;  // for dstVgroup
4494
  SSchemaWrapper schemaTag;  // for dstVgroup
4495
} STSma;                     // Time-range-wise SMA
4496

4497
typedef STSma SVCreateTSmaReq;
4498

4499
typedef struct {
4500
  int8_t  type;  // 0 status report, 1 update data
4501
  int64_t indexUid;
4502
  int64_t skey;  // start TS key of interval/sliding window
4503
} STSmaMsg;
4504

4505
typedef struct {
4506
  int64_t indexUid;
4507
  char    indexName[TSDB_INDEX_NAME_LEN];
4508
} SVDropTSmaReq;
4509

4510
typedef struct {
4511
  int tmp;  // TODO: to avoid compile error
4512
} SVCreateTSmaRsp, SVDropTSmaRsp;
4513

4514
#if 0
4515
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4516
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4517
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4518
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4519
#endif
4520

4521
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4522
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4523
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4524
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4525

4526
typedef struct {
4527
  int32_t number;
4528
  STSma*  tSma;
4529
} STSmaWrapper;
4530

4531
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4532
  if (pSma) {
×
4533
    taosMemoryFreeClear(pSma->dstTbName);
×
4534
    taosMemoryFreeClear(pSma->expr);
×
4535
    taosMemoryFreeClear(pSma->tagsFilter);
×
4536
  }
4537
}
×
4538

4539
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4540
  if (pSW) {
×
4541
    if (pSW->tSma) {
×
4542
      if (deepCopy) {
×
4543
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4544
          tDestroyTSma(pSW->tSma + i);
×
4545
        }
4546
      }
4547
      taosMemoryFreeClear(pSW->tSma);
×
4548
    }
4549
  }
4550
}
×
4551

4552
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4553
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4554
  taosMemoryFreeClear(pSW);
×
4555
  return NULL;
×
4556
}
4557

4558
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4559
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4560

4561
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4562
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4563

4564
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4565
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4566
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4567
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4568
  }
4569
  return 0;
×
4570
}
4571

4572
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4573
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4574
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4575
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4576
  }
4577
  return 0;
×
4578
}
4579

4580
typedef struct {
4581
  int idx;
4582
} SMCreateFullTextReq;
4583

4584
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4585
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4586
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4587

4588
typedef struct {
4589
  char   name[TSDB_TABLE_FNAME_LEN];
4590
  int8_t igNotExists;
4591
} SMDropFullTextReq;
4592

4593
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4594
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4595

4596
typedef struct {
4597
  char indexFName[TSDB_INDEX_FNAME_LEN];
4598
} SUserIndexReq;
4599

4600
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4601
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4602

4603
typedef struct {
4604
  char dbFName[TSDB_DB_FNAME_LEN];
4605
  char tblFName[TSDB_TABLE_FNAME_LEN];
4606
  char colName[TSDB_COL_NAME_LEN];
4607
  char indexType[TSDB_INDEX_TYPE_LEN];
4608
  char indexExts[TSDB_INDEX_EXTS_LEN];
4609
} SUserIndexRsp;
4610

4611
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4612
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4613

4614
typedef struct {
4615
  char tbFName[TSDB_TABLE_FNAME_LEN];
4616
} STableIndexReq;
4617

4618
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4619
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4620

4621
typedef struct {
4622
  int8_t  intervalUnit;
4623
  int8_t  slidingUnit;
4624
  int64_t interval;
4625
  int64_t offset;
4626
  int64_t sliding;
4627
  int64_t dstTbUid;
4628
  int32_t dstVgId;
4629
  SEpSet  epSet;
4630
  char*   expr;
4631
} STableIndexInfo;
4632

4633
typedef struct {
4634
  char     tbName[TSDB_TABLE_NAME_LEN];
4635
  char     dbFName[TSDB_DB_FNAME_LEN];
4636
  uint64_t suid;
4637
  int32_t  version;
4638
  int32_t  indexSize;
4639
  SArray*  pIndex;  // STableIndexInfo
4640
} STableIndexRsp;
4641

4642
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4643
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4644
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4645

4646
void tFreeSTableIndexInfo(void* pInfo);
4647

4648
typedef struct {
4649
  int8_t  mqMsgType;
4650
  int32_t code;
4651
  int32_t epoch;
4652
  int64_t consumerId;
4653
  int64_t walsver;
4654
  int64_t walever;
4655
} SMqRspHead;
4656

4657
typedef struct {
4658
  SMsgHead     head;
4659
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4660
  int8_t       withTbName;
4661
  int8_t       useSnapshot;
4662
  int32_t      epoch;
4663
  uint64_t     reqId;
4664
  int64_t      consumerId;
4665
  int64_t      timeout;
4666
  STqOffsetVal reqOffset;
4667
  int8_t       enableReplay;
4668
  int8_t       sourceExcluded;
4669
  int8_t       rawData;
4670
  int32_t      minPollRows;
4671
  int8_t       enableBatchMeta;
4672
  SHashObj*    uidHash;  // to find if uid is duplicated
4673
} SMqPollReq;
4674

4675
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4676
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4677
void    tDestroySMqPollReq(SMqPollReq* pReq);
4678

4679
typedef struct {
4680
  int32_t vgId;
4681
  int64_t offset;
4682
  SEpSet  epSet;
4683
} SMqSubVgEp;
4684

4685
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4686
  int32_t tlen = 0;
6,664✔
4687
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
6,664✔
4688
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
6,664✔
4689
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
6,664✔
4690
  return tlen;
6,664✔
4691
}
4692

4693
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4694
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
186!
4695
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
186!
4696
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
186✔
4697
  return buf;
186✔
4698
}
4699

4700
typedef struct {
4701
  char           topic[TSDB_TOPIC_FNAME_LEN];
4702
  char           db[TSDB_DB_FNAME_LEN];
4703
  SArray*        vgs;  // SArray<SMqSubVgEp>
4704
  SSchemaWrapper schema;
4705
} SMqSubTopicEp;
4706

4707
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4708
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4709
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4710

4711
typedef struct {
4712
  SMqRspHead   head;
4713
  STqOffsetVal rspOffset;
4714
  int16_t      resMsgType;
4715
  int32_t      metaRspLen;
4716
  void*        metaRsp;
4717
} SMqMetaRsp;
4718

4719
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4720
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4721
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4722

4723
#define MQ_DATA_RSP_VERSION 100
4724

4725
typedef struct {
4726
  SMqRspHead   head;
4727
  STqOffsetVal rspOffset;
4728
  STqOffsetVal reqOffset;
4729
  int32_t      blockNum;
4730
  int8_t       withTbName;
4731
  int8_t       withSchema;
4732
  SArray*      blockDataLen;
4733
  SArray*      blockData;
4734
  SArray*      blockTbName;
4735
  SArray*      blockSchema;
4736

4737
  union {
4738
    struct {
4739
      int64_t sleepTime;
4740
    };
4741
    struct {
4742
      int32_t createTableNum;
4743
      SArray* createTableLen;
4744
      SArray* createTableReq;
4745
    };
4746
    struct {
4747
      int32_t len;
4748
      void*   rawData;
4749
    };
4750
  };
4751
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4752
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4753
} SMqDataRsp;
4754

4755
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4756
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4757
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4758
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4759
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4760

4761
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4762
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4763
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4764

4765
typedef struct SMqBatchMetaRsp {
4766
  SMqRspHead   head;  // not serialize
4767
  STqOffsetVal rspOffset;
4768
  SArray*      batchMetaLen;
4769
  SArray*      batchMetaReq;
4770
  void*        pMetaBuff;    // not serialize
4771
  uint32_t     metaBuffLen;  // not serialize
4772
} SMqBatchMetaRsp;
4773

4774
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4775
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4776
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4777
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4778

4779
typedef struct {
4780
  SMqRspHead head;
4781
  char       cgroup[TSDB_CGROUP_LEN];
4782
  SArray*    topics;  // SArray<SMqSubTopicEp>
4783
} SMqAskEpRsp;
4784

4785
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4786
  int32_t tlen = 0;
13,804✔
4787
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4788
  int32_t sz = taosArrayGetSize(pRsp->topics);
13,804!
4789
  tlen += taosEncodeFixedI32(buf, sz);
13,804✔
4790
  for (int32_t i = 0; i < sz; i++) {
19,062✔
4791
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
5,258✔
4792
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
5,258✔
4793
  }
4794
  return tlen;
13,804✔
4795
}
4796

4797
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4798
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4799
  int32_t sz;
4800
  buf = taosDecodeFixedI32(buf, &sz);
275✔
4801
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
275✔
4802
  if (pRsp->topics == NULL) {
275!
4803
    return NULL;
×
4804
  }
4805
  for (int32_t i = 0; i < sz; i++) {
350✔
4806
    SMqSubTopicEp topicEp;
4807
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
75✔
4808
    if (buf == NULL) {
75!
4809
      return NULL;
×
4810
    }
4811
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
150!
4812
      return NULL;
×
4813
    }
4814
  }
4815
  return buf;
275✔
4816
}
4817

4818
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4819
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,270✔
4820
}
9,270✔
4821

4822
typedef struct {
4823
  int32_t      vgId;
4824
  STqOffsetVal offset;
4825
  int64_t      rows;
4826
  int64_t      ever;
4827
} OffsetRows;
4828

4829
typedef struct {
4830
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4831
  SArray* offsetRows;
4832
} TopicOffsetRows;
4833

4834
typedef struct {
4835
  int64_t consumerId;
4836
  int32_t epoch;
4837
  SArray* topics;
4838
  int8_t  pollFlag;
4839
} SMqHbReq;
4840

4841
typedef struct {
4842
  char   topic[TSDB_TOPIC_FNAME_LEN];
4843
  int8_t noPrivilege;
4844
} STopicPrivilege;
4845

4846
typedef struct {
4847
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4848
  int32_t debugFlag;
4849
} SMqHbRsp;
4850

4851
typedef struct {
4852
  SMsgHead head;
4853
  int64_t  consumerId;
4854
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4855
} SMqSeekReq;
4856

4857
#define TD_AUTO_CREATE_TABLE 0x1
4858
typedef struct {
4859
  int64_t       suid;
4860
  int64_t       uid;
4861
  int32_t       sver;
4862
  uint32_t      nData;
4863
  uint8_t*      pData;
4864
  SVCreateTbReq cTbReq;
4865
} SVSubmitBlk;
4866

4867
typedef struct {
4868
  SMsgHead header;
4869
  uint64_t sId;
4870
  uint64_t queryId;
4871
  uint64_t clientId;
4872
  uint64_t taskId;
4873
  uint32_t sqlLen;
4874
  uint32_t phyLen;
4875
  char*    sql;
4876
  char*    msg;
4877
  int8_t   source;
4878
} SVDeleteReq;
4879

4880
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4881
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4882

4883
typedef struct {
4884
  int64_t affectedRows;
4885
} SVDeleteRsp;
4886

4887
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4888
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4889

4890
typedef struct SDeleteRes {
4891
  uint64_t suid;
4892
  SArray*  uidList;
4893
  int64_t  skey;
4894
  int64_t  ekey;
4895
  int64_t  affectedRows;
4896
  char     tableFName[TSDB_TABLE_NAME_LEN];
4897
  char     tsColName[TSDB_COL_NAME_LEN];
4898
  int64_t  ctimeMs;  // fill by vnode
4899
  int8_t   source;
4900
} SDeleteRes;
4901

4902
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4903
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4904

4905
typedef struct {
4906
  // int64_t uid;
4907
  char    tbname[TSDB_TABLE_NAME_LEN];
4908
  int64_t startTs;
4909
  int64_t endTs;
4910
} SSingleDeleteReq;
4911

4912
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4913
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4914

4915
typedef struct {
4916
  int64_t suid;
4917
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4918
  int64_t ctimeMs;     // fill by vnode
4919
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4920
} SBatchDeleteReq;
4921

4922
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4923
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4924
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4925

4926
typedef struct {
4927
  int32_t msgIdx;
4928
  int32_t msgType;
4929
  int32_t msgLen;
4930
  void*   msg;
4931
} SBatchMsg;
4932

4933
typedef struct {
4934
  SMsgHead header;
4935
  SArray*  pMsgs;  // SArray<SBatchMsg>
4936
} SBatchReq;
4937

4938
typedef struct {
4939
  int32_t reqType;
4940
  int32_t msgIdx;
4941
  int32_t msgLen;
4942
  int32_t rspCode;
4943
  void*   msg;
4944
} SBatchRspMsg;
4945

4946
typedef struct {
4947
  SArray* pRsps;  // SArray<SBatchRspMsg>
4948
} SBatchRsp;
4949

4950
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4951
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4952
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
18,661,019✔
4953
  if (NULL == msg) {
18,661,019!
4954
    return;
×
4955
  }
4956
  SBatchMsg* pMsg = (SBatchMsg*)msg;
18,661,019✔
4957
  taosMemoryFree(pMsg->msg);
18,661,019!
4958
}
4959

4960
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4961
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4962

4963
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
4,037,861✔
4964
  if (NULL == p) {
4,037,861!
4965
    return;
×
4966
  }
4967

4968
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
4,037,861✔
4969
  taosMemoryFree(pRsp->msg);
4,037,861!
4970
}
4971

4972
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4973
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4974
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4975
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4976
void    tDestroySMqHbReq(SMqHbReq* pReq);
4977

4978
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4979
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4980
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4981

4982
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4983
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4984

4985
#define TD_REQ_FROM_APP               0x0
4986
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4987
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4988
#define SUBMIT_REQ_FROM_FILE          0x4
4989
#define TD_REQ_FROM_TAOX              0x8
4990
#define TD_REQ_FROM_SML               0x10
4991
#define SUBMIT_REQUEST_VERSION        (1)
4992
#define SUBMIT_REQ_WITH_BLOB          0x10
4993
#define SUBMIT_REQ_SCHEMA_RES         0x20
4994

4995
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4996

4997
typedef struct {
4998
  int32_t        flags;
4999
  SVCreateTbReq* pCreateTbReq;
5000
  int64_t        suid;
5001
  int64_t        uid;
5002
  int32_t        sver;
5003
  union {
5004
    SArray* aRowP;
5005
    SArray* aCol;
5006
  };
5007
  int64_t    ctimeMs;
5008
  SBlobSet*  pBlobSet;
5009
} SSubmitTbData;
5010

5011
typedef struct {
5012
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5013
  SArray* aSubmitBlobData;
5014
  bool    raw;
5015
} SSubmitReq2;
5016

5017
typedef struct {
5018
  SMsgHead header;
5019
  int64_t  version;
5020
  char     data[];  // SSubmitReq2
5021
} SSubmitReq2Msg;
5022

5023
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5024
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5025
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5026
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5027
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5028

5029
typedef struct {
5030
  int32_t affectedRows;
5031
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5032
} SSubmitRsp2;
5033

5034
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5035
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5036
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5037

5038
#define TSDB_MSG_FLG_ENCODE 0x1
5039
#define TSDB_MSG_FLG_DECODE 0x2
5040
#define TSDB_MSG_FLG_CMPT   0x3
5041

5042
typedef struct {
5043
  union {
5044
    struct {
5045
      void*   msgStr;
5046
      int32_t msgLen;
5047
      int64_t ver;
5048
    };
5049
    void* pDataBlock;
5050
  };
5051
} SPackedData;
5052

5053
typedef struct {
5054
  char     fullname[TSDB_VIEW_FNAME_LEN];
5055
  char     name[TSDB_VIEW_NAME_LEN];
5056
  char     dbFName[TSDB_DB_FNAME_LEN];
5057
  char*    querySql;
5058
  char*    sql;
5059
  int8_t   orReplace;
5060
  int8_t   precision;
5061
  int32_t  numOfCols;
5062
  SSchema* pSchema;
5063
} SCMCreateViewReq;
5064

5065
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5066
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5067
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5068

5069
typedef struct {
5070
  char   fullname[TSDB_VIEW_FNAME_LEN];
5071
  char   name[TSDB_VIEW_NAME_LEN];
5072
  char   dbFName[TSDB_DB_FNAME_LEN];
5073
  char*  sql;
5074
  int8_t igNotExists;
5075
} SCMDropViewReq;
5076

5077
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5078
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5079
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5080

5081
typedef struct {
5082
  char fullname[TSDB_VIEW_FNAME_LEN];
5083
} SViewMetaReq;
5084
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5085
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5086

5087
typedef struct {
5088
  char     name[TSDB_VIEW_NAME_LEN];
5089
  char     dbFName[TSDB_DB_FNAME_LEN];
5090
  char*    user;
5091
  uint64_t dbId;
5092
  uint64_t viewId;
5093
  char*    querySql;
5094
  int8_t   precision;
5095
  int8_t   type;
5096
  int32_t  version;
5097
  int32_t  numOfCols;
5098
  SSchema* pSchema;
5099
} SViewMetaRsp;
5100
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5101
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5102
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5103
typedef struct {
5104
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5105
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5106
} STableTSMAInfoReq;
5107

5108
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5109
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5110

5111
typedef struct {
5112
  int32_t  funcId;
5113
  col_id_t colId;
5114
} STableTSMAFuncInfo;
5115

5116
typedef struct {
5117
  char     name[TSDB_TABLE_NAME_LEN];
5118
  uint64_t tsmaId;
5119
  char     targetTb[TSDB_TABLE_NAME_LEN];
5120
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5121
  char     tb[TSDB_TABLE_NAME_LEN];
5122
  char     dbFName[TSDB_DB_FNAME_LEN];
5123
  uint64_t suid;
5124
  uint64_t destTbUid;
5125
  uint64_t dbId;
5126
  int32_t  version;
5127
  int64_t  interval;
5128
  int8_t   unit;
5129
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5130
  SArray*  pTags;      // SArray<SSchema>
5131
  SArray*  pUsedCols;  // SArray<SSchema>
5132
  char*    ast;
5133

5134
  int64_t streamUid;
5135
  int64_t reqTs;
5136
  int64_t rspTs;
5137
  int64_t delayDuration;  // ms
5138
  bool    fillHistoryFinished;
5139

5140
  void*   streamAddr;  // for stream task, the address of the stream task
5141
} STableTSMAInfo;
5142

5143
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5144
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5145
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5146
void    tFreeTableTSMAInfo(void* p);
5147
void    tFreeAndClearTableTSMAInfo(void* p);
5148
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5149

5150
#define STSMAHbRsp            STableTSMAInfoRsp
5151
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5152
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5153
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5154

5155
typedef struct SDropCtbWithTsmaSingleVgReq {
5156
  SVgroupInfo vgInfo;
5157
  SArray*     pTbs;  // SVDropTbReq
5158
} SMDropTbReqsOnSingleVg;
5159

5160
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5161
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5162
void    tFreeSMDropTbReqOnSingleVg(void* p);
5163

5164
typedef struct SDropTbsReq {
5165
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5166
} SMDropTbsReq;
5167

5168
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5169
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5170
void    tFreeSMDropTbsReq(void*);
5171

5172
typedef struct SVFetchTtlExpiredTbsRsp {
5173
  SArray* pExpiredTbs;  // SVDropTbReq
5174
  int32_t vgId;
5175
} SVFetchTtlExpiredTbsRsp;
5176

5177
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5178
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5179

5180
void tFreeFetchTtlExpiredTbsRsp(void* p);
5181

5182
void setDefaultOptionsForField(SFieldWithOptions* field);
5183
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5184

5185
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5186
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5187

5188
#ifdef USE_MOUNT
5189
typedef struct {
5190
  char     mountName[TSDB_MOUNT_NAME_LEN];
5191
  int8_t   ignoreExist;
5192
  int16_t  nMounts;
5193
  int32_t* dnodeIds;
5194
  char**   mountPaths;
5195
  int32_t  sqlLen;
5196
  char*    sql;
5197
} SCreateMountReq;
5198

5199
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5200
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5201
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5202

5203
typedef struct {
5204
  char    mountName[TSDB_MOUNT_NAME_LEN];
5205
  int8_t  ignoreNotExists;
5206
  int32_t sqlLen;
5207
  char*   sql;
5208
} SDropMountReq;
5209

5210
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5211
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5212
void    tFreeSDropMountReq(SDropMountReq* pReq);
5213

5214
typedef struct {
5215
  char     mountName[TSDB_MOUNT_NAME_LEN];
5216
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5217
  int64_t  mountUid;
5218
  int32_t  dnodeId;
5219
  uint32_t valLen;
5220
  int8_t   ignoreExist;
5221
  void*    pVal;
5222
} SRetrieveMountPathReq;
5223

5224
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5225
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5226

5227
typedef struct {
5228
  // path
5229
  int32_t diskPrimary;
5230
  // vgInfo
5231
  int32_t  vgId;
5232
  int32_t  cacheLastSize;
5233
  int32_t  szPage;
5234
  int32_t  szCache;
5235
  uint64_t szBuf;
5236
  int8_t   cacheLast;
5237
  int8_t   standby;
5238
  int8_t   hashMethod;
5239
  uint32_t hashBegin;
5240
  uint32_t hashEnd;
5241
  int16_t  hashPrefix;
5242
  int16_t  hashSuffix;
5243
  int16_t  sttTrigger;
5244
  // syncInfo
5245
  int32_t replications;
5246
  // tsdbInfo
5247
  int8_t  precision;
5248
  int8_t  compression;
5249
  int8_t  slLevel;
5250
  int32_t daysPerFile;
5251
  int32_t keep0;
5252
  int32_t keep1;
5253
  int32_t keep2;
5254
  int32_t keepTimeOffset;
5255
  int32_t minRows;
5256
  int32_t maxRows;
5257
  int32_t tsdbPageSize;
5258
  int32_t ssChunkSize;
5259
  int32_t ssKeepLocal;
5260
  int8_t  ssCompact;
5261
  // walInfo
5262
  int32_t walFsyncPeriod;      // millisecond
5263
  int32_t walRetentionPeriod;  // secs
5264
  int32_t walRollPeriod;       // secs
5265
  int64_t walRetentionSize;
5266
  int64_t walSegSize;
5267
  int32_t walLevel;
5268
  // encryptInfo
5269
  int32_t encryptAlgorithm;
5270
  // SVState
5271
  int64_t committed;
5272
  int64_t commitID;
5273
  int64_t commitTerm;
5274
  // stats
5275
  int64_t numOfSTables;
5276
  int64_t numOfCTables;
5277
  int64_t numOfNTables;
5278
  // dbInfo
5279
  uint64_t dbId;
5280
} SMountVgInfo;
5281

5282
typedef struct {
5283
  SMCreateStbReq req;
5284
  SArray*        pColExts;  // element: column id
5285
  SArray*        pTagExts;  // element: tag id
5286
} SMountStbInfo;
5287

5288
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5289
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5290

5291
typedef struct {
5292
  char     dbName[TSDB_DB_FNAME_LEN];
5293
  uint64_t dbId;
5294
  SArray*  pVgs;      // SMountVgInfo
5295
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5296
} SMountDbInfo;
5297

5298
typedef struct {
5299
  // common fields
5300
  char     mountName[TSDB_MOUNT_NAME_LEN];
5301
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5302
  int8_t   ignoreExist;
5303
  int64_t  mountUid;
5304
  int64_t  clusterId;
5305
  int32_t  dnodeId;
5306
  uint32_t valLen;
5307
  void*    pVal;
5308

5309
  // response fields
5310
  SArray* pDbs;  // SMountDbInfo
5311

5312
  // memory fields, no serialized
5313
  SArray*   pDisks[TFS_MAX_TIERS];
5314
  TdFilePtr pFile;
5315
} SMountInfo;
5316

5317
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5318
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5319
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5320

5321
typedef struct {
5322
  SCreateVnodeReq createReq;
5323
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5324
  char            mountName[TSDB_MOUNT_NAME_LEN];
5325
  int64_t         mountId;
5326
  int32_t         diskPrimary;
5327
  int32_t         mountVgId;
5328
  int64_t         committed;
5329
  int64_t         commitID;
5330
  int64_t         commitTerm;
5331
  int64_t         numOfSTables;
5332
  int64_t         numOfCTables;
5333
  int64_t         numOfNTables;
5334
} SMountVnodeReq;
5335

5336
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5337
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5338
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5339

5340
#endif  // USE_MOUNT
5341

5342
#pragma pack(pop)
5343

5344
#ifdef __cplusplus
5345
}
5346
#endif
5347

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