mndDef.h 9.8 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 22

#include "cJSON.h"
#include "sync.h"
H
Hongze Cheng 已提交
23
#include "tmsg.h"
S
Shengliang Guan 已提交
24
#include "thash.h"
L
Liu Jicong 已提交
25
#include "tlist.h"
S
Shengliang Guan 已提交
26 27 28
#include "tlog.h"
#include "trpc.h"
#include "ttimer.h"
S
Shengliang Guan 已提交
29

S
Shengliang Guan 已提交
30
#include "mnode.h"
S
Shengliang Guan 已提交
31

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

S
Shengliang Guan 已提交
36 37 38 39 40 41 42 43 44 45 46
extern int32_t mDebugFlag;

// mnode log function
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
#define mWarn(...)  { if (mDebugFlag & DEBUG_WARN)  { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
#define mInfo(...)  { if (mDebugFlag & DEBUG_INFO)  { taosPrintLog("MND ", 255, __VA_ARGS__); }}
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}

typedef enum {
47 48 49 50 51 52 53 54
  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 已提交
55 56

typedef enum {
57 58 59 60 61 62
  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 已提交
63

S
Shengliang Guan 已提交
64
typedef enum {
65
  TRN_STAGE_PREPARE = 0,
S
Shengliang Guan 已提交
66 67
  TRN_STAGE_REDO_LOG = 1,
  TRN_STAGE_REDO_ACTION = 2,
68 69
  TRN_STAGE_COMMIT = 3,
  TRN_STAGE_COMMIT_LOG = 4,
70 71
  TRN_STAGE_UNDO_ACTION = 5,
  TRN_STAGE_UNDO_LOG = 6,
S
Shengliang Guan 已提交
72 73
  TRN_STAGE_ROLLBACK = 7,
  TRN_STAGE_FINISHED = 8
S
Shengliang Guan 已提交
74 75
} ETrnStage;

76
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
S
Shengliang Guan 已提交
77

S
Shengliang Guan 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91
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 已提交
92
typedef struct {
S
Shengliang Guan 已提交
93 94 95
  int32_t    id;
  ETrnStage  stage;
  ETrnPolicy policy;
S
Shengliang Guan 已提交
96 97
  int32_t    code;
  int32_t    failedTimes;
S
Shengliang Guan 已提交
98
  void      *rpcHandle;
S
Shengliang Guan 已提交
99
  void      *rpcAHandle;
S
Shengliang Guan 已提交
100 101 102 103 104 105
  SArray    *redoLogs;
  SArray    *undoLogs;
  SArray    *commitLogs;
  SArray    *redoActions;
  SArray    *undoActions;
} STrans;
S
Shengliang Guan 已提交
106

S
Shengliang Guan 已提交
107
typedef struct {
108
  int64_t id;
S
Shengliang Guan 已提交
109
  char    name[TSDB_CLUSTER_ID_LEN];
S
Shengliang Guan 已提交
110 111 112 113
  int64_t createdTime;
  int64_t updateTime;
} SClusterObj;

S
Shengliang Guan 已提交
114
typedef struct {
S
Shengliang Guan 已提交
115 116 117 118
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  int64_t    rebootTime;
119
  int64_t    lastAccessTime;
S
Shengliang Guan 已提交
120
  int32_t    accessTimes;
S
Shengliang Guan 已提交
121
  int32_t    numOfVnodes;
S
Shengliang Guan 已提交
122 123
  int32_t    numOfSupportVnodes;
  int32_t    numOfCores;
S
Shengliang Guan 已提交
124 125 126 127
  EDndReason offlineReason;
  uint16_t   port;
  char       fqdn[TSDB_FQDN_LEN];
  char       ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
128 129
} SDnodeObj;

S
Shengliang Guan 已提交
130
typedef struct {
S
Shengliang Guan 已提交
131
  int32_t    id;
S
Shengliang Guan 已提交
132 133
  int64_t    createdTime;
  int64_t    updateTime;
S
Shengliang Guan 已提交
134
  ESyncState role;
S
Shengliang Guan 已提交
135 136
  int32_t    roleTerm;
  int64_t    roleTime;
137
  SDnodeObj *pDnode;
S
Shengliang Guan 已提交
138 139
} SMnodeObj;

S
Shengliang Guan 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  SDnodeObj *pDnode;
} SQnodeObj;

typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  SDnodeObj *pDnode;
} SSnodeObj;

typedef struct {
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  SDnodeObj *pDnode;
} SBnodeObj;

S
Shengliang Guan 已提交
161 162 163
typedef struct {
  int32_t maxUsers;
  int32_t maxDbs;
S
Shengliang Guan 已提交
164 165
  int32_t maxStbs;
  int32_t maxTbs;
S
Shengliang Guan 已提交
166 167
  int32_t maxTimeSeries;
  int32_t maxStreams;
S
Shengliang Guan 已提交
168 169 170 171
  int32_t maxFuncs;
  int32_t maxConsumers;
  int32_t maxConns;
  int32_t maxTopics;
S
Shengliang Guan 已提交
172 173
  int64_t maxStorage;   // In unit of GB
  int32_t accessState;  // Configured only by command
S
Shengliang Guan 已提交
174 175 176 177 178 179 180
} SAcctCfg;

typedef struct {
  int32_t numOfUsers;
  int32_t numOfDbs;
  int32_t numOfTimeSeries;
  int32_t numOfStreams;
S
Shengliang Guan 已提交
181 182
  int64_t totalStorage;  // Total storage wrtten from this account
  int64_t compStorage;   // Compressed storage on disk
S
Shengliang Guan 已提交
183 184
} SAcctInfo;

S
Shengliang Guan 已提交
185
typedef struct {
S
Shengliang Guan 已提交
186 187 188 189
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  int32_t   acctId;
S
Shengliang Guan 已提交
190
  int32_t   status;
S
Shengliang Guan 已提交
191 192 193 194
  SAcctCfg  cfg;
  SAcctInfo info;
} SAcctObj;

S
Shengliang Guan 已提交
195
typedef struct {
S
Shengliang Guan 已提交
196
  char      user[TSDB_USER_LEN];
197
  char      pass[TSDB_PASSWORD_LEN];
S
Shengliang Guan 已提交
198 199 200
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
201
  int8_t    superUser;
S
Shengliang Guan 已提交
202
  int32_t   acctId;
S
Shengliang Guan 已提交
203
  SHashObj *prohibitDbHash;
S
Shengliang Guan 已提交
204 205 206
} SUserObj;

typedef struct {
207
  int32_t numOfVgroups;
S
Shengliang Guan 已提交
208 209 210 211 212 213
  int32_t cacheBlockSize;
  int32_t totalBlocks;
  int32_t daysPerFile;
  int32_t daysToKeep0;
  int32_t daysToKeep1;
  int32_t daysToKeep2;
S
Shengliang Guan 已提交
214 215
  int32_t minRows;
  int32_t maxRows;
S
Shengliang Guan 已提交
216 217
  int32_t commitTime;
  int32_t fsyncPeriod;
S
Shengliang Guan 已提交
218
  int8_t  walLevel;
S
Shengliang Guan 已提交
219 220 221 222 223 224 225 226
  int8_t  precision;
  int8_t  compression;
  int8_t  replications;
  int8_t  quorum;
  int8_t  update;
  int8_t  cacheLastRow;
} SDbCfg;

S
Shengliang Guan 已提交
227
typedef struct {
228
  char    name[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
229 230 231 232
  char    acct[TSDB_USER_LEN];
  int64_t createdTime;
  int64_t updateTime;
  int64_t uid;
S
Shengliang Guan 已提交
233 234
  int32_t cfgVersion;
  int32_t vgVersion;
S
Shengliang Guan 已提交
235
  int8_t  hashMethod;  // default is 1
S
Shengliang Guan 已提交
236
  SDbCfg  cfg;
S
Shengliang Guan 已提交
237 238 239 240
} SDbObj;

typedef struct {
  int32_t    dnodeId;
S
Shengliang Guan 已提交
241
  ESyncState role;
S
Shengliang Guan 已提交
242 243
} SVnodeGid;

S
Shengliang Guan 已提交
244
typedef struct {
S
Shengliang Guan 已提交
245
  int32_t   vgId;
S
Shengliang Guan 已提交
246 247
  int64_t   createdTime;
  int64_t   updateTime;
S
Shengliang Guan 已提交
248
  int32_t   version;
S
Shengliang Guan 已提交
249 250
  uint32_t  hashBegin;
  uint32_t  hashEnd;
251
  char      dbName[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
252
  int64_t   dbUid;
S
Shengliang Guan 已提交
253
  int32_t   numOfTables;
S
Shengliang Guan 已提交
254
  int32_t   numOfTimeSeries;
S
Shengliang Guan 已提交
255 256 257
  int64_t   totalStorage;
  int64_t   compStorage;
  int64_t   pointsWritten;
S
Shengliang Guan 已提交
258 259 260
  int8_t    compact;
  int8_t    replica;
  SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
261 262
} SVgObj;

S
Shengliang Guan 已提交
263
typedef struct {
S
Shengliang Guan 已提交
264
  char     name[TSDB_TABLE_FNAME_LEN];
265
  char     db[TSDB_DB_FNAME_LEN];
266 267
  int64_t  createdTime;
  int64_t  updateTime;
S
Shengliang Guan 已提交
268
  uint64_t uid;
S
Shengliang Guan 已提交
269
  uint64_t dbUid;
S
Shengliang Guan 已提交
270
  int32_t  version;
S
Shengliang Guan 已提交
271 272
  int32_t  numOfColumns;
  int32_t  numOfTags;
S
Shengliang Guan 已提交
273
  SRWLatch lock;
S
Shengliang Guan 已提交
274 275
  SSchema *pSchema;
} SStbObj;
S
Shengliang Guan 已提交
276

S
Shengliang Guan 已提交
277
typedef struct {
S
Shengliang Guan 已提交
278 279
  char    name[TSDB_FUNC_NAME_LEN];
  int64_t createdTime;
S
Shengliang Guan 已提交
280 281 282 283 284 285 286 287 288 289 290 291
  int8_t  funcType;
  int8_t  scriptType;
  int8_t  align;
  int8_t  outputType;
  int32_t outputLen;
  int32_t bufSize;
  int64_t sigature;
  int32_t commentSize;
  int32_t codeSize;
  char   *pComment;
  char   *pCode;
  char    pData[];
S
Shengliang Guan 已提交
292 293
} SFuncObj;

S
Shengliang Guan 已提交
294
typedef struct {
295
  int64_t id;
S
Shengliang Guan 已提交
296 297 298 299 300 301 302 303 304
  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;
305
  char    db[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
306 307 308
  int16_t offset[TSDB_MAX_COLUMNS];
  int32_t bytes[TSDB_MAX_COLUMNS];
  char    payload[];
S
Shengliang Guan 已提交
309 310
} SShowObj;

L
Liu Jicong 已提交
311
#if 0
L
Liu Jicong 已提交
312
typedef struct SConsumerObj {
L
Liu Jicong 已提交
313
  uint64_t uid;
L
Liu Jicong 已提交
314 315
  int64_t  createTime;
  int64_t  updateTime;
L
Liu Jicong 已提交
316
  //uint64_t dbUid;
L
Liu Jicong 已提交
317
  int32_t  version;
L
Liu Jicong 已提交
318
  SRWLatch lock;
L
Liu Jicong 已提交
319
  SArray*   topics;
L
Liu Jicong 已提交
320 321
} SConsumerObj;

L
Liu Jicong 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
typedef struct SMqTopicConsumer {
  int64_t consumerId;
  SList*  topicList;
} SMqTopicConsumer;
#endif

typedef struct SMqCGroup {
  char    name[TSDB_CONSUMER_GROUP_LEN];
  int32_t status;       // 0 - uninitialized, 1 - wait rebalance, 2- normal
  SList  *consumerIds;  // SList<int64_t>
  SList  *idleVGroups;  // SList<int32_t>
} SMqCGroup;

typedef struct SMqTopicObj {
  char      name[TSDB_TOPIC_FNAME_LEN];
  char      db[TSDB_DB_FNAME_LEN];
  int64_t   createTime;
  int64_t   updateTime;
  uint64_t  uid;
  uint64_t  dbUid;
  int32_t   version;
  SRWLatch  lock;
  int32_t   sqlLen;
  char     *sql;
  char     *logicalPlan;
  char     *physicalPlan;
  SHashObj *cgroups;  // SHashObj<SMqCGroup>
} SMqTopicObj;

// TODO: add cache and change name to id
typedef struct SMqConsumerTopic {
353
  char   name[TSDB_TOPIC_NAME_LEN];
L
Liu Jicong 已提交
354 355 356 357 358 359 360 361 362 363
  SList *vgroups;  // SList<int32_t>
} SMqConsumerTopic;

typedef struct SMqConsumerObj {
  SRWLatch lock;
  int64_t  consumerId;
  char     cgroup[TSDB_CONSUMER_GROUP_LEN];
  SArray  *topics;  // SArray<SMqConsumerTopic>
} SMqConsumerObj;

L
Liu Jicong 已提交
364 365
typedef struct SMqSubConsumerObj {
  int64_t consumerUid;  // if -1, unassigned
L
Liu Jicong 已提交
366
  SList  *vgId;         // SList<int32_t>
L
Liu Jicong 已提交
367 368 369 370
} SMqSubConsumerObj;

typedef struct SMqSubCGroupObj {
  char   name[TSDB_CONSUMER_GROUP_LEN];
L
Liu Jicong 已提交
371
  SList *consumers;  // SList<SMqConsumerObj>
L
Liu Jicong 已提交
372 373 374 375 376 377 378 379 380 381
} SMqSubCGroupObj;

typedef struct SMqSubTopicObj {
  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 已提交
382 383
  SRWLatch lock;
  int32_t  sqlLen;
L
Liu Jicong 已提交
384 385 386 387
  char    *sql;
  char    *logicalPlan;
  char    *physicalPlan;
  SList   *cgroups;  // SList<SMqSubCGroupObj>
L
Liu Jicong 已提交
388 389 390 391
} SMqSubTopicObj;

typedef struct SMqConsumerSubObj {
  int64_t topicUid;
L
Liu Jicong 已提交
392
  SList  *vgIds;  // SList<int64_t>
L
Liu Jicong 已提交
393 394 395 396
} SMqConsumerSubObj;

typedef struct SMqConsumerHbObj {
  int64_t consumerId;
L
Liu Jicong 已提交
397
  SList  *consumerSubs;  // SList<SMqConsumerSubObj>
L
Liu Jicong 已提交
398 399 400 401
} SMqConsumerHbObj;

typedef struct SMqVGroupSubObj {
  int64_t topicUid;
L
Liu Jicong 已提交
402
  SList  *consumerIds;  // SList<int64_t>
L
Liu Jicong 已提交
403 404 405 406
} SMqVGroupSubObj;

typedef struct SMqVGroupHbObj {
  int64_t vgId;
L
Liu Jicong 已提交
407
  SList  *vgSubs;  // SList<SMqVGroupSubObj>
L
Liu Jicong 已提交
408 409
} SMqVGroupHbObj;

L
Liu Jicong 已提交
410
#if 0
L
Liu Jicong 已提交
411
typedef struct SCGroupObj {
412
  char     name[TSDB_TOPIC_NAME_LEN];
L
Liu Jicong 已提交
413 414
  int64_t  createTime;
  int64_t  updateTime;
L
Liu Jicong 已提交
415 416
  uint64_t uid;
  //uint64_t dbUid;
L
Liu Jicong 已提交
417
  int32_t  version;
L
Liu Jicong 已提交
418
  SRWLatch lock;
L
Liu Jicong 已提交
419
  SList*   consumerIds;
L
Liu Jicong 已提交
420
} SCGroupObj;
L
Liu Jicong 已提交
421
#endif
L
Liu Jicong 已提交
422

S
Shengliang Guan 已提交
423
typedef struct SMnodeMsg {
S
Shengliang Guan 已提交
424
  char    user[TSDB_USER_LEN];
425
  char    db[TSDB_DB_FNAME_LEN];
S
Shengliang Guan 已提交
426
  int32_t acctId;
427
  SMnode *pMnode;
S
Shengliang Guan 已提交
428 429 430 431
  int64_t createdTime;
  SRpcMsg rpcMsg;
  int32_t contLen;
  void   *pCont;
S
Shengliang Guan 已提交
432
} SMnodeMsg;
S
Shengliang Guan 已提交
433

S
Shengliang Guan 已提交
434 435 436
#ifdef __cplusplus
}
#endif
S
Shengliang Guan 已提交
437

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