catalog.h 5.3 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 25 26 27
#include "os.h"
#include "thash.h"
#include "tarray.h"
#include "taosdef.h"
#include "transport.h"
28
#include "common.h"
H
Hongze Cheng 已提交
29
#include "tmsg.h"
D
dapan1121 已提交
30
#include "query.h"
H
Haojun Liao 已提交
31 32 33

struct SCatalog;

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

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

D
dapan1121 已提交
47
typedef struct SCatalogCfg {
D
dapan1121 已提交
48 49 50
  bool     enableVgroupCache;
  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 57 58 59
 * Get a cluster's catalog handle for all later operations. 
 * @param clusterId (input, end with \0)
 * @param catalogHandle (output, NO need to free it)
 * @return error code
H
Haojun Liao 已提交
60
 */
D
dapan1121 已提交
61 62 63
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);

int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
64
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo* dbInfo);
D
dapan1121 已提交
65
int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
D
dapan1121 已提交
66

67 68 69
/**
 * Get a table's meta data. 
 * @param pCatalog (input, got with catalogGetHandle)
70
 * @param pTransporter (input, rpc object)
71 72 73 74 75 76
 * @param pMgmtEps (input, mnode EPs)
 * @param pDBName (input, full db name)
 * @param pTableName (input, table name, NOT including db name)
 * @param pTableMeta(output, table meta data, NEED to free it by calller)
 * @return error code
 */
77
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
78 79 80 81 82 83 84 85 86 87

/**
 * 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 pDBName (input, full db name)
 * @param pTableName (input, table name, NOT including db name)
 * @return error code
 */
D
dapan1121 已提交
88
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName);
89 90 91 92 93 94 95 96 97 98 99

/**
 * 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 pDBName (input, full db name)
 * @param pTableName (input, table name, NOT including db name)
 * @param pTableMeta(output, table meta data, NEED to free it by calller) 
 * @return error code
 */
D
dapan1121 已提交
100
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
H
Haojun Liao 已提交
101

D
dapan1121 已提交
102 103

/**
104 105 106 107 108 109 110 111
 * 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 pDBName (input, full db name)
 * @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 已提交
112
 */
D
dapan 已提交
113
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray** pVgroupList);
D
dapan1121 已提交
114 115

/**
116 117
 * Get a table's vgroup from its name's hash value.
 * @param pCatalog (input, got with catalogGetHandle)
118
 * @param pTransporter (input, rpc object)
119 120 121 122 123
 * @param pMgmtEps (input, mnode EPs)
 * @param pDBName (input, full db name)
 * @param pTableName (input, table name, NOT including db name)
 * @param vgInfo (output, vgroup info)
 * @return error code
D
dapan1121 已提交
124
 */
125
int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo);
D
dapan 已提交
126 127


H
Haojun Liao 已提交
128
/**
129 130 131 132 133 134 135
 * 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 已提交
136
 */
D
dapan1121 已提交
137
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
138

D
dapan 已提交
139

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

D
dapan1121 已提交
142

H
Haojun Liao 已提交
143 144

/**
D
dapan1121 已提交
145
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
146
 */
D
dapan1121 已提交
147
void catalogDestroy(void);
H
Haojun Liao 已提交
148

H
Hongze Cheng 已提交
149 150 151 152
#ifdef __cplusplus
}
#endif

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