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

dengyihao's avatar
dengyihao 已提交
19
#include "index.h"
S
Shungang Li 已提交
20
#include "metaTtl.h"
dengyihao's avatar
dengyihao 已提交
21
#include "vnodeInt.h"
H
Hongze Cheng 已提交
22

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

H
Hongze Cheng 已提交
27 28 29
typedef struct SMetaIdx   SMetaIdx;
typedef struct SMetaDB    SMetaDB;
typedef struct SMetaCache SMetaCache;
H
refact  
Hongze Cheng 已提交
30

H
Hongze Cheng 已提交
31 32
// metaDebug ==================
// clang-format off
S
Shengliang Guan 已提交
33 34 35 36 37 38
#define metaFatal(...) do { if (metaDebugFlag & DEBUG_FATAL) { taosPrintLog("MTA FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}     while(0)
#define metaError(...) do { if (metaDebugFlag & DEBUG_ERROR) { taosPrintLog("MTA ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}     while(0)
#define metaWarn(...)  do { if (metaDebugFlag & DEBUG_WARN)  { taosPrintLog("MTA WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}       while(0)
#define metaInfo(...)  do { if (metaDebugFlag & DEBUG_INFO)  { taosPrintLog("MTA ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
#define metaDebug(...) do { if (metaDebugFlag & DEBUG_DEBUG) { taosPrintLog("MTA ", DEBUG_DEBUG, metaDebugFlag, __VA_ARGS__); }} while(0)
#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("MTA ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
H
Hongze Cheng 已提交
39 40
// clang-format on

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

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

H
Hongze Cheng 已提交
50
// 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 63 64
// metaTable ==================
int metaHandleEntry(SMeta* pMeta, const SMetaEntry* pME);

H
Hongze Cheng 已提交
65 66 67 68 69 70
// metaCache ==================
int32_t metaCacheOpen(SMeta* pMeta);
void    metaCacheClose(SMeta* pMeta);
int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo);
int32_t metaCacheDrop(SMeta* pMeta, int64_t uid);

71 72 73
int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo);
int32_t metaStatsCacheDrop(SMeta* pMeta, int64_t uid);
int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo);
74
void    metaUpdateStbStats(SMeta* pMeta, int64_t uid, int64_t delta);
75
int32_t metaUidFilterCacheGet(SMeta* pMeta, uint64_t suid, const void* pKey, int32_t keyLen, LRUHandle** pHandle);
76

H
Hongze Cheng 已提交
77
struct SMeta {
H
Hongze Cheng 已提交
78 79
  TdThreadRwlock lock;

dengyihao's avatar
dengyihao 已提交
80 81 82
  char*   path;
  SVnode* pVnode;
  TDB*    pEnv;
83
  TXN*    txn;
dengyihao's avatar
dengyihao 已提交
84 85 86 87 88
  TTB*    pTbDb;
  TTB*    pSkmDb;
  TTB*    pUidIdx;
  TTB*    pNameIdx;
  TTB*    pCtbIdx;
C
Cary Xu 已提交
89
  TTB*    pSuidIdx;
dengyihao's avatar
dengyihao 已提交
90
  // ivt idx and idx
dengyihao's avatar
dengyihao 已提交
91
  void* pTagIvtIdx;
dengyihao's avatar
dengyihao 已提交
92

93 94
  TTB*        pTagIdx;
  STtlManger* pTtlMgr;
dengyihao's avatar
dengyihao 已提交
95

96
  TTB* pBtimeIdx;  // table created time idx
dengyihao's avatar
dengyihao 已提交
97
  TTB* pNcolIdx;   // ncol of table idx, normal table only
dengyihao's avatar
dengyihao 已提交
98

L
Liu Jicong 已提交
99 100
  TTB* pSmaIdx;

L
Liu Jicong 已提交
101 102
  // stream
  TTB* pStreamDb;
L
Liu Jicong 已提交
103

H
Hongze Cheng 已提交
104
  SMetaIdx* pIdx;
H
Hongze Cheng 已提交
105 106

  SMetaCache* pCache;
H
Hongze Cheng 已提交
107 108
};

H
Hongze Cheng 已提交
109 110 111 112 113
typedef struct {
  int64_t  version;
  tb_uid_t uid;
} STbDbKey;

wafwerar's avatar
wafwerar 已提交
114
#pragma pack(push, 1)
H
Hongze Cheng 已提交
115 116 117 118 119 120
typedef struct {
  tb_uid_t suid;
  int64_t  version;
  int32_t  skmVer;
} SUidIdxVal;

wafwerar's avatar
wafwerar 已提交
121
typedef struct {
H
Hongze Cheng 已提交
122 123 124
  tb_uid_t uid;
  int32_t  sver;
} SSkmDbKey;
wafwerar's avatar
wafwerar 已提交
125
#pragma pack(pop)
H
Hongze Cheng 已提交
126 127 128 129 130 131

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

wafwerar's avatar
wafwerar 已提交
132 133
#pragma pack(push, 1)
typedef struct {
H
Hongze Cheng 已提交
134
  tb_uid_t suid;
H
Hongze Cheng 已提交
135 136 137 138
  int32_t  cid;
  uint8_t  isNull : 1;
  uint8_t  type : 7;
  uint8_t  data[];  // val + uid
H
Hongze Cheng 已提交
139
} STagIdxKey;
wafwerar's avatar
wafwerar 已提交
140
#pragma pack(pop)
H
Hongze Cheng 已提交
141

142 143 144 145 146
typedef struct {
  tb_uid_t uid;
  int64_t  smaUid;
} SSmaIdxKey;

dengyihao's avatar
dengyihao 已提交
147
typedef struct {
148
  int64_t  btime;
dengyihao's avatar
dengyihao 已提交
149
  tb_uid_t uid;
150
} SBtimeIdxKey;
dengyihao's avatar
dengyihao 已提交
151 152

typedef struct {
dengyihao's avatar
dengyihao 已提交
153
  int64_t  ncol;
dengyihao's avatar
dengyihao 已提交
154 155 156
  tb_uid_t uid;
} SNcolIdxKey;

dengyihao's avatar
dengyihao 已提交
157
// metaTable ==================
dengyihao's avatar
dengyihao 已提交
158
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
dengyihao's avatar
dengyihao 已提交
159 160
                        STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey);

161 162 163 164 165 166
// TODO, refactor later
int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *param, SArray *results);
int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *parm, SArray *pUids);
int32_t metaFilterTableName(void *pVnode, SMetaFltParam *param, SArray *pUids);
int32_t metaFilterTtl(void *pVnode, SMetaFltParam *param, SArray *pUids);

H
Hongze Cheng 已提交
167
#ifndef META_REFACT
H
refact  
Hongze Cheng 已提交
168 169 170
// SMetaDB
int  metaOpenDB(SMeta* pMeta);
void metaCloseDB(SMeta* pMeta);
171
int  metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
H
Hongze Cheng 已提交
172
int  metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
H
Hongze Cheng 已提交
173
#endif
H
more  
Hongze Cheng 已提交
174 175 176 177 178

#ifdef __cplusplus
}
#endif

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