catalog.h 5.4 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 53
} SCatalogCfg;

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

H
Haojun Liao 已提交
55
/**
56
 * Get a cluster's catalog handle for all later operations. 
57
 * @param clusterId
58 59
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
60
 */
61
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
D
dapan1121 已提交
62 63

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

D
dapan1121 已提交
65 66 67 68 69 70 71 72 73 74 75 76
/**
 * Get a DB's all vgroup info.
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pRpc (input, rpc object)
 * @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
 */
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, int32_t forceUpdate, SArray** pVgroupList);

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

79 80 81
/**
 * Get a table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
82
 * @param pTransporter (input, rpc object)
83 84 85 86 87
 * @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 已提交
88
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
89 90 91 92 93 94 95 96 97

/**
 * Force renew a table's local cached meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pRpc (input, rpc object)
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @return error code
 */
H
Haojun Liao 已提交
98
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName);
99 100 101 102 103 104 105 106 107 108

/**
 * Force renew a table's local cached meta data and get the new one. 
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pRpc (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
 */
H
Haojun Liao 已提交
109
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
H
Haojun Liao 已提交
110

D
dapan1121 已提交
111 112

/**
113 114 115 116 117 118 119
 * Get a table's actual vgroup, for stable it's all possible vgroup list.
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pRpc (input, rpc object)
 * @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 已提交
120
 */
H
Haojun Liao 已提交
121
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
D
dapan1121 已提交
122 123

/**
124 125
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
126
 * @param pTransporter (input, rpc object)
127 128 129 130
 * @param pMgmtEps (input, mnode EPs)
 * @param pTableName (input, table name, NOT including db name)
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
131
 */
H
Haojun Liao 已提交
132
int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
D
dapan 已提交
133 134


H
Haojun Liao 已提交
135
/**
136 137 138 139 140 141 142
 * Get all meta data required in pReq.
 * @param pCatalog (input, got with catalogGetHandle)
 * @param pRpc (input, rpc object)
 * @param pMgmtEps (input, mnode EPs)
 * @param pReq (input, reqest info)
 * @param pRsp (output, response data)
 * @return error code 
H
Haojun Liao 已提交
143
 */
D
dapan1121 已提交
144
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
145

D
dapan 已提交
146

D
dapan1121 已提交
147
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList);
D
dapan 已提交
148

D
dapan1121 已提交
149

H
Haojun Liao 已提交
150 151

/**
D
dapan1121 已提交
152
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
153
 */
D
dapan1121 已提交
154
void catalogDestroy(void);
H
Haojun Liao 已提交
155

H
Hongze Cheng 已提交
156 157 158 159
#ifdef __cplusplus
}
#endif

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