Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
35e5120c
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
35e5120c
编写于
12月 08, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
b80da12d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
157 addition
and
143 deletion
+157
-143
cmake/cmake.options
cmake/cmake.options
+1
-1
source/dnode/vnode/meta/src/metaBDBImpl.c
source/dnode/vnode/meta/src/metaBDBImpl.c
+156
-142
未找到文件。
cmake/cmake.options
浏览文件 @
35e5120c
...
...
@@ -22,7 +22,7 @@ option(
option(
BUILD_WITH_SQLITE
"If build with sqlite"
O
N
O
FF
)
option(
...
...
source/dnode/vnode/meta/src/metaBDBImpl.c
浏览文件 @
35e5120c
...
...
@@ -20,126 +20,201 @@
#include "tcoding.h"
#include "thash.h"
typedef
struct
{
tb_uid_t
uid
;
int32_t
sver
;
}
SSchemaKey
;
struct
SMetaDB
{
// DB
DB
*
pStbDB
;
DB
*
pNtbDB
;
SHashObj
*
pCtbMap
;
DB
*
pSchemaDB
;
DB
*
pTbDB
;
DB
*
pSchemaDB
;
// IDX
SHashObj
*
pIdxMap
;
DB
*
pNameIdx
;
DB
*
pUidIdx
;
DB
*
pNameIdx
;
DB
*
pStbIdx
;
DB
*
pNtbIdx
;
DB
*
pCtbIdx
;
// ENV
DB_ENV
*
pEvn
;
};
#define P_ERROR(info, code) fprintf(stderr, info "reason: %s", db_strerror(code))
static
SMetaDB
*
metaNewDB
();
static
void
metaFreeDB
(
SMetaDB
*
pDB
);
static
int
metaCreateDBEnv
(
SMetaDB
*
pDB
,
const
char
*
path
);
static
void
metaDestroyDBEnv
(
SMetaDB
*
pDB
);
static
int
metaEncodeSchemaKey
(
void
**
buf
,
SSchemaKey
*
pSchemaKey
);
static
void
*
metaDecodeSchemaKey
(
void
*
buf
,
SSchemaKey
*
pSchemaKey
);
static
int
metaNameIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
int
metaUidIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
void
metaPutSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
STSchema
*
pSchema
);
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
);
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
);
static
int
metaSaveTbInfo
(
DB
*
pDB
,
tb_uid_t
uid
,
STbCfg
*
pTbCfg
);
#define META_OPEN_DB(pDB, pEnv, fName) \
do { \
int ret; \
ret = db_create(&((pDB)), (pEnv), 0); \
if (ret != 0) { \
P_ERROR("Failed to create META DB", ret); \
metaCloseDB(pMeta); \
return -1; \
} \
\
ret = (pDB)->open((pDB), NULL, (fName), NULL, DB_BTREE, DB_CREATE, 0); \
if (ret != 0) { \
P_ERROR("Failed to open META DB", ret); \
metaCloseDB(pMeta); \
return -1; \
} \
} while (0)
static
int
metaOpenBDBEnv
(
DB_ENV
**
ppEnv
,
const
char
*
path
);
static
void
metaCloseBDBEnv
(
DB_ENV
*
pEnv
);
static
int
metaOpenBDBDb
(
DB
**
ppDB
,
DB_ENV
*
pEnv
,
const
char
*
pFName
);
static
void
metaCloseBDBDb
(
DB
*
pDB
);
#define META_CLOSE_DB(pDB)
#define META_ASSOCIATE_IDX(pDB, pIdx, cbf) \
do { \
int ret = (pDB)->associate((pDB), NULL, (pIdx), (cbf), 0); \
if (ret != 0) { \
P_ERROR("Failed to associate META DB", ret); \
metaCloseDB(pMeta); \
} \
} while (0)
#define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
#define metaOpenBDBIdx metaOpenBDBDb
int
metaOpenDB
(
SMeta
*
pMeta
)
{
int
ret
;
SMetaDB
*
pDB
;
pMeta
->
pDB
=
metaNewDB
();
if
(
pMeta
->
pDB
==
NULL
)
{
// Create DB object
pDB
=
metaNewDB
();
if
(
pDB
==
NULL
)
{
return
-
1
;
}
p
DB
=
pMeta
->
pDB
;
p
Meta
->
pDB
=
pDB
;
if
(
metaCreateDBEnv
(
pDB
,
pMeta
->
path
)
<
0
)
{
// Open DB Env
if
(
metaOpenBDBEnv
(
&
(
pDB
->
pEvn
),
pMeta
->
path
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
META_OPEN_DB
(
pDB
->
pStbDB
,
pDB
->
pEvn
,
"meta.db"
);
META_OPEN_DB
(
pDB
->
pNtbDB
,
pDB
->
pEvn
,
"meta.db"
);
META_OPEN_DB
(
pDB
->
pSchemaDB
,
pDB
->
pEvn
,
"meta.db"
);
{
// TODO: Loop to open each super table db
// Open DBs
if
(
metaOpenBDBDb
(
&
(
pDB
->
pTbDB
),
pDB
->
pEvn
,
"meta.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
META_OPEN_DB
(
pDB
->
pNameIdx
,
pDB
->
pEvn
,
"index.db"
);
if
(
metaOpenBDBDb
(
&
(
pDB
->
pSchemaDB
),
pDB
->
pEvn
,
"meta.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
// META_OPEN_DB(pDB->pUidIdx, pDB->pEvn, "index.db");
// Open Indices
if
(
metaOpenBDBIdx
(
&
(
pDB
->
pNameIdx
),
pDB
->
pEvn
,
"index.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
// Associate name index
META_ASSOCIATE_IDX
(
pDB
->
pStbDB
,
pDB
->
pNameIdx
,
metaNameIdxCb
);
// META_ASSOCIATE_IDX(pDB->pStbDB, pDB->pUidIdx, metaUidIdxCb);
// META_ASSOCIATE_IDX(pDB->pNtbDB, pDB->pNameIdx, metaNameIdxCb);
// META_ASSOCIATE_IDX(pDB->pNtbDB, pDB->pUidIdx, metaUidIdxCb);
if
(
metaOpenBDBIdx
(
&
(
pDB
->
pStbIdx
),
pDB
->
pEvn
,
"index.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
for
(;;
)
{
// Loop to associate each super table db
break
;
if
(
metaOpenBDBIdx
(
&
(
pDB
->
pNtbIdx
),
pDB
->
pEvn
,
"index.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
{
// TODO: Loop to open index DB for each super table
// and create the association between main DB and index
if
(
metaOpenBDBIdx
(
&
(
pDB
->
pCtbIdx
),
pDB
->
pEvn
,
"index.db"
)
<
0
)
{
metaCloseDB
(
pMeta
);
return
-
1
;
}
// Associate Indices
return
0
;
}
void
metaCloseDB
(
SMeta
*
pMeta
)
{
if
(
pMeta
->
pDB
)
{
meta
DestroyDBEnv
(
pMeta
->
pDB
);
meta
CloseBDBEnv
(
pMeta
->
pDB
->
pEvn
);
metaFreeDB
(
pMeta
->
pDB
);
pMeta
->
pDB
=
NULL
;
}
}
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
// TODO
return
0
;
}
int
metaRemoveTableFromDb
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
// TODO
return
0
;
}
/* ------------------------ STATIC METHODS ------------------------ */
static
SMetaDB
*
metaNewDB
()
{
SMetaDB
*
pDB
=
NULL
;
pDB
=
(
SMetaDB
*
)
calloc
(
1
,
sizeof
(
*
pDB
));
if
(
pDB
==
NULL
)
{
return
NULL
;
}
return
pDB
;
}
static
void
metaFreeDB
(
SMetaDB
*
pDB
)
{
if
(
pDB
)
{
free
(
pDB
);
}
}
static
int
metaOpenBDBEnv
(
DB_ENV
**
ppEnv
,
const
char
*
path
)
{
int
ret
;
DB_ENV
*
pEnv
;
if
(
path
==
NULL
)
return
0
;
ret
=
db_env_create
(
&
pEnv
,
0
);
if
(
ret
!=
0
)
{
BDB_PERR
(
"Failed to create META env"
,
ret
);
return
-
1
;
}
ret
=
pEnv
->
open
(
pEnv
,
path
,
DB_CREATE
|
DB_INIT_MPOOL
,
0
);
if
(
ret
!=
0
)
{
BDB_PERR
(
"Failed to open META env"
,
ret
);
return
-
1
;
}
*
ppEnv
=
pEnv
;
return
0
;
}
static
void
metaCloseBDBEnv
(
DB_ENV
*
pEnv
)
{
if
(
pEnv
)
{
pEnv
->
close
(
pEnv
,
0
);
}
}
static
int
metaOpenBDBDb
(
DB
**
ppDB
,
DB_ENV
*
pEnv
,
const
char
*
pFName
)
{
int
ret
;
DB
*
pDB
;
ret
=
db_create
(
&
((
pDB
)),
(
pEnv
),
0
);
if
(
ret
!=
0
)
{
BDB_PERR
(
"Failed to create META DB"
,
ret
);
return
-
1
;
}
ret
=
pDB
->
open
(
pDB
,
NULL
,
pFName
,
NULL
,
DB_BTREE
,
DB_CREATE
,
0
);
if
(
ret
)
{
BDB_PERR
(
"Failed to open META DB"
,
ret
);
return
-
1
;
}
return
0
;
}
static
void
metaCloseBDBDb
(
DB
*
pDB
)
{
if
(
pDB
)
{
pDB
->
close
(
pDB
,
0
);
}
}
#if 0
typedef struct {
tb_uid_t uid;
int32_t sver;
} SSchemaKey;
static SMetaDB *metaNewDB();
static void metaFreeDB(SMetaDB *pDB);
static int metaCreateDBEnv(SMetaDB *pDB, const char *path);
static void metaDestroyDBEnv(SMetaDB *pDB);
static int metaEncodeSchemaKey(void **buf, SSchemaKey *pSchemaKey);
static void * metaDecodeSchemaKey(void *buf, SSchemaKey *pSchemaKey);
static int metaNameIdxCb(DB *sdbp, const DBT *pKey, const DBT *pValue, DBT *pSKey);
static int metaUidIdxCb(DB *sdbp, const DBT *pKey, const DBT *pValue, DBT *pSKey);
static void metaPutSchema(SMeta *pMeta, tb_uid_t uid, STSchema *pSchema);
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
static int metaSaveTbInfo(DB *pDB, tb_uid_t uid, STbCfg *pTbCfg);
#define META_ASSOCIATE_IDX(pDB, pIdx, cbf) \
do { \
int ret = (pDB)->associate((pDB), NULL, (pIdx), (cbf), 0); \
if (ret != 0) { \
P_ERROR("Failed to associate META DB", ret); \
metaCloseDB(pMeta); \
} \
} while (0)
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
char buf[512];
void * pBuf;
...
...
@@ -199,68 +274,6 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
}
/* ------------------------ STATIC METHODS ------------------------ */
static
SMetaDB
*
metaNewDB
()
{
SMetaDB
*
pDB
;
pDB
=
(
SMetaDB
*
)
calloc
(
1
,
sizeof
(
*
pDB
));
if
(
pDB
==
NULL
)
{
return
NULL
;
}
pDB
->
pCtbMap
=
taosHashInit
(
0
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
if
(
pDB
->
pCtbMap
==
NULL
)
{
metaFreeDB
(
pDB
);
return
NULL
;
}
pDB
->
pIdxMap
=
taosHashInit
(
0
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
if
(
pDB
->
pIdxMap
==
NULL
)
{
metaFreeDB
(
pDB
);
return
NULL
;
}
return
pDB
;
}
static
void
metaFreeDB
(
SMetaDB
*
pDB
)
{
if
(
pDB
==
NULL
)
{
if
(
pDB
->
pIdxMap
)
{
taosHashCleanup
(
pDB
->
pIdxMap
);
}
if
(
pDB
->
pCtbMap
)
{
taosHashCleanup
(
pDB
->
pCtbMap
);
}
free
(
pDB
);
}
}
static
int
metaCreateDBEnv
(
SMetaDB
*
pDB
,
const
char
*
path
)
{
int
ret
;
if
(
path
==
NULL
)
return
0
;
ret
=
db_env_create
(
&
(
pDB
->
pEvn
),
0
);
if
(
ret
!=
0
)
{
P_ERROR
(
"Failed to create META DB ENV"
,
ret
);
return
-
1
;
}
ret
=
pDB
->
pEvn
->
open
(
pDB
->
pEvn
,
path
,
DB_CREATE
|
DB_INIT_MPOOL
,
0
);
if
(
ret
!=
0
)
{
P_ERROR
(
"failed to open META DB ENV"
,
ret
);
return
-
1
;
}
return
0
;
}
static
void
metaDestroyDBEnv
(
SMetaDB
*
pDB
)
{
if
(
pDB
->
pEvn
)
{
pDB
->
pEvn
->
close
(
pDB
->
pEvn
,
0
);
}
}
static int metaEncodeSchemaKey(void **buf, SSchemaKey *pSchemaKey) {
int tsize = 0;
...
...
@@ -362,4 +375,5 @@ static int metaSaveTbInfo(DB *pDB, tb_uid_t uid, STbCfg *pTbCfg) {
pDB->put(pDB, NULL, &key, &value, 0);
return 0;
}
\ No newline at end of file
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录