meta.h 3.7 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

H
Hongze Cheng 已提交
19 20
#include "vnodeInt.h"

H
more  
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

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

H
Hongze Cheng 已提交
29 30 31 32 33 34 35 36 37 38
// 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

H
Hongze Cheng 已提交
39
// metaOpen ==================
H
Hongze Cheng 已提交
40 41 42
int32_t metaRLock(SMeta* pMeta);
int32_t metaWLock(SMeta* pMeta);
int32_t metaULock(SMeta* pMeta);
H
Hongze Cheng 已提交
43

H
Hongze Cheng 已提交
44
// metaEntry ==================
H
Hongze Cheng 已提交
45 46
int metaEncodeEntry(SEncoder* pCoder, const SMetaEntry* pME);
int metaDecodeEntry(SDecoder* pCoder, SMetaEntry* pME);
H
Hongze Cheng 已提交
47

H
Hongze Cheng 已提交
48 49 50
// metaTable ==================

// metaQuery ==================
H
Hongze Cheng 已提交
51
int metaGetTableEntryByVersion(SMetaReader* pReader, int64_t version, tb_uid_t uid);
H
Hongze Cheng 已提交
52

H
Hongze Cheng 已提交
53 54 55 56 57 58
// metaIdx ==================
int  metaOpenIdx(SMeta* pMeta);
void metaCloseIdx(SMeta* pMeta);
int  metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions);
int  metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);

H
Hongze Cheng 已提交
59
// metaCommit ==================
H
Hongze Cheng 已提交
60 61
static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); }

H
Hongze Cheng 已提交
62
struct SMeta {
H
Hongze Cheng 已提交
63 64
  TdThreadRwlock lock;

H
Hongze Cheng 已提交
65 66 67
  char*     path;
  SVnode*   pVnode;
  TENV*     pEnv;
H
Hongze Cheng 已提交
68
  TXN       txn;
H
Hongze Cheng 已提交
69 70
  TDB*      pTbDb;
  TDB*      pSkmDb;
H
Hongze Cheng 已提交
71
  TDB*      pUidIdx;
H
Hongze Cheng 已提交
72 73 74 75
  TDB*      pNameIdx;
  TDB*      pCtbIdx;
  TDB*      pTagIdx;
  TDB*      pTtlIdx;
H
Hongze Cheng 已提交
76 77 78
  SMetaIdx* pIdx;
};

H
Hongze Cheng 已提交
79 80 81 82 83
typedef struct {
  int64_t  version;
  tb_uid_t uid;
} STbDbKey;

wafwerar's avatar
wafwerar 已提交
84 85
#pragma pack(push, 1)
typedef struct {
H
Hongze Cheng 已提交
86 87 88
  tb_uid_t uid;
  int32_t  sver;
} SSkmDbKey;
wafwerar's avatar
wafwerar 已提交
89
#pragma pack(pop)
H
Hongze Cheng 已提交
90 91 92 93 94 95

typedef struct {
  tb_uid_t suid;
  tb_uid_t uid;
} SCtbIdxKey;

wafwerar's avatar
wafwerar 已提交
96 97
#pragma pack(push, 1)
typedef struct {
H
Hongze Cheng 已提交
98 99 100 101
  tb_uid_t suid;
  int16_t  cid;
  char     data[];
} STagIdxKey;
wafwerar's avatar
wafwerar 已提交
102
#pragma pack(pop)
H
Hongze Cheng 已提交
103 104 105 106 107 108

typedef struct {
  int64_t  dtime;
  tb_uid_t uid;
} STtlIdxKey;

H
Hongze Cheng 已提交
109
#if 1
H
Hongze Cheng 已提交
110

H
Hongze Cheng 已提交
111 112 113
SMSmaCursor* metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid);
void         metaCloseSmaCursor(SMSmaCursor* pSmaCur);
int64_t      metaSmaCursorNext(SMSmaCursor* pSmaCur);
H
Hongze Cheng 已提交
114

H
Hongze Cheng 已提交
115
#ifndef META_REFACT
H
refact  
Hongze Cheng 已提交
116 117 118
// SMetaDB
int  metaOpenDB(SMeta* pMeta);
void metaCloseDB(SMeta* pMeta);
L
Liu Jicong 已提交
119 120 121 122
// int  metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
H
Hongze Cheng 已提交
123
#endif
H
refact  
Hongze Cheng 已提交
124

H
Hongze Cheng 已提交
125
#endif
H
more  
Hongze Cheng 已提交
126 127 128 129 130

#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
131
#endif /*_TD_VNODE_META_H_*/