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

taosdata / TDengine / #4720

08 Sep 2025 08:43AM UTC coverage: 58.139% (-0.6%) from 58.762%
#4720

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

133181 of 292179 branches covered (45.58%)

Branch coverage included in aggregate %.

201691 of 283811 relevant lines covered (71.07%)

5442780.71 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

65
typedef uint16_t tmsg_t;
66

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

71

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

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

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

98

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,832,153✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,744,732!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
5,576,885!
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
6,584,581✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
6,584,581✔
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)) {
183!
901
    return TSDB_CODE_INVALID_PARA;
×
902
  }
903
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
183!
904
  if (pCmpr->pColCmpr == NULL) {
183!
905
    return terrno;
×
906
  }
907
  pCmpr->nCols = nCols;
183✔
908
  return 0;
183✔
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,535,698!
937

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

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

954
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
263,375✔
955
  if (pSchemaWrapper) {
6,151,929!
956
    taosMemoryFree(pSchemaWrapper->pSchema);
2,660,136!
957
    taosMemoryFree(pSchemaWrapper);
2,660,140!
958
  }
959
}
6,021,658✔
960

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

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

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

987
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
988
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
103,445,172!
989
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
157,702,860!
990
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
157,702,860!
991
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
157,702,860!
992
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
157,702,860!
993
  return 0;
78,851,430✔
994
}
995

996
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
997
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
118,756,451!
998
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
236,578,943!
999
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
236,285,198!
1000
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
236,276,861!
1001
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
118,234,485!
1002
  return 0;
118,378,793✔
1003
}
1004

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

1012
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1013
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
520,236!
1014
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
520,236!
1015
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
520,235!
1016
  return 0;
260,117✔
1017
}
1018

1019
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1020
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
35,728!
1021
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
35,728!
1022
  if (pColRef->hasRef) {
17,864✔
1023
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
21,644!
1024
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
21,644!
1025
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
21,644!
1026
  }
1027
  return 0;
17,864✔
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;
7,732✔
1044
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
7,732✔
1045
  tlen += taosEncodeVariantI32(buf, pSW->version);
7,732✔
1046
  for (int32_t i = 0; i < pSW->nCols; i++) {
67,422✔
1047
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
119,380!
1048
  }
1049
  return tlen;
7,732✔
1050
}
1051

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

1061
    for (int32_t i = 0; i < pSW->nCols; i++) {
5,055✔
1062
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
8,894✔
1063
    }
1064
  } else {
1065
    pSW->pSchema = NULL;
40✔
1066
  }
1067
  return (void*)buf;
648✔
1068
}
1069

1070
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1071
  if (pSW == NULL) {
703,633!
1072
    return TSDB_CODE_INVALID_PARA;
×
1073
  }
1074
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,407,266!
1075
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,407,266!
1076
  for (int32_t i = 0; i < pSW->nCols; i++) {
54,961,321!
1077
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
108,515,376!
1078
  }
1079
  return 0;
703,633✔
1080
}
1081

1082
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1083
  if (pSW == NULL) {
167,379!
1084
    return TSDB_CODE_INVALID_PARA;
×
1085
  }
1086
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
334,811!
1087
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
334,867!
1088

1089
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
167,435✔
1090
  if (pSW->pSchema == NULL) {
167,353!
1091
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1092
  }
1093
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,431,272✔
1094
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
8,527,417!
1095
  }
1096

1097
  return 0;
167,774✔
1098
}
1099

1100
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1101
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
13,432,774!
1102
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
13,447,061!
1103

1104
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
6,723,316!
1105
  if (pSW->pSchema == NULL) {
6,726,755!
1106
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1107
  }
1108
  for (int32_t i = 0; i < pSW->nCols; i++) {
120,421,299!
1109
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
227,416,759!
1110
  }
1111

1112
  return 0;
6,699,084✔
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

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

1797
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1798
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
1799

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

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

1810

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

1819
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1820
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
1821

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

1829
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1830
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
1831

1832

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

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

1851
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1852
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
1853

1854

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

1862
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1863
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1864

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

1919
typedef SDbCfgRsp SDbCfgInfo;
1920

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

1927
typedef struct {
1928
  int32_t rowNum;
1929
} SQnodeListReq;
1930

1931
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1932
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1933

1934
typedef struct {
1935
  int32_t rowNum;
1936
} SDnodeListReq;
1937

1938
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1939

1940
typedef struct {
1941
  int32_t useless;  // useless
1942
} SServerVerReq;
1943

1944
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1945
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1946

1947
typedef struct {
1948
  char ver[TSDB_VERSION_LEN];
1949
} SServerVerRsp;
1950

1951
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1952
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1953

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

1959
typedef struct {
1960
  SQueryNodeAddr addr;
1961
  uint64_t       load;
1962
} SQueryNodeLoad;
1963

1964
typedef struct {
1965
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1966
} SQnodeListRsp;
1967

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

1972
typedef struct SDNodeAddr {
1973
  int32_t nodeId;  // dnodeId
1974
  SEpSet  epSet;
1975
} SDNodeAddr;
1976

1977
typedef struct {
1978
  SArray* dnodeList;  // SArray<SDNodeAddr>
1979
} SDnodeListRsp;
1980

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

1985
typedef struct {
1986
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1987
} STableTSMAInfoRsp;
1988

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

1998
typedef struct {
1999
  SArray* pArray;  // Array of SDbHbRsp
2000
} SDbHbBatchRsp;
2001

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

2006
typedef struct {
2007
  SArray* pArray;  // Array of SGetUserAuthRsp
2008
} SUserAuthBatchRsp;
2009

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

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

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

2027
typedef struct {
2028
  int32_t compactId;
2029
  int8_t  bAccepted;
2030
} SCompactDbRsp;
2031

2032
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2033
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2034

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

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

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

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

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

2069
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2070
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2071

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

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

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

2096
typedef struct {
2097
  int32_t funcVersion;
2098
  int64_t funcCreatedTime;
2099
} SFuncExtraInfo;
2100

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

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

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

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

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

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

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

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

2200
typedef struct {
2201
  int32_t vgId;
2202
  int64_t nTimeSeries;
2203
} SVnodeLoadLite;
2204

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

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

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

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

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

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

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

2271
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2272
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2273

2274
typedef enum {
2275
  MONITOR_TYPE_COUNTER = 0,
2276
  MONITOR_TYPE_SLOW_LOG = 1,
2277
} MONITOR_TYPE;
2278

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

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

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

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

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

2310
typedef struct {
2311
  int32_t dnodeId;
2312
  int64_t clusterId;
2313
} SDnodeCfg;
2314

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

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

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

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

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

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

2355
typedef struct {
2356
  int32_t reserved;
2357
} SMTimerReq;
2358

2359
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2360
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2361

2362
typedef struct SOrphanTask {
2363
  int64_t streamId;
2364
  int32_t taskId;
2365
  int32_t nodeId;
2366
} SOrphanTask;
2367

2368
typedef struct SMStreamDropOrphanMsg {
2369
  SArray* pList;  // SArray<SOrphanTask>
2370
} SMStreamDropOrphanMsg;
2371

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

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

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

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

2438
typedef struct {
2439
  int32_t compactId;
2440
  int32_t vgId;
2441
  int32_t dnodeId;
2442
} SQueryCompactProgressReq;
2443

2444
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2445
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2446

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

2457
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2458
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2459

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

2468
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2469
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2470

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

2479
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2480
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2481

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

2491
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2492
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2493

2494
typedef struct {
2495
  int32_t compactId;
2496
  int32_t vgId;
2497
  int32_t dnodeId;
2498
} SVKillCompactReq;
2499

2500
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2501
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2502

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

2529
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2530
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2531

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

2545
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2546
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2547

2548
typedef struct {
2549
  int32_t vgId;
2550
  int8_t  disable;
2551
} SDisableVnodeWriteReq;
2552

2553
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2554
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2555

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

2565
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2566
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2567

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

2578
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2579
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2580

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

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

2601
typedef struct {
2602
  int32_t     numOfVgroups;
2603
  SVgroupInfo vgroups[];
2604
} SVgroupsInfo;
2605

2606
typedef struct {
2607
  STableMetaRsp* pMeta;
2608
} SMAlterStbRsp;
2609

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

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

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

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

2628
typedef struct {
2629
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2630
} SViewHbRsp;
2631

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

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

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

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

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

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

2671
typedef struct {
2672
  SArray* variables;  // SArray<SVariablesInfo>
2673
} SShowVariablesRsp;
2674

2675
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2676
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2677

2678
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2679

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

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

2696
typedef struct {
2697
  int64_t       showId;
2698
  STableMetaRsp tableMeta;
2699
} SShowRsp, SVShowTablesRsp;
2700

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

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

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

2721
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2722
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2723

2724
#define RETRIEVE_TABLE_RSP_VERSION         0
2725
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2726
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2727

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

2747
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2748

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

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

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

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

2783
typedef struct {
2784
  int32_t           numOfPlans;
2785
  SExplainExecInfo* subplanInfo;
2786
} SExplainRsp;
2787

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2885
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2886
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2887

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

2895

2896
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2897
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2898

2899

2900
typedef struct {
2901
  int32_t nodeId;
2902
  SEpSet  epSet;
2903
} SNodeEpSet;
2904

2905

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

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

2918

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

2929
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2930
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2931

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

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

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

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

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

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

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

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

2977
typedef struct {
2978
  int32_t vgId;
2979
  int32_t hbSeq;
2980
} SVArbHbReqMember;
2981

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

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

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

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

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

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

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

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

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

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

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

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

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

3053
typedef struct {
3054
  int32_t dnodeId;
3055
  char*   token;
3056
} SMArbUpdateGroupMember;
3057

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

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

3076
typedef struct {
3077
  SArray* updateArray;  // SMArbUpdateGroup
3078
} SMArbUpdateGroupBatchReq;
3079

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

3084
typedef struct {
3085
  char queryStrId[TSDB_QUERY_ID_LEN];
3086
} SKillQueryReq;
3087

3088
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3089
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3090

3091
typedef struct {
3092
  uint32_t connId;
3093
} SKillConnReq;
3094

3095
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3096
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3097

3098
typedef struct {
3099
  int32_t transId;
3100
} SKillTransReq;
3101

3102
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3103
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3104

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

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

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

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

3129
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3130
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3131

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

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

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

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

3157
typedef struct {
3158
  int32_t vgId;
3159
} SForceBecomeFollowerReq;
3160

3161
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3162
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3163

3164
typedef struct {
3165
  int32_t vgId;
3166
  bool    force;
3167
} SSplitVgroupReq;
3168

3169
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3170
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3171

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

3180
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3181
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3182

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

3188
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3189
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3190

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

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

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

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

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

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

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

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

3264
typedef struct SColIdPair {
3265
  col_id_t vtbColId;
3266
  col_id_t orgColId;
3267
} SColIdPair;
3268

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

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

3282
typedef struct STagScanOperatorParam {
3283
  tb_uid_t       vcUid;
3284
} STagScanOperatorParam;
3285

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

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

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

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

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

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

3331
typedef struct {
3332
  uint64_t queryId;
3333
  uint64_t taskId;
3334
  int8_t   action;
3335
} STaskAction;
3336

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

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

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

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

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

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

3372
typedef struct {
3373
  int32_t code;
3374
} STaskCancelRsp;
3375

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

3386
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3387
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3388

3389
typedef enum {
3390
  TASK_NOTIFY_FINISHED = 1,
3391
} ETaskNotifyType;
3392

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

3404
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3405
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3406

3407
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3408
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3409

3410
typedef struct {
3411
  int32_t code;
3412
} STaskDropRsp;
3413

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

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

3428
typedef struct SVgroupVer {
3429
  int32_t vgId;
3430
  int64_t ver;
3431
} SVgroupVer;
3432

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

3449
enum {
3450
  TOPIC_SUB_TYPE__DB = 1,
3451
  TOPIC_SUB_TYPE__TABLE,
3452
  TOPIC_SUB_TYPE__COLUMN,
3453
};
3454

3455
#define DEFAULT_MAX_POLL_INTERVAL  300000
3456
#define DEFAULT_SESSION_TIMEOUT    12000
3457
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3458
#define DEFAULT_MIN_POLL_ROWS      4096
3459

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

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

3475
typedef struct {
3476
  int64_t consumerId;
3477
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3478

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

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

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

3503
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
296!
3504
  tlen += taosEncodeFixedI32(buf, topicNum);
296✔
3505

3506
  for (int32_t i = 0; i < topicNum; i++) {
446✔
3507
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
300✔
3508
  }
3509

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

3521
  return tlen;
296✔
3522
}
3523

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

3530
  int32_t topicNum = 0;
1,011!
3531
  buf = taosDecodeFixedI32(buf, &topicNum);
1,011✔
3532

3533
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,011✔
3534
  if (pReq->topicNames == NULL) {
1,011!
3535
    return terrno;
×
3536
  }
3537
  for (int32_t i = 0; i < topicNum; i++) {
1,463✔
3538
    char* name = NULL;
452✔
3539
    buf = taosDecodeString(buf, &name);
452✔
3540
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
904!
3541
      return terrno;
×
3542
    }
3543
  }
3544

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

3561
  return 0;
1,011✔
3562
}
3563

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

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

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

3598
typedef struct {
3599
  int64_t status;
3600
} SMVSubscribeRsp;
3601

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

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

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

3621
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3622
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3623

3624
typedef struct {
3625
  int8_t reserved;
3626
} SMDropCgroupRsp;
3627

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

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

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

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

3659
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3660
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3661

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

3680
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3681
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3682

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

3689
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3690
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3691

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

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

3729
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3730
  if (NULL == req) {
268,138!
3731
    return;
199,323✔
3732
  }
3733

3734
  taosMemoryFreeClear(req->sql);
68,815!
3735
  taosMemoryFreeClear(req->name);
68,815!
3736
  taosMemoryFreeClear(req->comment);
68,843!
3737
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
68,843!
3738
    taosMemoryFreeClear(req->ctb.pTag);
68,468!
3739
    taosMemoryFreeClear(req->ctb.stbName);
68,460!
3740
    taosArrayDestroy(req->ctb.tagName);
68,474✔
3741
    req->ctb.tagName = NULL;
68,460✔
3742
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
375!
3743
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
375!
3744
  }
3745
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
68,835!
3746
  taosMemoryFreeClear(req->pExtSchemas);
68,835!
3747
  taosMemoryFreeClear(req->colRef.pColRef);
68,835!
3748
}
3749

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

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

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

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

3772
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3773
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3774

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

3783
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3784
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3785

3786
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3787
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3788

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

3798
typedef struct {
3799
  int32_t code;
3800
} SVDropTbRsp;
3801

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

3810
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3811
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3812

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

3821
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3822
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3823

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

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

3879
typedef struct {
3880
  int32_t        code;
3881
  STableMetaRsp* pMeta;
3882
} SVAlterTbRsp;
3883

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

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

3902
typedef struct {
3903
  SMsgHead head;
3904
} SUpdateTagValRsp;
3905

3906
typedef struct {
3907
  SMsgHead head;
3908
} SVShowTablesReq;
3909

3910
typedef struct {
3911
  SMsgHead head;
3912
  int32_t  id;
3913
} SVShowTablesFetchReq;
3914

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

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

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

3937
typedef struct {
3938
  int64_t tscRid;
3939
  int8_t  connType;
3940
} SClientHbKey;
3941

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

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

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

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

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

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

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

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

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

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

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

4032
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
38,037✔
4033

4034
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4035
  void* pIter = taosHashIterate(info, NULL);
63,271✔
4036
  while (pIter != NULL) {
120,065!
4037
    SKv* kv = (SKv*)pIter;
56,794✔
4038
    taosMemoryFreeClear(kv->value);
56,794!
4039
    pIter = taosHashIterate(info, pIter);
56,794✔
4040
  }
4041
}
63,271✔
4042

4043
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
28,227✔
4044
  SQueryDesc* desc = (SQueryDesc*)pDesc;
28,227✔
4045
  if (desc->subDesc) {
28,227✔
4046
    taosArrayDestroy(desc->subDesc);
28,211✔
4047
    desc->subDesc = NULL;
28,211✔
4048
  }
4049
}
28,227✔
4050

4051
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
75,481✔
4052
  SClientHbReq* req = (SClientHbReq*)pReq;
82,372✔
4053
  if (req->query) {
82,372!
4054
    if (req->query->queryDesc) {
70,174!
4055
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
5,789✔
4056
    }
4057
    taosMemoryFreeClear(req->query);
70,174!
4058
  }
4059

4060
  if (req->info) {
82,372!
4061
    tFreeReqKvHash(req->info);
63,271✔
4062
    taosHashCleanup(req->info);
63,271✔
4063
    req->info = NULL;
63,270✔
4064
  }
4065
}
69,165✔
4066

4067
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4068
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4069

4070
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4071
  if (pReq == NULL) return;
1,219!
4072
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
1,219✔
4073
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
1,219✔
4074
  taosMemoryFree(pReq);
1,219!
4075
}
4076

4077
static FORCE_INLINE void tFreeClientKv(void* pKv) {
22,106✔
4078
  SKv* kv = (SKv*)pKv;
22,106✔
4079
  if (kv) {
22,106!
4080
    taosMemoryFreeClear(kv->value);
22,106!
4081
  }
4082
}
22,106✔
4083

4084
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
75,477✔
4085
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
75,477✔
4086
  if (rsp->query) {
75,477✔
4087
    taosArrayDestroy(rsp->query->pQnodeList);
70,173✔
4088
    taosMemoryFreeClear(rsp->query);
70,172!
4089
  }
4090
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
75,477!
4091
}
13,206✔
4092

4093
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4094
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
46,590✔
4095
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
46,590✔
4096
}
46,591✔
4097

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

4102
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4103
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
91,780!
4104
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
91,780!
4105
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
91,780!
4106
  return 0;
45,890✔
4107
}
4108

4109
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4110
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
111,906!
4111
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
111,906!
4112
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
55,953!
4113
  if (pKv->value == NULL) {
55,953!
4114
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4115
  }
4116
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
55,953!
4117
  return 0;
55,953✔
4118
}
4119

4120
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4121
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
301,912!
4122
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
301,912!
4123
  return 0;
150,956✔
4124
}
4125

4126
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4127
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
150,956!
4128
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
150,957!
4129
  return 0;
75,479✔
4130
}
4131

4132
typedef struct {
4133
  int32_t vgId;
4134
  // TODO stas
4135
} SMqReportVgInfo;
4136

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

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

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

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

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

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

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

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

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

4236
typedef struct {
4237
  int8_t reserved;
4238
} SMqVDeleteRsp;
4239

4240
typedef struct {
4241
  char*   name;
4242
  int8_t  igNotExists;
4243
} SMDropStreamReq;
4244

4245
typedef struct {
4246
  int8_t reserved;
4247
} SMDropStreamRsp;
4248

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

4256
typedef struct {
4257
  int8_t reserved;
4258
} SVDropStreamTaskRsp;
4259

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

4264
typedef struct {
4265
  char*  name;
4266
  int8_t igNotExists;
4267
} SMPauseStreamReq;
4268

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

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

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

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

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

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

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

4318
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4319
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4320

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

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

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

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

4347
#define TQ_OFFSET_VERSION 1
4348

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

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

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

4380
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4381
  pOffsetVal->type = TMQ_OFFSET__LOG;
269,836✔
4382
  pOffsetVal->version = ver;
269,836✔
4383
}
269,836✔
4384

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

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

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

4401
typedef struct SMqVgOffset {
4402
  int64_t   consumerId;
4403
  STqOffset offset;
4404
} SMqVgOffset;
4405

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

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

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

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

4454
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4455
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4456

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

4465
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4466
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4467

4468
typedef SMDropSmaReq SDropTagIndexReq;
4469

4470
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4471
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4472

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

4495
typedef STSma SVCreateTSmaReq;
4496

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

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

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

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

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

4524
typedef struct {
4525
  int32_t number;
4526
  STSma*  tSma;
4527
} STSmaWrapper;
4528

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

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

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

4556
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4557
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4558

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

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

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

4578
typedef struct {
4579
  int idx;
4580
} SMCreateFullTextReq;
4581

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

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

4591
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4592
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4593

4594
typedef struct {
4595
  char indexFName[TSDB_INDEX_FNAME_LEN];
4596
} SUserIndexReq;
4597

4598
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4599
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4600

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

4609
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4610
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4611

4612
typedef struct {
4613
  char tbFName[TSDB_TABLE_FNAME_LEN];
4614
} STableIndexReq;
4615

4616
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4617
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4618

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

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

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

4644
void tFreeSTableIndexInfo(void* pInfo);
4645

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

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

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

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

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

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

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

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

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

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

4721
#define MQ_DATA_RSP_VERSION 100
4722

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

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

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

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

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

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

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

4783
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4784
  int32_t tlen = 0;
16,132✔
4785
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4786
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,132!
4787
  tlen += taosEncodeFixedI32(buf, sz);
16,132✔
4788
  for (int32_t i = 0; i < sz; i++) {
22,544✔
4789
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,412✔
4790
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,412✔
4791
  }
4792
  return tlen;
16,132✔
4793
}
4794

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

4816
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4817
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
10,585✔
4818
}
10,585✔
4819

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

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

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

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

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

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

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

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

4878
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4879
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4880

4881
typedef struct {
4882
  int64_t affectedRows;
4883
} SVDeleteRsp;
4884

4885
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4886
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4887

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

4900
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4901
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4902

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

4910
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4911
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4912

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

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

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

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

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

4944
typedef struct {
4945
  SArray* pRsps;  // SArray<SBatchRspMsg>
4946
} SBatchRsp;
4947

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

4958
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4959
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4960

4961
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
145,906✔
4962
  if (NULL == p) {
145,906!
4963
    return;
×
4964
  }
4965

4966
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
145,906✔
4967
  taosMemoryFree(pRsp->msg);
145,906!
4968
}
4969

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

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

4980
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4981
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4982

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

4993
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4994

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

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

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

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

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

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

5036
#define TSDB_MSG_FLG_ENCODE 0x1
5037
#define TSDB_MSG_FLG_DECODE 0x2
5038
#define TSDB_MSG_FLG_CMPT   0x3
5039

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

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

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

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

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

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

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

5106
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5107
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5108

5109
typedef struct {
5110
  int32_t  funcId;
5111
  col_id_t colId;
5112
} STableTSMAFuncInfo;
5113

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

5132
  int64_t streamUid;
5133
  int64_t reqTs;
5134
  int64_t rspTs;
5135
  int64_t delayDuration;  // ms
5136
  bool    fillHistoryFinished;
5137

5138
  void*   streamAddr;  // for stream task, the address of the stream task
5139
} STableTSMAInfo;
5140

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

5148
#define STSMAHbRsp            STableTSMAInfoRsp
5149
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5150
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5151
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5152

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

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

5162
typedef struct SDropTbsReq {
5163
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5164
} SMDropTbsReq;
5165

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

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

5175
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5176
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5177

5178
void tFreeFetchTtlExpiredTbsRsp(void* p);
5179

5180
void setDefaultOptionsForField(SFieldWithOptions* field);
5181
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5182

5183
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp *pRsp);
5184
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp *pRsp);
5185

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

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

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

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

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

5222
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5223
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5224

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

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

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

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

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

5307
  // response fields
5308
  SArray* pDbs;  // SMountDbInfo
5309

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

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

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

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

5338
#endif  // USE_MOUNT
5339

5340
#pragma pack(pop)
5341

5342
#ifdef __cplusplus
5343
}
5344
#endif
5345

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

© 2025 Coveralls, Inc