mnode.h 6.7 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"
S
#1177  
slguan 已提交
24 25 26
#include "taosdef.h"
#include "taosmsg.h"
#include "taoserror.h"
H
hzcheng 已提交
27 28 29 30 31 32
#include "tglobalcfg.h"
#include "thash.h"
#include "tidpool.h"
#include "tlog.h"
#include "tmempool.h"
#include "trpc.h"
S
slguan 已提交
33
#include "taosdef.h"
H
hzcheng 已提交
34 35 36 37 38 39
#include "tskiplist.h"
#include "tsocket.h"
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"

S
[TD-61]  
slguan 已提交
40 41
struct _vg_obj;
struct _db_obj;
S
slguan 已提交
42 43
struct _acct_obj;
struct _user_obj;
S
slguan 已提交
44
struct _mnode_obj;
S
[TD-61]  
slguan 已提交
45

S
slguan 已提交
46
typedef struct _mnode_obj {
S
slguan 已提交
47 48
  int32_t  mnodeId;
  int64_t  createdTime;
S
slguan 已提交
49
  int8_t   reserved[14];
S
slguan 已提交
50
  int8_t   updateEnd[1];
S
slguan 已提交
51
  int32_t  refCount;
S
slguan 已提交
52 53
  uint32_t privateIp;
  uint32_t publicIp;  
S
slguan 已提交
54 55
  uint16_t port;
  int8_t   role;
S
slguan 已提交
56
  char     mnodeName[TSDB_NODE_NAME_LEN + 1];
S
slguan 已提交
57 58
} SMnodeObj;

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

typedef struct {
90
  int32_t  dnodeId;
S
slguan 已提交
91
  uint16_t port;
92 93
  uint32_t privateIp;
  uint32_t publicIp;
H
hzcheng 已提交
94 95
} SVnodeGid;

S
slguan 已提交
96
typedef struct {
S
slguan 已提交
97
  char   tableId[TSDB_TABLE_ID_LEN + 1];
98
  int8_t type;
S
slguan 已提交
99
} STableObj;
S
#1177  
slguan 已提交
100 101

typedef struct SSuperTableObj {
S
slguan 已提交
102
  STableObj  info;
103 104 105 106 107 108 109
  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 已提交
110
  int32_t    refCount;
111 112 113
  int32_t    numOfTables;
  int16_t    nextColId;
  SSchema *  schema;
S
slguan 已提交
114 115
  int32_t    vgLen;
  int32_t *  vgList;
S
#1177  
slguan 已提交
116 117 118
} SSuperTableObj;

typedef struct {
S
slguan 已提交
119
  STableObj  info;
120 121 122 123 124 125 126 127 128 129 130
  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 已提交
131
  int32_t    refCount;
132 133
  char*      sql;          //used by normal table
  SSchema*   schema;       //used by normal table
S
#1177  
slguan 已提交
134 135 136
  SSuperTableObj *superTable;
} SChildTableObj;

H
hzcheng 已提交
137 138
typedef struct _vg_obj {
  uint32_t        vgId;
S
slguan 已提交
139
  char            dbName[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
140 141
  int64_t         createdTime;
  SVnodeGid       vnodeGid[TSDB_VNODES_SUPPORT];
142
  int32_t         numOfVnodes;
S
slguan 已提交
143
  int32_t         lbDnodeId;
H
hzcheng 已提交
144
  int32_t         lbTime;
S
slguan 已提交
145
  int8_t          status;
146 147
  int8_t          inUse;
  int8_t          reserved[13];
S
slguan 已提交
148
  int8_t          updateEnd[1];
S
slguan 已提交
149
  int32_t         refCount;
H
hzcheng 已提交
150
  struct _vg_obj *prev, *next;
S
slguan 已提交
151
  struct _db_obj *pDb;
S
slguan 已提交
152
  int32_t         numOfTables;
H
hzcheng 已提交
153
  void *          idPool;
S
slguan 已提交
154
  SChildTableObj ** tableList;
H
hzcheng 已提交
155 156 157
} SVgObj;

typedef struct _db_obj {
S
slguan 已提交
158
  char    name[TSDB_DB_NAME_LEN + 1];
S
slguan 已提交
159
  int8_t  status;
H
hzcheng 已提交
160 161
  int64_t createdTime;
  SDbCfg  cfg;
S
slguan 已提交
162 163
  int8_t  reserved[15];
  int8_t  updateEnd[1];
S
slguan 已提交
164
  int32_t refCount;
S
slguan 已提交
165 166 167
  int32_t numOfVgroups;
  int32_t numOfTables;
  int32_t numOfSuperTables;
S
slguan 已提交
168 169
  SVgObj *pHead;
  SVgObj *pTail;
S
slguan 已提交
170
  struct _acct_obj *pAcct;
H
hzcheng 已提交
171 172 173
} SDbObj;

typedef struct _user_obj {
S
slguan 已提交
174 175 176
  char              user[TSDB_USER_LEN + 1];
  char              pass[TSDB_KEY_LEN + 1];
  char              acct[TSDB_USER_LEN + 1];
H
hzcheng 已提交
177
  int64_t           createdTime;
S
slguan 已提交
178 179
  int8_t            superAuth;
  int8_t            writeAuth;
S
slguan 已提交
180
  int8_t            reserved[13];
S
slguan 已提交
181
  int8_t            updateEnd[1];
S
slguan 已提交
182
  int32_t           refCount;
S
slguan 已提交
183
  struct _acct_obj * pAcct;
S
slguan 已提交
184 185
  SQqueryList *     pQList;  // query list
  SStreamList *     pSList;  // stream list
H
hzcheng 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
} 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 已提交
202 203
  int64_t sKey;
  int8_t  accessState;   // Checked by mgmt heartbeat message
H
hzcheng 已提交
204 205
} SAcctInfo;

S
slguan 已提交
206
typedef struct _acct_obj {
S
slguan 已提交
207 208
  char      user[TSDB_USER_LEN + 1];
  char      pass[TSDB_KEY_LEN + 1];
S
slguan 已提交
209
  SAcctCfg  cfg;
H
hzcheng 已提交
210 211
  int32_t   acctId;
  int64_t   createdTime;
S
[TD-16]  
slguan 已提交
212 213
  int8_t    dirty;
  int8_t    reserved[14];
S
slguan 已提交
214
  int8_t    updateEnd[1];
S
slguan 已提交
215
  int32_t  refCount;
H
hzcheng 已提交
216 217 218 219 220
  SAcctInfo acctInfo;
  pthread_mutex_t  mutex;
} SAcctObj;

typedef struct {
S
slguan 已提交
221
  int8_t   type;
S
slguan 已提交
222
  char     db[TSDB_DB_NAME_LEN + 1];
H
hzcheng 已提交
223
  void *   pNode;
S
slguan 已提交
224 225 226 227 228 229
  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 已提交
230
  void *   signature;
231 232
  uint16_t payloadLen;
  char     payload[];
H
hzcheng 已提交
233 234
} SShowObj;

235 236
typedef struct {
  uint8_t  msgType;
237
  int8_t   usePublicIp;
238 239
  int8_t   received;
  int8_t   successed;
S
slguan 已提交
240
  int8_t   expected;
241 242
  int8_t   retry;
  int8_t   maxRetry;
243 244 245 246 247
  int32_t  contLen;
  int32_t  code;
  void     *ahandle;
  void     *thandle;
  void     *pCont;
S
slguan 已提交
248 249
  SAcctObj *pAcct;
  SDnodeObj*pDnode;
250
  SUserObj *pUser;
S
slguan 已提交
251
  SDbObj   *pDb;
S
slguan 已提交
252
  SVgObj   *pVgroup;
S
slguan 已提交
253
  STableObj *pTable;
254 255
} SQueuedMsg;

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

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

H
hzcheng 已提交
265 266 267 268
#ifdef __cplusplus
}
#endif

S
#1177  
slguan 已提交
269
#endif