catalog.h 7.1 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"
27
#include "common.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 33 34

struct SCatalog;

D
dapan1121 已提交
35
typedef struct SCatalogReq {
36
  SArray *pTableName;     // element is SNAME
H
Haojun Liao 已提交
37
  SArray *pUdf;           // udf name
D
dapan 已提交
38
  bool    qNodeRequired;  // valid qnode
D
dapan1121 已提交
39
} SCatalogReq;
H
Haojun Liao 已提交
40 41

typedef struct SMetaData {
D
dapan1121 已提交
42 43
  SArray    *pTableMeta;  // STableMeta array
  SArray    *pVgroupInfo; // SVgroupInfo list
H
Haojun Liao 已提交
44 45 46 47
  SArray    *pUdfList;    // udf info list
  SEpSet    *pEpSet;      // qnode epset list
} SMetaData;

D
dapan1121 已提交
48
typedef struct SCatalogCfg {
D
dapan1121 已提交
49 50
  uint32_t maxTblCacheNum;
  uint32_t maxDBCacheNum;
D
dapan1121 已提交
51 52
  uint32_t dbRentSec;
  uint32_t stableRentSec;
D
dapan1121 已提交
53 54
} SCatalogCfg;

D
dapan1121 已提交
55 56 57 58 59 60 61
typedef struct SSTableMetaVersion {
  uint64_t suid;
  int16_t  sversion;
  int16_t  tversion;  
} SSTableMetaVersion;

typedef struct SDbVgVersion {
D
dapan1121 已提交
62
  char    dbName[TSDB_DB_FNAME_LEN];
D
dapan1121 已提交
63 64 65 66
  int64_t dbId;
  int32_t vgVersion;
} SDbVgVersion;

D
dapan1121 已提交
67

D
dapan1121 已提交
68
int32_t catalogInit(SCatalogCfg *cfg);
D
dapan1121 已提交
69

H
Haojun Liao 已提交
70
/**
71
 * Get a cluster's catalog handle for all later operations. 
72
 * @param clusterId
73 74
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
75
 */
76
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
D
dapan1121 已提交
77

D
dapan1121 已提交
78 79 80 81 82 83
/**
 * 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 已提交
84 85
void catalogFreeHandle(struct SCatalog* pCatalog);

D
dapan1121 已提交
86
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
D
dapan1121 已提交
87

D
dapan1121 已提交
88 89 90
/**
 * Get a DB's all vgroup info.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
91
 * @param pTransporter (input, rpc object)
D
dapan1121 已提交
92 93 94 95 96 97
 * @param pMgmtEps (input, mnode EPs)
 * @param pDBName (input, full db name)
 * @param forceUpdate (input, force update db vgroup info from mnode) 
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
 */
H
Haojun Liao 已提交
98
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList);
D
dapan1121 已提交
99

D
dapan1121 已提交
100
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
D
dapan1121 已提交
101

D
dapan1121 已提交
102 103
int32_t catalogRemoveDBVgroup(struct SCatalog* pCatalog, SDbVgVersion* dbInfo);

104 105 106
/**
 * Get a table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
107
 * @param pTransporter (input, rpc object)
108 109 110 111 112
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
H
Haojun Liao 已提交
113
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
114

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


127 128 129
/**
 * Force renew a table's local cached meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
130
 * @param pTransporter (input, rpc object)
131 132
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
D
dapan1121 已提交
133
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
134 135
 * @return error code
 */
D
dapan1121 已提交
136
  int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
137 138 139 140

/**
 * Force renew a table's local cached meta data and get the new one. 
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
141
 * @param pTransporter (input, rpc object)
142 143 144
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @param pTableMeta(output, table meta data, NEED to free it by calller) 
D
dapan1121 已提交
145
 * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) 
146 147
 * @return error code
 */
D
dapan1121 已提交
148 149
  int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);

H
Haojun Liao 已提交
150

D
dapan1121 已提交
151 152

/**
153 154
 * Get a table's actual vgroup, for stable it's all possible vgroup list.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
155
 * @param pTransporter (input, rpc object)
156 157 158 159
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
 * @return error code
D
dapan1121 已提交
160
 */
H
Haojun Liao 已提交
161
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
D
dapan1121 已提交
162 163

/**
164 165
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
166
 * @param pTransporter (input, rpc object)
167 168 169 170
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
171
 */
H
Haojun Liao 已提交
172
int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
D
dapan 已提交
173 174


H
Haojun Liao 已提交
175
/**
176 177
 * Get all meta data required in pReq.
 * @param pCatalog (input, got with catalogGetHandle)
H
Haojun Liao 已提交
178
 * @param pTransporter (input, rpc object)
179 180 181 182
 * @param pMgmtEps (input, mnode EPs)
 * @param pReq (input, reqest info)
 * @param pRsp (output, response data)
 * @return error code 
H
Haojun Liao 已提交
183
 */
H
Haojun Liao 已提交
184
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
185

D
dapan 已提交
186

H
Haojun Liao 已提交
187
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
D
dapan 已提交
188

D
dapan1121 已提交
189 190 191
int32_t catalogGetExpiredSTables(struct SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);

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

H
Haojun Liao 已提交
193 194

/**
D
dapan1121 已提交
195
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
196
 */
D
dapan1121 已提交
197
void catalogDestroy(void);
H
Haojun Liao 已提交
198

H
Hongze Cheng 已提交
199 200 201 202
#ifdef __cplusplus
}
#endif

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