catalog.h 12.0 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
#include "os.h"
H
Haojun Liao 已提交
24
#include "query.h"
X
Xiaoyu Wang 已提交
25
#include "taosdef.h"
H
Haojun Liao 已提交
26
#include "tarray.h"
X
Xiaoyu Wang 已提交
27
#include "tcommon.h"
H
Haojun Liao 已提交
28
#include "thash.h"
H
Hongze Cheng 已提交
29
#include "tmsg.h"
X
Xiaoyu Wang 已提交
30
#include "tname.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
typedef enum {
  AUTH_TYPE_READ = 1,
  AUTH_TYPE_WRITE,
  AUTH_TYPE_OTHER,
D
dapan1121 已提交
47
  AUTH_TYPE_READ_OR_WRITE,
D
dapan 已提交
48
} AUTH_TYPE;
D
dapan1121 已提交
49

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

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

63 64 65 66 67
typedef struct STablesReq {
  char    dbFName[TSDB_DB_FNAME_LEN];
  SArray* pTables;
} STablesReq;

D
dapan1121 已提交
68
typedef struct SCatalogReq {
X
Xiaoyu Wang 已提交
69 70 71
  SArray* pDbVgroup;      // element is db full name
  SArray* pDbCfg;         // element is db full name
  SArray* pDbInfo;        // element is db full name
72 73
  SArray* pTableMeta;     // element is STablesReq
  SArray* pTableHash;     // element is STablesReq
X
Xiaoyu Wang 已提交
74 75 76 77
  SArray* pUdf;           // element is udf name
  SArray* pIndex;         // element is index name
  SArray* pUser;          // element is SUserAuthInfo
  SArray* pTableIndex;    // element is SNAME
D
dapan1121 已提交
78
  SArray* pTableCfg;      // element is SNAME
D
dapan 已提交
79
  bool    qNodeRequired;  // valid qnode
80
  bool    dNodeRequired;  // valid dnode
D
dapan1121 已提交
81
  bool    svrVerRequired;
X
Xiaoyu Wang 已提交
82
  bool    forceUpdate;
D
dapan1121 已提交
83
} SCatalogReq;
H
Haojun Liao 已提交
84

D
dapan1121 已提交
85 86 87 88 89
typedef struct SMetaRes {
  int32_t code;
  void*   pRes;
} SMetaRes;

H
Haojun Liao 已提交
90
typedef struct SMetaData {
D
dapan1121 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103
  SArray*   pDbVgroup;    // pRes = SArray<SVgroupInfo>*
  SArray*   pDbCfg;       // pRes = SDbCfgInfo*
  SArray*   pDbInfo;      // pRes = SDbInfo*
  SArray*   pTableMeta;   // pRes = STableMeta*
  SArray*   pTableHash;   // pRes = SVgroupInfo*
  SArray*   pTableIndex;  // pRes = SArray<STableIndexInfo>*
  SArray*   pUdfList;     // pRes = SFuncInfo*
  SArray*   pIndex;       // pRes = SIndexInfo*
  SArray*   pUser;        // pRes = bool*
  SArray*   pQnodeList;   // pRes = SArray<SQueryNodeLoad>*
  SArray*   pTableCfg;    // pRes = STableCfg*
  SArray*   pDnodeList;   // pRes = SArray<SEpSet>*
  SMetaRes* pSvrVer;      // pRes = char*
H
Haojun Liao 已提交
104 105
} SMetaData;

D
dapan1121 已提交
106
typedef struct SCatalogCfg {
D
dapan1121 已提交
107 108
  uint32_t maxTblCacheNum;
  uint32_t maxDBCacheNum;
D
dapan 已提交
109
  uint32_t maxUserCacheNum;
D
dapan1121 已提交
110
  uint32_t dbRentSec;
D
dapan1121 已提交
111
  uint32_t stbRentSec;
D
dapan1121 已提交
112 113
} SCatalogCfg;

D
dapan1121 已提交
114
typedef struct SSTableVersion {
D
dapan 已提交
115 116
  char     dbFName[TSDB_DB_FNAME_LEN];
  char     stbName[TSDB_TABLE_NAME_LEN];
D
dapan1121 已提交
117
  uint64_t dbId;
D
dapan1121 已提交
118 119
  uint64_t suid;
  int16_t  sversion;
H
Hongze Cheng 已提交
120
  int16_t  tversion;
D
dapan1121 已提交
121 122
  int32_t  smaVer;
} SSTableVersion;
D
dapan1121 已提交
123 124

typedef struct SDbVgVersion {
D
dapan 已提交
125
  char    dbFName[TSDB_DB_FNAME_LEN];
D
dapan1121 已提交
126 127
  int64_t dbId;
  int32_t vgVersion;
X
Xiaoyu Wang 已提交
128
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
129
  int64_t stateTs;
D
dapan1121 已提交
130 131
} SDbVgVersion;

D
dapan1121 已提交
132
typedef struct STbSVersion {
X
Xiaoyu Wang 已提交
133
  char*   tbFName;
D
dapan1121 已提交
134
  int32_t sver;
D
dapan1121 已提交
135
  int32_t tver;
D
dapan1121 已提交
136 137
} STbSVersion;

D
dapan 已提交
138 139 140 141 142
typedef struct SUserAuthVersion {
  char    user[TSDB_USER_LEN];
  int32_t version;
} SUserAuthVersion;

X
Xiaoyu Wang 已提交
143
typedef SDbCfgRsp     SDbCfgInfo;
D
dapan1121 已提交
144
typedef SUserIndexRsp SIndexInfo;
D
dapan1121 已提交
145

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

X
Xiaoyu Wang 已提交
148
int32_t catalogInit(SCatalogCfg* cfg);
D
dapan1121 已提交
149

H
Haojun Liao 已提交
150
/**
X
Xiaoyu Wang 已提交
151
 * Get a cluster's catalog handle for all later operations.
152
 * @param clusterId
153 154
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
155
 */
D
dapan1121 已提交
156
int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
D
dapan1121 已提交
157

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

D
dapan1121 已提交
160 161 162
/**
 * Get a DB's all vgroup info.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
163
 * @param pTransporter (input, rpc object)
D
dapan1121 已提交
164 165 166 167 168
 * @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
 */
169
int32_t catalogGetDBVgList(SCatalog* pCatalog, SRequestConnInfo* pConn, const char* pDBName, SArray** pVgroupList);
D
dapan1121 已提交
170

171 172
int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, TAOS_DB_ROUTE_INFO* pInfo);

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

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

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

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

181
/**
X
Xiaoyu Wang 已提交
182
 * Get a table's meta data.
183
 * @param pCatalog (input, got with catalogGetHandle)
184
 * @param pTransporter (input, rpc object)
185
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
186
 * @param pTableName (input, table name)
187 188 189
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
H
Hongze Cheng 已提交
190 191
int32_t catalogGetTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
                            STableMeta** pTableMeta);
192

D
dapan1121 已提交
193
/**
X
Xiaoyu Wang 已提交
194
 * Get a super table's meta data.
D
dapan1121 已提交
195 196 197
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pTransporter (input, rpc object)
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
198
 * @param pTableName (input, table name)
D
dapan1121 已提交
199 200 201
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
H
Hongze Cheng 已提交
202 203
int32_t catalogGetSTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
                             STableMeta** pTableMeta);
D
dapan1121 已提交
204

H
Hongze Cheng 已提交
205
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg);
D
dapan1121 已提交
206

X
Xiaoyu Wang 已提交
207
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg);
D
dapan1121 已提交
208

D
dapan1121 已提交
209
int32_t catalogGetCachedTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta);
D
dapan1121 已提交
210

D
dapan1121 已提交
211
int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta);
D
dapan1121 已提交
212

D
dapan1121 已提交
213 214 215
int32_t catalogGetTablesHashVgId(SCatalog* pCtg, SRequestConnInfo* pConn, int32_t acctId, const char* pDb, const char* pTableName[],
                                  int32_t tableNum, int32_t *vgId);

X
Xiaoyu Wang 已提交
216
int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists);
D
dapan1121 已提交
217

218 219
int32_t catalogGetCachedTableVgMeta(SCatalog* pCtg, const SName* pTableName,          SVgroupInfo* pVgroup, STableMeta** pTableMeta);

D
dapan1121 已提交
220
/**
X
Xiaoyu Wang 已提交
221
 * Force refresh DB's local cached vgroup info.
D
dapan1121 已提交
222 223 224 225 226 227
 * @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
 */
D
dapan1121 已提交
228
int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName);
D
dapan1121 已提交
229

D
dapan1121 已提交
230
int32_t catalogChkTbMetaVersion(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* pTables);
D
dapan1121 已提交
231

232
/**
X
Xiaoyu Wang 已提交
233
 * Force refresh a table's local cached meta data.
234
 * @param pCatalog (input, got with catalogGetHandle)
235
 * @param pTransporter (input, rpc object)
236
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
237
 * @param pTableName (input, table name)
X
Xiaoyu Wang 已提交
238
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
239 240
 * @return error code
 */
D
dapan1121 已提交
241
int32_t catalogRefreshTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName, int32_t isSTable);
242 243

/**
X
Xiaoyu Wang 已提交
244
 * Force refresh a table's local cached meta data and get the new one.
245
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
246
 * @param pTransporter (input, rpc object)
247
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
248
 * @param pTableName (input, table name)
X
Xiaoyu Wang 已提交
249 250
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
251 252
 * @return error code
 */
H
Hongze Cheng 已提交
253 254
int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
                                   STableMeta** pTableMeta, int32_t isSTable);
D
dapan1121 已提交
255

D
dapan1121 已提交
256
/**
257 258
 * Get a table's actual vgroup, for stable it's all possible vgroup list.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
259
 * @param pTransporter (input, rpc object)
260
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
261
 * @param pTableName (input, table name)
262 263
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
D
dapan1121 已提交
264
 */
H
Hongze Cheng 已提交
265 266
int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
                                  SArray** pVgroupList);
D
dapan1121 已提交
267 268

/**
269 270
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
271
 * @param pTransporter (input, rpc object)
272
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
273
 * @param pTableName (input, table name)
274 275
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
276
 */
D
dapan1121 已提交
277
int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pName, SVgroupInfo* vgInfo);
X
Xiaoyu Wang 已提交
278

H
Haojun Liao 已提交
279
/**
280 281
 * Get all meta data required in pReq.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
282
 * @param pTransporter (input, rpc object)
283 284 285
 * @param pMgmtEps (input, mnode EPs)
 * @param pReq (input, reqest info)
 * @param pRsp (output, response data)
X
Xiaoyu Wang 已提交
286
 * @return error code
H
Haojun Liao 已提交
287
 */
D
dapan1121 已提交
288
int32_t catalogGetAllMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
289

H
Hongze Cheng 已提交
290 291
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, catalogCallback fp,
                               void* param, int64_t* jobId);
D
dapan1121 已提交
292

D
dapan1121 已提交
293
int32_t catalogGetQnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray* pQnodeList);
D
dapan 已提交
294

295 296
int32_t catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray** pDnodeList);

H
Hongze Cheng 已提交
297
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableVersion** stables, uint32_t* num);
D
dapan1121 已提交
298

X
Xiaoyu Wang 已提交
299
int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion** dbs, uint32_t* num);
D
dapan1121 已提交
300

X
Xiaoyu Wang 已提交
301
int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_t* num);
D
dapan 已提交
302

D
dapan1121 已提交
303
int32_t catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg);
D
dapan1121 已提交
304

D
dapan1121 已提交
305
int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const char* indexName, SIndexInfo* pInfo);
D
dapan1121 已提交
306

D
dapan1121 已提交
307
int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pRes);
D
dapan1121 已提交
308

H
Hongze Cheng 已提交
309
int32_t catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** pCfg);
D
dapan1121 已提交
310

H
Hongze Cheng 已提交
311
int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp* pRsp);
D
dapan1121 已提交
312

D
dapan1121 已提交
313
int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* pInfo);
D
dapan1121 已提交
314

H
Hongze Cheng 已提交
315 316
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
                       bool* pass);
D
dapan 已提交
317

X
Xiaoyu Wang 已提交
318 319
int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass,
                                bool* exists);
D
dapan1121 已提交
320

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

H
Hongze Cheng 已提交
323
int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet* epSet);
D
dapan1121 已提交
324

H
Hongze Cheng 已提交
325
int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion);
D
dapan1121 已提交
326

D
dapan1121 已提交
327
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t reqId, bool forceUpdate);
D
dapan1121 已提交
328

D
dapan1121 已提交
329 330
int32_t catalogClearCache(void);

331 332 333 334
SMetaData* catalogCloneMetaData(SMetaData* pData);

void catalogFreeMetaData(SMetaData* pData);

X
Xiaoyu Wang 已提交
335
int32_t ctgdEnableDebug(char* option, bool enable);
D
dapan1121 已提交
336

X
Xiaoyu Wang 已提交
337
int32_t ctgdHandleDbgCommand(char* command);
D
dapan1121 已提交
338

H
Haojun Liao 已提交
339
/**
D
dapan1121 已提交
340
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
341
 */
D
dapan1121 已提交
342
void catalogDestroy(void);
H
Haojun Liao 已提交
343

H
Hongze Cheng 已提交
344 345 346 347
#ifdef __cplusplus
}
#endif

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