mnode.h 7.2 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 28 29
#include "taosdef.h"
#include "taosmsg.h"
#include "taoserror.h"


H
hzcheng 已提交
30 31 32 33 34 35 36
#include "sdb.h"
#include "tglobalcfg.h"
#include "thash.h"
#include "tidpool.h"
#include "tlog.h"
#include "tmempool.h"
#include "trpc.h"
S
slguan 已提交
37
#include "taosdef.h"
H
hzcheng 已提交
38 39 40 41 42 43 44 45
#include "tskiplist.h"
#include "tsocket.h"
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"

// internal globals
extern char  version[];
S
slguan 已提交
46 47 48
extern void *tsMgmtTmr;
extern void *tsMgmtTranQhandle;
extern char  tsMgmtDirectory[];
H
hzcheng 已提交
49

S
#1177  
slguan 已提交
50 51 52 53 54
extern int tsAcctUpdateSize;
extern int tsDbUpdateSize;
extern int tsDnodeUpdateSize;
extern int tsMnodeUpdateSize;
extern int tsVgUpdateSize;
H
hzcheng 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

typedef struct {
  uint32_t   privateIp;
  int32_t    sid;
  uint32_t   moduleStatus;
  int32_t    openVnodes;
  int32_t    numOfVnodes;
  int32_t    numOfFreeVnodes;
  int64_t    createdTime;
  uint32_t   publicIp;
  int32_t    status;
  uint32_t   lastAccess;
  uint32_t   rebootTimes;
  uint32_t   lastReboot;       // time stamp for last reboot
  uint16_t   numOfCores;       // from dnode status msg
  uint8_t    alternativeRole;  // from dnode status msg, 0-any, 1-mgmt, 2-dnode
  uint8_t    reserveStatus;
S
slguan 已提交
72 73
  uint16_t   numOfTotalVnodes; // from dnode status msg, config information
  uint16_t   unused;
H
hzcheng 已提交
74 75 76 77 78 79 80 81 82 83 84
  float      diskAvailable;    // from dnode status msg
  int32_t    bandwidthMb;      // config by user
  int16_t    cpuAvgUsage;      // calc from sys.cpu
  int16_t    memoryAvgUsage;   // calc from sys.mem
  int16_t    diskAvgUsage;     // calc from sys.disk
  int16_t    bandwidthUsage;   // calc from sys.band
  uint32_t   rack;
  uint16_t   idc;
  uint16_t   slot;
  int32_t    customScore;     // config by user
  float      lbScore;         // calc in balance function
S
slguan 已提交
85
  int16_t    lbStatus;         // set in balance function
H
hzcheng 已提交
86 87 88 89
  int16_t    lastAllocVnode;  // increase while create vnode
  SVnodeLoad vload[TSDB_MAX_VNODES];
  char       reserved[16];
  char       updateEnd[1];
S
slguan 已提交
90
  void *     thandle;
H
hzcheng 已提交
91 92 93 94 95 96 97 98 99 100 101
} SDnodeObj;

typedef struct {
  uint32_t ip;
  uint32_t publicIp;
  int32_t  vnode;
} SVnodeGid;

typedef struct {
  int32_t sid;
  int32_t vgId;  // vnode group ID
S
#1177  
slguan 已提交
102
} STableGid;
H
hzcheng 已提交
103

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

S
slguan 已提交
113 114
struct _vg_obj;

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

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

typedef struct {
S
slguan 已提交
146
  char     tableId[TSDB_TABLE_ID_LEN];
S
slguan 已提交
147
  int8_t   type;
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 155
  int8_t   reserved[3];
  int8_t   updateEnd[1];
S
#1177  
slguan 已提交
156
  int16_t  nextColId;
S
slguan 已提交
157
  SSchema* schema;
S
#1177  
slguan 已提交
158 159 160
} SNormalTableObj;

typedef struct {
S
slguan 已提交
161
  char     tableId[TSDB_TABLE_ID_LEN];
S
slguan 已提交
162
  int8_t   type;
S
#1177  
slguan 已提交
163 164 165 166 167 168
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfColumns;
S
slguan 已提交
169
  int16_t  sqlLen;
S
slguan 已提交
170 171
  int8_t   reserved[3];
  int8_t   updateEnd[1];
S
#1177  
slguan 已提交
172
  int16_t  nextColId;
S
slguan 已提交
173
  char*    sql;  //null-terminated string
S
slguan 已提交
174
  SSchema* schema;
S
#1177  
slguan 已提交
175 176
} SStreamTableObj;

H
hzcheng 已提交
177 178 179 180 181 182 183 184
typedef struct _vg_obj {
  uint32_t        vgId;
  char            dbName[TSDB_DB_NAME_LEN];
  int64_t         createdTime;
  uint64_t        lastCreate;
  uint64_t        lastRemove;
  int32_t         numOfVnodes;
  SVnodeGid       vnodeGid[TSDB_VNODES_SUPPORT];
S
slguan 已提交
185
  int32_t         numOfTables;
H
hzcheng 已提交
186 187
  int32_t         lbIp;
  int32_t         lbTime;
S
slguan 已提交
188
  int8_t          lbStatus;
S
slguan 已提交
189 190
  int8_t          reserved[16];
  int8_t          updateEnd[1];
H
hzcheng 已提交
191 192
  struct _vg_obj *prev, *next;
  void *          idPool;
S
slguan 已提交
193
  STableInfo **   tableList;
H
hzcheng 已提交
194 195 196
} SVgObj;

typedef struct _db_obj {
S
slguan 已提交
197
  char    name[TSDB_DB_NAME_LEN];
H
hzcheng 已提交
198 199
  int64_t createdTime;
  SDbCfg  cfg;
S
slguan 已提交
200
  int8_t  dropStatus;
H
hzcheng 已提交
201 202 203
  char    reserved[16];
  char    updateEnd[1];
  struct _db_obj *prev, *next;
S
slguan 已提交
204 205 206 207 208 209 210
  int32_t numOfVgroups;
  int32_t numOfTables;
  int32_t numOfSuperTables;
  int32_t vgStatus;
  SVgObj *pHead;  // empty vgroup first
  SVgObj *pTail;  // empty vgroup end
  void *  vgTimer;
H
hzcheng 已提交
211 212
} SDbObj;

S
slguan 已提交
213 214
struct _acctObj;

H
hzcheng 已提交
215
typedef struct _user_obj {
S
slguan 已提交
216
  char              user[TSDB_USER_LEN];
H
hzcheng 已提交
217 218 219
  char              pass[TSDB_KEY_LEN];
  char              acct[TSDB_USER_LEN];
  int64_t           createdTime;
S
slguan 已提交
220 221 222 223
  int8_t            superAuth;
  int8_t            writeAuth;
  int8_t            reserved[16];
  int8_t            updateEnd[1];
H
hzcheng 已提交
224
  struct _user_obj *prev, *next;
S
slguan 已提交
225
  struct _acctObj * pAcct;
S
slguan 已提交
226 227
  SQqueryList *     pQList;  // query list
  SStreamList *     pSList;  // stream list
H
hzcheng 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
} 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 已提交
244 245
  int64_t sKey;
  int8_t  accessState;   // Checked by mgmt heartbeat message
H
hzcheng 已提交
246 247
} SAcctInfo;

S
slguan 已提交
248
typedef struct _acctObj {
S
slguan 已提交
249
  char      user[TSDB_USER_LEN];
H
hzcheng 已提交
250
  char      pass[TSDB_KEY_LEN];
S
slguan 已提交
251
  SAcctCfg  cfg;
H
hzcheng 已提交
252 253
  int32_t   acctId;
  int64_t   createdTime;
S
slguan 已提交
254 255
  int8_t    reserved[15];
  int8_t    updateEnd[1];
H
hzcheng 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269
  SAcctInfo acctInfo;
  SDbObj *         pHead;
  SUserObj *       pUser;
  pthread_mutex_t  mutex;
} SAcctObj;

typedef struct {
  char spi;
  char encrypt;
  char secret[TSDB_KEY_LEN];
  char cipheringKey[TSDB_KEY_LEN];
} SSecInfo;

typedef struct {
S
slguan 已提交
270
  int8_t   type;
S
slguan 已提交
271
  char     db[TSDB_DB_NAME_LEN];
H
hzcheng 已提交
272
  void *   pNode;
S
slguan 已提交
273 274 275 276 277 278
  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 已提交
279 280 281 282 283
  void *   signature;
  uint16_t payloadLen; /* length of payload*/
  char     payload[];  /* payload for wildcard match in show tables */
} SShowObj;

S
dnode  
slguan 已提交
284
//mgmtSystem
S
slguan 已提交
285 286
int32_t mgmtStartSystem();
void mgmtCleanUpSystem();
S
slguan 已提交
287
void mgmtProcessMsgFromDnode(int8_t *pCont, int32_t contLen, int32_t msgType, void *pConn);
S
dnode  
slguan 已提交
288 289 290
extern int32_t (*mgmtInitSystem)();
extern void (*mgmtStopSystem)();
extern void (*mgmtCleanUpRedirect)();
S
slguan 已提交
291

H
hzcheng 已提交
292 293 294 295
#ifdef __cplusplus
}
#endif

S
#1177  
slguan 已提交
296
#endif