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

S
Shengliang Guan 已提交
16 17
#ifndef _TD_MND_DEF_H_
#define _TD_MND_DEF_H_
S
Shengliang Guan 已提交
18

19
#include "os.h"
S
Shengliang Guan 已提交
20 21

#include "cJSON.h"
L
Liu Jicong 已提交
22
#include "scheduler.h"
S
Shengliang Guan 已提交
23 24
#include "sync.h"
#include "thash.h"
L
Liu Jicong 已提交
25
#include "tlist.h"
S
Shengliang Guan 已提交
26
#include "tlog.h"
L
Liu Jicong 已提交
27
#include "tmsg.h"
S
Shengliang Guan 已提交
28
#include "trpc.h"
L
Liu Jicong 已提交
29
#include "tstream.h"
S
Shengliang Guan 已提交
30
#include "ttimer.h"
S
Shengliang Guan 已提交
31

S
Shengliang Guan 已提交
32
#include "mnode.h"
S
Shengliang Guan 已提交
33

S
Shengliang Guan 已提交
34 35 36
#ifdef __cplusplus
extern "C" {
#endif
S
Shengliang Guan 已提交
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
typedef enum {
  MND_OPER_CONNECT = 1,
  MND_OPER_CREATE_ACCT,
  MND_OPER_DROP_ACCT,
  MND_OPER_ALTER_ACCT,
  MND_OPER_CREATE_USER,
  MND_OPER_DROP_USER,
  MND_OPER_ALTER_USER,
  MND_OPER_CREATE_BNODE,
  MND_OPER_DROP_BNODE,
  MND_OPER_CREATE_DNODE,
  MND_OPER_DROP_DNODE,
  MND_OPER_CONFIG_DNODE,
  MND_OPER_CREATE_MNODE,
  MND_OPER_DROP_MNODE,
  MND_OPER_CREATE_QNODE,
  MND_OPER_DROP_QNODE,
  MND_OPER_CREATE_SNODE,
  MND_OPER_DROP_SNODE,
  MND_OPER_REDISTRIBUTE_VGROUP,
  MND_OPER_MERGE_VGROUP,
  MND_OPER_SPLIT_VGROUP,
  MND_OPER_BALANCE_VGROUP,
  MND_OPER_CREATE_FUNC,
  MND_OPER_DROP_FUNC,
  MND_OPER_KILL_TRANS,
  MND_OPER_KILL_CONN,
  MND_OPER_KILL_QUERY,
  MND_OPER_CREATE_DB,
  MND_OPER_ALTER_DB,
  MND_OPER_DROP_DB,
  MND_OPER_COMPACT_DB,
  MND_OPER_TRIM_DB,
  MND_OPER_USE_DB,
  MND_OPER_WRITE_DB,
  MND_OPER_READ_DB,
  MND_OPER_READ_OR_WRITE_DB,
  MND_OPER_SHOW_VARIBALES,
} EOperType;

S
Shengliang Guan 已提交
78
typedef enum {
79 80 81 82 83 84 85 86
  MND_AUTH_ACCT_START = 0,
  MND_AUTH_ACCT_USER,
  MND_AUTH_ACCT_DNODE,
  MND_AUTH_ACCT_MNODE,
  MND_AUTH_ACCT_DB,
  MND_AUTH_ACCT_TABLE,
  MND_AUTH_ACCT_MAX
} EAuthAcct;
S
Shengliang Guan 已提交
87 88

typedef enum {
89 90 91 92 93 94
  MND_AUTH_OP_START = 0,
  MND_AUTH_OP_CREATE_USER,
  MND_AUTH_OP_ALTER_USER,
  MND_AUTH_OP_DROP_USER,
  MND_AUTH_MAX
} EAuthOp;
S
Shengliang Guan 已提交
95

S
Shengliang Guan 已提交
96
typedef enum {
97 98 99
  TRN_CONFLICT_NOTHING = 0,
  TRN_CONFLICT_GLOBAL = 1,
  TRN_CONFLICT_DB = 2,
100
  TRN_CONFLICT_DB_INSIDE = 3,
101
} ETrnConflct;
S
Shengliang Guan 已提交
102

S
Shengliang Guan 已提交
103
typedef enum {
104
  TRN_STAGE_PREPARE = 0,
105 106 107 108 109 110
  TRN_STAGE_REDO_ACTION = 1,
  TRN_STAGE_ROLLBACK = 2,
  TRN_STAGE_UNDO_ACTION = 3,
  TRN_STAGE_COMMIT = 4,
  TRN_STAGE_COMMIT_ACTION = 5,
  TRN_STAGE_FINISHED = 6
S
Shengliang Guan 已提交
111 112
} ETrnStage;

S
Shengliang Guan 已提交
113 114 115 116
typedef enum {
  TRN_POLICY_ROLLBACK = 0,
  TRN_POLICY_RETRY = 1,
} ETrnPolicy;
S
Shengliang Guan 已提交
117

118
typedef enum {
119 120 121
  TRN_EXEC_PRARLLEL = 0,
  TRN_EXEC_SERIAL = 1,
} ETrnExec;
122

S
Shengliang Guan 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136
typedef enum {
  DND_REASON_ONLINE = 0,
  DND_REASON_STATUS_MSG_TIMEOUT,
  DND_REASON_STATUS_NOT_RECEIVED,
  DND_REASON_VERSION_NOT_MATCH,
  DND_REASON_DNODE_ID_NOT_MATCH,
  DND_REASON_CLUSTER_ID_NOT_MATCH,
  DND_REASON_STATUS_INTERVAL_NOT_MATCH,
  DND_REASON_TIME_ZONE_NOT_MATCH,
  DND_REASON_LOCALE_NOT_MATCH,
  DND_REASON_CHARSET_NOT_MATCH,
  DND_REASON_OTHERS
} EDndReason;

S
Shengliang Guan 已提交
137 138 139 140 141 142 143 144 145
typedef enum {
  CONSUMER_UPDATE__TOUCH = 1,
  CONSUMER_UPDATE__ADD,
  CONSUMER_UPDATE__REMOVE,
  CONSUMER_UPDATE__LOST,
  CONSUMER_UPDATE__RECOVER,
  CONSUMER_UPDATE__MODIFY,
} ECsmUpdateType;

S
Shengliang Guan 已提交
146
typedef struct {
L
Liu Jicong 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
  int32_t     id;
  ETrnStage   stage;
  ETrnPolicy  policy;
  ETrnConflct conflict;
  ETrnExec    exec;
  EOperType   oper;
  int32_t     code;
  int32_t     failedTimes;
  void*       rpcRsp;
  int32_t     rpcRspLen;
  int32_t     redoActionPos;
  SArray*     redoActions;
  SArray*     undoActions;
  SArray*     commitActions;
  int64_t     createdTime;
  int64_t     lastExecTime;
  int32_t     lastAction;
  int32_t     lastErrorNo;
  SEpSet      lastEpset;
166 167
  tmsg_t      lastMsgType;
  tmsg_t      originRpcType;
168 169
  char        dbname1[TSDB_TABLE_FNAME_LEN];
  char        dbname2[TSDB_TABLE_FNAME_LEN];
L
Liu Jicong 已提交
170 171 172 173 174
  int32_t     startFunc;
  int32_t     stopFunc;
  int32_t     paramLen;
  void*       param;
  SArray*     pRpcArray;
S
Shengliang Guan 已提交
175
} STrans;
S
Shengliang Guan 已提交
176

S
Shengliang Guan 已提交
177
typedef struct {
178
  int64_t id;
S
Shengliang Guan 已提交
179
  char    name[TSDB_CLUSTER_ID_LEN];
S
Shengliang Guan 已提交
180 181
  int64_t createdTime;
  int64_t updateTime;
182
  int32_t upTime;
S
Shengliang Guan 已提交
183 184
} SClusterObj;

S
Shengliang Guan 已提交
185
typedef struct {
S
Shengliang Guan 已提交
186 187 188 189
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  int64_t    rebootTime;
190
  int64_t    lastAccessTime;
S
Shengliang Guan 已提交
191
  int32_t    accessTimes;
S
Shengliang Guan 已提交
192
  int32_t    numOfVnodes;
S
Shengliang Guan 已提交
193
  int32_t    numOfSupportVnodes;
S
Shengliang Guan 已提交
194
  float      numOfCores;
195 196 197
  int64_t    memTotal;
  int64_t    memAvail;
  int64_t    memUsed;
S
Shengliang Guan 已提交
198 199 200 201
  EDndReason offlineReason;
  uint16_t   port;
  char       fqdn[TSDB_FQDN_LEN];
  char       ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
202 203
} SDnodeObj;

S
Shengliang Guan 已提交
204
typedef struct {
S
Shengliang Guan 已提交
205
  int32_t    id;
S
Shengliang Guan 已提交
206 207
  int64_t    createdTime;
  int64_t    updateTime;
208 209
  ESyncState state;
  int64_t    stateStartTime;
L
Liu Jicong 已提交
210
  SDnodeObj* pDnode;
S
Shengliang Guan 已提交
211 212
} SMnodeObj;

S
Shengliang Guan 已提交
213 214 215 216
typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
L
Liu Jicong 已提交
217
  SDnodeObj* pDnode;
L
Liu Jicong 已提交
218
  SQnodeLoad load;
S
Shengliang Guan 已提交
219 220 221 222 223 224
} SQnodeObj;

typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
L
Liu Jicong 已提交
225
  SDnodeObj* pDnode;
S
Shengliang Guan 已提交
226 227 228 229 230 231
} SSnodeObj;

typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
L
Liu Jicong 已提交
232
  SDnodeObj* pDnode;
S
Shengliang Guan 已提交
233 234
} SBnodeObj;

S
Shengliang Guan 已提交
235 236 237
typedef struct {
  int32_t maxUsers;
  int32_t maxDbs;
S
Shengliang Guan 已提交
238 239
  int32_t maxStbs;
  int32_t maxTbs;
S
Shengliang Guan 已提交
240 241
  int32_t maxTimeSeries;
  int32_t maxStreams;
S
Shengliang Guan 已提交
242 243 244 245
  int32_t maxFuncs;
  int32_t maxConsumers;
  int32_t maxConns;
  int32_t maxTopics;
246
  int64_t maxStorage;
S
Shengliang Guan 已提交
247
  int32_t accessState;  // Configured only by command
S
Shengliang Guan 已提交
248 249 250 251 252 253 254
} SAcctCfg;

typedef struct {
  int32_t numOfUsers;
  int32_t numOfDbs;
  int32_t numOfTimeSeries;
  int32_t numOfStreams;
S
Shengliang Guan 已提交
255 256
  int64_t totalStorage;  // Total storage wrtten from this account
  int64_t compStorage;   // Compressed storage on disk
S
Shengliang Guan 已提交
257 258
} SAcctInfo;

S
Shengliang Guan 已提交
259
typedef struct {
S
Shengliang Guan 已提交
260 261 262 263
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  int32_t   acctId;
S
Shengliang Guan 已提交
264
  int32_t   status;
S
Shengliang Guan 已提交
265 266 267 268
  SAcctCfg  cfg;
  SAcctInfo info;
} SAcctObj;

S
Shengliang Guan 已提交
269
typedef struct {
S
Shengliang Guan 已提交
270
  char      user[TSDB_USER_LEN];
271
  char      pass[TSDB_PASSWORD_LEN];
S
Shengliang Guan 已提交
272 273 274
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
275
  int8_t    superUser;
276 277 278
  int8_t    sysInfo;
  int8_t    enable;
  int8_t    reserve;
S
Shengliang Guan 已提交
279
  int32_t   acctId;
D
dapan 已提交
280
  int32_t   authVersion;
281 282
  SHashObj* readDbs;
  SHashObj* writeDbs;
S
Shengliang Guan 已提交
283
  SRWLatch  lock;
S
Shengliang Guan 已提交
284 285 286
} SUserObj;

typedef struct {
287
  int32_t numOfVgroups;
S
Shengliang Guan 已提交
288 289 290 291
  int32_t numOfStables;
  int32_t buffer;
  int32_t pageSize;
  int32_t pages;
292
  int32_t cacheLastSize;
S
Shengliang Guan 已提交
293 294 295 296
  int32_t daysPerFile;
  int32_t daysToKeep0;
  int32_t daysToKeep1;
  int32_t daysToKeep2;
S
Shengliang Guan 已提交
297 298
  int32_t minRows;
  int32_t maxRows;
299
  int32_t walFsyncPeriod;
S
Shengliang Guan 已提交
300
  int8_t  walLevel;
S
Shengliang Guan 已提交
301 302 303
  int8_t  precision;
  int8_t  compression;
  int8_t  replications;
S
Shengliang Guan 已提交
304 305
  int8_t  strict;
  int8_t  hashMethod;  // default is 1
306
  int8_t  cacheLast;
S
Shengliang Guan 已提交
307
  int8_t  schemaless;
S
sma  
Shengliang Guan 已提交
308 309
  int32_t numOfRetensions;
  SArray* pRetensions;
S
Shengliang Guan 已提交
310
  int32_t walRetentionPeriod;
L
Liu Jicong 已提交
311
  int64_t walRetentionSize;
S
Shengliang Guan 已提交
312
  int32_t walRollPeriod;
L
Liu Jicong 已提交
313
  int64_t walSegmentSize;
S
Shengliang Guan 已提交
314 315
} SDbCfg;

S
Shengliang Guan 已提交
316
typedef struct {
317 318 319 320 321 322 323 324 325 326
  char     name[TSDB_DB_FNAME_LEN];
  char     acct[TSDB_USER_LEN];
  char     createUser[TSDB_USER_LEN];
  int64_t  createdTime;
  int64_t  updateTime;
  int64_t  uid;
  int32_t  cfgVersion;
  int32_t  vgVersion;
  SDbCfg   cfg;
  SRWLatch lock;
S
Shengliang Guan 已提交
327 328 329 330
} SDbObj;

typedef struct {
  int32_t    dnodeId;
S
Shengliang Guan 已提交
331
  ESyncState role;
S
Shengliang Guan 已提交
332 333
} SVnodeGid;

S
Shengliang Guan 已提交
334
typedef struct {
S
Shengliang Guan 已提交
335
  int32_t   vgId;
S
Shengliang Guan 已提交
336 337
  int64_t   createdTime;
  int64_t   updateTime;
S
Shengliang Guan 已提交
338
  int32_t   version;
S
Shengliang Guan 已提交
339 340
  uint32_t  hashBegin;
  uint32_t  hashEnd;
341
  char      dbName[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
342
  int64_t   dbUid;
S
Shengliang Guan 已提交
343 344
  int64_t   numOfTables;
  int64_t   numOfTimeSeries;
S
Shengliang Guan 已提交
345 346 347
  int64_t   totalStorage;
  int64_t   compStorage;
  int64_t   pointsWritten;
S
Shengliang Guan 已提交
348
  int8_t    compact;
S
Shengliang Guan 已提交
349
  int8_t    isTsma;
S
Shengliang Guan 已提交
350 351
  int8_t    replica;
  SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
C
Cary Xu 已提交
352
  void*     pTsma;
S
Shengliang Guan 已提交
353 354
} SVgObj;

S
Shengliang Guan 已提交
355
typedef struct {
C
Cary Xu 已提交
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  char           name[TSDB_TABLE_FNAME_LEN];
  char           stb[TSDB_TABLE_FNAME_LEN];
  char           db[TSDB_DB_FNAME_LEN];
  char           dstTbName[TSDB_TABLE_FNAME_LEN];
  int64_t        createdTime;
  int64_t        uid;
  int64_t        stbUid;
  int64_t        dbUid;
  int64_t        dstTbUid;
  int8_t         intervalUnit;
  int8_t         slidingUnit;
  int8_t         timezone;
  int32_t        dstVgId;  // for stream
  int64_t        interval;
  int64_t        offset;
  int64_t        sliding;
  int32_t        exprLen;  // strlen + 1
  int32_t        tagsFilterLen;
  int32_t        sqlLen;
  int32_t        astLen;
  char*          expr;
  char*          tagsFilter;
  char*          sql;
  char*          ast;
  SSchemaWrapper schemaRow;  // for dstVgroup
  SSchemaWrapper schemaTag;  // for dstVgroup
S
Shengliang Guan 已提交
382 383
} SSmaObj;

S
Shengliang Guan 已提交
384
typedef struct {
S
Shengliang Guan 已提交
385
  char     name[TSDB_TABLE_FNAME_LEN];
386
  char     db[TSDB_DB_FNAME_LEN];
387 388
  int64_t  createdTime;
  int64_t  updateTime;
L
Liu Jicong 已提交
389 390
  int64_t  uid;
  int64_t  dbUid;
391 392
  int32_t  tagVer;
  int32_t  colVer;
D
dapan1121 已提交
393
  int32_t  smaVer;
S
Shengliang Guan 已提交
394
  int32_t  nextColId;
395
  int64_t  maxdelay[2];
S
Shengliang Guan 已提交
396
  int64_t  watermark[2];
S
sma  
Shengliang Guan 已提交
397
  int32_t  ttl;
S
Shengliang Guan 已提交
398 399
  int32_t  numOfColumns;
  int32_t  numOfTags;
S
Shengliang Guan 已提交
400
  int32_t  numOfFuncs;
S
sma  
Shengliang Guan 已提交
401
  int32_t  commentLen;
402 403
  int32_t  ast1Len;
  int32_t  ast2Len;
D
dapan1121 已提交
404
  SArray*  pFuncs;
S
Shengliang Guan 已提交
405
  SSchema* pColumns;
S
Shengliang Guan 已提交
406
  SSchema* pTags;
S
sma  
Shengliang Guan 已提交
407
  char*    comment;
408 409
  char*    pAst1;
  char*    pAst2;
S
Shengliang Guan 已提交
410
  SRWLatch lock;
S
Shengliang Guan 已提交
411
} SStbObj;
S
Shengliang Guan 已提交
412

S
Shengliang Guan 已提交
413
typedef struct {
S
Shengliang Guan 已提交
414 415
  char    name[TSDB_FUNC_NAME_LEN];
  int64_t createdTime;
S
Shengliang Guan 已提交
416 417 418 419 420 421
  int8_t  funcType;
  int8_t  scriptType;
  int8_t  align;
  int8_t  outputType;
  int32_t outputLen;
  int32_t bufSize;
S
Shengliang 已提交
422
  int64_t signature;
S
Shengliang Guan 已提交
423 424
  int32_t commentSize;
  int32_t codeSize;
L
Liu Jicong 已提交
425 426
  char*   pComment;
  char*   pCode;
S
Shengliang Guan 已提交
427 428
} SFuncObj;

S
Shengliang Guan 已提交
429
typedef struct {
L
Liu Jicong 已提交
430 431 432 433 434 435 436
  int64_t        id;
  int8_t         type;
  int8_t         replica;
  int16_t        numOfColumns;
  int32_t        numOfRows;
  void*          pIter;
  SMnode*        pMnode;
437
  STableMetaRsp* pMeta;
L
Liu Jicong 已提交
438 439
  bool           sysDbRsp;
  char           db[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
440 441
} SShowObj;

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
typedef struct {
  int64_t id;
  int8_t  type;
  int8_t  replica;
  int16_t numOfColumns;
  int32_t rowSize;
  int32_t numOfRows;
  int32_t numOfReads;
  int32_t payloadLen;
  void*   pIter;
  SMnode* pMnode;
  char    db[TSDB_DB_FNAME_LEN];
  int16_t offset[TSDB_MAX_COLUMNS];
  int32_t bytes[TSDB_MAX_COLUMNS];
  char    payload[];
} SSysTableRetrieveObj;

L
Liu Jicong 已提交
459 460
typedef struct {
  char    key[TSDB_PARTITION_KEY_LEN];
L
Liu Jicong 已提交
461
  int64_t dbUid;
L
Liu Jicong 已提交
462 463 464
  int64_t offset;
} SMqOffsetObj;

S
Shengliang Guan 已提交
465 466
int32_t tEncodeSMqOffsetObj(void** buf, const SMqOffsetObj* pOffset);
void*   tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset);
L
Liu Jicong 已提交
467

L
Liu Jicong 已提交
468
typedef struct {
L
Liu Jicong 已提交
469 470 471 472 473 474 475
  char           name[TSDB_TOPIC_FNAME_LEN];
  char           db[TSDB_DB_FNAME_LEN];
  int64_t        createTime;
  int64_t        updateTime;
  int64_t        uid;
  int64_t        dbUid;
  int32_t        version;
L
Liu Jicong 已提交
476 477
  int8_t         subType;   // column, db or stable
  int8_t         withMeta;  // TODO
L
Liu Jicong 已提交
478 479
  SRWLatch       lock;
  int32_t        sqlLen;
L
Liu Jicong 已提交
480
  int32_t        astLen;
L
Liu Jicong 已提交
481
  char*          sql;
L
Liu Jicong 已提交
482
  char*          ast;
L
Liu Jicong 已提交
483 484
  char*          physicalPlan;
  SSchemaWrapper schema;
L
Liu Jicong 已提交
485
  int64_t        stbUid;
L
Liu Jicong 已提交
486 487 488
  // forbid condition
  int64_t ntbUid;
  SArray* ntbColIds;
L
Liu Jicong 已提交
489
  int64_t ctbStbUid;
L
Liu Jicong 已提交
490 491
} SMqTopicObj;

L
Liu Jicong 已提交
492
typedef struct {
S
Shengliang Guan 已提交
493 494
  int64_t  consumerId;
  char     cgroup[TSDB_CGROUP_LEN];
L
Liu Jicong 已提交
495
  char     clientId[256];
S
Shengliang Guan 已提交
496 497 498 499 500
  int8_t   updateType;  // used only for update
  int32_t  epoch;
  int32_t  status;
  int32_t  hbStatus;          // hbStatus is not applicable to serialization
  SRWLatch lock;              // lock is used for topics update
L
Liu Jicong 已提交
501 502 503
  SArray*  currentTopics;     // SArray<char*>
  SArray*  rebNewTopics;      // SArray<char*>
  SArray*  rebRemovedTopics;  // SArray<char*>
L
Liu Jicong 已提交
504

L
Liu Jicong 已提交
505 506 507
  // subscribed by user
  SArray* assignedTopics;  // SArray<char*>

L
Liu Jicong 已提交
508 509 510 511 512 513
  // data for display
  int32_t pid;
  SEpSet  ep;
  int64_t upTime;
  int64_t subscribeTime;
  int64_t rebalanceTime;
L
Liu Jicong 已提交
514 515
} SMqConsumerObj;

516 517 518 519
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
void            tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer);
int32_t         tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer);
void*           tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer);
L
Liu Jicong 已提交
520

521 522 523
typedef struct {
  int32_t vgId;
  char*   qmsg;
L
Liu Jicong 已提交
524
  SEpSet  epSet;
525 526 527 528 529 530 531 532 533 534
} SMqVgEp;

SMqVgEp* tCloneSMqVgEp(const SMqVgEp* pVgEp);
void     tDeleteSMqVgEp(SMqVgEp* pVgEp);
int32_t  tEncodeSMqVgEp(void** buf, const SMqVgEp* pVgEp);
void*    tDecodeSMqVgEp(const void* buf, SMqVgEp* pVgEp);

typedef struct {
  int64_t consumerId;  // -1 for unassigned
  SArray* vgs;         // SArray<SMqVgEp*>
535
} SMqConsumerEp;
536

537 538 539 540
SMqConsumerEp* tCloneSMqConsumerEp(const SMqConsumerEp* pEp);
void           tDeleteSMqConsumerEp(SMqConsumerEp* pEp);
int32_t        tEncodeSMqConsumerEp(void** buf, const SMqConsumerEp* pEp);
void*          tDecodeSMqConsumerEp(const void* buf, SMqConsumerEp* pEp);
541 542

typedef struct {
L
Liu Jicong 已提交
543 544 545 546 547
  char      key[TSDB_SUBSCRIBE_KEY_LEN];
  SRWLatch  lock;
  int64_t   dbUid;
  int32_t   vgNum;
  int8_t    subType;
L
Liu Jicong 已提交
548
  int8_t    withMeta;
L
Liu Jicong 已提交
549
  int64_t   stbUid;
550 551
  SHashObj* consumerHash;   // consumerId -> SMqConsumerEp
  SArray*   unassignedVgs;  // SArray<SMqVgEp*>
L
Liu Jicong 已提交
552
  char      dbName[TSDB_DB_FNAME_LEN];
553 554 555 556 557 558 559 560 561 562
} SMqSubscribeObj;

SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]);
SMqSubscribeObj* tCloneSubscribeObj(const SMqSubscribeObj* pSub);
void             tDeleteSubscribeObj(SMqSubscribeObj* pSub);
int32_t          tEncodeSubscribeObj(void** buf, const SMqSubscribeObj* pSub);
void*            tDecodeSubscribeObj(const void* buf, SMqSubscribeObj* pSub);

typedef struct {
  int32_t epoch;
563
  SArray* consumers;  // SArray<SMqConsumerEp*>
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
} SMqSubActionLogEntry;

SMqSubActionLogEntry* tCloneSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry);
void                  tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry);
int32_t               tEncodeSMqSubActionLogEntry(void** buf, const SMqSubActionLogEntry* pEntry);
void*                 tDecodeSMqSubActionLogEntry(const void* buf, SMqSubActionLogEntry* pEntry);

typedef struct {
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
  SArray* logs;  // SArray<SMqSubActionLogEntry*>
} SMqSubActionLogObj;

SMqSubActionLogObj* tCloneSMqSubActionLogObj(SMqSubActionLogObj* pLog);
void                tDeleteSMqSubActionLogObj(SMqSubActionLogObj* pLog);
int32_t             tEncodeSMqSubActionLogObj(void** buf, const SMqSubActionLogObj* pLog);
void*               tDecodeSMqSubActionLogObj(const void* buf, SMqSubActionLogObj* pLog);

typedef struct {
L
Liu Jicong 已提交
582 583
  int32_t           oldConsumerNum;
  const SMqRebInfo* pRebInfo;
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
} SMqRebInputObj;

typedef struct {
  int64_t  oldConsumerId;
  int64_t  newConsumerId;
  SMqVgEp* pVgEp;
} SMqRebOutputVg;

typedef struct {
  SArray*               rebVgs;            // SArray<SMqRebOutputVg>
  SArray*               newConsumers;      // SArray<int64_t>
  SArray*               removedConsumers;  // SArray<int64_t>
  SArray*               touchedConsumers;  // SArray<int64_t>
  SMqSubscribeObj*      pSub;
  SMqSubActionLogEntry* pLogEntry;
} SMqRebOutputObj;
L
Liu Jicong 已提交
600

L
Liu Jicong 已提交
601
typedef struct {
L
Liu Jicong 已提交
602 603 604 605 606 607 608
  char name[TSDB_STREAM_FNAME_LEN];
  // ctl
  SRWLatch lock;
  // create info
  int64_t createTime;
  int64_t updateTime;
  int32_t version;
L
Liu Jicong 已提交
609
  int32_t totalLevel;
L
Liu Jicong 已提交
610 611 612 613 614
  int64_t smaId;  // 0 for unused
  // info
  int64_t uid;
  int8_t  status;
  // config
615
  int8_t  igExpired;
L
Liu Jicong 已提交
616 617 618 619 620 621 622 623 624 625 626
  int8_t  trigger;
  int64_t triggerParam;
  int64_t watermark;
  // source and target
  int64_t sourceDbUid;
  int64_t targetDbUid;
  char    sourceDb[TSDB_DB_FNAME_LEN];
  char    targetDb[TSDB_DB_FNAME_LEN];
  char    targetSTbName[TSDB_TABLE_FNAME_LEN];
  int64_t targetStbUid;
  int32_t fixedSinkVgId;  // 0 for shuffle
L
Liu Jicong 已提交
627 628 629
  // fixedSinkVg is not applicable for encode and decode
  SVgObj fixedSinkVg;

L
Liu Jicong 已提交
630
  // transformation
L
Liu Jicong 已提交
631
  char*          sql;
L
Liu Jicong 已提交
632
  char*          ast;
L
Liu Jicong 已提交
633 634 635
  char*          physicalPlan;
  SArray*        tasks;  // SArray<SArray<SStreamTask>>
  SSchemaWrapper outputSchema;
L
Liu Jicong 已提交
636 637
} SStreamObj;

H
Hongze Cheng 已提交
638 639
int32_t tEncodeSStreamObj(SEncoder* pEncoder, const SStreamObj* pObj);
int32_t tDecodeSStreamObj(SDecoder* pDecoder, SStreamObj* pObj);
L
Liu Jicong 已提交
640
void    tFreeStreamObj(SStreamObj* pObj);
L
Liu Jicong 已提交
641

L
Liu Jicong 已提交
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
typedef struct {
  char    streamName[TSDB_STREAM_FNAME_LEN];
  int64_t uid;
  int64_t streamUid;
  SArray* childInfo;  // SArray<SStreamChildEpInfo>
} SStreamCheckpointObj;

#if 0
typedef struct {
  int64_t uid;
  int64_t streamId;
  int8_t  status;
  int8_t  stage;
} SStreamRecoverObj;
#endif

S
Shengliang Guan 已提交
658 659 660
#ifdef __cplusplus
}
#endif
S
Shengliang Guan 已提交
661

S
Shengliang Guan 已提交
662
#endif /*_TD_MND_DEF_H_*/