catalog.h 7.7 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 43
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
dapan1121 已提交
44
typedef struct SCatalogReq {
45
  SArray *pTableName;     // element is SNAME
H
Haojun Liao 已提交
46
  SArray *pUdf;           // udf name
D
dapan 已提交
47
  bool    qNodeRequired;  // valid qnode
D
dapan1121 已提交
48
} SCatalogReq;
H
Haojun Liao 已提交
49 50

typedef struct SMetaData {
D
dapan1121 已提交
51 52
  SArray    *pTableMeta;  // STableMeta array
  SArray    *pVgroupInfo; // SVgroupInfo list
H
Haojun Liao 已提交
53
  SArray    *pUdfList;    // udf info list
D
dapan1121 已提交
54
  SArray    *pEpSetList;  // qnode epset list, SArray<SEpSet>
H
Haojun Liao 已提交
55 56
} SMetaData;

D
dapan1121 已提交
57
typedef struct SCatalogCfg {
D
dapan1121 已提交
58 59
  uint32_t maxTblCacheNum;
  uint32_t maxDBCacheNum;
D
dapan1121 已提交
60
  uint32_t dbRentSec;
D
dapan1121 已提交
61
  uint32_t stbRentSec;
D
dapan1121 已提交
62 63
} SCatalogCfg;

D
dapan1121 已提交
64
typedef struct SSTableMetaVersion {
D
dapan 已提交
65 66
  char     dbFName[TSDB_DB_FNAME_LEN];
  char     stbName[TSDB_TABLE_NAME_LEN];
D
dapan1121 已提交
67
  uint64_t dbId;
D
dapan1121 已提交
68 69 70 71 72 73
  uint64_t suid;
  int16_t  sversion;
  int16_t  tversion;  
} SSTableMetaVersion;

typedef struct SDbVgVersion {
D
dapan 已提交
74
  char    dbFName[TSDB_DB_FNAME_LEN];
D
dapan1121 已提交
75 76
  int64_t dbId;
  int32_t vgVersion;
D
dapan1121 已提交
77
  int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
D
dapan1121 已提交
78 79
} SDbVgVersion;

D
dapan1121 已提交
80
int32_t catalogInit(SCatalogCfg *cfg);
D
dapan1121 已提交
81

H
Haojun Liao 已提交
82
/**
83
 * Get a cluster's catalog handle for all later operations. 
84
 * @param clusterId
85 86
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
87
 */
D
dapan1121 已提交
88
int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
D
dapan1121 已提交
89

D
dapan1121 已提交
90 91 92 93 94 95
/**
 * 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 已提交
96
void catalogFreeHandle(SCatalog* pCatalog);
D
dapan1121 已提交
97

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

D
dapan1121 已提交
100 101 102
/**
 * Get a DB's all vgroup info.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
103
 * @param pTransporter (input, rpc object)
D
dapan1121 已提交
104 105 106 107 108
 * @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 已提交
109
int32_t catalogGetDBVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, SArray** pVgroupList);
D
dapan1121 已提交
110

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

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

D
dapan1121 已提交
115
int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName);
D
dapan 已提交
116

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

119 120 121
/**
 * Get a table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
122
 * @param pTransporter (input, rpc object)
123
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
124
 * @param pTableName (input, table name)
125 126 127
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
D
dapan1121 已提交
128
int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
129

D
dapan1121 已提交
130 131 132 133 134
/**
 * 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 已提交
135
 * @param pTableName (input, table name)
D
dapan1121 已提交
136 137 138
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
D
dapan1121 已提交
139
int32_t catalogGetSTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
D
dapan1121 已提交
140

D
dapan1121 已提交
141
int32_t catalogUpdateSTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg);
D
dapan1121 已提交
142

D
dapan1121 已提交
143

D
dapan1121 已提交
144 145 146 147 148 149 150 151 152 153
/**
 * 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);

154
/**
D
dapan1121 已提交
155
 * Force refresh a table's local cached meta data. 
156
 * @param pCatalog (input, got with catalogGetHandle)
157
 * @param pTransporter (input, rpc object)
158
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
159
 * @param pTableName (input, table name)
D
dapan1121 已提交
160
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
161 162
 * @return error code
 */
D
dapan1121 已提交
163
int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
164 165

/**
D
dapan1121 已提交
166
 * Force refresh a table's local cached meta data and get the new one. 
167
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
168
 * @param pTransporter (input, rpc object)
169
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
170
 * @param pTableName (input, table name)
171
 * @param pTableMeta(output, table meta data, NEED to free it by calller) 
D
dapan1121 已提交
172
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
173 174
 * @return error code
 */
D
dapan1121 已提交
175
int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
D
dapan1121 已提交
176

H
Haojun Liao 已提交
177

D
dapan1121 已提交
178 179

/**
180 181
 * Get a table's actual vgroup, for stable it's all possible vgroup list.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
182
 * @param pTransporter (input, rpc object)
183
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
184
 * @param pTableName (input, table name)
185 186
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
D
dapan1121 已提交
187
 */
D
dapan1121 已提交
188
int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
D
dapan1121 已提交
189 190

/**
191 192
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
193
 * @param pTransporter (input, rpc object)
194
 * @param pMgmtEps (input, mnode EPs)
D
dapan1121 已提交
195
 * @param pTableName (input, table name)
196 197
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
198
 */
D
dapan1121 已提交
199
int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
D
dapan 已提交
200 201


H
Haojun Liao 已提交
202
/**
203 204
 * Get all meta data required in pReq.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
205
 * @param pTransporter (input, rpc object)
206 207 208 209
 * @param pMgmtEps (input, mnode EPs)
 * @param pReq (input, reqest info)
 * @param pRsp (output, response data)
 * @return error code 
H
Haojun Liao 已提交
210
 */
D
dapan1121 已提交
211
int32_t catalogGetAllMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
212

D
dapan 已提交
213

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

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

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

H
Haojun Liao 已提交
220 221

/**
D
dapan1121 已提交
222
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
223
 */
D
dapan1121 已提交
224
void catalogDestroy(void);
H
Haojun Liao 已提交
225

H
Hongze Cheng 已提交
226 227 228 229
#ifdef __cplusplus
}
#endif

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