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

taosdata / TDengine / #4693

29 Aug 2025 06:36AM UTC coverage: 58.007% (-1.1%) from 59.151%
#4693

push

travis-ci

web-flow
fix(gpt): fix race-condition in preparing tmp files (#32800)

132676 of 291873 branches covered (45.46%)

Branch coverage included in aggregate %.

5 of 34 new or added lines in 6 files covered. (14.71%)

4288 existing lines in 199 files now uncovered.

201114 of 283561 relevant lines covered (70.92%)

5433357.08 hits per line

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

39.88
/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) {
34,676,789✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
34,676,789✔
102
  int    segIdx = TMSG_SEG_CODE(type);
34,676,789✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
34,676,789!
104
    return type < tMsgRangeDict[segIdx];
34,680,585✔
105
  }
UNCOV
106
  return false;
×
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,789,386✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,702,638!
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
5,492,024!
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
6,545,862✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
6,545,862✔
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,531,994!
937

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

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

954
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
264,428✔
955
  if (pSchemaWrapper) {
6,150,953!
956
    taosMemoryFree(pSchemaWrapper->pSchema);
2,656,664!
957
    taosMemoryFree(pSchemaWrapper);
2,656,694!
958
  }
959
}
6,020,073✔
960

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

968
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
969
  int32_t tlen = 0;
56,906✔
970
  tlen += taosEncodeFixedI8(buf, pSchema->type);
113,812✔
971
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
56,906!
972
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
56,906!
973
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
56,906!
974
  tlen += taosEncodeString(buf, pSchema->name);
56,906✔
975
  return tlen;
56,906✔
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));
102,358,987!
989
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
156,054,768!
990
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
156,054,768!
991
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
156,054,768!
992
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
156,054,768!
993
  return 0;
78,027,384✔
994
}
995

996
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
997
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
119,813,459!
998
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
238,694,626!
999
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
238,379,022!
1000
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
238,373,202!
1001
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
119,294,069!
1002
  return 0;
119,489,689✔
1003
}
1004

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

1012
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1013
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
519,001!
1014
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
519,003!
1015
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
519,004!
1016
  return 0;
259,502✔
1017
}
1018

1019
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1020
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
30,180!
1021
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
30,180!
1022
  if (pColRef->hasRef) {
15,090✔
1023
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
17,188!
1024
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
17,188!
1025
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
17,188!
1026
  }
1027
  return 0;
15,090✔
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,880✔
1044
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
7,880✔
1045
  tlen += taosEncodeVariantI32(buf, pSW->version);
7,880✔
1046
  for (int32_t i = 0; i < pSW->nCols; i++) {
64,786✔
1047
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
113,812!
1048
  }
1049
  return tlen;
7,880✔
1050
}
1051

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

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

1070
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1071
  if (pSW == NULL) {
713,042!
1072
    return TSDB_CODE_INVALID_PARA;
×
1073
  }
1074
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,426,084!
1075
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,426,084!
1076
  for (int32_t i = 0; i < pSW->nCols; i++) {
54,408,823!
1077
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
107,391,562!
1078
  }
1079
  return 0;
713,042✔
1080
}
1081

1082
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1083
  if (pSW == NULL) {
165,976!
1084
    return TSDB_CODE_INVALID_PARA;
×
1085
  }
1086
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
331,935!
1087
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
331,860!
1088

1089
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
165,901✔
1090
  if (pSW->pSchema == NULL) {
166,014!
1091
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1092
  }
1093
  for (int32_t i = 0; i < pSW->nCols; i++) {
4,441,827✔
1094
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
8,552,030!
1095
  }
1096

1097
  return 0;
165,610✔
1098
}
1099

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

1104
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
6,724,352!
1105
  if (pSW->pSchema == NULL) {
6,727,541!
1106
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1107
  }
1108
  for (int32_t i = 0; i < pSW->nCols; i++) {
121,522,694!
1109
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
229,607,829!
1110
  }
1111

1112
  return 0;
6,710,018✔
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
} SClusterCfg;
2124

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2677
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2678

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2894

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

2898

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

2904

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

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

2917

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3520
  return tlen;
298✔
3521
}
3522

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

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

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

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

3560
  return 0;
1,008✔
3561
}
3562

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3728
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3729
  if (NULL == req) {
267,141!
3730
    return;
198,763✔
3731
  }
3732

3733
  taosMemoryFreeClear(req->sql);
68,378!
3734
  taosMemoryFreeClear(req->name);
68,378!
3735
  taosMemoryFreeClear(req->comment);
68,383!
3736
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
68,383!
3737
    taosMemoryFreeClear(req->ctb.pTag);
68,040!
3738
    taosMemoryFreeClear(req->ctb.stbName);
68,072!
3739
    taosArrayDestroy(req->ctb.tagName);
68,060✔
3740
    req->ctb.tagName = NULL;
68,040✔
3741
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
343!
3742
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
343!
3743
  }
3744
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
68,383!
3745
  taosMemoryFreeClear(req->pExtSchemas);
68,383!
3746
  taosMemoryFreeClear(req->colRef.pColRef);
68,383!
3747
}
3748

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4031
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
42,983✔
4032

4033
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4034
  void* pIter = taosHashIterate(info, NULL);
69,181✔
4035
  while (pIter != NULL) {
126,139!
4036
    SKv* kv = (SKv*)pIter;
56,959✔
4037
    taosMemoryFreeClear(kv->value);
56,959!
4038
    pIter = taosHashIterate(info, pIter);
56,960✔
4039
  }
4040
}
69,180✔
4041

4042
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
36,777✔
4043
  SQueryDesc* desc = (SQueryDesc*)pDesc;
36,777✔
4044
  if (desc->subDesc) {
36,777✔
4045
    taosArrayDestroy(desc->subDesc);
36,769✔
4046
    desc->subDesc = NULL;
36,769✔
4047
  }
4048
}
36,777✔
4049

4050
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
87,457✔
4051
  SClientHbReq* req = (SClientHbReq*)pReq;
93,988✔
4052
  if (req->query) {
93,988!
4053
    if (req->query->queryDesc) {
82,242!
4054
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
9,742✔
4055
    }
4056
    taosMemoryFreeClear(req->query);
82,242!
4057
  }
4058

4059
  if (req->info) {
93,988!
4060
    tFreeReqKvHash(req->info);
69,181✔
4061
    taosHashCleanup(req->info);
69,180✔
4062
    req->info = NULL;
69,179✔
4063
  }
4064
}
74,595✔
4065

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

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

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

4083
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
87,455✔
4084
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
87,455✔
4085
  if (rsp->query) {
87,455✔
4086
    taosArrayDestroy(rsp->query->pQnodeList);
82,242✔
4087
    taosMemoryFreeClear(rsp->query);
82,242!
4088
  }
4089
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
87,455!
4090
}
19,391✔
4091

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

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

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

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

4119
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4120
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
350,130!
4121
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
350,130!
4122
  return 0;
175,065✔
4123
}
4124

4125
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4126
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
175,062!
4127
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
175,062!
4128
  return 0;
87,531✔
4129
}
4130

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4346
#define TQ_OFFSET_VERSION 1
4347

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4467
typedef SMDropSmaReq SDropTagIndexReq;
4468

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

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

4494
typedef STSma SVCreateTSmaReq;
4495

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4643
void tFreeSTableIndexInfo(void* pInfo);
4644

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

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

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

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

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

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

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

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

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

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

4720
#define MQ_DATA_RSP_VERSION 100
4721

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4992
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4993

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5177
void tFreeFetchTtlExpiredTbsRsp(void* p);
5178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

5337
#endif  // USE_MOUNT
5338

5339
#pragma pack(pop)
5340

5341
#ifdef __cplusplus
5342
}
5343
#endif
5344

5345
#endif /*_TD_COMMON_TAOS_MSG_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc