mnode.h 9.0 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 46 47 48 49 50 51 52
#include "tskiplist.h"
#include "tsocket.h"
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"

// internal globals
extern char  version[];
extern void *mgmtTmr;
extern void *mgmtQhandle;
extern void *mgmtTranQhandle;
extern int   mgmtShellConns;
extern int   mgmtDnodeConns;
extern char  mgmtDirectory[];

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

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 已提交
76 77
  uint16_t   numOfTotalVnodes; // from dnode status msg, config information
  uint16_t   unused;
H
hzcheng 已提交
78 79 80 81 82 83 84 85 86 87 88
  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 已提交
89
  int16_t    lbStatus;         // set in balance function
H
hzcheng 已提交
90 91 92 93
  int16_t    lastAllocVnode;  // increase while create vnode
  SVnodeLoad vload[TSDB_MAX_VNODES];
  char       reserved[16];
  char       updateEnd[1];
S
slguan 已提交
94
  void *     thandle;
H
hzcheng 已提交
95 96 97 98 99 100 101 102 103 104 105
} 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 已提交
106
} STableGid;
H
hzcheng 已提交
107 108

typedef struct _tab_obj {
S
slguan 已提交
109
  char      meterId[TSDB_TABLE_ID_LEN + 1];
H
hzcheng 已提交
110
  uint64_t  uid;
S
#1177  
slguan 已提交
111
  STableGid gid;
H
hzcheng 已提交
112 113 114 115 116 117 118 119

  int32_t sversion;     // schema version
  int64_t createdTime;
  int32_t numOfTags;    // for metric
  int32_t numOfMeters;  // for metric
  int32_t numOfColumns;
  int32_t schemaSize;
  short   nextColId;
S
slguan 已提交
120
  char    tableType : 4;
H
hzcheng 已提交
121 122 123 124 125 126 127 128 129
  char    status : 3;
  char    isDirty : 1;  // if the table change tag column 1 value
  char    reserved[15];
  char    updateEnd[1];

  pthread_rwlock_t rwLock;
  tSkipList *      pSkipList;
  struct _tab_obj *pHead;  // for metric, a link list for all meters created
                           // according to this metric
S
slguan 已提交
130
  char *pTagData;          // TSDB_TABLE_ID_LEN(metric_name)+
H
hzcheng 已提交
131 132 133 134 135 136 137 138 139
                           // tags_value1/tags_value2/tags_value3
  struct _tab_obj *prev, *next;
  char *           pSql;   // pointer to SQL, for SC, null-terminated string
  char *           pReserve1;
  char *           pReserve2;
  char *           schema;
  // SSchema    schema[];
} STabObj;

S
#1177  
slguan 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153

typedef struct SSuperTableObj {
  char     tableId[TSDB_TABLE_ID_LEN + 1];
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfTags;
  int32_t  numOfMeters;
  int32_t  numOfColumns;
  int32_t  schemaSize;
  int8_t   reserved[7];
  int8_t   updateEnd[1];
S
#1177  
slguan 已提交
154 155 156


  pthread_rwlock_t rwLock;
S
#1177  
slguan 已提交
157
  struct SSuperTableObj *prev, *next;
S
#1177  
slguan 已提交
158 159 160
  int16_t  nextColId;

  int8_t   *schema;
S
#1177  
slguan 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
} SSuperTableObj;

typedef struct {
  char     tableId[TSDB_TABLE_ID_LEN + 1];
  char     superTableId[TSDB_TABLE_ID_LEN + 1];
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int8_t   reserved[7];
  int8_t   updateEnd[1];
  SSuperTableObj *superTable;
} SChildTableObj;

typedef struct {
  char     tableId[TSDB_TABLE_ID_LEN + 1];
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfColumns;
  int32_t  schemaSize;
S
#1177  
slguan 已提交
184 185
  int8_t     reserved[3];
  int8_t     updateEnd[1];
S
#1177  
slguan 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198
  int16_t  nextColId;
  char*    schema;
} SNormalTableObj;

typedef struct {
  char     tableId[TSDB_TABLE_ID_LEN + 1];
  uint64_t uid;
  int32_t  sid;
  int32_t  vgId;
  int64_t  createdTime;
  int32_t  sversion;
  int32_t  numOfColumns;
  int32_t  schemaSize;
S
slguan 已提交
199
  int16_t  sqlLen;
S
#1177  
slguan 已提交
200 201
  int8_t     reserved[3];
  int8_t     updateEnd[1];
S
#1177  
slguan 已提交
202 203 204 205 206 207
  int16_t  nextColId;
  char*    pSql;  //null-terminated string
  char*    schema;
} SStreamTableObj;


H
hzcheng 已提交
208 209 210 211 212 213 214 215 216 217 218
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];
  int32_t         numOfMeters;
  int32_t         lbIp;
  int32_t         lbTime;
S
slguan 已提交
219
  int8_t          lbStatus;
S
#1177  
slguan 已提交
220 221
  int8_t            reserved[16];
  int8_t            updateEnd[1];
H
hzcheng 已提交
222 223 224 225 226 227
  struct _vg_obj *prev, *next;
  void *          idPool;
  STabObj **      meterList;
} SVgObj;

typedef struct _db_obj {
S
slguan 已提交
228 229 230 231
  /*
   * this length will cause the storage structure to change, rollback
   */
  char    name[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  int64_t createdTime;
  SDbCfg  cfg;
  int32_t numOfVgroups;
  int32_t numOfTables;
  int32_t numOfMetrics;
  uint8_t vgStatus;
  uint8_t dropStatus;
  char    reserved[16];
  char    updateEnd[1];

  STabObj *       pMetric;
  struct _db_obj *prev, *next;
  SVgObj *        pHead;  // empty vgroup first
  SVgObj *        pTail;  // empty vgroup end
  void *          vgTimer;
} SDbObj;

typedef struct _user_obj {
  char              user[TSDB_USER_LEN + 1];
  char              pass[TSDB_KEY_LEN];
  char              acct[TSDB_USER_LEN];
  int64_t           createdTime;
  char              superAuth : 1;
  char              writeAuth : 1;
  char              reserved[16];
  char              updateEnd[1];
  struct _user_obj *prev, *next;
} 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;
  TSKEY   sKey;
  char    accessState;  // Checked by mgmt heartbeat message
} SAcctInfo;

typedef struct {
  char      user[TSDB_USER_LEN + 1];
  char      pass[TSDB_KEY_LEN];
  SAcctCfg  cfg;
  int32_t   acctId;
  int64_t   createdTime;
  char      reserved[15];
  char      updateEnd[1];
  SAcctInfo acctInfo;

  SDbObj *         pHead;
  SUserObj *       pUser;
  struct _connObj *pConn;
  pthread_mutex_t  mutex;
} SAcctObj;

typedef struct _connObj {
  SAcctObj *       pAcct;
  SDbObj *         pDb;
  SUserObj *       pUser;
  char             user[TSDB_USER_LEN];
  uint64_t         stime;               // login time
  char             superAuth : 1;       // super user flag
  char             writeAuth : 1;       // write flag
  char             killConnection : 1;  // kill the connection flag
S
slguan 已提交
304 305
  uint8_t          usePublicIp : 1;     // if the connection request is publicIp
  uint8_t          reserved : 4;
H
hzcheng 已提交
306 307 308
  uint32_t         queryId;             // query ID to be killed
  uint32_t         streamId;            // stream ID to be killed
  uint32_t         ip;                  // shell IP
L
lihui 已提交
309
  uint16_t         port;                // shell port
H
hzcheng 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
  void *           thandle;
  SQList *         pQList;  // query list
  SSList *         pSList;  // stream list
  uint64_t         qhandle;
  struct _connObj *prev, *next;
} SConnObj;

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

typedef struct {
  char     type;
  void *   pNode;
  short    numOfColumns;
  int      rowSize;
  int      numOfRows;
  int      numOfReads;
  short    offset[TSDB_MAX_COLUMNS];
  short    bytes[TSDB_MAX_COLUMNS];
  void *   signature;
  uint16_t payloadLen; /* length of payload*/
  char     payload[];  /* payload for wildcard match in show tables */
} SShowObj;

S
slguan 已提交
338
void mgmtProcessMsgFromDnode(int8_t *pCont, int32_t contLen, int32_t msgType, void *pConn);
H
hzcheng 已提交
339 340 341 342 343

#ifdef __cplusplus
}
#endif

S
#1177  
slguan 已提交
344
#endif