catalog.h 10.2 KB
Newer Older
H
Hongze Cheng 已提交
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 _TD_CATALOG_H_
#define _TD_CATALOG_H_

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23 24
#include "os.h"
#include "taosdef.h"
H
Haojun Liao 已提交
25 26
#include "query.h"
#include "tname.h"
S
common  
Shengliang Guan 已提交
27
#include "tcommon.h"
H
Haojun Liao 已提交
28 29
#include "tarray.h"
#include "thash.h"
H
Hongze Cheng 已提交
30
#include "tmsg.h"
H
Haojun Liao 已提交
31
#include "transport.h"
H
Haojun Liao 已提交
32

D
dapan1121 已提交
33
typedef struct SCatalog SCatalog;
H
Haojun Liao 已提交
34

D
dapan1121 已提交
35 36 37 38 39 40 41 42
enum {
  CTG_DBG_DB_NUM = 1,
  CTG_DBG_META_NUM,
  CTG_DBG_STB_NUM,
  CTG_DBG_DB_RENT_NUM,
  CTG_DBG_STB_RENT_NUM,
};

D
dapan 已提交
43 44 45 46 47
typedef enum {
  AUTH_TYPE_READ = 1,
  AUTH_TYPE_WRITE,
  AUTH_TYPE_OTHER,
} AUTH_TYPE;
D
dapan1121 已提交
48

D
dapan1121 已提交
49 50 51 52 53 54
typedef struct SUserAuthInfo {
  char user[TSDB_USER_LEN]; 
  char dbFName[TSDB_DB_FNAME_LEN]; 
  AUTH_TYPE type;
} SUserAuthInfo;

D
dapan1121 已提交
55 56 57 58 59 60
typedef struct SDbInfo {
  int32_t vgVer;
  int32_t tbNum;
  int64_t dbId;
} SDbInfo;

D
dapan1121 已提交
61
typedef struct SCatalogReq {
D
dapan1121 已提交
62
  SArray *pDbVgroup;      // element is db full name
D
dapan1121 已提交
63 64 65
  SArray *pDbCfg;         // element is db full name
  SArray *pDbInfo;        // element is db full name
  SArray *pTableMeta;     // element is SNAME
D
dapan1121 已提交
66 67 68 69
  SArray *pTableHash;     // element is SNAME
  SArray *pUdf;           // element is udf name
  SArray *pIndex;         // element is index name
  SArray *pUser;          // element is SUserAuthInfo
D
dapan 已提交
70
  bool    qNodeRequired;  // valid qnode
D
dapan1121 已提交
71
  bool    forceUpdate;    
D
dapan1121 已提交
72
} SCatalogReq;
H
Haojun Liao 已提交
73 74

typedef struct SMetaData {
D
dapan1121 已提交
75
  SArray    *pDbVgroup;   // SArray<SArray<SVgroupInfo>*>
D
dapan1121 已提交
76 77 78
  SArray    *pDbCfg;      // SArray<SDbCfgInfo>
  SArray    *pDbInfo;     // SArray<SDbInfo>
  SArray    *pTableMeta;  // SArray<STableMeta*>
D
dapan1121 已提交
79 80 81 82 83
  SArray    *pTableHash;  // SArray<SVgroupInfo>
  SArray    *pUdfList;    // SArray<SFuncInfo>
  SArray    *pIndex;      // SArray<SIndexInfo>
  SArray    *pUser;       // SArray<bool>
  SArray    *pQnodeList;  // SArray<SQueryNodeAddr>
H
Haojun Liao 已提交
84 85
} SMetaData;

D
dapan1121 已提交
86
typedef struct SCatalogCfg {
D
dapan1121 已提交
87 88
  uint32_t maxTblCacheNum;
  uint32_t maxDBCacheNum;
D
dapan 已提交
89
  uint32_t maxUserCacheNum;
D
dapan1121 已提交
90
  uint32_t dbRentSec;
D
dapan1121 已提交
91
  uint32_t stbRentSec;
D
dapan1121 已提交
92 93
} SCatalogCfg;

D
dapan1121 已提交
94
typedef struct SSTableMetaVersion {
D
dapan 已提交
95 96
  char     dbFName[TSDB_DB_FNAME_LEN];
  char     stbName[TSDB_TABLE_NAME_LEN];
D
dapan1121 已提交
97
  uint64_t dbId;
D
dapan1121 已提交
98 99 100 101 102 103
  uint64_t suid;
  int16_t  sversion;
  int16_t  tversion;  
} SSTableMetaVersion;

typedef struct SDbVgVersion {
D
dapan 已提交
104
  char    dbFName[TSDB_DB_FNAME_LEN];
D
dapan1121 已提交
105 106
  int64_t dbId;
  int32_t vgVersion;
D
dapan1121 已提交
107
  int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
D
dapan1121 已提交
108 109
} SDbVgVersion;

D
dapan1121 已提交
110 111 112
typedef struct STbSVersion {
  char* tbFName;
  int32_t sver;
D
dapan1121 已提交
113
  int32_t tver;
D
dapan1121 已提交
114 115
} STbSVersion;

D
dapan 已提交
116 117 118 119 120
typedef struct SUserAuthVersion {
  char    user[TSDB_USER_LEN];
  int32_t version;
} SUserAuthVersion;

D
dapan1121 已提交
121
typedef SDbCfgRsp SDbCfgInfo;
D
dapan1121 已提交
122
typedef SUserIndexRsp SIndexInfo;
D
dapan1121 已提交
123

D
dapan1121 已提交
124 125
typedef void (*catalogCallback)(SMetaData* pResult, void* param, int32_t code);

D
dapan1121 已提交
126
int32_t catalogInit(SCatalogCfg *cfg);
D
dapan1121 已提交
127

H
Haojun Liao 已提交
128
/**
129
 * Get a cluster's catalog handle for all later operations. 
130
 * @param clusterId
131 132
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
133
 */
D
dapan1121 已提交
134
int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
D
dapan1121 已提交
135

D
dapan1121 已提交
136 137 138 139 140 141
/**
 * Free a cluster's all catalog info, usually it's not necessary, until the application is closing. 
 * no current or future usage should be guaranteed by application
 * @param pCatalog (input, NO more usage)
 * @return error code
 */
D
dapan1121 已提交
142
void catalogFreeHandle(SCatalog* pCatalog);
D
dapan1121 已提交
143

D
dapan1121 已提交
144
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum);
D
dapan1121 已提交
145

D
dapan1121 已提交
146 147 148
/**
 * Get a DB's all vgroup info.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
149
 * @param pTransporter (input, rpc object)
D
dapan1121 已提交
150 151 152 153 154
 * @param pMgmtEps (input, mnode EPs)
 * @param pDBName (input, full db name)
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
 */
D
dapan1121 已提交
155
int32_t catalogGetDBVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, SArray** pVgroupList);
D
dapan1121 已提交
156

D
dapan1121 已提交
157
int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgInfo* dbInfo);
D
dapan1121 已提交
158

D
dapan1121 已提交
159
int32_t catalogRemoveDB(SCatalog* pCatalog, const char* dbName, uint64_t dbId);
D
dapan1121 已提交
160

D
dapan1121 已提交
161
int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName);
D
dapan 已提交
162

D
dapan1121 已提交
163
int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* stbName, uint64_t suid);
D
dapan 已提交
164

165 166 167
/**
 * Get a table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
168
 * @param pTransporter (input, rpc object)
169
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
170
 * @param pTableName (input, table name)
171 172 173
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
D
dapan1121 已提交
174
int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
175

D
dapan1121 已提交
176 177 178 179 180
/**
 * Get a super table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pTransporter (input, rpc object)
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
181
 * @param pTableName (input, table name)
D
dapan1121 已提交
182 183 184
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
D
dapan1121 已提交
185
int32_t catalogGetSTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
D
dapan1121 已提交
186

D
dapan1121 已提交
187
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg);
D
dapan1121 已提交
188

D
dapan1121 已提交
189

D
dapan1121 已提交
190 191 192 193 194 195 196 197 198 199
/**
 * Force refresh DB's local cached vgroup info. 
 * @param pCtg (input, got with catalogGetHandle)
 * @param pTrans (input, rpc object)
 * @param pMgmtEps (input, mnode EPs)
 * @param dbFName (input, db full name)
 * @return error code
 */
int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* dbFName);

D
dapan1121 已提交
200 201
int32_t catalogChkTbMetaVersion(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, SArray* pTables);

202
/**
D
dapan1121 已提交
203
 * Force refresh a table's local cached meta data. 
204
 * @param pCatalog (input, got with catalogGetHandle)
205
 * @param pTransporter (input, rpc object)
206
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
207
 * @param pTableName (input, table name)
D
dapan1121 已提交
208
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
209 210
 * @return error code
 */
D
dapan1121 已提交
211
int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
212 213

/**
D
dapan1121 已提交
214
 * Force refresh a table's local cached meta data and get the new one. 
215
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
216
 * @param pTransporter (input, rpc object)
217
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
218
 * @param pTableName (input, table name)
219
 * @param pTableMeta(output, table meta data, NEED to free it by calller) 
D
dapan1121 已提交
220
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
221 222
 * @return error code
 */
D
dapan1121 已提交
223
int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
D
dapan1121 已提交
224

H
Haojun Liao 已提交
225

D
dapan1121 已提交
226 227

/**
228 229
 * Get a table's actual vgroup, for stable it's all possible vgroup list.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
230
 * @param pTransporter (input, rpc object)
231
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
232
 * @param pTableName (input, table name)
233 234
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
D
dapan1121 已提交
235
 */
D
dapan1121 已提交
236
int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
D
dapan1121 已提交
237 238

/**
239 240
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
241
 * @param pTransporter (input, rpc object)
242
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
243
 * @param pTableName (input, table name)
244 245
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
246
 */
D
dapan1121 已提交
247
int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
D
dapan 已提交
248 249


H
Haojun Liao 已提交
250
/**
251 252
 * Get all meta data required in pReq.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
253
 * @param pTransporter (input, rpc object)
254 255 256 257
 * @param pMgmtEps (input, mnode EPs)
 * @param pReq (input, reqest info)
 * @param pRsp (output, response data)
 * @return error code 
H
Haojun Liao 已提交
258
 */
D
dapan1121 已提交
259
int32_t catalogGetAllMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
260

D
dapan1121 已提交
261 262
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId);

D
dapan1121 已提交
263
int32_t catalogGetQnodeList(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
D
dapan 已提交
264

D
dapan1121 已提交
265
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
D
dapan1121 已提交
266

D
dapan1121 已提交
267
int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num);
D
dapan1121 已提交
268

D
dapan 已提交
269 270
int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion **users, uint32_t *num);

D
dapan1121 已提交
271 272
int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg);

D
dapan1121 已提交
273
int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* indexName, SIndexInfo* pInfo);
D
dapan1121 已提交
274

X
Xiaoyu Wang 已提交
275
int32_t catalogGetTableIndex(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pName, SArray** pRes);
D
dapan1121 已提交
276

D
dapan1121 已提交
277
int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo);
D
dapan1121 已提交
278

D
dapan 已提交
279 280 281
int32_t catalogChkAuth(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass);

int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
D
dapan 已提交
282

D
dapan1121 已提交
283 284
int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet *epSet);

D
dapan1121 已提交
285
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, bool forceUpdate);
D
dapan1121 已提交
286 287


H
Haojun Liao 已提交
288
/**
D
dapan1121 已提交
289
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
290
 */
D
dapan1121 已提交
291
void catalogDestroy(void);
H
Haojun Liao 已提交
292

H
Hongze Cheng 已提交
293 294 295 296
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
297
#endif /*_TD_CATALOG_H_*/