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

S
Shengliang Guan 已提交
28 29 30
#ifdef __cplusplus
extern "C" {
#endif
S
Shengliang Guan 已提交
31

S
Shengliang Guan 已提交
32 33 34 35 36 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 78
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__); }}

// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
// #define mLWarn(...)  { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__)  }
// #define mLInfo(...)  { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }

#define mLError(...) {mError(__VA_ARGS__) }
#define mLWarn(...)  {mWarn(__VA_ARGS__)  }
#define mLInfo(...)  {mInfo(__VA_ARGS__) }

typedef struct SClusterObj SClusterObj; 
typedef struct SDnodeObj SDnodeObj;
typedef struct SMnodeObj SMnodeObj;
typedef struct SAcctObj SAcctObj;
typedef struct SUserObj SUserObj;
typedef struct SDbObj SDbObj;
typedef struct SVgObj SVgObj;
typedef struct SSTableObj SSTableObj;
typedef struct SFuncObj SFuncObj; 
typedef struct SOperObj SOperObj;

typedef enum {
  MN_AUTH_ACCT_START = 0,
  MN_AUTH_ACCT_USER,
  MN_AUTH_ACCT_DNODE,
  MN_AUTH_ACCT_MNODE,
  MN_AUTH_ACCT_DB,
  MN_AUTH_ACCT_TABLE,
  MN_AUTH_ACCT_MAX
} EMnAuthAcct;

typedef enum {
  MN_AUTH_OP_START = 0,
  MN_AUTH_OP_CREATE_USER,
  MN_AUTH_OP_ALTER_USER,
  MN_AUTH_OP_DROP_USER,
  MN_AUTH_MAX
} EMnAuthOp;

S
Shengliang Guan 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
typedef enum {
  TRN_STAGE_PREPARE = 1,
  TRN_STAGE_EXECUTE = 2,
  TRN_STAGE_COMMIT = 3,
  TRN_STAGE_ROLLBACK = 4,
  TRN_STAGE_RETRY = 5
} ETrnStage;

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


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 已提交
101

102

S
Shengliang Guan 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115
typedef struct SClusterObj {
  int64_t id;
  char    uid[TSDB_CLUSTER_ID_LEN];
  int64_t createdTime;
  int64_t updateTime;
} SClusterObj;

typedef struct SDnodeObj {
  int32_t  id;
  int32_t  vnodes;
  int64_t  createdTime;
  int64_t  updateTime;
  int64_t  lastAccess;
S
Shengliang Guan 已提交
116
  int64_t  rebootTime;  // time stamp for last reboot
S
Shengliang Guan 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  char     fqdn[TSDB_FQDN_LEN];
  char     ep[TSDB_EP_LEN];
  uint16_t port;
  int16_t  numOfCores;       // from dnode status msg
  int8_t   alternativeRole;  // from dnode status msg, 0-any, 1-mgmt, 2-dnode
  int8_t   status;           // set in balance function
  int8_t   offlineReason;
} SDnodeObj;

typedef struct SMnodeObj {
  int32_t    id;
  int8_t     status;
  int8_t     role;
  int32_t    roleTerm;
  int64_t    roleTime;
  int64_t    createdTime;
  int64_t    updateTime;
134
  SDnodeObj *pDnode;
S
Shengliang Guan 已提交
135 136 137 138 139 140 141
} SMnodeObj;

typedef struct {
  int32_t maxUsers;
  int32_t maxDbs;
  int32_t maxTimeSeries;
  int32_t maxStreams;
S
Shengliang Guan 已提交
142 143
  int64_t maxStorage;   // In unit of GB
  int32_t accessState;  // Configured only by command
S
Shengliang Guan 已提交
144 145 146 147 148 149 150
} SAcctCfg;

typedef struct {
  int32_t numOfUsers;
  int32_t numOfDbs;
  int32_t numOfTimeSeries;
  int32_t numOfStreams;
S
Shengliang Guan 已提交
151 152
  int64_t totalStorage;  // Total storage wrtten from this account
  int64_t compStorage;   // Compressed storage on disk
S
Shengliang Guan 已提交
153 154 155 156 157 158 159
} SAcctInfo;

typedef struct SAcctObj {
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  int32_t   acctId;
S
Shengliang Guan 已提交
160
  int32_t   status;
S
Shengliang Guan 已提交
161 162 163 164 165 166 167 168 169 170 171
  SAcctCfg  cfg;
  SAcctInfo info;
} SAcctObj;

typedef struct SUserObj {
  char      user[TSDB_USER_LEN];
  char      pass[TSDB_KEY_LEN];
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  int8_t    rootAuth;
S
Shengliang Guan 已提交
172
  SHashObj *prohibitDbHash;
S
Shengliang Guan 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
  SAcctObj *pAcct;
} SUserObj;

typedef struct {
  int32_t cacheBlockSize;
  int32_t totalBlocks;
  int32_t maxTables;
  int32_t daysPerFile;
  int32_t daysToKeep0;
  int32_t daysToKeep1;
  int32_t daysToKeep2;
  int32_t minRowsPerFileBlock;
  int32_t maxRowsPerFileBlock;
  int32_t commitTime;
  int32_t fsyncPeriod;
  int8_t  precision;
  int8_t  compression;
  int8_t  walLevel;
  int8_t  replications;
  int8_t  quorum;
  int8_t  update;
  int8_t  cacheLastRow;
  int8_t  dbType;
  int16_t partitions;
} SDbCfg;

typedef struct SDbObj {
S
Shengliang Guan 已提交
200
  char      name[TSDB_FULL_DB_NAME_LEN];
S
Shengliang Guan 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
  char      acct[TSDB_USER_LEN];
  int64_t   createdTime;
  int64_t   updateTime;
  SDbCfg    cfg;
  int8_t    status;
  int32_t   numOfVgroups;
  int32_t   numOfTables;
  int32_t   numOfSuperTables;
  int32_t   vgListSize;
  int32_t   vgListIndex;
  SVgObj  **vgList;
  SAcctObj *pAcct;
} SDbObj;

typedef struct {
  int32_t    dnodeId;
  int8_t     role;
218
  SDnodeObj *pDnode;
S
Shengliang Guan 已提交
219 220 221 222 223 224 225 226 227
} SVnodeGid;

typedef struct SVgObj {
  uint32_t  vgId;
  int32_t   numOfVnodes;
  int64_t   createdTime;
  int64_t   updateTime;
  int32_t   lbDnodeId;
  int32_t   lbTime;
S
Shengliang Guan 已提交
228
  char      dbName[TSDB_FULL_DB_NAME_LEN];
S
Shengliang Guan 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  int8_t    inUse;
  int8_t    accessState;
  int8_t    status;
  SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
  int32_t   vgCfgVersion;
  int8_t    compact;
  int32_t   numOfTables;
  int64_t   totalStorage;
  int64_t   compStorage;
  int64_t   pointsWritten;
  SDbObj   *pDb;
} SVgObj;

typedef struct SSTableObj {
  char       tableId[TSDB_TABLE_NAME_LEN];
  uint64_t   uid;
  int64_t    createdTime;
  int64_t    updateTime;
  int32_t    numOfColumns;  // used by normal table
  int32_t    numOfTags;
  SSchema *  schema;
} SSTableObj;

typedef struct SFuncObj {
  char    name[TSDB_FUNC_NAME_LEN];
  char    path[128];
  int32_t contLen;
  char    cont[TSDB_FUNC_CODE_LEN];
  int32_t funcType;
  int32_t bufSize;
  int64_t createdTime;
  uint8_t resType;
  int16_t resBytes;
  int64_t sig;
  int16_t type;
} SFuncObj;

typedef struct {
  int8_t   type;
  int8_t   maxReplica;
  int16_t  numOfColumns;
  int32_t  index;
  int32_t  rowSize;
  int32_t  numOfRows;
  int32_t  numOfReads;
  uint16_t payloadLen;
  void    *pIter;
  void    *pVgIter;
  void   **ppShow;
S
Shengliang Guan 已提交
278
  char     db[TSDB_FULL_DB_NAME_LEN];
S
Shengliang Guan 已提交
279 280 281 282 283 284 285 286 287 288
  int16_t  offset[TSDB_MAX_COLUMNS];
  int32_t  bytes[TSDB_MAX_COLUMNS];
  char     payload[];
} SShowObj;

typedef struct {
  int32_t len;
  void   *rsp;
} SMnRsp;

S
Shengliang Guan 已提交
289 290 291
typedef struct SMnodeMsg {
  void (*fp)(SMnodeMsg *pMsg, int32_t code);
  SRpcConnInfo conn;
S
Shengliang Guan 已提交
292 293 294 295 296 297 298 299 300 301
  SUserObj *pUser;
  int16_t   received;
  int16_t   successed;
  int16_t   expected;
  int16_t   retry;
  int32_t   code;
  int64_t   createdTime;
  SMnRsp    rpcRsp;
  SRpcMsg   rpcMsg;
  char      pCont[];
S
Shengliang Guan 已提交
302
} SMnodeMsg;
S
Shengliang Guan 已提交
303

S
Shengliang Guan 已提交
304 305 306
#ifdef __cplusplus
}
#endif
S
Shengliang Guan 已提交
307

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