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

taosdata / TDengine / #4513

17 Jul 2025 02:02AM UTC coverage: 31.359% (-31.1%) from 62.446%
#4513

push

travis-ci

web-flow
Merge pull request #31914 from taosdata/fix/3.0/compare-ans-failed

fix:Convert line endings from LF to CRLF for ans file

68541 of 301034 branches covered (22.77%)

Branch coverage included in aggregate %.

117356 of 291771 relevant lines covered (40.22%)

602262.98 hits per line

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

30.19
/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) {
771,384✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
771,384✔
102
  int    segIdx = TMSG_SEG_CODE(type);
771,384✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
771,384!
104
    return type < tMsgRangeDict[segIdx];
771,449✔
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) {
26,222✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
26,145!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
52,367!
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

499
  // physical plan node
500
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
501
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
502
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
503
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
504
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
505
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
506
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
507
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
508
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
509
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
510
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
511
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
512
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
513
  QUERY_NODE_PHYSICAL_PLAN_SORT,
514
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
515
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
516
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
517
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
518
  QUERY_NODE_PHYSICAL_PLAN_FILL,
519
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
520
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
521
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
522
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
523
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
524
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
525
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
526
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
527
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
528
  QUERY_NODE_PHYSICAL_SUBPLAN,
529
  QUERY_NODE_PHYSICAL_PLAN,
530
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
531
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
532
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
533
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
534
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
535
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
536
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
537
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
538
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
539
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
540
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
541
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
542
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
543
} ENodeType;
544

545
typedef struct {
546
  int32_t     vgId;
547
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
548
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
549
  const char* dbFName;
550
  const char* tbName;
551
} SBuildTableInput;
552

553
typedef struct {
554
  char    db[TSDB_DB_FNAME_LEN];
555
  int64_t dbId;
556
  int32_t vgVersion;
557
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
558
  int64_t stateTs;
559
} SBuildUseDBInput;
560

561
typedef struct SField {
562
  char    name[TSDB_COL_NAME_LEN];
563
  uint8_t type;
564
  int8_t  flags;
565
  int32_t bytes;
566
} SField;
567

568
typedef struct SFieldWithOptions {
569
  char     name[TSDB_COL_NAME_LEN];
570
  uint8_t  type;
571
  int8_t   flags;
572
  int32_t  bytes;
573
  uint32_t compress;
574
  STypeMod typeMod;
575
} SFieldWithOptions;
576

577
typedef struct SRetention {
578
  int64_t freq;
579
  int64_t keep;
580
  int8_t  freqUnit;
581
  int8_t  keepUnit;
582
} SRetention;
583

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

586
#pragma pack(push, 1)
587
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
588
typedef struct SEp {
589
  char     fqdn[TSDB_FQDN_LEN];
590
  uint16_t port;
591
} SEp;
592

593
typedef struct {
594
  int32_t contLen;
595
  int32_t vgId;
596
} SMsgHead;
597

598
// Submit message for one table
599
typedef struct SSubmitBlk {
600
  int64_t uid;        // table unique id
601
  int64_t suid;       // stable id
602
  int32_t sversion;   // data schema version
603
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
604
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
605
  int32_t numOfRows;  // total number of rows in current submit block
606
  char    data[];
607
} SSubmitBlk;
608

609
// Submit message for this TSDB
610
typedef struct {
611
  SMsgHead header;
612
  int64_t  version;
613
  int32_t  length;
614
  int32_t  numOfBlocks;
615
  char     blocks[];
616
} SSubmitReq;
617

618
typedef struct {
619
  int32_t totalLen;
620
  int32_t len;
621
  STSRow* row;
622
} SSubmitBlkIter;
623

624
typedef struct {
625
  int32_t totalLen;
626
  int32_t len;
627
  // head of SSubmitBlk
628
  int64_t uid;        // table unique id
629
  int64_t suid;       // stable id
630
  int32_t sversion;   // data schema version
631
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
632
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
633
  int32_t numOfRows;  // total number of rows in current submit block
634
  // head of SSubmitBlk
635
  int32_t     numOfBlocks;
636
  const void* pMsg;
637
} SSubmitMsgIter;
638

639
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
640
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
641
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
642
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
643
// for debug
644
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
645

646
typedef struct {
647
  bool     hasRef;
648
  col_id_t id;
649
  char     refDbName[TSDB_DB_NAME_LEN];
650
  char     refTableName[TSDB_TABLE_NAME_LEN];
651
  char     refColName[TSDB_COL_NAME_LEN];
652
} SColRef;
653

654
typedef struct {
655
  int32_t  nCols;
656
  int32_t  version;
657
  SColRef* pColRef;
658
} SColRefWrapper;
659

660
int32_t tEncodeSColRefWrapper(SEncoder *pCoder, const SColRefWrapper *pWrapper);
661
int32_t tDecodeSColRefWrapperEx(SDecoder *pDecoder, SColRefWrapper *pWrapper, bool decoderMalloc);
662
typedef struct {
663
  int32_t vgId;
664
  SColRef colRef;
665
} SColRefEx;
666

667
typedef struct {
668
  int16_t colId;
669
  char    refDbName[TSDB_DB_NAME_LEN];
670
  char    refTableName[TSDB_TABLE_NAME_LEN];
671
  char    refColName[TSDB_COL_NAME_LEN];
672
} SRefColInfo;
673

674
typedef struct SVCTableRefCols {
675
  uint64_t     uid;
676
  int32_t      numOfSrcTbls;
677
  int32_t      numOfColRefs;
678
  SRefColInfo* refCols;
679
} SVCTableRefCols;
680

681
typedef struct SVCTableMergeInfo {
682
  uint64_t uid;
683
  int32_t  numOfSrcTbls;
684
} SVCTableMergeInfo;
685

686
typedef struct {
687
  int32_t    nCols;
688
  SColRefEx* pColRefEx;
689
} SColRefExWrapper;
690

691
struct SSchema {
692
  int8_t   type;
693
  int8_t   flags;
694
  col_id_t colId;
695
  int32_t  bytes;
696
  char     name[TSDB_COL_NAME_LEN];
697
};
698
struct SSchemaExt {
699
  col_id_t colId;
700
  uint32_t compress;
701
  STypeMod typeMod;
702
};
703

704
//
705

706
struct SSchema2 {
707
  int8_t   type;
708
  int8_t   flags;
709
  col_id_t colId;
710
  int32_t  bytes;
711
  char     name[TSDB_COL_NAME_LEN];
712
  uint32_t compress;
713
};
714

715
typedef struct {
716
  char        tbName[TSDB_TABLE_NAME_LEN];
717
  char        stbName[TSDB_TABLE_NAME_LEN];
718
  char        dbFName[TSDB_DB_FNAME_LEN];
719
  int64_t     dbId;
720
  int32_t     numOfTags;
721
  int32_t     numOfColumns;
722
  int8_t      precision;
723
  int8_t      tableType;
724
  int32_t     sversion;
725
  int32_t     tversion;
726
  int32_t     rversion;
727
  uint64_t    suid;
728
  uint64_t    tuid;
729
  int32_t     vgId;
730
  int8_t      sysInfo;
731
  SSchema*    pSchemas;
732
  SSchemaExt* pSchemaExt;
733
  int8_t      virtualStb;
734
  int32_t     numOfColRefs;
735
  SColRef*    pColRefs;
736
} STableMetaRsp;
737

738
typedef struct {
739
  int32_t        code;
740
  int64_t        uid;
741
  char*          tblFName;
742
  int32_t        numOfRows;
743
  int32_t        affectedRows;
744
  int64_t        sver;
745
  STableMetaRsp* pMeta;
746
} SSubmitBlkRsp;
747

748
typedef struct {
749
  int32_t numOfRows;
750
  int32_t affectedRows;
751
  int32_t nBlocks;
752
  union {
753
    SArray*        pArray;
754
    SSubmitBlkRsp* pBlocks;
755
  };
756
} SSubmitRsp;
757

758
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
759
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
760
// void    tFreeSSubmitBlkRsp(void* param);
761
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
762

763
#define COL_SMA_ON       ((int8_t)0x1)
764
#define COL_IDX_ON       ((int8_t)0x2)
765
#define COL_IS_KEY       ((int8_t)0x4)
766
#define COL_SET_NULL     ((int8_t)0x10)
767
#define COL_SET_VAL      ((int8_t)0x20)
768
#define COL_IS_SYSINFO   ((int8_t)0x40)
769
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
770
#define COL_REF_BY_STM   ((int8_t)0x08)
771

772
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
773
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
774

775
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
776
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
777
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
778

779
#define SSCHMEA_SET_IDX_ON(s) \
780
  do {                        \
781
    (s)->flags |= COL_IDX_ON; \
782
  } while (0)
783

784
#define SSCHMEA_SET_IDX_OFF(s)   \
785
  do {                           \
786
    (s)->flags &= (~COL_IDX_ON); \
787
  } while (0)
788

789
#define SSCHEMA_SET_TYPE_MOD(s)     \
790
  do {                              \
791
    (s)->flags |= COL_HAS_TYPE_MOD; \
792
  } while (0)
793

794
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
795

796
#define SSCHMEA_TYPE(s)  ((s)->type)
797
#define SSCHMEA_FLAGS(s) ((s)->flags)
798
#define SSCHMEA_COLID(s) ((s)->colId)
799
#define SSCHMEA_BYTES(s) ((s)->bytes)
800
#define SSCHMEA_NAME(s)  ((s)->name)
801

802
typedef struct {
803
  bool    tsEnableMonitor;
804
  int32_t tsMonitorInterval;
805
  int32_t tsSlowLogThreshold;
806
  int32_t tsSlowLogMaxLen;
807
  int32_t tsSlowLogScope;
808
  int32_t tsSlowLogThresholdTest;  // Obsolete
809
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
810
} SMonitorParas;
811

812
typedef struct {
813
  STypeMod typeMod;
814
} SExtSchema;
815

816
bool hasExtSchema(const SExtSchema* pExtSchema);
817

818
typedef struct {
819
  int32_t  nCols;
820
  int32_t  version;
821
  SSchema* pSchema;
822
} SSchemaWrapper;
823

824
typedef struct {
825
  col_id_t id;
826
  uint32_t alg;
827
} SColCmpr;
828

829
typedef struct {
830
  int32_t   nCols;
831
  int32_t   version;
832
  SColCmpr* pColCmpr;
833
} SColCmprWrapper;
834

835
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
836
  if (pRef->pColRef) {
×
837
    return TSDB_CODE_INVALID_PARA;
×
838
  }
839
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
×
840
  if (pRef->pColRef == NULL) {
×
841
    return terrno;
×
842
  }
843
  pRef->nCols = nCols;
×
844
  for (int32_t i = 0; i < nCols; i++) {
×
845
    pRef->pColRef[i].hasRef = false;
×
846
    pRef->pColRef[i].id = (col_id_t)(i + 1);
×
847
  }
848
  return 0;
×
849
}
850

851
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
852
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
853
    terrno = TSDB_CODE_INVALID_PARA;
854
    return NULL;
855
  }
856

857
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
858
  if (pDstWrapper == NULL) {
859
    return NULL;
860
  }
861
  pDstWrapper->nCols = pSrcWrapper->nCols;
862
  pDstWrapper->version = pSrcWrapper->version;
863

864
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
865
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
866
  if (pDstWrapper->pColCmpr == NULL) {
867
    taosMemoryFree(pDstWrapper);
868
    return NULL;
869
  }
870
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
871

872
  return pDstWrapper;
873
}
874

875
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
876
  if (!(!pCmpr->pColCmpr)) {
27!
877
    return TSDB_CODE_INVALID_PARA;
×
878
  }
879
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
27!
880
  if (pCmpr->pColCmpr == NULL) {
27!
881
    return terrno;
×
882
  }
883
  pCmpr->nCols = nCols;
27✔
884
  return 0;
27✔
885
}
886

887
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
888
  pCmpr->nCols = pSchema->nCols;
889
  if (!(!pCmpr->pColCmpr)) {
890
    return TSDB_CODE_INVALID_PARA;
891
  }
892
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
893
  if (pCmpr->pColCmpr == NULL) {
894
    return terrno;
895
  }
896
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
897
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
898
    SSchema*  pColSchema = &pSchema->pSchema[i];
899
    pColCmpr->id = pColSchema->colId;
900
    pColCmpr->alg = 0;
901
  }
902
  return 0;
903
}
904

905
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
906
  if (pWrapper == NULL) return;
907

908
  taosMemoryFreeClear(pWrapper->pColCmpr);
909
  taosMemoryFreeClear(pWrapper);
910
}
911
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
912
  if (pSchemaWrapper->pSchema == NULL) return NULL;
25,294!
913

914
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
25,294!
915
  if (pSW == NULL) {
25,294!
916
    return NULL;
×
917
  }
918
  pSW->nCols = pSchemaWrapper->nCols;
25,294✔
919
  pSW->version = pSchemaWrapper->version;
25,294✔
920
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
25,294!
921
  if (pSW->pSchema == NULL) {
25,292!
922
    taosMemoryFree(pSW);
×
923
    return NULL;
×
924
  }
925

926
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
25,292✔
927
  return pSW;
25,292✔
928
}
929

930
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
360✔
931
  if (pSchemaWrapper) {
65,443!
932
    taosMemoryFree(pSchemaWrapper->pSchema);
30,304!
933
    taosMemoryFree(pSchemaWrapper);
30,305!
934
  }
935
}
65,434✔
936

937
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
×
938
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
×
939
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
×
940
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
×
941
  }
942
}
×
943

944
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
945
  int32_t tlen = 0;
246✔
946
  tlen += taosEncodeFixedI8(buf, pSchema->type);
492✔
947
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
246!
948
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
246!
949
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
246!
950
  tlen += taosEncodeString(buf, pSchema->name);
246✔
951
  return tlen;
246✔
952
}
953

954
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
955
  buf = taosDecodeFixedI8(buf, &pSchema->type);
192✔
956
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
96✔
957
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
96!
958
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
96!
959
  buf = taosDecodeStringTo(buf, pSchema->name);
96✔
960
  return (void*)buf;
96✔
961
}
962

963
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
964
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
3,190!
965
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
5,076!
966
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
5,076!
967
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
5,076!
968
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
5,076!
969
  return 0;
2,538✔
970
}
971

972
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
973
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
79,916!
974
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
159,176!
975
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
159,163!
976
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
159,150!
977
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
79,573!
978
  return 0;
79,569✔
979
}
980

981
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
982
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
736!
983
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
736!
984
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
736!
985
  return 0;
368✔
986
}
987

988
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
989
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
368!
990
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
368!
991
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
368!
992
  return 0;
184✔
993
}
994

995
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
996
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
×
997
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
×
998
  if (pColRef->hasRef) {
×
999
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
×
1000
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
×
1001
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
×
1002
  }
1003
  return 0;
×
1004
}
1005

1006
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1007
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
×
1008
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
×
1009
  if (pColRef->hasRef) {
×
1010
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
×
1011
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
×
1012
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
×
1013
  }
1014

1015
  return 0;
×
1016
}
1017

1018
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1019
  int32_t tlen = 0;
80✔
1020
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
80✔
1021
  tlen += taosEncodeVariantI32(buf, pSW->version);
80✔
1022
  for (int32_t i = 0; i < pSW->nCols; i++) {
326✔
1023
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
492!
1024
  }
1025
  return tlen;
80✔
1026
}
1027

1028
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1029
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
31✔
1030
  buf = taosDecodeVariantI32(buf, &pSW->version);
31✔
1031
  if (pSW->nCols > 0) {
31!
1032
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
31!
1033
    if (pSW->pSchema == NULL) {
31!
1034
      return NULL;
×
1035
    }
1036

1037
    for (int32_t i = 0; i < pSW->nCols; i++) {
127✔
1038
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
192✔
1039
    }
1040
  } else {
1041
    pSW->pSchema = NULL;
×
1042
  }
1043
  return (void*)buf;
31✔
1044
}
1045

1046
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1047
  if (pSW == NULL) {
636!
1048
    return TSDB_CODE_INVALID_PARA;
×
1049
  }
1050
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,272!
1051
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,272!
1052
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,522!
1053
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
3,772!
1054
  }
1055
  return 0;
636✔
1056
}
1057

1058
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1059
  if (pSW == NULL) {
108!
1060
    return TSDB_CODE_INVALID_PARA;
×
1061
  }
1062
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
216!
1063
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
216!
1064

1065
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
108!
1066
  if (pSW->pSchema == NULL) {
108!
1067
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1068
  }
1069
  for (int32_t i = 0; i < pSW->nCols; i++) {
626✔
1070
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,038!
1071
  }
1072

1073
  return 0;
106✔
1074
}
1075

1076
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1077
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
101,022!
1078
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
101,025!
1079

1080
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
50,513!
1081
  if (pSW->pSchema == NULL) {
50,519!
1082
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1083
  }
1084
  for (int32_t i = 0; i < pSW->nCols; i++) {
129,244!
1085
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
157,472!
1086
  }
1087

1088
  return 0;
50,497✔
1089
}
1090

1091
typedef struct {
1092
  char     name[TSDB_TABLE_FNAME_LEN];
1093
  int8_t   igExists;
1094
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1095
  int8_t   reserved[6];
1096
  tb_uid_t suid;
1097
  int64_t  delay1;
1098
  int64_t  delay2;
1099
  int64_t  watermark1;
1100
  int64_t  watermark2;
1101
  int32_t  ttl;
1102
  int32_t  colVer;
1103
  int32_t  tagVer;
1104
  int32_t  numOfColumns;
1105
  int32_t  numOfTags;
1106
  int32_t  numOfFuncs;
1107
  int32_t  commentLen;
1108
  int32_t  ast1Len;
1109
  int32_t  ast2Len;
1110
  SArray*  pColumns;  // array of SFieldWithOptions
1111
  SArray*  pTags;     // array of SField
1112
  SArray*  pFuncs;
1113
  char*    pComment;
1114
  char*    pAst1;
1115
  char*    pAst2;
1116
  int64_t  deleteMark1;
1117
  int64_t  deleteMark2;
1118
  int32_t  sqlLen;
1119
  char*    sql;
1120
  int64_t  keep;
1121
  int8_t   virtualStb;
1122
} SMCreateStbReq;
1123

1124
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1125
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1126
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1127

1128
typedef struct {
1129
  STableMetaRsp* pMeta;
1130
} SMCreateStbRsp;
1131

1132
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1133
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1134
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1135

1136
typedef struct {
1137
  char     name[TSDB_TABLE_FNAME_LEN];
1138
  int8_t   igNotExists;
1139
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1140
  int8_t   reserved[6];
1141
  tb_uid_t suid;
1142
  int32_t  sqlLen;
1143
  char*    sql;
1144
} SMDropStbReq;
1145

1146
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1147
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1148
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1149

1150
typedef struct {
1151
  char    name[TSDB_TABLE_FNAME_LEN];
1152
  int8_t  alterType;
1153
  int32_t numOfFields;
1154
  SArray* pFields;
1155
  int32_t ttl;
1156
  int32_t commentLen;
1157
  char*   comment;
1158
  int32_t sqlLen;
1159
  char*   sql;
1160
  int64_t keep;
1161
  SArray* pTypeMods;
1162
} SMAlterStbReq;
1163

1164
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1165
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1166
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1167

1168
typedef struct SEpSet {
1169
  int8_t inUse;
1170
  int8_t numOfEps;
1171
  SEp    eps[TSDB_MAX_REPLICA];
1172
} SEpSet;
1173

1174
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1175
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1176
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1177
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1178

1179
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1180
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1181

1182
typedef struct {
1183
  int8_t  connType;
1184
  int32_t pid;
1185
  char    app[TSDB_APP_NAME_LEN];
1186
  char    db[TSDB_DB_NAME_LEN];
1187
  char    user[TSDB_USER_LEN];
1188
  char    passwd[TSDB_PASSWORD_LEN];
1189
  int64_t startTime;
1190
  char    sVer[TSDB_VERSION_LEN];
1191
} SConnectReq;
1192

1193
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1194
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1195

1196
typedef struct {
1197
  int32_t       acctId;
1198
  int64_t       clusterId;
1199
  uint32_t      connId;
1200
  int32_t       dnodeNum;
1201
  int8_t        superUser;
1202
  int8_t        sysInfo;
1203
  int8_t        connType;
1204
  SEpSet        epSet;
1205
  int32_t       svrTimestamp;
1206
  int32_t       passVer;
1207
  int32_t       authVer;
1208
  char          sVer[TSDB_VERSION_LEN];
1209
  char          sDetailVer[128];
1210
  int64_t       whiteListVer;
1211
  SMonitorParas monitorParas;
1212
  int8_t        enableAuditDelete;
1213
} SConnectRsp;
1214

1215
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1216
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1217

1218
typedef struct {
1219
  char    user[TSDB_USER_LEN];
1220
  char    pass[TSDB_PASSWORD_LEN];
1221
  int32_t maxUsers;
1222
  int32_t maxDbs;
1223
  int32_t maxTimeSeries;
1224
  int32_t maxStreams;
1225
  int32_t accessState;  // Configured only by command
1226
  int64_t maxStorage;
1227
} SCreateAcctReq, SAlterAcctReq;
1228

1229
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1230
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1231

1232
typedef struct {
1233
  char    user[TSDB_USER_LEN];
1234
  int32_t sqlLen;
1235
  char*   sql;
1236
} SDropUserReq, SDropAcctReq;
1237

1238
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1239
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1240
void    tFreeSDropUserReq(SDropUserReq* pReq);
1241

1242
typedef struct SIpV4Range {
1243
  uint32_t ip;
1244
  uint32_t mask;
1245
} SIpV4Range;
1246

1247
typedef struct SIpv6Range {
1248
  uint64_t addr[2];
1249
  uint32_t mask;
1250
} SIpV6Range;
1251

1252
typedef struct {
1253
  int8_t type;
1254
  union {
1255
    SIpV4Range ipV4;
1256
    SIpV6Range ipV6;
1257
  };
1258
} SIpRange;
1259

1260
typedef struct {
1261
  int32_t    num;
1262
  SIpV4Range pIpRange[];
1263
} SIpWhiteList;
1264

1265
typedef struct {
1266
  int32_t  num;
1267
  SIpRange pIpRanges[];
1268
} SIpWhiteListDual;
1269

1270
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1271
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1272
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1273
int32_t           createDefaultIp6Range(SIpRange* pRange);
1274
int32_t           createDefaultIp4Range(SIpRange* pRange);
1275

1276
typedef struct {
1277
  int8_t  createType;
1278
  int8_t  superUser;  // denote if it is a super user or not
1279
  int8_t  sysInfo;
1280
  int8_t  enable;
1281
  char    user[TSDB_USER_LEN];
1282
  char    pass[TSDB_USET_PASSWORD_LEN];
1283
  int32_t numIpRanges;
1284

1285
  SIpV4Range* pIpRanges;
1286
  int32_t     sqlLen;
1287
  char*       sql;
1288
  int8_t      isImport;
1289
  int8_t      createDb;
1290
  int8_t      passIsMd5;
1291
  SIpRange*   pIpDualRanges;
1292
} SCreateUserReq;
1293

1294
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1295
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1296
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1297

1298
typedef struct {
1299
  int32_t dnodeId;
1300
  int64_t analVer;
1301
} SRetrieveAnalyticsAlgoReq;
1302

1303
typedef struct {
1304
  int64_t   ver;
1305
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1306
} SRetrieveAnalyticAlgoRsp;
1307

1308
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1309
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1310
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1311
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1312
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1313

1314
typedef struct {
1315
  int8_t alterType;
1316
  int8_t superUser;
1317
  int8_t sysInfo;
1318
  int8_t enable;
1319
  int8_t isView;
1320
  union {
1321
    uint8_t flag;
1322
    struct {
1323
      uint8_t createdb : 1;
1324
      uint8_t reserve : 7;
1325
    };
1326
  };
1327
  char        user[TSDB_USER_LEN];
1328
  char        pass[TSDB_USET_PASSWORD_LEN];
1329
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1330
  char        tabName[TSDB_TABLE_NAME_LEN];
1331
  char*       tagCond;
1332
  int32_t     tagCondLen;
1333
  int32_t     numIpRanges;
1334
  SIpV4Range* pIpRanges;
1335
  int64_t     privileges;
1336
  int32_t     sqlLen;
1337
  char*       sql;
1338
  int8_t      passIsMd5;
1339
  SIpRange*   pIpDualRanges;
1340
} SAlterUserReq;
1341

1342
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1343
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1344
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1345

1346
typedef struct {
1347
  char user[TSDB_USER_LEN];
1348
} SGetUserAuthReq;
1349

1350
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1351
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1352

1353
typedef struct {
1354
  char      user[TSDB_USER_LEN];
1355
  int32_t   version;
1356
  int32_t   passVer;
1357
  int8_t    superAuth;
1358
  int8_t    sysInfo;
1359
  int8_t    enable;
1360
  int8_t    dropped;
1361
  SHashObj* createdDbs;
1362
  SHashObj* readDbs;
1363
  SHashObj* writeDbs;
1364
  SHashObj* readTbs;
1365
  SHashObj* writeTbs;
1366
  SHashObj* alterTbs;
1367
  SHashObj* readViews;
1368
  SHashObj* writeViews;
1369
  SHashObj* alterViews;
1370
  SHashObj* useDbs;
1371
  int64_t   whiteListVer;
1372
} SGetUserAuthRsp;
1373

1374
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1375
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1376
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1377

1378
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1379
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1380
typedef struct {
1381
  int64_t ver;
1382
  char    user[TSDB_USER_LEN];
1383
  int32_t numOfRange;
1384
  union {
1385
    SIpV4Range* pIpRanges;
1386
    SIpRange*   pIpDualRanges;
1387
  };
1388
} SUpdateUserIpWhite;
1389

1390
typedef struct {
1391
  int64_t             ver;
1392
  int                 numOfUser;
1393
  SUpdateUserIpWhite* pUserIpWhite;
1394
} SUpdateIpWhite;
1395

1396
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1397
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1398
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1399
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1400

1401
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1402
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1403
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1404

1405
typedef struct {
1406
  int64_t ipWhiteVer;
1407
} SRetrieveIpWhiteReq;
1408

1409
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1410
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1411
typedef struct {
1412
  char user[TSDB_USER_LEN];
1413
} SGetUserWhiteListReq;
1414

1415
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1416
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1417

1418
typedef struct {
1419
  char    user[TSDB_USER_LEN];
1420
  int32_t numWhiteLists;
1421
  union {
1422
    SIpV4Range* pWhiteLists;
1423
    SIpRange*   pWhiteListsDual;
1424
  };
1425
} SGetUserWhiteListRsp;
1426

1427
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1428
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1429
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1430
void    tIpRangeSetDefaultMask(SIpRange* range);
1431

1432
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1433
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1434
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1435

1436
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1437
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1438
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1439

1440
/*
1441
 * for client side struct, only column id, type, bytes are necessary
1442
 * But for data in vnode side, we need all the following information.
1443
 */
1444
typedef struct {
1445
  union {
1446
    col_id_t colId;
1447
    int16_t  slotId;
1448
  };
1449

1450
  uint8_t precision;
1451
  uint8_t scale;
1452
  int32_t bytes;
1453
  int8_t  type;
1454
  uint8_t pk;
1455
  bool    noData;
1456
} SColumnInfo;
1457

1458
typedef struct STimeWindow {
1459
  TSKEY skey;
1460
  TSKEY ekey;
1461
} STimeWindow;
1462

1463
typedef struct SQueryHint {
1464
  bool batchScan;
1465
} SQueryHint;
1466

1467
typedef struct {
1468
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1469
  int32_t tsLen;          // total length of ts comp block
1470
  int32_t tsNumOfBlocks;  // ts comp block numbers
1471
  int32_t tsOrder;        // ts comp block order
1472
} STsBufInfo;
1473

1474
typedef struct {
1475
  void*       timezone;
1476
  char        intervalUnit;
1477
  char        slidingUnit;
1478
  char        offsetUnit;
1479
  int8_t      precision;
1480
  int64_t     interval;
1481
  int64_t     sliding;
1482
  int64_t     offset;
1483
  STimeWindow timeRange;
1484
} SInterval;
1485

1486
typedef struct STbVerInfo {
1487
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1488
  int32_t sversion;
1489
  int32_t tversion;
1490
  int32_t rversion;  // virtual table's column ref's version
1491
} STbVerInfo;
1492

1493
typedef struct {
1494
  int32_t code;
1495
  int64_t affectedRows;
1496
  SArray* tbVerInfo;  // STbVerInfo
1497
} SQueryTableRsp;
1498

1499
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1500

1501
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1502

1503
typedef struct {
1504
  SMsgHead header;
1505
  char     dbFName[TSDB_DB_FNAME_LEN];
1506
  char     tbName[TSDB_TABLE_NAME_LEN];
1507
} STableCfgReq;
1508

1509
typedef struct {
1510
  char        tbName[TSDB_TABLE_NAME_LEN];
1511
  char        stbName[TSDB_TABLE_NAME_LEN];
1512
  char        dbFName[TSDB_DB_FNAME_LEN];
1513
  int32_t     numOfTags;
1514
  int32_t     numOfColumns;
1515
  int8_t      tableType;
1516
  int64_t     delay1;
1517
  int64_t     delay2;
1518
  int64_t     watermark1;
1519
  int64_t     watermark2;
1520
  int32_t     ttl;
1521
  int32_t     keep;
1522
  SArray*     pFuncs;
1523
  int32_t     commentLen;
1524
  char*       pComment;
1525
  SSchema*    pSchemas;
1526
  int32_t     tagsLen;
1527
  char*       pTags;
1528
  SSchemaExt* pSchemaExt;
1529
  int8_t      virtualStb;
1530
  SColRef*    pColRefs;
1531
} STableCfg;
1532

1533
typedef STableCfg STableCfgRsp;
1534

1535
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1536
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1537

1538
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1539
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1540
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1541

1542
typedef struct {
1543
  SMsgHead header;
1544
  tb_uid_t suid;
1545
} SVSubTablesReq;
1546

1547
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1548
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1549

1550
typedef struct {
1551
  int32_t vgId;
1552
  SArray* pTables;  // SArray<SVCTableRefCols*>
1553
} SVSubTablesRsp;
1554

1555
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1556
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1557
void    tDestroySVSubTablesRsp(void* rsp);
1558

1559
typedef struct {
1560
  SMsgHead header;
1561
  tb_uid_t suid;
1562
} SVStbRefDbsReq;
1563

1564
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1565
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1566

1567
typedef struct {
1568
  int32_t vgId;
1569
  SArray* pDbs;  // SArray<char* (db name)>
1570
} SVStbRefDbsRsp;
1571

1572
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1573
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1574
void    tDestroySVStbRefDbsRsp(void* rsp);
1575

1576
typedef struct {
1577
  char    db[TSDB_DB_FNAME_LEN];
1578
  int32_t numOfVgroups;
1579
  int32_t numOfStables;  // single_stable
1580
  int32_t buffer;        // MB
1581
  int32_t pageSize;
1582
  int32_t pages;
1583
  int32_t cacheLastSize;
1584
  int32_t daysPerFile;
1585
  int32_t daysToKeep0;
1586
  int32_t daysToKeep1;
1587
  int32_t daysToKeep2;
1588
  int32_t keepTimeOffset;
1589
  int32_t minRows;
1590
  int32_t maxRows;
1591
  int32_t walFsyncPeriod;
1592
  int8_t  walLevel;
1593
  int8_t  precision;  // time resolution
1594
  int8_t  compression;
1595
  int8_t  replications;
1596
  int8_t  strict;
1597
  int8_t  cacheLast;
1598
  int8_t  schemaless;
1599
  int8_t  ignoreExist;
1600
  int32_t numOfRetensions;
1601
  SArray* pRetensions;  // SRetention
1602
  int32_t walRetentionPeriod;
1603
  int64_t walRetentionSize;
1604
  int32_t walRollPeriod;
1605
  int64_t walSegmentSize;
1606
  int32_t sstTrigger;
1607
  int16_t hashPrefix;
1608
  int16_t hashSuffix;
1609
  int32_t ssChunkSize;
1610
  int32_t ssKeepLocal;
1611
  int8_t  ssCompact;
1612
  int32_t tsdbPageSize;
1613
  int32_t sqlLen;
1614
  char*   sql;
1615
  int8_t  withArbitrator;
1616
  int8_t  encryptAlgorithm;
1617
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1618
  // 1. add auto-compact parameters
1619
  int32_t compactInterval;    // minutes
1620
  int32_t compactStartTime;   // minutes
1621
  int32_t compactEndTime;     // minutes
1622
  int8_t  compactTimeOffset;  // hour
1623
} SCreateDbReq;
1624

1625
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1626
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1627
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1628

1629
typedef struct {
1630
  char    db[TSDB_DB_FNAME_LEN];
1631
  int32_t buffer;
1632
  int32_t pageSize;
1633
  int32_t pages;
1634
  int32_t cacheLastSize;
1635
  int32_t daysPerFile;
1636
  int32_t daysToKeep0;
1637
  int32_t daysToKeep1;
1638
  int32_t daysToKeep2;
1639
  int32_t keepTimeOffset;
1640
  int32_t walFsyncPeriod;
1641
  int8_t  walLevel;
1642
  int8_t  strict;
1643
  int8_t  cacheLast;
1644
  int8_t  replications;
1645
  int32_t sstTrigger;
1646
  int32_t minRows;
1647
  int32_t walRetentionPeriod;
1648
  int32_t walRetentionSize;
1649
  int32_t ssKeepLocal;
1650
  int8_t  ssCompact;
1651
  int32_t sqlLen;
1652
  char*   sql;
1653
  int8_t  withArbitrator;
1654
  // 1. add auto-compact parameters
1655
  int32_t compactInterval;
1656
  int32_t compactStartTime;
1657
  int32_t compactEndTime;
1658
  int8_t  compactTimeOffset;
1659
} SAlterDbReq;
1660

1661
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1662
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1663
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1664

1665
typedef struct {
1666
  char    db[TSDB_DB_FNAME_LEN];
1667
  int8_t  ignoreNotExists;
1668
  int8_t  force;
1669
  int32_t sqlLen;
1670
  char*   sql;
1671
} SDropDbReq;
1672

1673
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1674
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1675
void    tFreeSDropDbReq(SDropDbReq* pReq);
1676

1677
typedef struct {
1678
  char    db[TSDB_DB_FNAME_LEN];
1679
  int64_t uid;
1680
} SDropDbRsp;
1681

1682
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1683
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1684

1685
typedef struct {
1686
  char    name[TSDB_MOUNT_NAME_LEN];
1687
  int64_t uid;
1688
} SDropMountRsp;
1689

1690
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1691
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1692

1693
typedef struct {
1694
  char    db[TSDB_DB_FNAME_LEN];
1695
  int64_t dbId;
1696
  int32_t vgVersion;
1697
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1698
  int64_t stateTs;     // ms
1699
} SUseDbReq;
1700

1701
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1702
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1703

1704
typedef struct {
1705
  char    db[TSDB_DB_FNAME_LEN];
1706
  int64_t uid;
1707
  int32_t vgVersion;
1708
  int32_t vgNum;
1709
  int16_t hashPrefix;
1710
  int16_t hashSuffix;
1711
  int8_t  hashMethod;
1712
  union {
1713
    uint8_t flags;
1714
    struct {
1715
      uint8_t isMount : 1;  // TS-5868
1716
      uint8_t padding : 7;
1717
    };
1718
  };
1719
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1720
  int32_t errCode;
1721
  int64_t stateTs;  // ms
1722
} SUseDbRsp;
1723

1724
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1725
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1726
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1727
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1728
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1729

1730
typedef struct {
1731
  char db[TSDB_DB_FNAME_LEN];
1732
} SDbCfgReq;
1733

1734
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1735
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1736

1737
typedef struct {
1738
  char    db[TSDB_DB_FNAME_LEN];
1739
  int32_t maxSpeed;
1740
} STrimDbReq;
1741

1742
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1743
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1744

1745
typedef struct {
1746
  int32_t timestamp;
1747
} SVTrimDbReq;
1748

1749
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1750
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1751

1752
typedef struct {
1753
  char db[TSDB_DB_FNAME_LEN];
1754
} SSsMigrateDbReq;
1755

1756
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1757
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1758

1759
typedef struct {
1760
  int32_t ssMigrateId;
1761
  bool    bAccepted;
1762
} SSsMigrateDbRsp;
1763

1764
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1765
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1766

1767
typedef struct {
1768
  int32_t ssMigrateId;
1769
  int32_t nodeId; // node id of the leader vnode
1770
  int64_t timestamp;
1771
} SSsMigrateVgroupReq;
1772

1773
int32_t tSerializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1774
int32_t tDeserializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1775

1776
typedef struct {
1777
  int32_t ssMigrateId;
1778
  int32_t vgId;   // vgroup id
1779
  int32_t nodeId; // node id of the leader vnode
1780
} SSsMigrateVgroupRsp;
1781

1782
int32_t tSerializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1783
int32_t tDeserializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1784

1785
typedef struct {
1786
  int32_t ssMigrateId;
1787
  int32_t vgId;
1788
} SQuerySsMigrateProgressReq;
1789

1790
int32_t tSerializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1791
int32_t tDeserializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1792

1793
#define FILE_SET_MIGRATE_STATE_IN_PROGRESS  0
1794
#define FILE_SET_MIGRATE_STATE_SUCCEEDED    1
1795
#define FILE_SET_MIGRATE_STATE_SKIPPED      2
1796
#define FILE_SET_MIGRATE_STATE_FAILED       3
1797

1798
typedef struct {
1799
  int32_t fid;  // file set id
1800
  int32_t state;
1801
} SFileSetSsMigrateState;
1802

1803
typedef struct {
1804
  // if all taosd were restarted during the migration, then vnode migrate id will be 0,
1805
  // that's mnode will repeatedly request the migration progress. to avoid this, we need
1806
  // to save mnode migrate id in the response, so that mnode can drop it.
1807
  int32_t mnodeMigrateId; // migrate id requested by mnode
1808
  int32_t vnodeMigrateId; // migrate id reponsed by vnode
1809
  int32_t dnodeId;
1810
  int32_t vgId;
1811
  int64_t startTimeSec;
1812
  SArray* pFileSetStates;
1813
} SVnodeSsMigrateState;
1814

1815
int32_t tSerializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1816
int32_t tDeserializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1817
void tFreeSVnodeSsMigrateState(SVnodeSsMigrateState* pState);
1818

1819
typedef SVnodeSsMigrateState SQuerySsMigrateProgressRsp;
1820
#define tSerializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1821
  tSerializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1822
#define tDeserializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1823
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1824
#define tFreeSQuerySsMigrateProgressRsp(pRsp) \
1825
  tFreeSVnodeSsMigrateState(pRsp)
1826

1827
typedef SVnodeSsMigrateState SFollowerSsMigrateReq;
1828
#define tSerializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1829
  tSerializeSVnodeSsMigrateState(buf, bufLen, pReq)
1830
#define tDeserializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1831
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pReq)
1832
#define tFreeSFollowerSsMigrateReq(pReq) \
1833
  tFreeSVnodeSsMigrateState(pReq)
1834

1835
typedef struct {
1836
  int32_t timestampSec;
1837
  int32_t ttlDropMaxCount;
1838
  int32_t nUids;
1839
  SArray* pTbUids;
1840
} SVDropTtlTableReq;
1841

1842
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1843
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1844

1845
typedef struct {
1846
  char    db[TSDB_DB_FNAME_LEN];
1847
  int64_t dbId;
1848
  int32_t cfgVersion;
1849
  int32_t numOfVgroups;
1850
  int32_t numOfStables;
1851
  int32_t buffer;
1852
  int32_t cacheSize;
1853
  int32_t pageSize;
1854
  int32_t pages;
1855
  int32_t daysPerFile;
1856
  int32_t daysToKeep0;
1857
  int32_t daysToKeep1;
1858
  int32_t daysToKeep2;
1859
  int32_t keepTimeOffset;
1860
  int32_t minRows;
1861
  int32_t maxRows;
1862
  int32_t walFsyncPeriod;
1863
  int16_t hashPrefix;
1864
  int16_t hashSuffix;
1865
  int8_t  hashMethod;
1866
  int8_t  walLevel;
1867
  int8_t  precision;
1868
  int8_t  compression;
1869
  int8_t  replications;
1870
  int8_t  strict;
1871
  int8_t  cacheLast;
1872
  int8_t  encryptAlgorithm;
1873
  int32_t ssChunkSize;
1874
  int32_t ssKeepLocal;
1875
  int8_t  ssCompact;
1876
  union {
1877
    uint8_t flags;
1878
    struct {
1879
      uint8_t isMount : 1;  // TS-5868
1880
      uint8_t padding : 7;
1881
    };
1882
  };
1883
  int8_t  compactTimeOffset;
1884
  int32_t compactInterval;
1885
  int32_t compactStartTime;
1886
  int32_t compactEndTime;
1887
  int32_t tsdbPageSize;
1888
  int32_t walRetentionPeriod;
1889
  int32_t walRollPeriod;
1890
  int64_t walRetentionSize;
1891
  int64_t walSegmentSize;
1892
  int32_t numOfRetensions;
1893
  SArray* pRetensions;
1894
  int8_t  schemaless;
1895
  int16_t sstTrigger;
1896
  int8_t  withArbitrator;
1897
} SDbCfgRsp;
1898

1899
typedef SDbCfgRsp SDbCfgInfo;
1900

1901
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1902
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1903
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1904
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1905
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1906

1907
typedef struct {
1908
  int32_t rowNum;
1909
} SQnodeListReq;
1910

1911
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1912
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1913

1914
typedef struct {
1915
  int32_t rowNum;
1916
} SDnodeListReq;
1917

1918
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1919

1920
typedef struct {
1921
  int32_t useless;  // useless
1922
} SServerVerReq;
1923

1924
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1925
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1926

1927
typedef struct {
1928
  char ver[TSDB_VERSION_LEN];
1929
} SServerVerRsp;
1930

1931
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1932
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1933

1934
typedef struct SQueryNodeAddr {
1935
  int32_t nodeId;  // vgId or qnodeId
1936
  SEpSet  epSet;
1937
} SQueryNodeAddr;
1938

1939
typedef struct {
1940
  SQueryNodeAddr addr;
1941
  uint64_t       load;
1942
} SQueryNodeLoad;
1943

1944
typedef struct {
1945
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1946
} SQnodeListRsp;
1947

1948
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1949
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1950
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1951

1952
typedef struct SDNodeAddr {
1953
  int32_t nodeId;  // dnodeId
1954
  SEpSet  epSet;
1955
} SDNodeAddr;
1956

1957
typedef struct {
1958
  SArray* dnodeList;  // SArray<SDNodeAddr>
1959
} SDnodeListRsp;
1960

1961
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1962
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1963
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1964

1965
typedef struct {
1966
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1967
} STableTSMAInfoRsp;
1968

1969
typedef struct {
1970
  SUseDbRsp*         useDbRsp;
1971
  SDbCfgRsp*         cfgRsp;
1972
  STableTSMAInfoRsp* pTsmaRsp;
1973
  int32_t            dbTsmaVersion;
1974
  char               db[TSDB_DB_FNAME_LEN];
1975
  int64_t            dbId;
1976
} SDbHbRsp;
1977

1978
typedef struct {
1979
  SArray* pArray;  // Array of SDbHbRsp
1980
} SDbHbBatchRsp;
1981

1982
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1983
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1984
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1985

1986
typedef struct {
1987
  SArray* pArray;  // Array of SGetUserAuthRsp
1988
} SUserAuthBatchRsp;
1989

1990
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1991
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1992
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1993

1994
typedef struct {
1995
  char        db[TSDB_DB_FNAME_LEN];
1996
  STimeWindow timeRange;
1997
  int32_t     sqlLen;
1998
  char*       sql;
1999
  SArray*     vgroupIds;
2000
  int8_t      metaOnly;
2001
} SCompactDbReq;
2002

2003
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2004
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2005
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2006

2007
typedef struct {
2008
  int32_t compactId;
2009
  int8_t  bAccepted;
2010
} SCompactDbRsp;
2011

2012
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2013
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2014

2015
typedef struct {
2016
  int32_t compactId;
2017
  int32_t sqlLen;
2018
  char*   sql;
2019
} SKillCompactReq;
2020

2021
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2022
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2023
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2024

2025
typedef struct {
2026
  char    name[TSDB_FUNC_NAME_LEN];
2027
  int8_t  igExists;
2028
  int8_t  funcType;
2029
  int8_t  scriptType;
2030
  int8_t  outputType;
2031
  int32_t outputLen;
2032
  int32_t bufSize;
2033
  int32_t codeLen;
2034
  int64_t signature;
2035
  char*   pComment;
2036
  char*   pCode;
2037
  int8_t  orReplace;
2038
} SCreateFuncReq;
2039

2040
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2041
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2042
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2043

2044
typedef struct {
2045
  char   name[TSDB_FUNC_NAME_LEN];
2046
  int8_t igNotExists;
2047
} SDropFuncReq;
2048

2049
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2050
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2051

2052
typedef struct {
2053
  int32_t numOfFuncs;
2054
  bool    ignoreCodeComment;
2055
  SArray* pFuncNames;
2056
} SRetrieveFuncReq;
2057

2058
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2059
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2060
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2061

2062
typedef struct {
2063
  char    name[TSDB_FUNC_NAME_LEN];
2064
  int8_t  funcType;
2065
  int8_t  scriptType;
2066
  int8_t  outputType;
2067
  int32_t outputLen;
2068
  int32_t bufSize;
2069
  int64_t signature;
2070
  int32_t commentSize;
2071
  int32_t codeSize;
2072
  char*   pComment;
2073
  char*   pCode;
2074
} SFuncInfo;
2075

2076
typedef struct {
2077
  int32_t funcVersion;
2078
  int64_t funcCreatedTime;
2079
} SFuncExtraInfo;
2080

2081
typedef struct {
2082
  int32_t numOfFuncs;
2083
  SArray* pFuncInfos;
2084
  SArray* pFuncExtraInfos;
2085
} SRetrieveFuncRsp;
2086

2087
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2088
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2089
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2090
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2091

2092
typedef struct {
2093
  int32_t       statusInterval;
2094
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2095
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2096
  char          locale[TD_LOCALE_LEN];      // tsLocale
2097
  char          charset[TD_LOCALE_LEN];     // tsCharset
2098
  int8_t        ttlChangeOnWrite;
2099
  int8_t        enableWhiteList;
2100
  int8_t        encryptionKeyStat;
2101
  uint32_t      encryptionKeyChksum;
2102
  SMonitorParas monitorParas;
2103
} SClusterCfg;
2104

2105
typedef struct {
2106
  int32_t openVnodes;
2107
  int32_t dropVnodes;
2108
  int32_t totalVnodes;
2109
  int32_t masterNum;
2110
  int64_t numOfSelectReqs;
2111
  int64_t numOfInsertReqs;
2112
  int64_t numOfInsertSuccessReqs;
2113
  int64_t numOfBatchInsertReqs;
2114
  int64_t numOfBatchInsertSuccessReqs;
2115
  int64_t errors;
2116
} SVnodesStat;
2117

2118
typedef struct {
2119
  int32_t vgId;
2120
  int8_t  syncState;
2121
  int8_t  syncRestore;
2122
  int64_t syncTerm;
2123
  int64_t roleTimeMs;
2124
  int64_t startTimeMs;
2125
  int8_t  syncCanRead;
2126
  int64_t cacheUsage;
2127
  int64_t numOfTables;
2128
  int64_t numOfTimeSeries;
2129
  int64_t totalStorage;
2130
  int64_t compStorage;
2131
  int64_t pointsWritten;
2132
  int64_t numOfSelectReqs;
2133
  int64_t numOfInsertReqs;
2134
  int64_t numOfInsertSuccessReqs;
2135
  int64_t numOfBatchInsertReqs;
2136
  int64_t numOfBatchInsertSuccessReqs;
2137
  int32_t numOfCachedTables;
2138
  int32_t learnerProgress;  // use one reservered
2139
  int64_t syncAppliedIndex;
2140
  int64_t syncCommitIndex;
2141
  int64_t bufferSegmentUsed;
2142
  int64_t bufferSegmentSize;
2143
} SVnodeLoad;
2144

2145
typedef struct {
2146
  int64_t total_requests;
2147
  int64_t total_rows;
2148
  int64_t total_bytes;
2149
  double  write_size;
2150
  double  cache_hit_ratio;
2151
  int64_t rpc_queue_wait;
2152
  int64_t preprocess_time;
2153

2154
  int64_t memory_table_size;
2155
  int64_t commit_count;
2156
  int64_t merge_count;
2157
  double  commit_time;
2158
  double  merge_time;
2159
  int64_t block_commit_time;
2160
  int64_t memtable_wait_time;
2161
} SVnodeMetrics;
2162

2163
typedef struct {
2164
  int32_t     vgId;
2165
  int64_t     numOfTables;
2166
  int64_t     memSize;
2167
  int64_t     l1Size;
2168
  int64_t     l2Size;
2169
  int64_t     l3Size;
2170
  int64_t     cacheSize;
2171
  int64_t     walSize;
2172
  int64_t     metaSize;
2173
  int64_t     rawDataSize;
2174
  int64_t     ssSize;
2175
  const char* dbname;
2176
} SDbSizeStatisInfo;
2177

2178
typedef struct {
2179
  int32_t vgId;
2180
  int64_t nTimeSeries;
2181
} SVnodeLoadLite;
2182

2183
typedef struct {
2184
  int8_t  syncState;
2185
  int64_t syncTerm;
2186
  int8_t  syncRestore;
2187
  int64_t roleTimeMs;
2188
} SMnodeLoad;
2189

2190
typedef struct {
2191
  int32_t dnodeId;
2192
  int64_t numOfProcessedQuery;
2193
  int64_t numOfProcessedCQuery;
2194
  int64_t numOfProcessedFetch;
2195
  int64_t numOfProcessedDrop;
2196
  int64_t numOfProcessedNotify;
2197
  int64_t numOfProcessedHb;
2198
  int64_t numOfProcessedDelete;
2199
  int64_t cacheDataSize;
2200
  int64_t numOfQueryInQueue;
2201
  int64_t numOfFetchInQueue;
2202
  int64_t timeInQueryQueue;
2203
  int64_t timeInFetchQueue;
2204
} SQnodeLoad;
2205

2206
typedef struct {
2207
  int32_t     sver;      // software version
2208
  int64_t     dnodeVer;  // dnode table version in sdb
2209
  int32_t     dnodeId;
2210
  int64_t     clusterId;
2211
  int64_t     rebootTime;
2212
  int64_t     updateTime;
2213
  float       numOfCores;
2214
  int32_t     numOfSupportVnodes;
2215
  int32_t     numOfDiskCfg;
2216
  int64_t     memTotal;
2217
  int64_t     memAvail;
2218
  char        dnodeEp[TSDB_EP_LEN];
2219
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2220
  SMnodeLoad  mload;
2221
  SQnodeLoad  qload;
2222
  SClusterCfg clusterCfg;
2223
  SArray*     pVloads;  // array of SVnodeLoad
2224
  int32_t     statusSeq;
2225
  int64_t     ipWhiteVer;
2226
  int64_t     analVer;
2227
  int64_t     timestamp;
2228
} SStatusReq;
2229

2230
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2231
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2232
void    tFreeSStatusReq(SStatusReq* pReq);
2233

2234
typedef struct {
2235
  int32_t forceReadConfig;
2236
  int32_t cver;
2237
  SArray* array;
2238
} SConfigReq;
2239

2240
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2241
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2242
void    tFreeSConfigReq(SConfigReq* pReq);
2243

2244
typedef struct {
2245
  int32_t dnodeId;
2246
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2247
} SDnodeInfoReq;
2248

2249
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2250
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2251

2252
typedef enum {
2253
  MONITOR_TYPE_COUNTER = 0,
2254
  MONITOR_TYPE_SLOW_LOG = 1,
2255
} MONITOR_TYPE;
2256

2257
typedef struct {
2258
  int32_t      contLen;
2259
  char*        pCont;
2260
  MONITOR_TYPE type;
2261
} SStatisReq;
2262

2263
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2264
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2265
void    tFreeSStatisReq(SStatisReq* pReq);
2266

2267
typedef struct {
2268
  char    db[TSDB_DB_FNAME_LEN];
2269
  char    table[TSDB_TABLE_NAME_LEN];
2270
  char    operation[AUDIT_OPERATION_LEN];
2271
  int32_t sqlLen;
2272
  char*   pSql;
2273
} SAuditReq;
2274
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2275
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2276
void    tFreeSAuditReq(SAuditReq* pReq);
2277

2278
typedef struct {
2279
  int32_t dnodeId;
2280
  int64_t clusterId;
2281
  SArray* pVloads;
2282
} SNotifyReq;
2283

2284
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2285
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2286
void    tFreeSNotifyReq(SNotifyReq* pReq);
2287

2288
typedef struct {
2289
  int32_t dnodeId;
2290
  int64_t clusterId;
2291
} SDnodeCfg;
2292

2293
typedef struct {
2294
  int32_t id;
2295
  int8_t  isMnode;
2296
  SEp     ep;
2297
} SDnodeEp;
2298

2299
typedef struct {
2300
  int32_t id;
2301
  int8_t  isMnode;
2302
  int8_t  offlineReason;
2303
  SEp     ep;
2304
  char    active[TSDB_ACTIVE_KEY_LEN];
2305
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2306
} SDnodeInfo;
2307

2308
typedef struct {
2309
  int64_t   dnodeVer;
2310
  SDnodeCfg dnodeCfg;
2311
  SArray*   pDnodeEps;  // Array of SDnodeEp
2312
  int32_t   statusSeq;
2313
  int64_t   ipWhiteVer;
2314
  int64_t   analVer;
2315
} SStatusRsp;
2316

2317
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2318
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2319
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2320

2321
typedef struct {
2322
  int32_t forceReadConfig;
2323
  int32_t isConifgVerified;
2324
  int32_t isVersionVerified;
2325
  int32_t cver;
2326
  SArray* array;
2327
} SConfigRsp;
2328

2329
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2330
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2331
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2332

2333
typedef struct {
2334
  int32_t reserved;
2335
} SMTimerReq;
2336

2337
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2338
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2339

2340
typedef struct SOrphanTask {
2341
  int64_t streamId;
2342
  int32_t taskId;
2343
  int32_t nodeId;
2344
} SOrphanTask;
2345

2346
typedef struct SMStreamDropOrphanMsg {
2347
  SArray* pList;  // SArray<SOrphanTask>
2348
} SMStreamDropOrphanMsg;
2349

2350
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2351
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2352
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2353

2354
typedef struct {
2355
  int32_t  id;
2356
  uint16_t port;                 // node sync Port
2357
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2358
} SReplica;
2359

2360
typedef struct {
2361
  int32_t  vgId;
2362
  char     db[TSDB_DB_FNAME_LEN];
2363
  int64_t  dbUid;
2364
  int32_t  vgVersion;
2365
  int32_t  numOfStables;
2366
  int32_t  buffer;
2367
  int32_t  pageSize;
2368
  int32_t  pages;
2369
  int32_t  cacheLastSize;
2370
  int32_t  daysPerFile;
2371
  int32_t  daysToKeep0;
2372
  int32_t  daysToKeep1;
2373
  int32_t  daysToKeep2;
2374
  int32_t  keepTimeOffset;
2375
  int32_t  minRows;
2376
  int32_t  maxRows;
2377
  int32_t  walFsyncPeriod;
2378
  uint32_t hashBegin;
2379
  uint32_t hashEnd;
2380
  int8_t   hashMethod;
2381
  int8_t   walLevel;
2382
  int8_t   precision;
2383
  int8_t   compression;
2384
  int8_t   strict;
2385
  int8_t   cacheLast;
2386
  int8_t   isTsma;
2387
  int8_t   replica;
2388
  int8_t   selfIndex;
2389
  SReplica replicas[TSDB_MAX_REPLICA];
2390
  int32_t  numOfRetensions;
2391
  SArray*  pRetensions;  // SRetention
2392
  void*    pTsma;
2393
  int32_t  walRetentionPeriod;
2394
  int64_t  walRetentionSize;
2395
  int32_t  walRollPeriod;
2396
  int64_t  walSegmentSize;
2397
  int16_t  sstTrigger;
2398
  int16_t  hashPrefix;
2399
  int16_t  hashSuffix;
2400
  int32_t  tsdbPageSize;
2401
  int32_t  ssChunkSize;
2402
  int32_t  ssKeepLocal;
2403
  int8_t   ssCompact;
2404
  int64_t  reserved[6];
2405
  int8_t   learnerReplica;
2406
  int8_t   learnerSelfIndex;
2407
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2408
  int32_t  changeVersion;
2409
  int8_t   encryptAlgorithm;
2410
} SCreateVnodeReq;
2411

2412
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2413
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2414
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2415

2416
typedef struct {
2417
  int32_t compactId;
2418
  int32_t vgId;
2419
  int32_t dnodeId;
2420
} SQueryCompactProgressReq;
2421

2422
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2423
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2424

2425
typedef struct {
2426
  int32_t compactId;
2427
  int32_t vgId;
2428
  int32_t dnodeId;
2429
  int32_t numberFileset;
2430
  int32_t finished;
2431
  int32_t progress;
2432
  int64_t remainingTime;
2433
} SQueryCompactProgressRsp;
2434

2435
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2436
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2437

2438
typedef struct {
2439
  int32_t vgId;
2440
  int32_t dnodeId;
2441
  int64_t dbUid;
2442
  char    db[TSDB_DB_FNAME_LEN];
2443
  int64_t reserved[8];
2444
} SDropVnodeReq;
2445

2446
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2447
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2448

2449
typedef struct {
2450
  char    colName[TSDB_COL_NAME_LEN];
2451
  char    stb[TSDB_TABLE_FNAME_LEN];
2452
  int64_t stbUid;
2453
  int64_t dbUid;
2454
  int64_t reserved[8];
2455
} SDropIndexReq;
2456

2457
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2458
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2459

2460
typedef struct {
2461
  int64_t     dbUid;
2462
  char        db[TSDB_DB_FNAME_LEN];
2463
  int64_t     compactStartTime;
2464
  STimeWindow tw;
2465
  int32_t     compactId;
2466
  int8_t      metaOnly;
2467
} SCompactVnodeReq;
2468

2469
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2470
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2471

2472
typedef struct {
2473
  int32_t compactId;
2474
  int32_t vgId;
2475
  int32_t dnodeId;
2476
} SVKillCompactReq;
2477

2478
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2479
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2480

2481
typedef struct {
2482
  int32_t vgVersion;
2483
  int32_t buffer;
2484
  int32_t pageSize;
2485
  int32_t pages;
2486
  int32_t cacheLastSize;
2487
  int32_t daysPerFile;
2488
  int32_t daysToKeep0;
2489
  int32_t daysToKeep1;
2490
  int32_t daysToKeep2;
2491
  int32_t keepTimeOffset;
2492
  int32_t walFsyncPeriod;
2493
  int8_t  walLevel;
2494
  int8_t  strict;
2495
  int8_t  cacheLast;
2496
  int64_t reserved[7];
2497
  // 1st modification
2498
  int16_t sttTrigger;
2499
  int32_t minRows;
2500
  // 2nd modification
2501
  int32_t walRetentionPeriod;
2502
  int32_t walRetentionSize;
2503
  int32_t ssKeepLocal;
2504
  int8_t  ssCompact;
2505
} SAlterVnodeConfigReq;
2506

2507
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2508
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2509

2510
typedef struct {
2511
  int32_t  vgId;
2512
  int8_t   strict;
2513
  int8_t   selfIndex;
2514
  int8_t   replica;
2515
  SReplica replicas[TSDB_MAX_REPLICA];
2516
  int64_t  reserved[8];
2517
  int8_t   learnerSelfIndex;
2518
  int8_t   learnerReplica;
2519
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2520
  int32_t  changeVersion;
2521
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2522

2523
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2524
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2525

2526
typedef struct {
2527
  int32_t vgId;
2528
  int8_t  disable;
2529
} SDisableVnodeWriteReq;
2530

2531
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2532
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2533

2534
typedef struct {
2535
  int32_t  srcVgId;
2536
  int32_t  dstVgId;
2537
  uint32_t hashBegin;
2538
  uint32_t hashEnd;
2539
  int32_t  changeVersion;
2540
  int32_t  reserved;
2541
} SAlterVnodeHashRangeReq;
2542

2543
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2544
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2545

2546
#define REQ_OPT_TBNAME 0x0
2547
#define REQ_OPT_TBUID  0x01
2548
typedef struct {
2549
  SMsgHead header;
2550
  char     dbFName[TSDB_DB_FNAME_LEN];
2551
  char     tbName[TSDB_TABLE_NAME_LEN];
2552
  uint8_t  option;
2553
  uint8_t  autoCreateCtb;
2554
} STableInfoReq;
2555

2556
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2557
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2558

2559
typedef struct {
2560
  int8_t  metaClone;  // create local clone of the cached table meta
2561
  int32_t numOfVgroups;
2562
  int32_t numOfTables;
2563
  int32_t numOfUdfs;
2564
  char    tableNames[];
2565
} SMultiTableInfoReq;
2566

2567
// todo refactor
2568
typedef struct SVgroupInfo {
2569
  int32_t  vgId;
2570
  uint32_t hashBegin;
2571
  uint32_t hashEnd;
2572
  SEpSet   epSet;
2573
  union {
2574
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2575
    int32_t taskId;      // used in stream
2576
  };
2577
} SVgroupInfo;
2578

2579
typedef struct {
2580
  int32_t     numOfVgroups;
2581
  SVgroupInfo vgroups[];
2582
} SVgroupsInfo;
2583

2584
typedef struct {
2585
  STableMetaRsp* pMeta;
2586
} SMAlterStbRsp;
2587

2588
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2589
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2590
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2591

2592
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2593
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2594
void    tFreeSTableMetaRsp(void* pRsp);
2595
void    tFreeSTableIndexRsp(void* info);
2596

2597
typedef struct {
2598
  SArray* pMetaRsp;   // Array of STableMetaRsp
2599
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2600
} SSTbHbRsp;
2601

2602
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2603
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2604
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2605

2606
typedef struct {
2607
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2608
} SViewHbRsp;
2609

2610
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2611
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2612
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2613

2614
typedef struct {
2615
  int32_t numOfTables;
2616
  int32_t numOfVgroup;
2617
  int32_t numOfUdf;
2618
  int32_t contLen;
2619
  int8_t  compressed;  // denote if compressed or not
2620
  int32_t rawLen;      // size before compress
2621
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2622
  char    meta[];
2623
} SMultiTableMeta;
2624

2625
typedef struct {
2626
  int32_t dataLen;
2627
  char    name[TSDB_TABLE_FNAME_LEN];
2628
  char*   data;
2629
} STagData;
2630

2631
typedef struct {
2632
  int32_t  opType;
2633
  uint32_t valLen;
2634
  char*    val;
2635
} SShowVariablesReq;
2636

2637
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2638
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2639
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2640

2641
typedef struct {
2642
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2643
  char value[TSDB_CONFIG_PATH_LEN + 1];
2644
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2645
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2646
  char info[TSDB_CONFIG_INFO_LEN + 1];
2647
} SVariablesInfo;
2648

2649
typedef struct {
2650
  SArray* variables;  // SArray<SVariablesInfo>
2651
} SShowVariablesRsp;
2652

2653
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2654
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2655

2656
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2657

2658
/*
2659
 * sql: show tables like '%a_%'
2660
 * payload is the query condition, e.g., '%a_%'
2661
 * payloadLen is the length of payload
2662
 */
2663
typedef struct {
2664
  int32_t type;
2665
  char    db[TSDB_DB_FNAME_LEN];
2666
  int32_t payloadLen;
2667
  char*   payload;
2668
} SShowReq;
2669

2670
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2671
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2672
void tFreeSShowReq(SShowReq* pReq);
2673

2674
typedef struct {
2675
  int64_t       showId;
2676
  STableMetaRsp tableMeta;
2677
} SShowRsp, SVShowTablesRsp;
2678

2679
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2680
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2681
// void    tFreeSShowRsp(SShowRsp* pRsp);
2682

2683
typedef struct {
2684
  char    db[TSDB_DB_FNAME_LEN];
2685
  char    tb[TSDB_TABLE_NAME_LEN];
2686
  char    user[TSDB_USER_LEN];
2687
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2688
  int64_t showId;
2689
  int64_t compactId;  // for compact
2690
  bool    withFull;   // for show users full
2691
} SRetrieveTableReq;
2692

2693
typedef struct SSysTableSchema {
2694
  int8_t   type;
2695
  col_id_t colId;
2696
  int32_t  bytes;
2697
} SSysTableSchema;
2698

2699
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2700
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2701

2702
#define RETRIEVE_TABLE_RSP_VERSION         0
2703
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2704
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2705

2706
typedef struct {
2707
  int64_t useconds;
2708
  int8_t  completed;  // all results are returned to client
2709
  int8_t  precision;
2710
  int8_t  compressed;
2711
  int8_t  streamBlockType;
2712
  int32_t payloadLen;
2713
  int32_t compLen;
2714
  int32_t numOfBlocks;
2715
  int64_t numOfRows;  // from int32_t change to int64_t
2716
  int64_t numOfCols;
2717
  int64_t skey;
2718
  int64_t ekey;
2719
  int64_t version;                         // for stream
2720
  TSKEY   watermark;                       // for stream
2721
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2722
  char    data[];
2723
} SRetrieveTableRsp;
2724

2725
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2726

2727
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2728
  do {                                          \
2729
    ((int32_t*)(_p))[0] = (_compLen);           \
2730
    ((int32_t*)(_p))[1] = (_fullLen);           \
2731
  } while (0);
2732

2733
typedef struct {
2734
  int64_t version;
2735
  int64_t numOfRows;
2736
  int8_t  compressed;
2737
  int8_t  precision;
2738
  char    data[];
2739
} SRetrieveTableRspForTmq;
2740

2741
typedef struct {
2742
  int64_t handle;
2743
  int64_t useconds;
2744
  int8_t  completed;  // all results are returned to client
2745
  int8_t  precision;
2746
  int8_t  compressed;
2747
  int32_t compLen;
2748
  int32_t numOfRows;
2749
  int32_t fullLen;
2750
  char    data[];
2751
} SRetrieveMetaTableRsp;
2752

2753
typedef struct SExplainExecInfo {
2754
  double   startupCost;
2755
  double   totalCost;
2756
  uint64_t numOfRows;
2757
  uint32_t verboseLen;
2758
  void*    verboseInfo;
2759
} SExplainExecInfo;
2760

2761
typedef struct {
2762
  int32_t           numOfPlans;
2763
  SExplainExecInfo* subplanInfo;
2764
} SExplainRsp;
2765

2766
typedef struct {
2767
  SExplainRsp rsp;
2768
  uint64_t    qId;
2769
  uint64_t    cId;
2770
  uint64_t    tId;
2771
  int64_t     rId;
2772
  int32_t     eId;
2773
} SExplainLocalRsp;
2774

2775
typedef struct STableScanAnalyzeInfo {
2776
  uint64_t totalRows;
2777
  uint64_t totalCheckedRows;
2778
  uint32_t totalBlocks;
2779
  uint32_t loadBlocks;
2780
  uint32_t loadBlockStatis;
2781
  uint32_t skipBlocks;
2782
  uint32_t filterOutBlocks;
2783
  double   elapsedTime;
2784
  double   filterTime;
2785
} STableScanAnalyzeInfo;
2786

2787
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2788
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2789
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2790

2791
typedef struct {
2792
  char    config[TSDB_DNODE_CONFIG_LEN];
2793
  char    value[TSDB_CLUSTER_VALUE_LEN];
2794
  int32_t sqlLen;
2795
  char*   sql;
2796
} SMCfgClusterReq;
2797

2798
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2799
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2800
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2801

2802
typedef struct {
2803
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2804
  int32_t port;
2805
  int32_t sqlLen;
2806
  char*   sql;
2807
} SCreateDnodeReq;
2808

2809
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2810
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2811
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2812

2813
typedef struct {
2814
  int32_t dnodeId;
2815
  char    fqdn[TSDB_FQDN_LEN];
2816
  int32_t port;
2817
  int8_t  force;
2818
  int8_t  unsafe;
2819
  int32_t sqlLen;
2820
  char*   sql;
2821
} SDropDnodeReq;
2822

2823
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2824
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2825
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2826

2827
enum {
2828
  RESTORE_TYPE__ALL = 1,
2829
  RESTORE_TYPE__MNODE,
2830
  RESTORE_TYPE__VNODE,
2831
  RESTORE_TYPE__QNODE,
2832
};
2833

2834
typedef struct {
2835
  int32_t dnodeId;
2836
  int8_t  restoreType;
2837
  int32_t sqlLen;
2838
  char*   sql;
2839
} SRestoreDnodeReq;
2840

2841
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2842
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2843
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2844

2845
typedef struct {
2846
  int32_t dnodeId;
2847
  char    config[TSDB_DNODE_CONFIG_LEN];
2848
  char    value[TSDB_DNODE_VALUE_LEN];
2849
  int32_t sqlLen;
2850
  char*   sql;
2851
} SMCfgDnodeReq;
2852

2853
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2854
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2855
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2856

2857
typedef struct {
2858
  char    config[TSDB_DNODE_CONFIG_LEN];
2859
  char    value[TSDB_DNODE_VALUE_LEN];
2860
  int32_t version;
2861
} SDCfgDnodeReq;
2862

2863
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2864
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2865

2866
typedef struct {
2867
  int32_t dnodeId;
2868
  int32_t sqlLen;
2869
  char*   sql;
2870
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2871
    SMCreateSnodeReq, SMDropSnodeReq,     SDDropSnodeReq;
2872

2873

2874
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2875
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2876

2877

2878
typedef struct {
2879
  int32_t nodeId;
2880
  SEpSet  epSet;
2881
} SNodeEpSet;
2882

2883

2884
typedef struct {
2885
  int32_t    snodeId;
2886
  SNodeEpSet leaders[2];
2887
  SNodeEpSet replica;
2888
  int32_t    sqlLen;
2889
  char*      sql;
2890
} SDCreateSnodeReq;
2891

2892
int32_t tSerializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
2893
int32_t tDeserializeSDCreateSNodeReq(void *buf, int32_t bufLen, SDCreateSnodeReq *pReq);
2894
void tFreeSDCreateSnodeReq(SDCreateSnodeReq *pReq);
2895

2896

2897
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2898
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2899
typedef struct {
2900
  int8_t   replica;
2901
  SReplica replicas[TSDB_MAX_REPLICA];
2902
  int8_t   learnerReplica;
2903
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2904
  int64_t  lastIndex;
2905
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2906

2907
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2908
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2909

2910
typedef struct {
2911
  int32_t urlLen;
2912
  int32_t sqlLen;
2913
  char*   url;
2914
  char*   sql;
2915
} SMCreateAnodeReq;
2916

2917
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2918
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2919
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2920

2921
typedef struct {
2922
  int32_t anodeId;
2923
  int32_t sqlLen;
2924
  char*   sql;
2925
} SMDropAnodeReq, SMUpdateAnodeReq;
2926

2927
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2928
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2929
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2930
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2931
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2932
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2933

2934
typedef struct {
2935
  int32_t dnodeId;
2936
  int32_t bnodeProto;
2937
  int32_t sqlLen;
2938
  char*   sql;
2939
} SMCreateBnodeReq, SDCreateBnodeReq;
2940

2941
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2942
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
2943
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
2944

2945
typedef struct {
2946
  int32_t dnodeId;
2947
  int32_t sqlLen;
2948
  char*   sql;
2949
} SMDropBnodeReq, SDDropBnodeReq;
2950

2951
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2952
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
2953
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
2954

2955
typedef struct {
2956
  int32_t vgId;
2957
  int32_t hbSeq;
2958
} SVArbHbReqMember;
2959

2960
typedef struct {
2961
  int32_t dnodeId;
2962
  char*   arbToken;
2963
  int64_t arbTerm;
2964
  SArray* hbMembers;  // SVArbHbReqMember
2965
} SVArbHeartBeatReq;
2966

2967
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2968
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2969
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2970

2971
typedef struct {
2972
  int32_t vgId;
2973
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2974
  int32_t hbSeq;
2975
} SVArbHbRspMember;
2976

2977
typedef struct {
2978
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2979
  int32_t dnodeId;
2980
  SArray* hbMembers;  // SVArbHbRspMember
2981
} SVArbHeartBeatRsp;
2982

2983
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2984
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2985
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2986

2987
typedef struct {
2988
  char*   arbToken;
2989
  int64_t arbTerm;
2990
  char*   member0Token;
2991
  char*   member1Token;
2992
} SVArbCheckSyncReq;
2993

2994
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2995
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2996
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2997

2998
typedef struct {
2999
  char*   arbToken;
3000
  char*   member0Token;
3001
  char*   member1Token;
3002
  int32_t vgId;
3003
  int32_t errCode;
3004
} SVArbCheckSyncRsp;
3005

3006
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3007
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3008
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3009

3010
typedef struct {
3011
  char*   arbToken;
3012
  int64_t arbTerm;
3013
  char*   memberToken;
3014
  int8_t  force;
3015
} SVArbSetAssignedLeaderReq;
3016

3017
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3018
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3019
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3020

3021
typedef struct {
3022
  char*   arbToken;
3023
  char*   memberToken;
3024
  int32_t vgId;
3025
} SVArbSetAssignedLeaderRsp;
3026

3027
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3028
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3029
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3030

3031
typedef struct {
3032
  int32_t dnodeId;
3033
  char*   token;
3034
} SMArbUpdateGroupMember;
3035

3036
typedef struct {
3037
  int32_t dnodeId;
3038
  char*   token;
3039
  int8_t  acked;
3040
} SMArbUpdateGroupAssigned;
3041

3042
typedef struct {
3043
  int32_t                  vgId;
3044
  int64_t                  dbUid;
3045
  SMArbUpdateGroupMember   members[2];
3046
  int8_t                   isSync;
3047
  int8_t                   assignedAcked;
3048
  SMArbUpdateGroupAssigned assignedLeader;
3049
  int64_t                  version;
3050
  int32_t                  code;
3051
  int64_t                  updateTimeMs;
3052
} SMArbUpdateGroup;
3053

3054
typedef struct {
3055
  SArray* updateArray;  // SMArbUpdateGroup
3056
} SMArbUpdateGroupBatchReq;
3057

3058
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3059
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3060
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3061

3062
typedef struct {
3063
  char queryStrId[TSDB_QUERY_ID_LEN];
3064
} SKillQueryReq;
3065

3066
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3067
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3068

3069
typedef struct {
3070
  uint32_t connId;
3071
} SKillConnReq;
3072

3073
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3074
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3075

3076
typedef struct {
3077
  int32_t transId;
3078
} SKillTransReq;
3079

3080
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3081
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3082

3083
typedef struct {
3084
  int32_t useless;  // useless
3085
  int32_t sqlLen;
3086
  char*   sql;
3087
} SBalanceVgroupReq;
3088

3089
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3090
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3091
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3092

3093
typedef struct {
3094
  int32_t useless;  // useless
3095
  int32_t sqlLen;
3096
  char*   sql;
3097
} SAssignLeaderReq;
3098

3099
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3100
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3101
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3102
typedef struct {
3103
  int32_t vgId1;
3104
  int32_t vgId2;
3105
} SMergeVgroupReq;
3106

3107
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3108
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3109

3110
typedef struct {
3111
  int32_t vgId;
3112
  int32_t dnodeId1;
3113
  int32_t dnodeId2;
3114
  int32_t dnodeId3;
3115
  int32_t sqlLen;
3116
  char*   sql;
3117
} SRedistributeVgroupReq;
3118

3119
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3120
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3121
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3122

3123
typedef struct {
3124
  int32_t reserved;
3125
  int32_t vgId;
3126
  int32_t sqlLen;
3127
  char*   sql;
3128
  char    db[TSDB_DB_FNAME_LEN];
3129
} SBalanceVgroupLeaderReq;
3130

3131
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3132
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3133
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3134

3135
typedef struct {
3136
  int32_t vgId;
3137
} SForceBecomeFollowerReq;
3138

3139
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3140
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3141

3142
typedef struct {
3143
  int32_t vgId;
3144
  bool    force;
3145
} SSplitVgroupReq;
3146

3147
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3148
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3149

3150
typedef struct {
3151
  char user[TSDB_USER_LEN];
3152
  char spi;
3153
  char encrypt;
3154
  char secret[TSDB_PASSWORD_LEN];
3155
  char ckey[TSDB_PASSWORD_LEN];
3156
} SAuthReq, SAuthRsp;
3157

3158
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3159
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3160

3161
typedef struct {
3162
  int32_t statusCode;
3163
  char    details[1024];
3164
} SServerStatusRsp;
3165

3166
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3167
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3168

3169
/**
3170
 * The layout of the query message payload is as following:
3171
 * +--------------------+---------------------------------+
3172
 * |Sql statement       | Physical plan                   |
3173
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3174
 * +--------------------+---------------------------------+
3175
 */
3176
typedef struct SSubQueryMsg {
3177
  SMsgHead header;
3178
  uint64_t sId;
3179
  uint64_t queryId;
3180
  uint64_t clientId;
3181
  uint64_t taskId;
3182
  int64_t  refId;
3183
  int32_t  execId;
3184
  int32_t  msgMask;
3185
  int8_t   taskType;
3186
  int8_t   explain;
3187
  int8_t   needFetch;
3188
  int8_t   compress;
3189
  uint32_t sqlLen;
3190
  char*    sql;
3191
  uint32_t msgLen;
3192
  char*    msg;
3193
} SSubQueryMsg;
3194

3195
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3196
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3197
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3198

3199
typedef struct {
3200
  SMsgHead header;
3201
  uint64_t sId;
3202
  uint64_t queryId;
3203
  uint64_t taskId;
3204
} SSinkDataReq;
3205

3206
typedef struct {
3207
  SMsgHead header;
3208
  uint64_t sId;
3209
  uint64_t queryId;
3210
  uint64_t clientId;
3211
  uint64_t taskId;
3212
  int32_t  execId;
3213
} SQueryContinueReq;
3214

3215
typedef struct {
3216
  SMsgHead header;
3217
  uint64_t sId;
3218
  uint64_t queryId;
3219
  uint64_t taskId;
3220
} SResReadyReq;
3221

3222
typedef struct {
3223
  int32_t code;
3224
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3225
  int32_t sversion;
3226
  int32_t tversion;
3227
} SResReadyRsp;
3228

3229
typedef struct SOperatorParam {
3230
  int32_t opType;
3231
  int32_t downstreamIdx;
3232
  void*   value;
3233
  SArray* pChildren;  // SArray<SOperatorParam*>
3234
  bool    reUse;
3235
} SOperatorParam;
3236

3237
typedef struct SColIdNameKV {
3238
  col_id_t colId;
3239
  char     colName[TSDB_COL_NAME_LEN];
3240
} SColIdNameKV;
3241

3242
typedef struct SColIdPair {
3243
  col_id_t vtbColId;
3244
  col_id_t orgColId;
3245
} SColIdPair;
3246

3247
typedef struct SOrgTbInfo {
3248
  int32_t vgId;
3249
  char    tbName[TSDB_TABLE_FNAME_LEN];
3250
  SArray* colMap;  // SArray<SColIdNameKV>
3251
} SOrgTbInfo;
3252

3253
typedef struct STableScanOperatorParam {
3254
  bool        tableSeq;
3255
  SArray*     pUidList;
3256
  SOrgTbInfo* pOrgTbInfo;
3257
  STimeWindow window;
3258
} STableScanOperatorParam;
3259

3260
typedef struct STagScanOperatorParam {
3261
  tb_uid_t       vcUid;
3262
} STagScanOperatorParam;
3263

3264
typedef struct SVTableScanOperatorParam {
3265
  uint64_t        uid;
3266
  SOperatorParam* pTagScanOp;
3267
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3268
} SVTableScanOperatorParam;
3269

3270
struct SStreamRuntimeFuncInfo;
3271
typedef struct {
3272
  SMsgHead                       header;
3273
  uint64_t                       sId;
3274
  uint64_t                       queryId;
3275
  uint64_t                       clientId;
3276
  uint64_t                       taskId;
3277
  int32_t                        execId;
3278
  SOperatorParam*                pOpParam;
3279

3280
  // used for new-stream
3281
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3282
  bool                           reset;
3283
  bool                           dynTbname;
3284
  // used for new-stream
3285
} SResFetchReq;
3286

3287
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3288
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3289
void    tDestroySResFetchReq(SResFetchReq* pReq);
3290
typedef struct {
3291
  SMsgHead header;
3292
  uint64_t clientId;
3293
} SSchTasksStatusReq;
3294

3295
typedef struct {
3296
  uint64_t queryId;
3297
  uint64_t clientId;
3298
  uint64_t taskId;
3299
  int64_t  refId;
3300
  int32_t  execId;
3301
  int8_t   status;
3302
} STaskStatus;
3303

3304
typedef struct {
3305
  int64_t refId;
3306
  SArray* taskStatus;  // SArray<STaskStatus>
3307
} SSchedulerStatusRsp;
3308

3309
typedef struct {
3310
  uint64_t queryId;
3311
  uint64_t taskId;
3312
  int8_t   action;
3313
} STaskAction;
3314

3315
typedef struct SQueryNodeEpId {
3316
  int32_t nodeId;  // vgId or qnodeId
3317
  SEp     ep;
3318
} SQueryNodeEpId;
3319

3320
typedef struct {
3321
  SMsgHead       header;
3322
  uint64_t       clientId;
3323
  SQueryNodeEpId epId;
3324
  SArray*        taskAction;  // SArray<STaskAction>
3325
} SSchedulerHbReq;
3326

3327
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3328
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3329
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3330

3331
typedef struct {
3332
  SQueryNodeEpId epId;
3333
  SArray*        taskStatus;  // SArray<STaskStatus>
3334
} SSchedulerHbRsp;
3335

3336
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3337
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3338
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3339

3340
typedef struct {
3341
  SMsgHead header;
3342
  uint64_t sId;
3343
  uint64_t queryId;
3344
  uint64_t clientId;
3345
  uint64_t taskId;
3346
  int64_t  refId;
3347
  int32_t  execId;
3348
} STaskCancelReq;
3349

3350
typedef struct {
3351
  int32_t code;
3352
} STaskCancelRsp;
3353

3354
typedef struct {
3355
  SMsgHead header;
3356
  uint64_t sId;
3357
  uint64_t queryId;
3358
  uint64_t clientId;
3359
  uint64_t taskId;
3360
  int64_t  refId;
3361
  int32_t  execId;
3362
} STaskDropReq;
3363

3364
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3365
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3366

3367
typedef enum {
3368
  TASK_NOTIFY_FINISHED = 1,
3369
} ETaskNotifyType;
3370

3371
typedef struct {
3372
  SMsgHead        header;
3373
  uint64_t        sId;
3374
  uint64_t        queryId;
3375
  uint64_t        clientId;
3376
  uint64_t        taskId;
3377
  int64_t         refId;
3378
  int32_t         execId;
3379
  ETaskNotifyType type;
3380
} STaskNotifyReq;
3381

3382
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3383
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3384

3385
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3386
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3387

3388
typedef struct {
3389
  int32_t code;
3390
} STaskDropRsp;
3391

3392
#define STREAM_TRIGGER_AT_ONCE                 1
3393
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3394
#define STREAM_TRIGGER_MAX_DELAY               3
3395
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3396
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3397

3398
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3399
#define STREAM_FILL_HISTORY_ON        1
3400
#define STREAM_FILL_HISTORY_OFF       0
3401
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3402
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3403
#define STREAM_CREATE_STABLE_TRUE     1
3404
#define STREAM_CREATE_STABLE_FALSE    0
3405

3406
typedef struct SVgroupVer {
3407
  int32_t vgId;
3408
  int64_t ver;
3409
} SVgroupVer;
3410

3411
typedef struct STaskNotifyEventStat {
3412
  int64_t notifyEventAddTimes;     // call times of add function
3413
  int64_t notifyEventAddElems;     // elements added by add function
3414
  double  notifyEventAddCostSec;   // time cost of add function
3415
  int64_t notifyEventPushTimes;    // call times of push function
3416
  int64_t notifyEventPushElems;    // elements pushed by push function
3417
  double  notifyEventPushCostSec;  // time cost of push function
3418
  int64_t notifyEventPackTimes;    // call times of pack function
3419
  int64_t notifyEventPackElems;    // elements packed by pack function
3420
  double  notifyEventPackCostSec;  // time cost of pack function
3421
  int64_t notifyEventSendTimes;    // call times of send function
3422
  int64_t notifyEventSendElems;    // elements sent by send function
3423
  double  notifyEventSendCostSec;  // time cost of send function
3424
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3425
} STaskNotifyEventStat;
3426

3427
enum {
3428
  TOPIC_SUB_TYPE__DB = 1,
3429
  TOPIC_SUB_TYPE__TABLE,
3430
  TOPIC_SUB_TYPE__COLUMN,
3431
};
3432

3433
#define DEFAULT_MAX_POLL_INTERVAL  300000
3434
#define DEFAULT_SESSION_TIMEOUT    12000
3435
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3436
#define DEFAULT_MIN_POLL_ROWS      4096
3437

3438
typedef struct {
3439
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3440
  int8_t igExists;
3441
  int8_t subType;
3442
  int8_t withMeta;
3443
  char*  sql;
3444
  char   subDbName[TSDB_DB_FNAME_LEN];
3445
  char*  ast;
3446
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3447
} SCMCreateTopicReq;
3448

3449
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3450
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3451
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3452

3453
typedef struct {
3454
  int64_t consumerId;
3455
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3456

3457
typedef struct {
3458
  int64_t consumerId;
3459
  char    cgroup[TSDB_CGROUP_LEN];
3460
  char    clientId[TSDB_CLIENT_ID_LEN];
3461
  char    user[TSDB_USER_LEN];
3462
  char    fqdn[TSDB_FQDN_LEN];
3463
  SArray* topicNames;  // SArray<char**>
3464

3465
  int8_t  withTbName;
3466
  int8_t  autoCommit;
3467
  int32_t autoCommitInterval;
3468
  int8_t  resetOffsetCfg;
3469
  int8_t  enableReplay;
3470
  int8_t  enableBatchMeta;
3471
  int32_t sessionTimeoutMs;
3472
  int32_t maxPollIntervalMs;
3473
} SCMSubscribeReq;
3474

3475
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3476
  int32_t tlen = 0;
36✔
3477
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
36!
3478
  tlen += taosEncodeString(buf, pReq->cgroup);
36✔
3479
  tlen += taosEncodeString(buf, pReq->clientId);
36✔
3480

3481
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
36!
3482
  tlen += taosEncodeFixedI32(buf, topicNum);
36✔
3483

3484
  for (int32_t i = 0; i < topicNum; i++) {
60✔
3485
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
48✔
3486
  }
3487

3488
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
36!
3489
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
36!
3490
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
36!
3491
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
36!
3492
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
36!
3493
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
36!
3494
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
36!
3495
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
36!
3496
  tlen += taosEncodeString(buf, pReq->user);
36✔
3497
  tlen += taosEncodeString(buf, pReq->fqdn);
36✔
3498

3499
  return tlen;
36✔
3500
}
3501

3502
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3503
  void* start = buf;
18✔
3504
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
18!
3505
  buf = taosDecodeStringTo(buf, pReq->cgroup);
18✔
3506
  buf = taosDecodeStringTo(buf, pReq->clientId);
18✔
3507

3508
  int32_t topicNum = 0;
18!
3509
  buf = taosDecodeFixedI32(buf, &topicNum);
18✔
3510

3511
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
18✔
3512
  if (pReq->topicNames == NULL) {
18!
3513
    return terrno;
×
3514
  }
3515
  for (int32_t i = 0; i < topicNum; i++) {
30✔
3516
    char* name = NULL;
12✔
3517
    buf = taosDecodeString(buf, &name);
12✔
3518
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
24!
3519
      return terrno;
×
3520
    }
3521
  }
3522

3523
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
18✔
3524
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
18✔
3525
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
18!
3526
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
18✔
3527
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
18✔
3528
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
18✔
3529
  if ((char*)buf - (char*)start < len) {
18!
3530
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
18!
3531
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
18!
3532
    buf = taosDecodeStringTo(buf, pReq->user);
18✔
3533
    buf = taosDecodeStringTo(buf, pReq->fqdn);
36✔
3534
  } else {
3535
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3536
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3537
  }
3538

3539
  return 0;
18✔
3540
}
3541

3542
typedef struct {
3543
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3544
  SArray* removedConsumers;  // SArray<int64_t>
3545
  SArray* newConsumers;      // SArray<int64_t>
3546
} SMqRebInfo;
3547

3548
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3549
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
21!
3550
  if (pRebInfo == NULL) {
21!
3551
    return NULL;
×
3552
  }
3553
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
21✔
3554
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
21✔
3555
  if (pRebInfo->removedConsumers == NULL) {
21!
3556
    goto _err;
×
3557
  }
3558
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
21✔
3559
  if (pRebInfo->newConsumers == NULL) {
21!
3560
    goto _err;
×
3561
  }
3562
  return pRebInfo;
21✔
3563
_err:
×
3564
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3565
  taosArrayDestroy(pRebInfo->newConsumers);
×
3566
  taosMemoryFreeClear(pRebInfo);
×
3567
  return NULL;
×
3568
}
3569

3570
typedef struct {
3571
  int64_t streamId;
3572
  int64_t checkpointId;
3573
  char    streamName[TSDB_STREAM_FNAME_LEN];
3574
} SMStreamDoCheckpointMsg;
3575

3576
typedef struct {
3577
  int64_t status;
3578
} SMVSubscribeRsp;
3579

3580
typedef struct {
3581
  char    name[TSDB_TOPIC_FNAME_LEN];
3582
  int8_t  igNotExists;
3583
  int32_t sqlLen;
3584
  char*   sql;
3585
  int8_t  force;
3586
} SMDropTopicReq;
3587

3588
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3589
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3590
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3591

3592
typedef struct {
3593
  char   topic[TSDB_TOPIC_FNAME_LEN];
3594
  char   cgroup[TSDB_CGROUP_LEN];
3595
  int8_t igNotExists;
3596
  int8_t force;
3597
} SMDropCgroupReq;
3598

3599
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3600
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3601

3602
typedef struct {
3603
  int8_t reserved;
3604
} SMDropCgroupRsp;
3605

3606
typedef struct {
3607
  char    name[TSDB_TABLE_FNAME_LEN];
3608
  int8_t  alterType;
3609
  SSchema schema;
3610
} SAlterTopicReq;
3611

3612
typedef struct {
3613
  SMsgHead head;
3614
  char     name[TSDB_TABLE_FNAME_LEN];
3615
  int64_t  tuid;
3616
  int32_t  sverson;
3617
  int32_t  execLen;
3618
  char*    executor;
3619
  int32_t  sqlLen;
3620
  char*    sql;
3621
} SDCreateTopicReq;
3622

3623
typedef struct {
3624
  SMsgHead head;
3625
  char     name[TSDB_TABLE_FNAME_LEN];
3626
  int64_t  tuid;
3627
} SDDropTopicReq;
3628

3629
typedef struct {
3630
  int64_t maxdelay[2];
3631
  int64_t watermark[2];
3632
  int64_t deleteMark[2];
3633
  int32_t qmsgLen[2];
3634
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3635
} SRSmaParam;
3636

3637
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3638
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3639

3640
// TDMT_VND_CREATE_STB ==============
3641
typedef struct SVCreateStbReq {
3642
  char*           name;
3643
  tb_uid_t        suid;
3644
  int8_t          rollup;
3645
  SSchemaWrapper  schemaRow;
3646
  SSchemaWrapper  schemaTag;
3647
  SRSmaParam      rsmaParam;
3648
  int32_t         alterOriDataLen;
3649
  void*           alterOriData;
3650
  int8_t          source;
3651
  int8_t          colCmpred;
3652
  SColCmprWrapper colCmpr;
3653
  int64_t         keep;
3654
  SExtSchema*     pExtSchemas;
3655
  int8_t          virtualStb;
3656
} SVCreateStbReq;
3657

3658
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3659
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3660

3661
// TDMT_VND_DROP_STB ==============
3662
typedef struct SVDropStbReq {
3663
  char*    name;
3664
  tb_uid_t suid;
3665
} SVDropStbReq;
3666

3667
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3668
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3669

3670
// TDMT_VND_CREATE_TABLE ==============
3671
#define TD_CREATE_IF_NOT_EXISTS       0x1
3672
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
3673
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
3674
typedef struct SVCreateTbReq {
3675
  int32_t  flags;
3676
  char*    name;
3677
  tb_uid_t uid;
3678
  int64_t  btime;
3679
  int32_t  ttl;
3680
  int32_t  commentLen;
3681
  char*    comment;
3682
  int8_t   type;
3683
  union {
3684
    struct {
3685
      char*    stbName;  // super table name
3686
      uint8_t  tagNum;
3687
      tb_uid_t suid;
3688
      SArray*  tagName;
3689
      uint8_t* pTag;
3690
    } ctb;
3691
    struct {
3692
      SSchemaWrapper schemaRow;
3693
    } ntb;
3694
  };
3695
  int32_t         sqlLen;
3696
  char*           sql;
3697
  SColCmprWrapper colCmpr;
3698
  SExtSchema*     pExtSchemas;
3699
  SColRefWrapper  colRef;  // col reference for virtual table
3700
} SVCreateTbReq;
3701

3702
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3703
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3704
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3705

3706
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3707
  if (NULL == req) {
28,876!
3708
    return;
28,732✔
3709
  }
3710

3711
  taosMemoryFreeClear(req->sql);
144!
3712
  taosMemoryFreeClear(req->name);
144!
3713
  taosMemoryFreeClear(req->comment);
144!
3714
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
144!
3715
    taosMemoryFreeClear(req->ctb.pTag);
117!
3716
    taosMemoryFreeClear(req->ctb.stbName);
117!
3717
    taosArrayDestroy(req->ctb.tagName);
117✔
3718
    req->ctb.tagName = NULL;
117✔
3719
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
27!
3720
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
27!
3721
  }
3722
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
144!
3723
  taosMemoryFreeClear(req->pExtSchemas);
144!
3724
  taosMemoryFreeClear(req->colRef.pColRef);
144!
3725
}
3726

3727
typedef struct {
3728
  int32_t nReqs;
3729
  union {
3730
    SVCreateTbReq* pReqs;
3731
    SArray*        pArray;
3732
  };
3733
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3734
} SVCreateTbBatchReq;
3735

3736
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3737
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3738
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3739

3740
typedef struct {
3741
  int32_t        code;
3742
  STableMetaRsp* pMeta;
3743
} SVCreateTbRsp, SVUpdateTbRsp;
3744

3745
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3746
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3747
void tFreeSVCreateTbRsp(void* param);
3748

3749
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3750
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3751

3752
typedef struct {
3753
  int32_t nRsps;
3754
  union {
3755
    SVCreateTbRsp* pRsps;
3756
    SArray*        pArray;
3757
  };
3758
} SVCreateTbBatchRsp;
3759

3760
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3761
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3762

3763
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3764
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3765

3766
// TDMT_VND_DROP_TABLE =================
3767
typedef struct {
3768
  char*    name;
3769
  uint64_t suid;  // for tmq in wal format
3770
  int64_t  uid;
3771
  int8_t   igNotExists;
3772
  int8_t   isVirtual;
3773
} SVDropTbReq;
3774

3775
typedef struct {
3776
  int32_t code;
3777
} SVDropTbRsp;
3778

3779
typedef struct {
3780
  int32_t nReqs;
3781
  union {
3782
    SVDropTbReq* pReqs;
3783
    SArray*      pArray;
3784
  };
3785
} SVDropTbBatchReq;
3786

3787
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3788
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3789

3790
typedef struct {
3791
  int32_t nRsps;
3792
  union {
3793
    SVDropTbRsp* pRsps;
3794
    SArray*      pArray;
3795
  };
3796
} SVDropTbBatchRsp;
3797

3798
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3799
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3800

3801
// TDMT_VND_ALTER_TABLE =====================
3802
typedef struct SMultiTagUpateVal {
3803
  char*    tagName;
3804
  int32_t  colId;
3805
  int8_t   tagType;
3806
  int8_t   tagFree;
3807
  uint32_t nTagVal;
3808
  uint8_t* pTagVal;
3809
  int8_t   isNull;
3810
  SArray*  pTagArray;
3811
} SMultiTagUpateVal;
3812
typedef struct SVAlterTbReq {
3813
  char*   tbName;
3814
  int8_t  action;
3815
  char*   colName;
3816
  int32_t colId;
3817
  // TSDB_ALTER_TABLE_ADD_COLUMN
3818
  int8_t  type;
3819
  int8_t  flags;
3820
  int32_t bytes;
3821
  // TSDB_ALTER_TABLE_DROP_COLUMN
3822
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3823
  int8_t   colModType;
3824
  int32_t  colModBytes;
3825
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3826
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3827
  int8_t   isNull;
3828
  int8_t   tagType;
3829
  int8_t   tagFree;
3830
  uint32_t nTagVal;
3831
  uint8_t* pTagVal;
3832
  SArray*  pTagArray;
3833
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3834
  int8_t   updateTTL;
3835
  int32_t  newTTL;
3836
  int32_t  newCommentLen;
3837
  char*    newComment;
3838
  int64_t  ctimeMs;    // fill by vnode
3839
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3840
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3841
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3842
  // for Add column
3843
  STypeMod typeMod;
3844
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3845
  char* refDbName;
3846
  char* refTbName;
3847
  char* refColName;
3848
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3849
} SVAlterTbReq;
3850

3851
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3852
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3853
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3854
void    tfreeMultiTagUpateVal(void* pMultiTag);
3855

3856
typedef struct {
3857
  int32_t        code;
3858
  STableMetaRsp* pMeta;
3859
} SVAlterTbRsp;
3860

3861
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3862
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3863
// ======================
3864

3865
typedef struct {
3866
  SMsgHead head;
3867
  int64_t  uid;
3868
  int32_t  tid;
3869
  int16_t  tversion;
3870
  int16_t  colId;
3871
  int8_t   type;
3872
  int16_t  bytes;
3873
  int32_t  tagValLen;
3874
  int16_t  numOfTags;
3875
  int32_t  schemaLen;
3876
  char     data[];
3877
} SUpdateTagValReq;
3878

3879
typedef struct {
3880
  SMsgHead head;
3881
} SUpdateTagValRsp;
3882

3883
typedef struct {
3884
  SMsgHead head;
3885
} SVShowTablesReq;
3886

3887
typedef struct {
3888
  SMsgHead head;
3889
  int32_t  id;
3890
} SVShowTablesFetchReq;
3891

3892
typedef struct {
3893
  int64_t useconds;
3894
  int8_t  completed;  // all results are returned to client
3895
  int8_t  precision;
3896
  int8_t  compressed;
3897
  int32_t compLen;
3898
  int32_t numOfRows;
3899
  char    data[];
3900
} SVShowTablesFetchRsp;
3901

3902
typedef struct {
3903
  int64_t consumerId;
3904
  int32_t epoch;
3905
  char    cgroup[TSDB_CGROUP_LEN];
3906
} SMqAskEpReq;
3907

3908
typedef struct {
3909
  int32_t key;
3910
  int32_t valueLen;
3911
  void*   value;
3912
} SKv;
3913

3914
typedef struct {
3915
  int64_t tscRid;
3916
  int8_t  connType;
3917
} SClientHbKey;
3918

3919
typedef struct {
3920
  int64_t tid;
3921
  char    status[TSDB_JOB_STATUS_LEN];
3922
} SQuerySubDesc;
3923

3924
typedef struct {
3925
  char     sql[TSDB_SHOW_SQL_LEN];
3926
  uint64_t queryId;
3927
  int64_t  useconds;
3928
  int64_t  stime;  // timestamp precision ms
3929
  int64_t  reqRid;
3930
  bool     stableQuery;
3931
  bool     isSubQuery;
3932
  char     fqdn[TSDB_FQDN_LEN];
3933
  int32_t  subPlanNum;
3934
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3935
} SQueryDesc;
3936

3937
typedef struct {
3938
  uint32_t connId;
3939
  SArray*  queryDesc;  // SArray<SQueryDesc>
3940
} SQueryHbReqBasic;
3941

3942
typedef struct {
3943
  uint32_t connId;
3944
  uint64_t killRid;
3945
  int32_t  totalDnodes;
3946
  int32_t  onlineDnodes;
3947
  int8_t   killConnection;
3948
  int8_t   align[3];
3949
  SEpSet   epSet;
3950
  SArray*  pQnodeList;
3951
} SQueryHbRspBasic;
3952

3953
typedef struct SAppClusterSummary {
3954
  uint64_t numOfInsertsReq;
3955
  uint64_t numOfInsertRows;
3956
  uint64_t insertElapsedTime;
3957
  uint64_t insertBytes;  // submit to tsdb since launched.
3958

3959
  uint64_t fetchBytes;
3960
  uint64_t numOfQueryReq;
3961
  uint64_t queryElapsedTime;
3962
  uint64_t numOfSlowQueries;
3963
  uint64_t totalRequests;
3964
  uint64_t currentRequests;  // the number of SRequestObj
3965
} SAppClusterSummary;
3966

3967
typedef struct {
3968
  int64_t            appId;
3969
  int32_t            pid;
3970
  char               name[TSDB_APP_NAME_LEN];
3971
  int64_t            startTime;
3972
  SAppClusterSummary summary;
3973
} SAppHbReq;
3974

3975
typedef struct {
3976
  SClientHbKey      connKey;
3977
  int64_t           clusterId;
3978
  SAppHbReq         app;
3979
  SQueryHbReqBasic* query;
3980
  SHashObj*         info;  // hash<Skv.key, Skv>
3981
  char              userApp[TSDB_APP_NAME_LEN];
3982
  uint32_t          userIp;
3983
  SIpRange          userDualIp;
3984
} SClientHbReq;
3985

3986
typedef struct {
3987
  int64_t reqId;
3988
  SArray* reqs;  // SArray<SClientHbReq>
3989
  int64_t ipWhiteListVer;
3990
} SClientHbBatchReq;
3991

3992
typedef struct {
3993
  SClientHbKey      connKey;
3994
  int32_t           status;
3995
  SQueryHbRspBasic* query;
3996
  SArray*           info;  // Array<Skv>
3997
} SClientHbRsp;
3998

3999
typedef struct {
4000
  int64_t       reqId;
4001
  int64_t       rspId;
4002
  int32_t       svrTimestamp;
4003
  SArray*       rsps;  // SArray<SClientHbRsp>
4004
  SMonitorParas monitorParas;
4005
  int8_t        enableAuditDelete;
4006
  int8_t        enableStrongPass;
4007
} SClientHbBatchRsp;
4008

4009
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
712✔
4010

4011
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4012
  void* pIter = taosHashIterate(info, NULL);
299✔
4013
  while (pIter != NULL) {
789!
4014
    SKv* kv = (SKv*)pIter;
490✔
4015
    taosMemoryFreeClear(kv->value);
490!
4016
    pIter = taosHashIterate(info, pIter);
490✔
4017
  }
4018
}
299✔
4019

4020
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
85✔
4021
  SQueryDesc* desc = (SQueryDesc*)pDesc;
85✔
4022
  if (desc->subDesc) {
85✔
4023
    taosArrayDestroy(desc->subDesc);
84✔
4024
    desc->subDesc = NULL;
84✔
4025
  }
4026
}
85✔
4027

4028
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
343✔
4029
  SClientHbReq* req = (SClientHbReq*)pReq;
412✔
4030
  if (req->query) {
412!
4031
    if (req->query->queryDesc) {
340!
4032
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
74✔
4033
    }
4034
    taosMemoryFreeClear(req->query);
340!
4035
  }
4036

4037
  if (req->info) {
412!
4038
    tFreeReqKvHash(req->info);
299✔
4039
    taosHashCleanup(req->info);
299✔
4040
    req->info = NULL;
299✔
4041
  }
4042
}
236✔
4043

4044
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4045
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4046

4047
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4048
  if (pReq == NULL) return;
133!
4049
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
133✔
4050
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
133✔
4051
  taosMemoryFree(pReq);
133!
4052
}
4053

4054
static FORCE_INLINE void tFreeClientKv(void* pKv) {
294✔
4055
  SKv* kv = (SKv*)pKv;
294✔
4056
  if (kv) {
294!
4057
    taosMemoryFreeClear(kv->value);
294!
4058
  }
4059
}
294✔
4060

4061
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
332✔
4062
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
332✔
4063
  if (rsp->query) {
332✔
4064
    taosArrayDestroy(rsp->query->pQnodeList);
330✔
4065
    taosMemoryFreeClear(rsp->query);
330!
4066
  }
4067
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
332!
4068
}
166✔
4069

4070
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4071
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
247✔
4072
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
247✔
4073
}
247✔
4074

4075
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4076
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4077
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4078

4079
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4080
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
1,276!
4081
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
1,276!
4082
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
1,276!
4083
  return 0;
638✔
4084
}
4085

4086
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4087
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
610!
4088
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
610!
4089
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
305!
4090
  if (pKv->value == NULL) {
305!
4091
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4092
  }
4093
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
305!
4094
  return 0;
305✔
4095
}
4096

4097
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4098
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
1,084!
4099
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
1,084!
4100
  return 0;
542✔
4101
}
4102

4103
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4104
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
528!
4105
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
528!
4106
  return 0;
264✔
4107
}
4108

4109
typedef struct {
4110
  int32_t vgId;
4111
  // TODO stas
4112
} SMqReportVgInfo;
4113

4114
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4115
  int32_t tlen = 0;
4116
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4117
  return tlen;
4118
}
4119

4120
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4121
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4122
  return buf;
4123
}
4124

4125
typedef struct {
4126
  int32_t epoch;
4127
  int64_t topicUid;
4128
  char    name[TSDB_TOPIC_FNAME_LEN];
4129
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4130
} SMqTopicInfo;
4131

4132
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4133
  int32_t tlen = 0;
4134
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4135
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4136
  tlen += taosEncodeString(buf, pTopicInfo->name);
4137
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4138
  tlen += taosEncodeFixedI32(buf, sz);
4139
  for (int32_t i = 0; i < sz; i++) {
4140
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4141
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4142
  }
4143
  return tlen;
4144
}
4145

4146
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4147
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4148
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4149
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4150
  int32_t sz;
4151
  buf = taosDecodeFixedI32(buf, &sz);
4152
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4153
    return NULL;
4154
  }
4155
  for (int32_t i = 0; i < sz; i++) {
4156
    SMqReportVgInfo vgInfo;
4157
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4158
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4159
      return NULL;
4160
    }
4161
  }
4162
  return buf;
4163
}
4164

4165
typedef struct {
4166
  int32_t status;  // ask hb endpoint
4167
  int32_t epoch;
4168
  int64_t consumerId;
4169
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4170
} SMqReportReq;
4171

4172
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4173
  int32_t tlen = 0;
4174
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4175
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4176
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4177
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4178
  tlen += taosEncodeFixedI32(buf, sz);
4179
  for (int32_t i = 0; i < sz; i++) {
4180
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4181
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4182
  }
4183
  return tlen;
4184
}
4185

4186
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4187
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4188
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4189
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4190
  int32_t sz;
4191
  buf = taosDecodeFixedI32(buf, &sz);
4192
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4193
    return NULL;
4194
  }
4195
  for (int32_t i = 0; i < sz; i++) {
4196
    SMqTopicInfo topicInfo;
4197
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4198
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4199
      return NULL;
4200
    }
4201
  }
4202
  return buf;
4203
}
4204

4205
typedef struct {
4206
  SMsgHead head;
4207
  int64_t  leftForVer;
4208
  int32_t  vgId;
4209
  int64_t  consumerId;
4210
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4211
} SMqVDeleteReq;
4212

4213
typedef struct {
4214
  int8_t reserved;
4215
} SMqVDeleteRsp;
4216

4217
typedef struct {
4218
  char*   name;
4219
  int8_t  igNotExists;
4220
} SMDropStreamReq;
4221

4222
typedef struct {
4223
  int8_t reserved;
4224
} SMDropStreamRsp;
4225

4226
typedef struct {
4227
  SMsgHead head;
4228
  int64_t  resetRelHalt;  // reset related stream task halt status
4229
  int64_t  streamId;
4230
  int32_t  taskId;
4231
} SVDropStreamTaskReq;
4232

4233
typedef struct {
4234
  int8_t reserved;
4235
} SVDropStreamTaskRsp;
4236

4237
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4238
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4239
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4240

4241
typedef struct {
4242
  char*  name;
4243
  int8_t igNotExists;
4244
} SMPauseStreamReq;
4245

4246
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4247
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4248
void    tFreeMPauseStreamReq(SMPauseStreamReq *pReq);
4249

4250
typedef struct {
4251
  char*  name;
4252
  int8_t igNotExists;
4253
  int8_t igUntreated;
4254
} SMResumeStreamReq;
4255

4256
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4257
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4258
void    tFreeMResumeStreamReq(SMResumeStreamReq *pReq);
4259

4260
typedef struct {
4261
  char*       name;
4262
  int8_t      calcAll;
4263
  STimeWindow timeRange;
4264
} SMRecalcStreamReq;
4265

4266
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4267
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4268
void    tFreeMRecalcStreamReq(SMRecalcStreamReq *pReq);
4269

4270
typedef struct SVUpdateCheckpointInfoReq {
4271
  SMsgHead head;
4272
  int64_t  streamId;
4273
  int32_t  taskId;
4274
  int64_t  checkpointId;
4275
  int64_t  checkpointVer;
4276
  int64_t  checkpointTs;
4277
  int32_t  transId;
4278
  int64_t  hStreamId;  // add encode/decode
4279
  int64_t  hTaskId;
4280
  int8_t   dropRelHTask;
4281
} SVUpdateCheckpointInfoReq;
4282

4283
typedef struct {
4284
  int64_t leftForVer;
4285
  int32_t vgId;
4286
  int64_t oldConsumerId;
4287
  int64_t newConsumerId;
4288
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4289
  int8_t  subType;
4290
  int8_t  withMeta;
4291
  char*   qmsg;  // SubPlanToString
4292
  int64_t suid;
4293
} SMqRebVgReq;
4294

4295
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4296
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4297

4298
typedef struct {
4299
  char    topic[TSDB_TOPIC_FNAME_LEN];
4300
  int64_t ntbUid;
4301
  SArray* colIdList;  // SArray<int16_t>
4302
} STqCheckInfo;
4303

4304
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4305
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4306
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4307

4308
// tqOffset
4309
enum {
4310
  TMQ_OFFSET__RESET_NONE = -3,
4311
  TMQ_OFFSET__RESET_EARLIEST = -2,
4312
  TMQ_OFFSET__RESET_LATEST = -1,
4313
  TMQ_OFFSET__LOG = 1,
4314
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4315
  TMQ_OFFSET__SNAPSHOT_META = 3,
4316
};
4317

4318
enum {
4319
  WITH_DATA = 0,
4320
  WITH_META = 1,
4321
  ONLY_META = 2,
4322
};
4323

4324
#define TQ_OFFSET_VERSION 1
4325

4326
typedef struct {
4327
  int8_t type;
4328
  union {
4329
    // snapshot
4330
    struct {
4331
      int64_t uid;
4332
      int64_t ts;
4333
      SValue  primaryKey;
4334
    };
4335
    // log
4336
    struct {
4337
      int64_t version;
4338
    };
4339
  };
4340
} STqOffsetVal;
4341

4342
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4343
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
×
4344
  pOffsetVal->uid = uid;
×
4345
  pOffsetVal->ts = ts;
×
4346
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
×
4347
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4348
  }
4349
  pOffsetVal->primaryKey = primaryKey;
×
4350
}
×
4351

4352
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4353
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
×
4354
  pOffsetVal->uid = uid;
×
4355
}
×
4356

4357
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4358
  pOffsetVal->type = TMQ_OFFSET__LOG;
391✔
4359
  pOffsetVal->version = ver;
391✔
4360
}
391✔
4361

4362
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4363
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4364
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4365
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4366
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4367
void    tOffsetDestroy(void* pVal);
4368

4369
typedef struct {
4370
  STqOffsetVal val;
4371
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4372
} STqOffset;
4373

4374
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4375
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4376
void    tDeleteSTqOffset(void* val);
4377

4378
typedef struct SMqVgOffset {
4379
  int64_t   consumerId;
4380
  STqOffset offset;
4381
} SMqVgOffset;
4382

4383
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4384
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4385

4386
typedef struct {
4387
  char    name[TSDB_TABLE_FNAME_LEN];
4388
  char    stb[TSDB_TABLE_FNAME_LEN];
4389
  int8_t  igExists;
4390
  int8_t  intervalUnit;
4391
  int8_t  slidingUnit;
4392
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4393
  int32_t dstVgId;   // for stream
4394
  int64_t interval;
4395
  int64_t offset;
4396
  int64_t sliding;
4397
  int64_t maxDelay;
4398
  int64_t watermark;
4399
  int32_t exprLen;        // strlen + 1
4400
  int32_t tagsFilterLen;  // strlen + 1
4401
  int32_t sqlLen;         // strlen + 1
4402
  int32_t astLen;         // strlen + 1
4403
  char*   expr;
4404
  char*   tagsFilter;
4405
  char*   sql;
4406
  char*   ast;
4407
  int64_t deleteMark;
4408
  int64_t lastTs;
4409
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4410
  SArray* pVgroupVerList;
4411
  int8_t  recursiveTsma;
4412
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4413
  char*   createStreamReq;
4414
  int32_t streamReqLen;
4415
  char*   dropStreamReq;
4416
  int32_t dropStreamReqLen;
4417
  int64_t uid;
4418
} SMCreateSmaReq;
4419

4420
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4421
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4422
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4423

4424
typedef struct {
4425
  char   name[TSDB_TABLE_FNAME_LEN];
4426
  int8_t igNotExists;
4427
  char*   dropStreamReq;
4428
  int32_t dropStreamReqLen;
4429
} SMDropSmaReq;
4430

4431
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4432
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4433

4434
typedef struct {
4435
  char   dbFName[TSDB_DB_FNAME_LEN];
4436
  char   stbName[TSDB_TABLE_NAME_LEN];
4437
  char   colName[TSDB_COL_NAME_LEN];
4438
  char   idxName[TSDB_INDEX_FNAME_LEN];
4439
  int8_t idxType;
4440
} SCreateTagIndexReq;
4441

4442
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4443
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4444

4445
typedef SMDropSmaReq SDropTagIndexReq;
4446

4447
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4448
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4449

4450
typedef struct {
4451
  int8_t         version;       // for compatibility(default 0)
4452
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4453
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4454
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4455
  int32_t        dstVgId;
4456
  char           indexName[TSDB_INDEX_NAME_LEN];
4457
  int32_t        exprLen;
4458
  int32_t        tagsFilterLen;
4459
  int64_t        indexUid;
4460
  tb_uid_t       tableUid;  // super/child/common table uid
4461
  tb_uid_t       dstTbUid;  // for dstVgroup
4462
  int64_t        interval;
4463
  int64_t        offset;  // use unit by precision of DB
4464
  int64_t        sliding;
4465
  char*          dstTbName;  // for dstVgroup
4466
  char*          expr;       // sma expression
4467
  char*          tagsFilter;
4468
  SSchemaWrapper schemaRow;  // for dstVgroup
4469
  SSchemaWrapper schemaTag;  // for dstVgroup
4470
} STSma;                     // Time-range-wise SMA
4471

4472
typedef STSma SVCreateTSmaReq;
4473

4474
typedef struct {
4475
  int8_t  type;  // 0 status report, 1 update data
4476
  int64_t indexUid;
4477
  int64_t skey;  // start TS key of interval/sliding window
4478
} STSmaMsg;
4479

4480
typedef struct {
4481
  int64_t indexUid;
4482
  char    indexName[TSDB_INDEX_NAME_LEN];
4483
} SVDropTSmaReq;
4484

4485
typedef struct {
4486
  int tmp;  // TODO: to avoid compile error
4487
} SVCreateTSmaRsp, SVDropTSmaRsp;
4488

4489
#if 0
4490
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4491
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4492
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4493
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4494
#endif
4495

4496
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4497
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4498
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4499
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4500

4501
typedef struct {
4502
  int32_t number;
4503
  STSma*  tSma;
4504
} STSmaWrapper;
4505

4506
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4507
  if (pSma) {
×
4508
    taosMemoryFreeClear(pSma->dstTbName);
×
4509
    taosMemoryFreeClear(pSma->expr);
×
4510
    taosMemoryFreeClear(pSma->tagsFilter);
×
4511
  }
4512
}
×
4513

4514
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4515
  if (pSW) {
×
4516
    if (pSW->tSma) {
×
4517
      if (deepCopy) {
×
4518
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4519
          tDestroyTSma(pSW->tSma + i);
×
4520
        }
4521
      }
4522
      taosMemoryFreeClear(pSW->tSma);
×
4523
    }
4524
  }
4525
}
×
4526

4527
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4528
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4529
  taosMemoryFreeClear(pSW);
×
4530
  return NULL;
×
4531
}
4532

4533
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4534
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4535

4536
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4537
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4538

4539
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4540
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4541
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4542
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4543
  }
4544
  return 0;
×
4545
}
4546

4547
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4548
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4549
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4550
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4551
  }
4552
  return 0;
×
4553
}
4554

4555
typedef struct {
4556
  int idx;
4557
} SMCreateFullTextReq;
4558

4559
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4560
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4561
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4562

4563
typedef struct {
4564
  char   name[TSDB_TABLE_FNAME_LEN];
4565
  int8_t igNotExists;
4566
} SMDropFullTextReq;
4567

4568
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4569
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4570

4571
typedef struct {
4572
  char indexFName[TSDB_INDEX_FNAME_LEN];
4573
} SUserIndexReq;
4574

4575
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4576
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4577

4578
typedef struct {
4579
  char dbFName[TSDB_DB_FNAME_LEN];
4580
  char tblFName[TSDB_TABLE_FNAME_LEN];
4581
  char colName[TSDB_COL_NAME_LEN];
4582
  char indexType[TSDB_INDEX_TYPE_LEN];
4583
  char indexExts[TSDB_INDEX_EXTS_LEN];
4584
} SUserIndexRsp;
4585

4586
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4587
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4588

4589
typedef struct {
4590
  char tbFName[TSDB_TABLE_FNAME_LEN];
4591
} STableIndexReq;
4592

4593
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4594
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4595

4596
typedef struct {
4597
  int8_t  intervalUnit;
4598
  int8_t  slidingUnit;
4599
  int64_t interval;
4600
  int64_t offset;
4601
  int64_t sliding;
4602
  int64_t dstTbUid;
4603
  int32_t dstVgId;
4604
  SEpSet  epSet;
4605
  char*   expr;
4606
} STableIndexInfo;
4607

4608
typedef struct {
4609
  char     tbName[TSDB_TABLE_NAME_LEN];
4610
  char     dbFName[TSDB_DB_FNAME_LEN];
4611
  uint64_t suid;
4612
  int32_t  version;
4613
  int32_t  indexSize;
4614
  SArray*  pIndex;  // STableIndexInfo
4615
} STableIndexRsp;
4616

4617
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4618
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4619
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4620

4621
void tFreeSTableIndexInfo(void* pInfo);
4622

4623
typedef struct {
4624
  int8_t  mqMsgType;
4625
  int32_t code;
4626
  int32_t epoch;
4627
  int64_t consumerId;
4628
  int64_t walsver;
4629
  int64_t walever;
4630
} SMqRspHead;
4631

4632
typedef struct {
4633
  SMsgHead     head;
4634
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4635
  int8_t       withTbName;
4636
  int8_t       useSnapshot;
4637
  int32_t      epoch;
4638
  uint64_t     reqId;
4639
  int64_t      consumerId;
4640
  int64_t      timeout;
4641
  STqOffsetVal reqOffset;
4642
  int8_t       enableReplay;
4643
  int8_t       sourceExcluded;
4644
  int8_t       rawData;
4645
  int32_t      minPollRows;
4646
  int8_t       enableBatchMeta;
4647
  SHashObj*    uidHash;  // to find if uid is duplicated
4648
} SMqPollReq;
4649

4650
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4651
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4652
void    tDestroySMqPollReq(SMqPollReq* pReq);
4653

4654
typedef struct {
4655
  int32_t vgId;
4656
  int64_t offset;
4657
  SEpSet  epSet;
4658
} SMqSubVgEp;
4659

4660
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4661
  int32_t tlen = 0;
38✔
4662
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
38✔
4663
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
38✔
4664
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
38✔
4665
  return tlen;
38✔
4666
}
4667

4668
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4669
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
19!
4670
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
19!
4671
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
19✔
4672
  return buf;
19✔
4673
}
4674

4675
typedef struct {
4676
  char           topic[TSDB_TOPIC_FNAME_LEN];
4677
  char           db[TSDB_DB_FNAME_LEN];
4678
  SArray*        vgs;  // SArray<SMqSubVgEp>
4679
  SSchemaWrapper schema;
4680
} SMqSubTopicEp;
4681

4682
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4683
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4684
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4685

4686
typedef struct {
4687
  SMqRspHead   head;
4688
  STqOffsetVal rspOffset;
4689
  int16_t      resMsgType;
4690
  int32_t      metaRspLen;
4691
  void*        metaRsp;
4692
} SMqMetaRsp;
4693

4694
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4695
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4696
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4697

4698
#define MQ_DATA_RSP_VERSION 100
4699

4700
typedef struct {
4701
  SMqRspHead   head;
4702
  STqOffsetVal rspOffset;
4703
  STqOffsetVal reqOffset;
4704
  int32_t      blockNum;
4705
  int8_t       withTbName;
4706
  int8_t       withSchema;
4707
  SArray*      blockDataLen;
4708
  SArray*      blockData;
4709
  SArray*      blockTbName;
4710
  SArray*      blockSchema;
4711

4712
  union {
4713
    struct {
4714
      int64_t sleepTime;
4715
    };
4716
    struct {
4717
      int32_t createTableNum;
4718
      SArray* createTableLen;
4719
      SArray* createTableReq;
4720
    };
4721
    struct {
4722
      int32_t len;
4723
      void*   rawData;
4724
    };
4725
  };
4726
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4727
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4728
} SMqDataRsp;
4729

4730
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4731
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4732
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4733
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4734
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4735

4736
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4737
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4738
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4739

4740
typedef struct SMqBatchMetaRsp {
4741
  SMqRspHead   head;  // not serialize
4742
  STqOffsetVal rspOffset;
4743
  SArray*      batchMetaLen;
4744
  SArray*      batchMetaReq;
4745
  void*        pMetaBuff;    // not serialize
4746
  uint32_t     metaBuffLen;  // not serialize
4747
} SMqBatchMetaRsp;
4748

4749
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4750
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4751
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4752
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4753

4754
typedef struct {
4755
  SMqRspHead head;
4756
  char       cgroup[TSDB_CGROUP_LEN];
4757
  SArray*    topics;  // SArray<SMqSubTopicEp>
4758
} SMqAskEpRsp;
4759

4760
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4761
  int32_t tlen = 0;
62✔
4762
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4763
  int32_t sz = taosArrayGetSize(pRsp->topics);
62!
4764
  tlen += taosEncodeFixedI32(buf, sz);
62✔
4765
  for (int32_t i = 0; i < sz; i++) {
106✔
4766
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
44✔
4767
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
44✔
4768
  }
4769
  return tlen;
62✔
4770
}
4771

4772
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4773
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4774
  int32_t sz;
4775
  buf = taosDecodeFixedI32(buf, &sz);
31✔
4776
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
31✔
4777
  if (pRsp->topics == NULL) {
31!
4778
    return NULL;
×
4779
  }
4780
  for (int32_t i = 0; i < sz; i++) {
53✔
4781
    SMqSubTopicEp topicEp;
4782
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
22✔
4783
    if (buf == NULL) {
22!
4784
      return NULL;
×
4785
    }
4786
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
44!
4787
      return NULL;
×
4788
    }
4789
  }
4790
  return buf;
31✔
4791
}
4792

4793
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4794
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
92✔
4795
}
92✔
4796

4797
typedef struct {
4798
  int32_t      vgId;
4799
  STqOffsetVal offset;
4800
  int64_t      rows;
4801
  int64_t      ever;
4802
} OffsetRows;
4803

4804
typedef struct {
4805
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4806
  SArray* offsetRows;
4807
} TopicOffsetRows;
4808

4809
typedef struct {
4810
  int64_t consumerId;
4811
  int32_t epoch;
4812
  SArray* topics;
4813
  int8_t  pollFlag;
4814
} SMqHbReq;
4815

4816
typedef struct {
4817
  char   topic[TSDB_TOPIC_FNAME_LEN];
4818
  int8_t noPrivilege;
4819
} STopicPrivilege;
4820

4821
typedef struct {
4822
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4823
  int32_t debugFlag;
4824
} SMqHbRsp;
4825

4826
typedef struct {
4827
  SMsgHead head;
4828
  int64_t  consumerId;
4829
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4830
} SMqSeekReq;
4831

4832
#define TD_AUTO_CREATE_TABLE 0x1
4833
typedef struct {
4834
  int64_t       suid;
4835
  int64_t       uid;
4836
  int32_t       sver;
4837
  uint32_t      nData;
4838
  uint8_t*      pData;
4839
  SVCreateTbReq cTbReq;
4840
} SVSubmitBlk;
4841

4842
typedef struct {
4843
  SMsgHead header;
4844
  uint64_t sId;
4845
  uint64_t queryId;
4846
  uint64_t clientId;
4847
  uint64_t taskId;
4848
  uint32_t sqlLen;
4849
  uint32_t phyLen;
4850
  char*    sql;
4851
  char*    msg;
4852
  int8_t   source;
4853
} SVDeleteReq;
4854

4855
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4856
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4857

4858
typedef struct {
4859
  int64_t affectedRows;
4860
} SVDeleteRsp;
4861

4862
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4863
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4864

4865
typedef struct SDeleteRes {
4866
  uint64_t suid;
4867
  SArray*  uidList;
4868
  int64_t  skey;
4869
  int64_t  ekey;
4870
  int64_t  affectedRows;
4871
  char     tableFName[TSDB_TABLE_NAME_LEN];
4872
  char     tsColName[TSDB_COL_NAME_LEN];
4873
  int64_t  ctimeMs;  // fill by vnode
4874
  int8_t   source;
4875
} SDeleteRes;
4876

4877
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4878
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4879

4880
typedef struct {
4881
  // int64_t uid;
4882
  char    tbname[TSDB_TABLE_NAME_LEN];
4883
  int64_t startTs;
4884
  int64_t endTs;
4885
} SSingleDeleteReq;
4886

4887
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4888
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4889

4890
typedef struct {
4891
  int64_t suid;
4892
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4893
  int64_t ctimeMs;     // fill by vnode
4894
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4895
} SBatchDeleteReq;
4896

4897
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4898
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4899
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4900

4901
typedef struct {
4902
  int32_t msgIdx;
4903
  int32_t msgType;
4904
  int32_t msgLen;
4905
  void*   msg;
4906
} SBatchMsg;
4907

4908
typedef struct {
4909
  SMsgHead header;
4910
  SArray*  pMsgs;  // SArray<SBatchMsg>
4911
} SBatchReq;
4912

4913
typedef struct {
4914
  int32_t reqType;
4915
  int32_t msgIdx;
4916
  int32_t msgLen;
4917
  int32_t rspCode;
4918
  void*   msg;
4919
} SBatchRspMsg;
4920

4921
typedef struct {
4922
  SArray* pRsps;  // SArray<SBatchRspMsg>
4923
} SBatchRsp;
4924

4925
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4926
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4927
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
109✔
4928
  if (NULL == msg) {
109!
4929
    return;
×
4930
  }
4931
  SBatchMsg* pMsg = (SBatchMsg*)msg;
109✔
4932
  taosMemoryFree(pMsg->msg);
109!
4933
}
4934

4935
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4936
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4937

4938
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
158✔
4939
  if (NULL == p) {
158!
4940
    return;
×
4941
  }
4942

4943
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
158✔
4944
  taosMemoryFree(pRsp->msg);
158!
4945
}
4946

4947
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4948
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4949
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4950
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4951
void    tDestroySMqHbReq(SMqHbReq* pReq);
4952

4953
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4954
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4955
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4956

4957
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4958
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4959

4960
#define TD_REQ_FROM_APP               0x0
4961
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4962
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4963
#define SUBMIT_REQ_FROM_FILE          0x4
4964
#define TD_REQ_FROM_TAOX              0x8
4965
#define TD_REQ_FROM_SML               0x10
4966
#define SUBMIT_REQUEST_VERSION        (1)
4967

4968
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4969

4970
typedef struct {
4971
  int32_t        flags;
4972
  SVCreateTbReq* pCreateTbReq;
4973
  int64_t        suid;
4974
  int64_t        uid;
4975
  int32_t        sver;
4976
  union {
4977
    SArray* aRowP;
4978
    SArray* aCol;
4979
  };
4980
  int64_t ctimeMs;
4981
} SSubmitTbData;
4982

4983
typedef struct {
4984
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4985
  bool    raw;
4986
} SSubmitReq2;
4987

4988
typedef struct {
4989
  SMsgHead header;
4990
  int64_t  version;
4991
  char     data[];  // SSubmitReq2
4992
} SSubmitReq2Msg;
4993

4994
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4995
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4996
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4997
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4998
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4999

5000
typedef struct {
5001
  int32_t affectedRows;
5002
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5003
} SSubmitRsp2;
5004

5005
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5006
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5007
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5008

5009
#define TSDB_MSG_FLG_ENCODE 0x1
5010
#define TSDB_MSG_FLG_DECODE 0x2
5011
#define TSDB_MSG_FLG_CMPT   0x3
5012

5013
typedef struct {
5014
  union {
5015
    struct {
5016
      void*   msgStr;
5017
      int32_t msgLen;
5018
      int64_t ver;
5019
    };
5020
    void* pDataBlock;
5021
  };
5022
} SPackedData;
5023

5024
typedef struct {
5025
  char     fullname[TSDB_VIEW_FNAME_LEN];
5026
  char     name[TSDB_VIEW_NAME_LEN];
5027
  char     dbFName[TSDB_DB_FNAME_LEN];
5028
  char*    querySql;
5029
  char*    sql;
5030
  int8_t   orReplace;
5031
  int8_t   precision;
5032
  int32_t  numOfCols;
5033
  SSchema* pSchema;
5034
} SCMCreateViewReq;
5035

5036
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5037
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5038
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5039

5040
typedef struct {
5041
  char   fullname[TSDB_VIEW_FNAME_LEN];
5042
  char   name[TSDB_VIEW_NAME_LEN];
5043
  char   dbFName[TSDB_DB_FNAME_LEN];
5044
  char*  sql;
5045
  int8_t igNotExists;
5046
} SCMDropViewReq;
5047

5048
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5049
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5050
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5051

5052
typedef struct {
5053
  char fullname[TSDB_VIEW_FNAME_LEN];
5054
} SViewMetaReq;
5055
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5056
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5057

5058
typedef struct {
5059
  char     name[TSDB_VIEW_NAME_LEN];
5060
  char     dbFName[TSDB_DB_FNAME_LEN];
5061
  char*    user;
5062
  uint64_t dbId;
5063
  uint64_t viewId;
5064
  char*    querySql;
5065
  int8_t   precision;
5066
  int8_t   type;
5067
  int32_t  version;
5068
  int32_t  numOfCols;
5069
  SSchema* pSchema;
5070
} SViewMetaRsp;
5071
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5072
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5073
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5074
typedef struct {
5075
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5076
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5077
} STableTSMAInfoReq;
5078

5079
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5080
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5081

5082
typedef struct {
5083
  int32_t  funcId;
5084
  col_id_t colId;
5085
} STableTSMAFuncInfo;
5086

5087
typedef struct {
5088
  char     name[TSDB_TABLE_NAME_LEN];
5089
  uint64_t tsmaId;
5090
  char     targetTb[TSDB_TABLE_NAME_LEN];
5091
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5092
  char     tb[TSDB_TABLE_NAME_LEN];
5093
  char     dbFName[TSDB_DB_FNAME_LEN];
5094
  uint64_t suid;
5095
  uint64_t destTbUid;
5096
  uint64_t dbId;
5097
  int32_t  version;
5098
  int64_t  interval;
5099
  int8_t   unit;
5100
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5101
  SArray*  pTags;      // SArray<SSchema>
5102
  SArray*  pUsedCols;  // SArray<SSchema>
5103
  char*    ast;
5104

5105
  int64_t streamUid;
5106
  int64_t reqTs;
5107
  int64_t rspTs;
5108
  int64_t delayDuration;  // ms
5109
  bool    fillHistoryFinished;
5110

5111
  void*   streamAddr;  // for stream task, the address of the stream task
5112
} STableTSMAInfo;
5113

5114
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5115
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5116
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5117
void    tFreeTableTSMAInfo(void* p);
5118
void    tFreeAndClearTableTSMAInfo(void* p);
5119
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5120

5121
#define STSMAHbRsp            STableTSMAInfoRsp
5122
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5123
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5124
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5125

5126
typedef struct SDropCtbWithTsmaSingleVgReq {
5127
  SVgroupInfo vgInfo;
5128
  SArray*     pTbs;  // SVDropTbReq
5129
} SMDropTbReqsOnSingleVg;
5130

5131
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5132
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5133
void    tFreeSMDropTbReqOnSingleVg(void* p);
5134

5135
typedef struct SDropTbsReq {
5136
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5137
} SMDropTbsReq;
5138

5139
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5140
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5141
void    tFreeSMDropTbsReq(void*);
5142

5143
typedef struct SVFetchTtlExpiredTbsRsp {
5144
  SArray* pExpiredTbs;  // SVDropTbReq
5145
  int32_t vgId;
5146
} SVFetchTtlExpiredTbsRsp;
5147

5148
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5149
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5150

5151
void tFreeFetchTtlExpiredTbsRsp(void* p);
5152

5153
void setDefaultOptionsForField(SFieldWithOptions* field);
5154
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5155

5156
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5157
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5158

5159
#ifdef USE_MOUNT
5160
typedef struct {
5161
  char     mountName[TSDB_MOUNT_NAME_LEN];
5162
  int8_t   ignoreExist;
5163
  int16_t  nMounts;
5164
  int32_t* dnodeIds;
5165
  char**   mountPaths;
5166
  int32_t  sqlLen;
5167
  char*    sql;
5168
} SCreateMountReq;
5169

5170
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5171
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5172
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5173

5174
typedef struct {
5175
  char    mountName[TSDB_MOUNT_NAME_LEN];
5176
  int8_t  ignoreNotExists;
5177
  int32_t sqlLen;
5178
  char*   sql;
5179
} SDropMountReq;
5180

5181
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5182
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5183
void    tFreeSDropMountReq(SDropMountReq* pReq);
5184

5185
typedef struct {
5186
  char     mountName[TSDB_MOUNT_NAME_LEN];
5187
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5188
  int64_t  mountUid;
5189
  int32_t  dnodeId;
5190
  uint32_t valLen;
5191
  int8_t   ignoreExist;
5192
  void*    pVal;
5193
} SRetrieveMountPathReq;
5194

5195
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5196
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5197

5198
typedef struct {
5199
  // path
5200
  int32_t diskPrimary;
5201
  // vgInfo
5202
  int32_t  vgId;
5203
  int32_t  cacheLastSize;
5204
  int32_t  szPage;
5205
  int32_t  szCache;
5206
  uint64_t szBuf;
5207
  int8_t   cacheLast;
5208
  int8_t   standby;
5209
  int8_t   hashMethod;
5210
  uint32_t hashBegin;
5211
  uint32_t hashEnd;
5212
  int16_t  hashPrefix;
5213
  int16_t  hashSuffix;
5214
  int16_t  sttTrigger;
5215
  // syncInfo
5216
  int32_t replications;
5217
  // tsdbInfo
5218
  int8_t  precision;
5219
  int8_t  compression;
5220
  int8_t  slLevel;
5221
  int32_t daysPerFile;
5222
  int32_t keep0;
5223
  int32_t keep1;
5224
  int32_t keep2;
5225
  int32_t keepTimeOffset;
5226
  int32_t minRows;
5227
  int32_t maxRows;
5228
  int32_t tsdbPageSize;
5229
  int32_t ssChunkSize;
5230
  int32_t ssKeepLocal;
5231
  int8_t  ssCompact;
5232
  // walInfo
5233
  int32_t walFsyncPeriod;      // millisecond
5234
  int32_t walRetentionPeriod;  // secs
5235
  int32_t walRollPeriod;       // secs
5236
  int64_t walRetentionSize;
5237
  int64_t walSegSize;
5238
  int32_t walLevel;
5239
  // encryptInfo
5240
  int32_t encryptAlgorithm;
5241
  // SVState
5242
  int64_t committed;
5243
  int64_t commitID;
5244
  int64_t commitTerm;
5245
  // stats
5246
  int64_t numOfSTables;
5247
  int64_t numOfCTables;
5248
  int64_t numOfNTables;
5249
  // dbInfo
5250
  uint64_t dbId;
5251
} SMountVgInfo;
5252

5253
typedef struct {
5254
  SMCreateStbReq req;
5255
  SArray*        pColExts;  // element: column id
5256
  SArray*        pTagExts;  // element: tag id
5257
} SMountStbInfo;
5258

5259
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5260
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5261

5262
typedef struct {
5263
  char     dbName[TSDB_DB_FNAME_LEN];
5264
  uint64_t dbId;
5265
  SArray*  pVgs;      // SMountVgInfo
5266
  SArray*  pStbs;     // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5267
} SMountDbInfo;
5268

5269
typedef struct {
5270
  // common fields
5271
  char     mountName[TSDB_MOUNT_NAME_LEN];
5272
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5273
  int8_t   ignoreExist;
5274
  int64_t  mountUid;
5275
  int64_t  clusterId;
5276
  int32_t  dnodeId;
5277
  uint32_t valLen;
5278
  void*    pVal;
5279

5280
  // response fields
5281
  SArray* pDbs;  // SMountDbInfo
5282

5283
  // memory fields, no serialized
5284
  SArray*   pDisks[TFS_MAX_TIERS];
5285
  TdFilePtr pFile;
5286
} SMountInfo;
5287

5288
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5289
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5290
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5291

5292
typedef struct {
5293
  SCreateVnodeReq createReq;
5294
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5295
  char            mountName[TSDB_MOUNT_NAME_LEN];
5296
  int64_t         mountId;
5297
  int32_t         diskPrimary;
5298
  int32_t         mountVgId;
5299
  int64_t         committed;
5300
  int64_t         commitID;
5301
  int64_t         commitTerm;
5302
  int64_t         numOfSTables;
5303
  int64_t         numOfCTables;
5304
  int64_t         numOfNTables;
5305
} SMountVnodeReq;
5306

5307
int32_t tSerializeSMountVnodeReq(void *buf, int32_t *cBufLen, int32_t *tBufLen, SMountVnodeReq *pReq);
5308
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5309
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5310

5311
#endif  // USE_MOUNT
5312

5313
#pragma pack(pop)
5314

5315
#ifdef __cplusplus
5316
}
5317
#endif
5318

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