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

taosdata / TDengine / #4665

12 Aug 2025 07:34AM UTC coverage: 59.901% (-0.6%) from 60.536%
#4665

push

travis-ci

web-flow
Merge pull request #32547 from taosdata/refactor/wangxu/get-started-installer

refactor: get started for installer and docker

137370 of 291999 branches covered (47.04%)

Branch coverage included in aggregate %.

207872 of 284354 relevant lines covered (73.1%)

4846328.0 hits per line

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

40.34
/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) {
42,752,594✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
42,752,594✔
102
  int    segIdx = TMSG_SEG_CODE(type);
42,752,594✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
42,752,594✔
104
    return type < tMsgRangeDict[segIdx];
42,757,728✔
105
  }
106
  return false;
1✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
3,102,818✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
3,010,715!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
6,113,533!
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
7,725,766✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
7,725,766✔
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_UNUSED_1,
519
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
520
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
521
  QUERY_NODE_PHYSICAL_PLAN_FILL,
522
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
523
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
524
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
525
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
526
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
527
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
528
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
529
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
530
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
531
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
532
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
533
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
534
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
535
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
536
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
537
  QUERY_NODE_PHYSICAL_SUBPLAN,
538
  QUERY_NODE_PHYSICAL_PLAN,
539
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
540
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
541
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
542
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
543
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
544
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
545
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
546
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
547
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
548
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
549
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
550
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
551
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
552
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
553
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
554
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
555
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
556
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
557
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
558
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
559
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
560
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
561
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
562
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
563
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
564
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
565
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
566
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
567
} ENodeType;
568

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

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

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

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

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

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

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

617
typedef struct {
618
  int32_t contLen;
619
  int32_t vgId;
620
} SMsgHead;
621

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

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

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

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

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

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

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

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

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

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

705
typedef struct SVCTableMergeInfo {
706
  uint64_t uid;
707
  int32_t  numOfSrcTbls;
708
} SVCTableMergeInfo;
709

710
typedef struct {
711
  int32_t    nCols;
712
  SColRefEx* pColRefEx;
713
} SColRefExWrapper;
714

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

728
//
729

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

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

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

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

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

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

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

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

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

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

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

818
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
819

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

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

836
typedef struct {
837
  STypeMod typeMod;
838
} SExtSchema;
839

840
bool hasExtSchema(const SExtSchema* pExtSchema);
841

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

848
typedef struct {
849
  col_id_t id;
850
  uint32_t alg;
851
} SColCmpr;
852

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

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

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

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

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

896
  return pDstWrapper;
897
}
898

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

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

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

932
  taosMemoryFreeClear(pWrapper->pColCmpr);
933
  taosMemoryFreeClear(pWrapper);
934
}
935
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
936
  if (pSchemaWrapper->pSchema == NULL) return NULL;
2,717,972!
937

938
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
2,717,972!
939
  if (pSW == NULL) {
2,718,125!
940
    return NULL;
×
941
  }
942
  pSW->nCols = pSchemaWrapper->nCols;
2,718,125✔
943
  pSW->version = pSchemaWrapper->version;
2,718,125✔
944
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,718,125!
945
  if (pSW->pSchema == NULL) {
2,717,546!
946
    taosMemoryFree(pSW);
×
947
    return NULL;
×
948
  }
949

950
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
2,717,546✔
951
  return pSW;
2,717,546✔
952
}
953

954
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
270,759✔
955
  if (pSchemaWrapper) {
6,277,911!
956
    taosMemoryFree(pSchemaWrapper->pSchema);
2,712,087!
957
    taosMemoryFree(pSchemaWrapper);
2,712,110!
958
  }
959
}
6,145,762✔
960

961
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,215✔
962
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,215!
963
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,215!
964
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,215!
965
  }
966
}
1,215✔
967

968
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
969
  int32_t tlen = 0;
63,028✔
970
  tlen += taosEncodeFixedI8(buf, pSchema->type);
126,056✔
971
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
63,028!
972
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
63,028!
973
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
63,028!
974
  tlen += taosEncodeString(buf, pSchema->name);
63,028✔
975
  return tlen;
63,028✔
976
}
977

978
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
979
  buf = taosDecodeFixedI8(buf, &pSchema->type);
10,992✔
980
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
5,496✔
981
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
5,496!
982
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
5,496!
983
  buf = taosDecodeStringTo(buf, pSchema->name);
5,496✔
984
  return (void*)buf;
5,496✔
985
}
986

987
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
988
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
105,238,079!
989
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
161,108,342!
990
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
161,108,342!
991
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
161,108,342!
992
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
161,108,342!
993
  return 0;
80,554,171✔
994
}
995

996
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
997
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
122,677,064!
998
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
244,381,725!
999
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
244,207,274!
1000
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
244,235,418!
1001
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
122,174,259!
1002
  return 0;
122,305,036✔
1003
}
1004

1005
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1006
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
46,763,222!
1007
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
46,763,222!
1008
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
46,763,222!
1009
  return 0;
23,381,611✔
1010
}
1011

1012
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1013
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
535,133!
1014
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
535,129!
1015
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
535,129!
1016
  return 0;
267,566✔
1017
}
1018

1019
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1020
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
31,796!
1021
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
31,796!
1022
  if (pColRef->hasRef) {
15,898✔
1023
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
19,112!
1024
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
19,112!
1025
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
19,112!
1026
  }
1027
  return 0;
15,898✔
1028
}
1029

1030
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1031
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
2,008!
1032
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
2,008!
1033
  if (pColRef->hasRef) {
1,004✔
1034
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
788!
1035
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
788!
1036
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
788!
1037
  }
1038

1039
  return 0;
1,004✔
1040
}
1041

1042
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1043
  int32_t tlen = 0;
8,884✔
1044
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,884✔
1045
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,884✔
1046
  for (int32_t i = 0; i < pSW->nCols; i++) {
71,912✔
1047
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
126,056!
1048
  }
1049
  return tlen;
8,884✔
1050
}
1051

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

1061
    for (int32_t i = 0; i < pSW->nCols; i++) {
6,452✔
1062
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
10,992✔
1063
    }
1064
  } else {
1065
    pSW->pSchema = NULL;
40✔
1066
  }
1067
  return (void*)buf;
996✔
1068
}
1069

1070
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1071
  if (pSW == NULL) {
727,122!
1072
    return TSDB_CODE_INVALID_PARA;
×
1073
  }
1074
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,454,244!
1075
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,454,244!
1076
  for (int32_t i = 0; i < pSW->nCols; i++) {
56,597,385!
1077
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
111,740,526!
1078
  }
1079
  return 0;
727,122✔
1080
}
1081

1082
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1083
  if (pSW == NULL) {
168,779!
1084
    return TSDB_CODE_INVALID_PARA;
×
1085
  }
1086
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
337,545!
1087
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
337,499!
1088

1089
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
168,733!
1090
  if (pSW->pSchema == NULL) {
168,796!
1091
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1092
  }
1093
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,431,717✔
1094
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
8,526,221!
1095
  }
1096

1097
  return 0;
168,417✔
1098
}
1099

1100
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1101
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
14,288,865!
1102
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
14,304,299!
1103

1104
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
7,152,635!
1105
  if (pSW->pSchema == NULL) {
7,155,280!
1106
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1107
  }
1108
  for (int32_t i = 0; i < pSW->nCols; i++) {
124,755,940!
1109
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
235,223,889!
1110
  }
1111

1112
  return 0;
7,132,711✔
1113
}
1114

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

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

1152
typedef struct {
1153
  STableMetaRsp* pMeta;
1154
} SMCreateStbRsp;
1155

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

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

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

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

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

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

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

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

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

1217
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1218
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1219

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

1239
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1240
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1241

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

1253
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1254
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1255

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

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

1266
typedef struct SIpV4Range {
1267
  uint32_t ip;
1268
  uint32_t mask;
1269
} SIpV4Range;
1270

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

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

1284
typedef struct {
1285
  int32_t    num;
1286
  SIpV4Range pIpRange[];
1287
} SIpWhiteList;
1288

1289
typedef struct {
1290
  int32_t  num;
1291
  SIpRange pIpRanges[];
1292
} SIpWhiteListDual;
1293

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

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

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

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

1322
typedef struct {
1323
  int32_t dnodeId;
1324
  int64_t analVer;
1325
} SRetrieveAnalyticsAlgoReq;
1326

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

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

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

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

1370
typedef struct {
1371
  char user[TSDB_USER_LEN];
1372
} SGetUserAuthReq;
1373

1374
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1375
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1376

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

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

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

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

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

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

1429
typedef struct {
1430
  int64_t ipWhiteVer;
1431
} SRetrieveIpWhiteReq;
1432

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

1439
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1440
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1441

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

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

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

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

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

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

1482
typedef struct STimeWindow {
1483
  TSKEY skey;
1484
  TSKEY ekey;
1485
} STimeWindow;
1486

1487
typedef struct SQueryHint {
1488
  bool batchScan;
1489
} SQueryHint;
1490

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

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

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

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

1523
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1524

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

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

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

1557
typedef STableCfg STableCfgRsp;
1558

1559
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1560
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1561

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

1566
typedef struct {
1567
  SMsgHead header;
1568
  tb_uid_t suid;
1569
} SVSubTablesReq;
1570

1571
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1572
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1573

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

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

1583
typedef struct {
1584
  SMsgHead header;
1585
  tb_uid_t suid;
1586
} SVStbRefDbsReq;
1587

1588
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1589
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1590

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

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

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

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

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

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

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

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

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

1706
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1707
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1708

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

1714
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1715
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1716

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

1725
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1726
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1727

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

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

1754
typedef struct {
1755
  char db[TSDB_DB_FNAME_LEN];
1756
} SDbCfgReq;
1757

1758
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1759
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1760

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

1766
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1767
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1768

1769
typedef struct {
1770
  int32_t timestamp;
1771
} SVTrimDbReq;
1772

1773
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1774
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1775

1776
typedef struct {
1777
  char db[TSDB_DB_FNAME_LEN];
1778
} SSsMigrateDbReq;
1779

1780
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1781
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
1782

1783
typedef struct {
1784
  int32_t ssMigrateId;
1785
  bool    bAccepted;
1786
} SSsMigrateDbRsp;
1787

1788
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1789
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
1790

1791
typedef struct {
1792
  int32_t ssMigrateId;
1793
  int32_t nodeId; // node id of the leader vnode
1794
  int64_t timestamp;
1795
} SSsMigrateVgroupReq;
1796

1797
int32_t tSerializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1798
int32_t tDeserializeSSsMigrateVgroupReq(void* buf, int32_t bufLen, SSsMigrateVgroupReq* pReq);
1799

1800
typedef struct {
1801
  int32_t ssMigrateId;
1802
  int32_t vgId;   // vgroup id
1803
  int32_t nodeId; // node id of the leader vnode
1804
} SSsMigrateVgroupRsp;
1805

1806
int32_t tSerializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1807
int32_t tDeserializeSSsMigrateVgroupRsp(void* buf, int32_t bufLen, SSsMigrateVgroupRsp* pRsp);
1808

1809
typedef struct {
1810
  int32_t ssMigrateId;
1811
  int32_t vgId;
1812
} SQuerySsMigrateProgressReq;
1813

1814
int32_t tSerializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1815
int32_t tDeserializeSQuerySsMigrateProgressReq(void* buf, int32_t bufLen, SQuerySsMigrateProgressReq* pReq);
1816

1817
#define FILE_SET_MIGRATE_STATE_IN_PROGRESS  0
1818
#define FILE_SET_MIGRATE_STATE_SUCCEEDED    1
1819
#define FILE_SET_MIGRATE_STATE_SKIPPED      2
1820
#define FILE_SET_MIGRATE_STATE_FAILED       3
1821

1822
typedef struct {
1823
  int32_t fid;  // file set id
1824
  int32_t state;
1825
} SFileSetSsMigrateState;
1826

1827
typedef struct {
1828
  // if all taosd were restarted during the migration, then vnode migrate id will be 0,
1829
  // that's mnode will repeatedly request the migration progress. to avoid this, we need
1830
  // to save mnode migrate id in the response, so that mnode can drop it.
1831
  int32_t mnodeMigrateId; // migrate id requested by mnode
1832
  int32_t vnodeMigrateId; // migrate id reponsed by vnode
1833
  int32_t dnodeId;
1834
  int32_t vgId;
1835
  int64_t startTimeSec;
1836
  SArray* pFileSetStates;
1837
} SVnodeSsMigrateState;
1838

1839
int32_t tSerializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1840
int32_t tDeserializeSVnodeSsMigrateState(void* buf, int32_t bufLen, SVnodeSsMigrateState* pState);
1841
void tFreeSVnodeSsMigrateState(SVnodeSsMigrateState* pState);
1842

1843
typedef SVnodeSsMigrateState SQuerySsMigrateProgressRsp;
1844
#define tSerializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1845
  tSerializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1846
#define tDeserializeSQuerySsMigrateProgressRsp(buf, bufLen, pRsp) \
1847
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pRsp)
1848
#define tFreeSQuerySsMigrateProgressRsp(pRsp) \
1849
  tFreeSVnodeSsMigrateState(pRsp)
1850

1851
typedef SVnodeSsMigrateState SFollowerSsMigrateReq;
1852
#define tSerializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1853
  tSerializeSVnodeSsMigrateState(buf, bufLen, pReq)
1854
#define tDeserializeSFollowerSsMigrateReq(buf, bufLen, pReq) \
1855
  tDeserializeSVnodeSsMigrateState(buf, bufLen, pReq)
1856
#define tFreeSFollowerSsMigrateReq(pReq) \
1857
  tFreeSVnodeSsMigrateState(pReq)
1858

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

1866
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1867
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1868

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

1923
typedef SDbCfgRsp SDbCfgInfo;
1924

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

1931
typedef struct {
1932
  int32_t rowNum;
1933
} SQnodeListReq;
1934

1935
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1936
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1937

1938
typedef struct {
1939
  int32_t rowNum;
1940
} SDnodeListReq;
1941

1942
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1943

1944
typedef struct {
1945
  int32_t useless;  // useless
1946
} SServerVerReq;
1947

1948
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1949
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1950

1951
typedef struct {
1952
  char ver[TSDB_VERSION_LEN];
1953
} SServerVerRsp;
1954

1955
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1956
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1957

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

1963
typedef struct {
1964
  SQueryNodeAddr addr;
1965
  uint64_t       load;
1966
} SQueryNodeLoad;
1967

1968
typedef struct {
1969
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1970
} SQnodeListRsp;
1971

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

1976
typedef struct SDNodeAddr {
1977
  int32_t nodeId;  // dnodeId
1978
  SEpSet  epSet;
1979
} SDNodeAddr;
1980

1981
typedef struct {
1982
  SArray* dnodeList;  // SArray<SDNodeAddr>
1983
} SDnodeListRsp;
1984

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

1989
typedef struct {
1990
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1991
} STableTSMAInfoRsp;
1992

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

2002
typedef struct {
2003
  SArray* pArray;  // Array of SDbHbRsp
2004
} SDbHbBatchRsp;
2005

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

2010
typedef struct {
2011
  SArray* pArray;  // Array of SGetUserAuthRsp
2012
} SUserAuthBatchRsp;
2013

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

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

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

2031
typedef struct {
2032
  int32_t compactId;
2033
  int8_t  bAccepted;
2034
} SCompactDbRsp;
2035

2036
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2037
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2038

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

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

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

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

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

2073
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2074
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2075

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

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

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

2100
typedef struct {
2101
  int32_t funcVersion;
2102
  int64_t funcCreatedTime;
2103
} SFuncExtraInfo;
2104

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2681
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2682

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2898

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

2902

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

2908

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

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

2921

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3524
  return tlen;
868✔
3525
}
3526

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

3533
  int32_t topicNum = 0;
1,301!
3534
  buf = taosDecodeFixedI32(buf, &topicNum);
1,301✔
3535

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

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

3564
  return 0;
1,301✔
3565
}
3566

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3732
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3733
  if (NULL == req) {
983,845!
3734
    return;
910,646✔
3735
  }
3736

3737
  taosMemoryFreeClear(req->sql);
73,199!
3738
  taosMemoryFreeClear(req->name);
73,199!
3739
  taosMemoryFreeClear(req->comment);
73,216!
3740
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
73,216!
3741
    taosMemoryFreeClear(req->ctb.pTag);
72,412!
3742
    taosMemoryFreeClear(req->ctb.stbName);
72,439!
3743
    taosArrayDestroy(req->ctb.tagName);
72,414✔
3744
    req->ctb.tagName = NULL;
72,401✔
3745
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
804!
3746
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
804!
3747
  }
3748
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
73,205!
3749
  taosMemoryFreeClear(req->pExtSchemas);
73,205!
3750
  taosMemoryFreeClear(req->colRef.pColRef);
73,205!
3751
}
3752

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4035
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
51,850✔
4036

4037
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4038
  void* pIter = taosHashIterate(info, NULL);
72,527✔
4039
  while (pIter != NULL) {
140,275!
4040
    SKv* kv = (SKv*)pIter;
67,747✔
4041
    taosMemoryFreeClear(kv->value);
67,747!
4042
    pIter = taosHashIterate(info, pIter);
67,747✔
4043
  }
4044
}
72,528✔
4045

4046
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
32,576✔
4047
  SQueryDesc* desc = (SQueryDesc*)pDesc;
32,576✔
4048
  if (desc->subDesc) {
32,576✔
4049
    taosArrayDestroy(desc->subDesc);
32,514✔
4050
    desc->subDesc = NULL;
32,514✔
4051
  }
4052
}
32,576✔
4053

4054
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
86,919✔
4055
  SClientHbReq* req = (SClientHbReq*)pReq;
94,280✔
4056
  if (req->query) {
94,280!
4057
    if (req->query->queryDesc) {
82,035!
4058
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
7,596✔
4059
    }
4060
    taosMemoryFreeClear(req->query);
82,035!
4061
  }
4062

4063
  if (req->info) {
94,279!
4064
    tFreeReqKvHash(req->info);
72,527✔
4065
    taosHashCleanup(req->info);
72,528✔
4066
    req->info = NULL;
72,528✔
4067
  }
4068
}
74,489✔
4069

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

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

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

4087
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
86,044✔
4088
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
86,044✔
4089
  if (rsp->query) {
86,044✔
4090
    taosArrayDestroy(rsp->query->pQnodeList);
81,162✔
4091
    taosMemoryFreeClear(rsp->query);
81,161!
4092
  }
4093
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
86,043!
4094
}
18,918✔
4095

4096
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4097
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
53,274✔
4098
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
53,274✔
4099
}
53,275✔
4100

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

4105
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4106
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
124,336!
4107
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
124,336!
4108
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
124,336!
4109
  return 0;
62,168✔
4110
}
4111

4112
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4113
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
124,886!
4114
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
124,886!
4115
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
62,443!
4116
  if (pKv->value == NULL) {
62,443!
4117
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4118
  }
4119
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
62,443!
4120
  return 0;
62,443✔
4121
}
4122

4123
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4124
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
347,666!
4125
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
347,666!
4126
  return 0;
173,833✔
4127
}
4128

4129
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4130
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
172,086!
4131
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
172,086!
4132
  return 0;
86,043✔
4133
}
4134

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4350
#define TQ_OFFSET_VERSION 1
4351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4471
typedef SMDropSmaReq SDropTagIndexReq;
4472

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

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

4498
typedef STSma SVCreateTSmaReq;
4499

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4647
void tFreeSTableIndexInfo(void* pInfo);
4648

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

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

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

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

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

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

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

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

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

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

4724
#define MQ_DATA_RSP_VERSION 100
4725

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

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

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

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

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

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

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

4786
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4787
  int32_t tlen = 0;
16,884✔
4788
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4789
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,884!
4790
  tlen += taosEncodeFixedI32(buf, sz);
16,884✔
4791
  for (int32_t i = 0; i < sz; i++) {
23,920✔
4792
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,036✔
4793
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,036✔
4794
  }
4795
  return tlen;
16,884✔
4796
}
4797

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

4819
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4820
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
11,852✔
4821
}
11,852✔
4822

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4964
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
154,735✔
4965
  if (NULL == p) {
154,735!
4966
    return;
×
4967
  }
4968

4969
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
154,735✔
4970
  taosMemoryFree(pRsp->msg);
154,735!
4971
}
4972

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

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

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

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

4996
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4997

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5181
void tFreeFetchTtlExpiredTbsRsp(void* p);
5182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5341
#endif  // USE_MOUNT
5342

5343
#pragma pack(pop)
5344

5345
#ifdef __cplusplus
5346
}
5347
#endif
5348

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