mnode.h 6.6 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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/>.
 */

#ifndef TDENGINE_MGMT_H
#define TDENGINE_MGMT_H

#ifdef __cplusplus
extern "C" {
#endif

23
#include "os.h"
H
hzcheng 已提交
24

S
#1177  
slguan 已提交
25 26 27
#include "taosdef.h"
#include "taosmsg.h"
#include "taoserror.h"
H
hzcheng 已提交
28 29 30 31 32 33
#include "tglobalcfg.h"
#include "thash.h"
#include "tidpool.h"
#include "tlog.h"
#include "tmempool.h"
#include "trpc.h"
S
slguan 已提交
34
#include "taosdef.h"
H
hzcheng 已提交
35 36 37 38 39 40
#include "tskiplist.h"
#include "tsocket.h"
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"

S
[TD-61]  
slguan 已提交
41 42 43 44
struct _vg_obj;
struct _db_obj;
struct _acctObj;

S
slguan 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
typedef struct {
  int32_t  mnodeId;
  uint32_t privateIp;
  uint32_t publicIp;
  int64_t  createdTime;
  int64_t  lostTime;
  uint64_t dbVersion;
  uint32_t rack;
  uint16_t idc;
  uint16_t slot;
  int8_t   role;
  int8_t   status;
  int8_t   numOfMnodes;
  int32_t  numOfDnodes;
  char     mnodeName[TSDB_DNODE_NAME_LEN + 1];
S
slguan 已提交
60 61
  int8_t   reserved[15];
  int8_t   updateEnd[1];
S
slguan 已提交
62
  int32_t  refCount;
S
slguan 已提交
63 64 65 66 67
  int      syncFd;
  void    *hbTimer;
  void    *pSync;
} SMnodeObj;

S
slguan 已提交
68
typedef struct {
S
slguan 已提交
69
  int32_t    dnodeId;
H
hzcheng 已提交
70
  uint32_t   privateIp;
71
  uint32_t   publicIp;
H
hzcheng 已提交
72 73 74
  uint32_t   moduleStatus;
  int64_t    createdTime;
  uint32_t   lastAccess;
75 76 77 78 79
  int32_t    openVnodes;
  int32_t    numOfTotalVnodes; // from dnode status msg, config information
  uint32_t   rack;
  uint16_t   idc;
  uint16_t   slot;
H
hzcheng 已提交
80
  uint16_t   numOfCores;       // from dnode status msg
81 82 83 84 85
  int8_t     alternativeRole;  // from dnode status msg, 0-any, 1-mgmt, 2-dnode
  int8_t     lbStatus;         // set in balance function
  float      lbScore;          // calc in balance function
  int32_t    customScore;      // config by user
  char       dnodeName[TSDB_DNODE_NAME_LEN + 1];
S
slguan 已提交
86 87
  int8_t     reserved[15];
  int8_t     updateEnd[1];
S
slguan 已提交
88
  int32_t    refCount;
89 90 91
  SVnodeLoad vload[TSDB_MAX_VNODES];
  int32_t    status;
  uint32_t   lastReboot;       // time stamp for last reboot
H
hzcheng 已提交
92
  float      diskAvailable;    // from dnode status msg
93
  int16_t    diskAvgUsage;     // calc from sys.disk
H
hzcheng 已提交
94 95 96 97 98 99
  int16_t    cpuAvgUsage;      // calc from sys.cpu
  int16_t    memoryAvgUsage;   // calc from sys.mem
  int16_t    bandwidthUsage;   // calc from sys.band
} SDnodeObj;

typedef struct {
100
  int32_t  dnodeId;
H
hzcheng 已提交
101
  int32_t  vnode;
102 103
  uint32_t privateIp;
  uint32_t publicIp;
H
hzcheng 已提交
104 105
} SVnodeGid;

S
slguan 已提交
106
typedef struct {
S
slguan 已提交
107
  char   tableId[TSDB_TABLE_ID_LEN + 1];
108
  int8_t type;
S
slguan 已提交
109
} STableInfo;
S
#1177  
slguan 已提交
110 111

typedef struct SSuperTableObj {
112 113 114 115 116 117 118 119
  STableInfo info;
  uint64_t   uid;
  int64_t    createdTime;
  int32_t    sversion;
  int32_t    numOfColumns;
  int32_t    numOfTags;
  int8_t     reserved[15];
  int8_t     updateEnd[1];
S
slguan 已提交
120
  int32_t    refCount;
121 122 123
  int32_t    numOfTables;
  int16_t    nextColId;
  SSchema *  schema;
S
#1177  
slguan 已提交
124 125 126
} SSuperTableObj;

typedef struct {
127 128 129 130 131 132 133 134 135 136 137 138
  STableInfo info;
  uint64_t   uid;
  int64_t    createdTime;
  int32_t    sversion;     //used by normal table
  int32_t    numOfColumns; //used by normal table
  int32_t    sid;
  int32_t    vgId;
  char       superTableId[TSDB_TABLE_ID_LEN + 1];
  int32_t    sqlLen;
  int8_t     reserved[1]; 
  int8_t     updateEnd[1];
  int16_t    nextColId;    //used by normal table
S
slguan 已提交
139
  int32_t    refCount;
140 141
  char*      sql;          //used by normal table
  SSchema*   schema;       //used by normal table
S
#1177  
slguan 已提交
142 143 144
  SSuperTableObj *superTable;
} SChildTableObj;

H
hzcheng 已提交
145 146
typedef struct _vg_obj {
  uint32_t        vgId;
S
slguan 已提交
147
  char            dbName[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
148 149
  int64_t         createdTime;
  SVnodeGid       vnodeGid[TSDB_VNODES_SUPPORT];
150
  int32_t         numOfVnodes;
H
hzcheng 已提交
151 152
  int32_t         lbIp;
  int32_t         lbTime;
S
slguan 已提交
153
  int8_t          lbStatus;
154
  int8_t          reserved[14];
S
slguan 已提交
155
  int8_t          updateEnd[1];
S
slguan 已提交
156
  int32_t         refCount;
H
hzcheng 已提交
157
  struct _vg_obj *prev, *next;
S
slguan 已提交
158
  struct _db_obj *pDb;
S
slguan 已提交
159
  int32_t         numOfTables;
H
hzcheng 已提交
160
  void *          idPool;
S
slguan 已提交
161
  SChildTableObj ** tableList;
H
hzcheng 已提交
162 163 164
} SVgObj;

typedef struct _db_obj {
S
slguan 已提交
165
  char    name[TSDB_DB_NAME_LEN + 1];
S
slguan 已提交
166
  int8_t  dirty;
H
hzcheng 已提交
167 168
  int64_t createdTime;
  SDbCfg  cfg;
S
slguan 已提交
169 170
  int8_t  reserved[15];
  int8_t  updateEnd[1];
S
slguan 已提交
171
  int32_t refCount;
S
slguan 已提交
172 173 174
  int32_t numOfVgroups;
  int32_t numOfTables;
  int32_t numOfSuperTables;
S
slguan 已提交
175 176
  SVgObj *pHead;
  SVgObj *pTail;
S
[TD-61]  
slguan 已提交
177
  struct _acctObj *pAcct;
H
hzcheng 已提交
178 179 180
} SDbObj;

typedef struct _user_obj {
S
slguan 已提交
181 182 183
  char              user[TSDB_USER_LEN + 1];
  char              pass[TSDB_KEY_LEN + 1];
  char              acct[TSDB_USER_LEN + 1];
H
hzcheng 已提交
184
  int64_t           createdTime;
S
slguan 已提交
185 186
  int8_t            superAuth;
  int8_t            writeAuth;
S
slguan 已提交
187
  int8_t            reserved[13];
S
slguan 已提交
188
  int8_t            updateEnd[1];
S
slguan 已提交
189
  int32_t           refCount;
S
slguan 已提交
190
  struct _acctObj * pAcct;
S
slguan 已提交
191 192
  SQqueryList *     pQList;  // query list
  SStreamList *     pSList;  // stream list
H
hzcheng 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
} SUserObj;

typedef struct {
  int32_t numOfUsers;
  int32_t numOfDbs;
  int32_t numOfTimeSeries;
  int32_t numOfPointsPerSecond;
  int32_t numOfConns;
  int32_t numOfQueries;
  int32_t numOfStreams;
  int64_t totalStorage;  // Total storage wrtten from this account
  int64_t compStorage;   // Compressed storage on disk
  int64_t queryTime;
  int64_t totalPoints;
  int64_t inblound;
  int64_t outbound;
S
slguan 已提交
209 210
  int64_t sKey;
  int8_t  accessState;   // Checked by mgmt heartbeat message
H
hzcheng 已提交
211 212
} SAcctInfo;

S
slguan 已提交
213
typedef struct _acctObj {
S
slguan 已提交
214 215
  char      user[TSDB_USER_LEN + 1];
  char      pass[TSDB_KEY_LEN + 1];
S
slguan 已提交
216
  SAcctCfg  cfg;
H
hzcheng 已提交
217 218
  int32_t   acctId;
  int64_t   createdTime;
S
[TD-16]  
slguan 已提交
219 220
  int8_t    dirty;
  int8_t    reserved[14];
S
slguan 已提交
221
  int8_t    updateEnd[1];
S
slguan 已提交
222
  int32_t   refCount;
H
hzcheng 已提交
223 224 225 226 227
  SAcctInfo acctInfo;
  pthread_mutex_t  mutex;
} SAcctObj;

typedef struct {
S
slguan 已提交
228
  int8_t   type;
S
slguan 已提交
229
  char     db[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
230
  void *   pNode;
S
slguan 已提交
231 232 233 234 235 236
  int16_t  numOfColumns;
  int32_t  rowSize;
  int32_t  numOfRows;
  int32_t  numOfReads;
  int16_t  offset[TSDB_MAX_COLUMNS];
  int16_t  bytes[TSDB_MAX_COLUMNS];
H
hzcheng 已提交
237
  void *   signature;
238 239
  uint16_t payloadLen;
  char     payload[];
H
hzcheng 已提交
240 241
} SShowObj;

242 243
typedef struct {
  uint8_t  msgType;
244
  int8_t   usePublicIp;
245 246
  int8_t   received;
  int8_t   successed;
S
slguan 已提交
247
  int8_t   expected;
248 249 250 251 252 253
  int32_t  contLen;
  int32_t  code;
  void     *ahandle;
  void     *thandle;
  void     *pCont;
  SUserObj *pUser;
S
slguan 已提交
254 255
  SDbObj   *pDb;
  STableInfo *pTable;
256 257
} SQueuedMsg;

S
slguan 已提交
258
int32_t mgmtInitSystem();
S
slguan 已提交
259
int32_t mgmtStartSystem();
S
slguan 已提交
260 261
void    mgmtCleanUpSystem();
void    mgmtStopSystem();
S
slguan 已提交
262

263 264
extern char  version[];
extern void *tsMgmtTmr;
S
slguan 已提交
265
extern char  tsMnodeDir[];
S
slguan 已提交
266

H
hzcheng 已提交
267 268 269 270
#ifdef __cplusplus
}
#endif

S
#1177  
slguan 已提交
271
#endif