catalog.h 3.8 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
Haojun Liao 已提交
29
#include "taosmsg.h"
D
dapan1121 已提交
30
#include "query.h"
H
Haojun Liao 已提交
31 32 33

struct SCatalog;

D
dapan1121 已提交
34
typedef struct SCatalogReq {
D
dapan1121 已提交
35
  char    dbName[TSDB_DB_NAME_LEN];
H
Haojun Liao 已提交
36 37
  SArray *pTableName;     // table full name
  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 51
  bool     enableVgroupCache;
  uint32_t maxTblCacheNum;
  uint32_t maxDBCacheNum;
D
dapan1121 已提交
52 53 54
} SCatalogCfg;

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

H
Haojun Liao 已提交
56 57 58
/**
 * Catalog service object, which is utilized to hold tableMeta (meta/vgroupInfo/udfInfo) at the client-side.
 * There is ONLY one SCatalog object for one process space, and this function returns a singleton.
D
dapan1121 已提交
59
 * @param clusterId
H
Haojun Liao 已提交
60 61
 * @return
 */
D
dapan1121 已提交
62 63
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);

D
dapan1121 已提交
64 65


D
dapan1121 已提交
66
int32_t catalogGetVgroupVersion(struct SCatalog* pCatalog, int32_t* version);
D
dapan1121 已提交
67 68 69 70 71 72 73 74

/**
 * get cluster vgroup list.
 * @pVgroupList  - hash of vgroup list, key:vgId, value:SVgroupInfo
 * @return
 */
int32_t catalogGetVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SHashObj** pVgroupHash);
int32_t catalogUpdateVgroupCache(struct SCatalog* pCatalog, SVgroupListInfo* pVgroup);
D
dapan1121 已提交
75

D
dapan1121 已提交
76 77 78


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


D
dapan1121 已提交
83 84
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName);
D
dapan1121 已提交
85
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
H
Haojun Liao 已提交
86

D
dapan1121 已提交
87 88 89 90 91 92 93

/**
 * get table's vgroup list.
 * @param clusterId
 * @pVgroupList  - array of SVgroupInfo
 * @return
 */
D
dapan1121 已提交
94
int32_t catalogGetTableVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray* pVgroupList);
D
dapan 已提交
95 96


H
Haojun Liao 已提交
97 98 99 100
/**
 * Get the required meta data from mnode.
 * Note that this is a synchronized API and is also thread-safety.
 * @param pCatalog
D
dapan1121 已提交
101
 * @param pMgmtEps
H
Haojun Liao 已提交
102 103 104 105
 * @param pMetaReq
 * @param pMetaData
 * @return
 */
D
dapan1121 已提交
106
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
D
dapan1121 已提交
107

D
dapan 已提交
108 109 110

int32_t catalogGetQnodeList(struct SCatalog* pCatalog, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet);

D
dapan1121 已提交
111

H
Haojun Liao 已提交
112 113

/**
D
dapan1121 已提交
114
 * Destroy catalog and relase all resources
H
Haojun Liao 已提交
115 116
 * @param pCatalog
 */
D
dapan1121 已提交
117
void catalogDestroy(void);
H
Haojun Liao 已提交
118

H
Hongze Cheng 已提交
119 120 121 122
#ifdef __cplusplus
}
#endif

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