mndDef.h 7.2 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"
S
Shengliang Guan 已提交
23
#include "taosmsg.h"
S
Shengliang Guan 已提交
24
#include "thash.h"
S
Shengliang Guan 已提交
25 26 27
#include "tlog.h"
#include "trpc.h"
#include "ttimer.h"
S
Shengliang Guan 已提交
28

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

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

S
Shengliang Guan 已提交
35 36 37 38 39 40 41 42 43 44
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__); }}

45 46 47 48 49 50 51
typedef struct SClusterObj SClusterObj;
typedef struct SMnodeObj   SMnodeObj;
typedef struct SAcctObj    SAcctObj;
typedef struct SDbObj      SDbObj;
typedef struct SVgObj      SVgObj;
typedef struct SFuncObj    SFuncObj;
typedef struct SOperObj    SOperObj;
S
Shengliang Guan 已提交
52 53

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

typedef enum {
64 65 66 67 68 69
  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 已提交
70

S
Shengliang Guan 已提交
71 72 73 74 75
typedef enum {
  TRN_STAGE_PREPARE = 1,
  TRN_STAGE_EXECUTE = 2,
  TRN_STAGE_COMMIT = 3,
  TRN_STAGE_ROLLBACK = 4,
S
Shengliang Guan 已提交
76 77
  TRN_STAGE_RETRY = 5,
  TRN_STAGE_OVER = 6,
S
Shengliang Guan 已提交
78 79 80 81
} ETrnStage;

typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;

S
Shengliang Guan 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
typedef enum {
  DND_STATUS_OFFLINE = 0,
  DND_STATUS_READY = 1,
  DND_STATUS_CREATING = 2,
  DND_STATUS_DROPPING = 3
} EDndStatus;

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 已提交
103 104 105 106 107 108 109 110 111 112 113
typedef struct STrans {
  int32_t    id;
  ETrnStage  stage;
  ETrnPolicy policy;
  void      *rpcHandle;
  SArray    *redoLogs;
  SArray    *undoLogs;
  SArray    *commitLogs;
  SArray    *redoActions;
  SArray    *undoActions;
} STrans;
S
Shengliang Guan 已提交
114 115

typedef struct SClusterObj {
S
Shengliang Guan 已提交
116
  int32_t id;
S
Shengliang Guan 已提交
117
  char    name[TSDB_CLUSTER_ID_LEN];
S
Shengliang Guan 已提交
118 119 120 121
  int64_t createdTime;
  int64_t updateTime;
} SClusterObj;

S
Shengliang Guan 已提交
122
typedef struct {
S
Shengliang Guan 已提交
123 124 125 126
  int32_t    id;
  int64_t    createdTime;
  int64_t    updateTime;
  int64_t    rebootTime;
127
  int64_t    lastAccessTime;
S
Shengliang Guan 已提交
128
  int32_t    accessTimes;
S
Shengliang Guan 已提交
129 130 131 132 133 134
  int16_t    numOfMnodes;
  int16_t    numOfVnodes;
  int16_t    numOfQnodes;
  int16_t    numOfSupportMnodes;
  int16_t    numOfSupportVnodes;
  int16_t    numOfSupportQnodes;
S
Shengliang Guan 已提交
135
  int16_t    numOfCores;
S
Shengliang Guan 已提交
136 137 138 139 140
  EDndStatus status;
  EDndReason offlineReason;
  uint16_t   port;
  char       fqdn[TSDB_FQDN_LEN];
  char       ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
141 142 143 144
} SDnodeObj;

typedef struct SMnodeObj {
  int32_t    id;
S
Shengliang Guan 已提交
145 146
  int64_t    createdTime;
  int64_t    updateTime;
S
Shengliang Guan 已提交
147
  ESyncState role;
S
Shengliang Guan 已提交
148 149
  int32_t    roleTerm;
  int64_t    roleTime;
150
  SDnodeObj *pDnode;
S
Shengliang Guan 已提交
151 152 153 154 155 156 157
} SMnodeObj;

typedef struct {
  int32_t maxUsers;
  int32_t maxDbs;
  int32_t maxTimeSeries;
  int32_t maxStreams;
S
Shengliang Guan 已提交
158 159
  int64_t maxStorage;   // In unit of GB
  int32_t accessState;  // Configured only by command
S
Shengliang Guan 已提交
160 161 162 163 164 165 166
} SAcctCfg;

typedef struct {
  int32_t numOfUsers;
  int32_t numOfDbs;
  int32_t numOfTimeSeries;
  int32_t numOfStreams;
S
Shengliang Guan 已提交
167 168
  int64_t totalStorage;  // Total storage wrtten from this account
  int64_t compStorage;   // Compressed storage on disk
S
Shengliang Guan 已提交
169 170 171 172 173 174 175
} SAcctInfo;

typedef struct SAcctObj {
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  int32_t   acctId;
S
Shengliang Guan 已提交
176
  int32_t   status;
S
Shengliang Guan 已提交
177 178 179 180
  SAcctCfg  cfg;
  SAcctInfo info;
} SAcctObj;

S
Shengliang Guan 已提交
181
typedef struct {
S
Shengliang Guan 已提交
182
  char      user[TSDB_USER_LEN];
183
  char      pass[TSDB_PASSWORD_LEN];
S
Shengliang Guan 已提交
184 185 186
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
187
  int8_t    superUser;
S
Shengliang Guan 已提交
188
  int32_t   acctId;
S
Shengliang Guan 已提交
189
  SHashObj *prohibitDbHash;
S
Shengliang Guan 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202
} SUserObj;

typedef struct {
  int32_t cacheBlockSize;
  int32_t totalBlocks;
  int32_t daysPerFile;
  int32_t daysToKeep0;
  int32_t daysToKeep1;
  int32_t daysToKeep2;
  int32_t minRowsPerFileBlock;
  int32_t maxRowsPerFileBlock;
  int32_t commitTime;
  int32_t fsyncPeriod;
S
Shengliang Guan 已提交
203
  int8_t  walLevel;
S
Shengliang Guan 已提交
204 205 206 207 208 209 210 211 212
  int8_t  precision;
  int8_t  compression;
  int8_t  replications;
  int8_t  quorum;
  int8_t  update;
  int8_t  cacheLastRow;
} SDbCfg;

typedef struct SDbObj {
S
Shengliang Guan 已提交
213 214 215 216 217 218
  char    name[TSDB_FULL_DB_NAME_LEN];
  char    acct[TSDB_USER_LEN];
  int64_t createdTime;
  int64_t updateTime;
  int64_t uid;
  SDbCfg  cfg;
S
Shengliang Guan 已提交
219 220 221 222
} SDbObj;

typedef struct {
  int32_t    dnodeId;
S
Shengliang Guan 已提交
223
  ESyncState role;
S
Shengliang Guan 已提交
224 225 226
} SVnodeGid;

typedef struct SVgObj {
S
Shengliang Guan 已提交
227
  int32_t   vgId;
S
Shengliang Guan 已提交
228 229
  int64_t   createdTime;
  int64_t   updateTime;
S
Shengliang Guan 已提交
230
  int32_t   version;
S
Shengliang Guan 已提交
231
  char      dbName[TSDB_FULL_DB_NAME_LEN];
S
Shengliang Guan 已提交
232
  int32_t   numOfTables;
S
Shengliang Guan 已提交
233
  int32_t   numOfTimeSeries;
S
Shengliang Guan 已提交
234 235 236
  int64_t   totalStorage;
  int64_t   compStorage;
  int64_t   pointsWritten;
S
Shengliang Guan 已提交
237 238 239
  int8_t    compact;
  int8_t    replica;
  SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
240 241
} SVgObj;

S
Shengliang Guan 已提交
242
typedef struct {
S
Shengliang Guan 已提交
243 244
  char     name[TSDB_TABLE_FNAME_LEN];
  char     db[TSDB_FULL_DB_NAME_LEN];
245 246
  int64_t  createdTime;
  int64_t  updateTime;
S
Shengliang Guan 已提交
247 248
  uint64_t uid;
  int32_t  version;
S
Shengliang Guan 已提交
249 250
  int32_t  numOfColumns;
  int32_t  numOfTags;
S
Shengliang Guan 已提交
251
  SRWLatch lock;
S
Shengliang Guan 已提交
252 253
  SSchema *pSchema;
} SStbObj;
S
Shengliang Guan 已提交
254 255 256 257

typedef struct SFuncObj {
  char    name[TSDB_FUNC_NAME_LEN];
  int64_t createdTime;
S
Shengliang Guan 已提交
258 259 260 261 262 263 264 265 266 267 268 269
  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 已提交
270 271
} SFuncObj;

S
Shengliang Guan 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
typedef struct {
  int32_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_FULL_DB_NAME_LEN];
  int16_t offset[TSDB_MAX_COLUMNS];
  int32_t bytes[TSDB_MAX_COLUMNS];
  char    payload[];
S
Shengliang Guan 已提交
287 288
} SShowObj;

S
Shengliang Guan 已提交
289
typedef struct SMnodeMsg {
S
Shengliang Guan 已提交
290
  char    user[TSDB_USER_LEN];
S
Shengliang Guan 已提交
291 292
  char    db[TSDB_FULL_DB_NAME_LEN];
  int32_t acctId;
293
  SMnode *pMnode;
S
Shengliang Guan 已提交
294 295 296 297 298 299 300 301 302
  int16_t received;
  int16_t successed;
  int16_t expected;
  int16_t retry;
  int32_t code;
  int64_t createdTime;
  SRpcMsg rpcMsg;
  int32_t contLen;
  void   *pCont;
S
Shengliang Guan 已提交
303
} SMnodeMsg;
S
Shengliang Guan 已提交
304

S
Shengliang Guan 已提交
305 306
typedef struct {
  int32_t id;
S
Shengliang Guan 已提交
307
  int32_t code;
S
Shengliang Guan 已提交
308 309 310
  void   *rpcHandle;
} STransMsg;

S
Shengliang Guan 已提交
311 312 313
#ifdef __cplusplus
}
#endif
S
Shengliang Guan 已提交
314

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