meta.h 4.4 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
Hongze Cheng 已提交
16 17
#ifndef _TD_VNODE_META_H_
#define _TD_VNODE_META_H_
H
more  
Hongze Cheng 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
23 24 25 26 27
typedef struct SMetaCache  SMetaCache;
typedef struct SMetaIdx    SMetaIdx;
typedef struct SMetaDB     SMetaDB;
typedef struct SMCtbCursor SMCtbCursor;
typedef struct SMSmaCursor SMSmaCursor;
H
refact  
Hongze Cheng 已提交
28

H
Hongze Cheng 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// metaDebug ==================
// clang-format off
#define metaFatal(...) do { if (metaDebugFlag & DEBUG_FATAL) { taosPrintLog("META FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}     while(0)
#define metaError(...) do { if (metaDebugFlag & DEBUG_ERROR) { taosPrintLog("META ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}     while(0)
#define metaWarn(...)  do { if (metaDebugFlag & DEBUG_WARN)  { taosPrintLog("META WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}       while(0)
#define metaInfo(...)  do { if (metaDebugFlag & DEBUG_INFO)  { taosPrintLog("META ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
#define metaDebug(...) do { if (metaDebugFlag & DEBUG_DEBUG) { taosPrintLog("META ", DEBUG_DEBUG, metaDebugFlag, __VA_ARGS__); }} while(0)
#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on

#define META_SUPER_TABLE  TD_SUPER_TABLE
#define META_CHILD_TABLE  TD_CHILD_TABLE
#define META_NORMAL_TABLE TD_NORMAL_TABLE

SMeta*          metaOpen(const char* path, const SMetaCfg* pMetaCfg, SMemAllocatorFactory* pMAF);
void            metaClose(SMeta* pMeta);
void            metaRemove(const char* path);
int             metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
int             metaDropTable(SMeta* pMeta, tb_uid_t uid);
int             metaCommit(SMeta* pMeta);
int32_t         metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
int32_t         metaDropTSma(SMeta* pMeta, int64_t indexUid);
STbCfg*         metaGetTbInfoByUid(SMeta* pMeta, tb_uid_t uid);
STbCfg*         metaGetTbInfoByName(SMeta* pMeta, char* tbname, tb_uid_t* uid);
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
STSchema*       metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
void*           metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid, bool isDecode);
STSmaWrapper*   metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid);
SArray*         metaGetSmaTbUids(SMeta* pMeta, bool isDup);
int             metaGetTbNum(SMeta* pMeta);
SMSmaCursor*    metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid);
void            metaCloseSmaCursor(SMSmaCursor* pSmaCur);
int64_t         metaSmaCursorNext(SMSmaCursor* pSmaCur);
SMCtbCursor*    metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
void            metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
tb_uid_t        metaCtbCursorNext(SMCtbCursor* pCtbCur);
H
Hongze Cheng 已提交
65

H
refact  
Hongze Cheng 已提交
66 67 68 69 70
// SMetaDB
int  metaOpenDB(SMeta* pMeta);
void metaCloseDB(SMeta* pMeta);
int  metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
int  metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
C
Cary Xu 已提交
71
int  metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
C
Cary Xu 已提交
72
int  metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
H
refact  
Hongze Cheng 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

// SMetaCache
int  metaOpenCache(SMeta* pMeta);
void metaCloseCache(SMeta* pMeta);

// SMetaIdx
int  metaOpenIdx(SMeta* pMeta);
void metaCloseIdx(SMeta* pMeta);
int  metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions);
int  metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);

// STbUidGnrt
typedef struct STbUidGenerator {
  tb_uid_t nextUid;
} STbUidGenerator;

// STableUidGenerator
H
refact  
Hongze Cheng 已提交
90 91
int  metaOpenUidGnrt(SMeta* pMeta);
void metaCloseUidGnrt(SMeta* pMeta);
H
refact  
Hongze Cheng 已提交
92 93 94

// tb_uid_t
#define IVLD_TB_UID 0
H
refact  
Hongze Cheng 已提交
95
tb_uid_t metaGenerateUid(SMeta* pMeta);
H
refact  
Hongze Cheng 已提交
96

H
more  
Hongze Cheng 已提交
97
struct SMeta {
H
refact  
Hongze Cheng 已提交
98
  char*                 path;
H
refact  
Hongze Cheng 已提交
99
  SVnode*               pVnode;
H
refact  
Hongze Cheng 已提交
100
  SMetaCfg              options;
H
more  
Hongze Cheng 已提交
101
  SMetaDB*              pDB;
H
Hongze Cheng 已提交
102 103
  SMetaIdx*             pIdx;
  SMetaCache*           pCache;
H
refact  
Hongze Cheng 已提交
104 105
  STbUidGenerator       uidGnrt;
  SMemAllocatorFactory* pmaf;
H
more  
Hongze Cheng 已提交
106 107 108 109 110 111
};

#ifdef __cplusplus
}
#endif

H
Hongze Cheng 已提交
112
#endif /*_TD_VNODE_META_H_*/