mnode.h 6.8 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
slguan 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
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 已提交
56 57
  int8_t   reserved[15];
  int8_t   updateEnd[1];
S
slguan 已提交
58 59 60 61 62
  int      syncFd;
  void    *hbTimer;
  void    *pSync;
} SMnodeObj;

S
slguan 已提交
63
typedef struct {
S
slguan 已提交
64
  int32_t    dnodeId;
H
hzcheng 已提交
65
  uint32_t   privateIp;
66
  uint32_t   publicIp;
H
hzcheng 已提交
67 68 69
  uint32_t   moduleStatus;
  int64_t    createdTime;
  uint32_t   lastAccess;
70 71 72 73 74
  int32_t    openVnodes;
  int32_t    numOfTotalVnodes; // from dnode status msg, config information
  uint32_t   rack;
  uint16_t   idc;
  uint16_t   slot;
H
hzcheng 已提交
75
  uint16_t   numOfCores;       // from dnode status msg
76 77 78 79 80
  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 已提交
81 82
  int8_t     reserved[15];
  int8_t     updateEnd[1];
83 84 85
  SVnodeLoad vload[TSDB_MAX_VNODES];
  int32_t    status;
  uint32_t   lastReboot;       // time stamp for last reboot
H
hzcheng 已提交
86
  float      diskAvailable;    // from dnode status msg
87
  int16_t    diskAvgUsage;     // calc from sys.disk
H
hzcheng 已提交
88 89 90 91 92 93
  int16_t    cpuAvgUsage;      // calc from sys.cpu
  int16_t    memoryAvgUsage;   // calc from sys.mem
  int16_t    bandwidthUsage;   // calc from sys.band
} SDnodeObj;

typedef struct {
94
  int32_t  dnodeId;
H
hzcheng 已提交
95
  int32_t  vnode;
96 97
  uint32_t privateIp;
  uint32_t publicIp;
H
hzcheng 已提交
98 99
} SVnodeGid;

S
slguan 已提交
100
typedef struct {
101
  char     tableId[TSDB_TABLE_ID_LEN];
S
slguan 已提交
102
  int8_t   type;
S
slguan 已提交
103
  int8_t   dirty;
S
slguan 已提交
104 105 106 107 108
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
} STableInfo;
S
#1177  
slguan 已提交
109

S
slguan 已提交
110 111
struct _vg_obj;

S
#1177  
slguan 已提交
112
typedef struct SSuperTableObj {
S
slguan 已提交
113
  char     tableId[TSDB_TABLE_ID_LEN + 1];
S
slguan 已提交
114
  int8_t   type;
S
slguan 已提交
115
  int8_t   dirty;
S
#1177  
slguan 已提交
116 117 118 119 120 121
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfColumns;
S
slguan 已提交
122
  int32_t  numOfTags;
S
slguan 已提交
123
  int8_t   reserved[15];
S
#1177  
slguan 已提交
124
  int8_t   updateEnd[1];
S
slguan 已提交
125
  int32_t  numOfTables;
S
#1177  
slguan 已提交
126
  int16_t  nextColId;
S
slguan 已提交
127
  SSchema *schema;
S
#1177  
slguan 已提交
128 129 130
} SSuperTableObj;

typedef struct {
S
slguan 已提交
131
  char     tableId[TSDB_TABLE_ID_LEN + 1];
S
slguan 已提交
132
  int8_t   type;
S
slguan 已提交
133
  int8_t   dirty;
S
#1177  
slguan 已提交
134 135 136 137
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
S
slguan 已提交
138
  char     superTableId[TSDB_TABLE_ID_LEN + 1];
S
slguan 已提交
139
  int8_t   reserved[1];
S
#1177  
slguan 已提交
140 141 142 143 144
  int8_t   updateEnd[1];
  SSuperTableObj *superTable;
} SChildTableObj;

typedef struct {
145
  char     tableId[TSDB_TABLE_ID_LEN];
S
slguan 已提交
146
  int8_t   type;
S
slguan 已提交
147
  int8_t   dirty;
S
#1177  
slguan 已提交
148 149 150 151 152 153
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfColumns;
S
slguan 已提交
154
  int32_t  sqlLen;
S
slguan 已提交
155
  int8_t   reserved[7];
S
slguan 已提交
156 157
  int8_t   updateEnd[1];
  char*    sql;  //null-terminated string
S
slguan 已提交
158
  int16_t  nextColId;
S
slguan 已提交
159
  SSchema* schema;
S
slguan 已提交
160
} SNormalTableObj;
S
#1177  
slguan 已提交
161

S
slguan 已提交
162 163
struct _db_obj;

H
hzcheng 已提交
164 165
typedef struct _vg_obj {
  uint32_t        vgId;
S
slguan 已提交
166
  char            dbName[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
167 168
  int64_t         createdTime;
  SVnodeGid       vnodeGid[TSDB_VNODES_SUPPORT];
169
  int32_t         numOfVnodes;
H
hzcheng 已提交
170 171
  int32_t         lbIp;
  int32_t         lbTime;
S
slguan 已提交
172
  int8_t          lbStatus;
173
  int8_t          reserved[14];
S
slguan 已提交
174
  int8_t          updateEnd[1];
H
hzcheng 已提交
175
  struct _vg_obj *prev, *next;
S
slguan 已提交
176
  struct _db_obj *pDb;
S
slguan 已提交
177
  int32_t         numOfTables;
H
hzcheng 已提交
178
  void *          idPool;
S
slguan 已提交
179
  STableInfo **   tableList;
H
hzcheng 已提交
180 181 182
} SVgObj;

typedef struct _db_obj {
S
slguan 已提交
183
  char    name[TSDB_DB_NAME_LEN + 1];
S
slguan 已提交
184
  int8_t  dirty;
H
hzcheng 已提交
185 186
  int64_t createdTime;
  SDbCfg  cfg;
S
slguan 已提交
187 188
  int8_t  reserved[15];
  int8_t  updateEnd[1];
H
hzcheng 已提交
189
  struct _db_obj *prev, *next;
S
slguan 已提交
190 191 192
  int32_t numOfVgroups;
  int32_t numOfTables;
  int32_t numOfSuperTables;
S
slguan 已提交
193 194
  SVgObj *pHead;
  SVgObj *pTail;
H
hzcheng 已提交
195 196
} SDbObj;

S
slguan 已提交
197 198
struct _acctObj;

H
hzcheng 已提交
199
typedef struct _user_obj {
S
slguan 已提交
200 201 202
  char              user[TSDB_USER_LEN + 1];
  char              pass[TSDB_KEY_LEN + 1];
  char              acct[TSDB_USER_LEN + 1];
H
hzcheng 已提交
203
  int64_t           createdTime;
S
slguan 已提交
204 205
  int8_t            superAuth;
  int8_t            writeAuth;
S
slguan 已提交
206
  int8_t            reserved[13];
S
slguan 已提交
207
  int8_t            updateEnd[1];
H
hzcheng 已提交
208
  struct _user_obj *prev, *next;
S
slguan 已提交
209
  struct _acctObj * pAcct;
S
slguan 已提交
210 211
  SQqueryList *     pQList;  // query list
  SStreamList *     pSList;  // stream list
H
hzcheng 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
} 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 已提交
228 229
  int64_t sKey;
  int8_t  accessState;   // Checked by mgmt heartbeat message
H
hzcheng 已提交
230 231
} SAcctInfo;

S
slguan 已提交
232
typedef struct _acctObj {
S
slguan 已提交
233 234
  char      user[TSDB_USER_LEN + 1];
  char      pass[TSDB_KEY_LEN + 1];
S
slguan 已提交
235
  SAcctCfg  cfg;
H
hzcheng 已提交
236 237
  int32_t   acctId;
  int64_t   createdTime;
S
slguan 已提交
238 239
  int8_t    reserved[15];
  int8_t    updateEnd[1];
H
hzcheng 已提交
240 241 242 243 244 245 246
  SAcctInfo acctInfo;
  SDbObj *         pHead;
  SUserObj *       pUser;
  pthread_mutex_t  mutex;
} SAcctObj;

typedef struct {
S
slguan 已提交
247
  int8_t   type;
S
slguan 已提交
248
  char     db[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
249
  void *   pNode;
S
slguan 已提交
250 251 252 253 254 255
  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 已提交
256
  void *   signature;
257 258
  uint16_t payloadLen;
  char     payload[];
H
hzcheng 已提交
259 260
} SShowObj;

261 262 263 264 265 266 267 268 269 270 271 272 273 274
typedef struct {
  uint8_t  msgType;
  int8_t   expected;
  int8_t   received;
  int8_t   successed;
  int32_t  contLen;
  int32_t  code;
  void     *ahandle;
  void     *thandle;
  void     *pCont;
  SDbObj   *pDb;
  SUserObj *pUser;
} SQueuedMsg;

S
slguan 已提交
275
int32_t mgmtInitSystem();
S
slguan 已提交
276
int32_t mgmtStartSystem();
S
slguan 已提交
277 278
void    mgmtCleanUpSystem();
void    mgmtStopSystem();
S
slguan 已提交
279

280 281
extern char  version[];
extern void *tsMgmtTmr;
S
slguan 已提交
282
extern char  tsMnodeDir[];
S
slguan 已提交
283

H
hzcheng 已提交
284 285 286 287
#ifdef __cplusplus
}
#endif

S
#1177  
slguan 已提交
288
#endif