Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7cc364bc
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7cc364bc
编写于
1月 26, 2022
作者:
H
Hongze Cheng
提交者:
GitHub
1月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10043 from taosdata/hotfix/meta_with_lock
Hotfix/meta with lock
上级
782fb854
107107a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
65 addition
and
19 deletion
+65
-19
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+65
-19
未找到文件。
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
7cc364bc
...
...
@@ -20,6 +20,10 @@
#include "tcoding.h"
#include "thash.h"
#define IMPL_WITH_LOCK 1
// #if IMPL_WITH_LOCK
// #endif
typedef
struct
{
tb_uid_t
uid
;
int32_t
sver
;
...
...
@@ -27,6 +31,9 @@ typedef struct {
}
SSchemaKey
;
struct
SMetaDB
{
#if IMPL_WITH_LOCK
pthread_rwlock_t
rwlock
;
#endif
// DB
DB
*
pTbDB
;
DB
*
pSchemaDB
;
...
...
@@ -58,6 +65,9 @@ static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
static
void
metaClearTbCfg
(
STbCfg
*
pTbCfg
);
static
int
metaEncodeSchema
(
void
**
buf
,
SSchemaWrapper
*
pSW
);
static
void
*
metaDecodeSchema
(
void
*
buf
,
SSchemaWrapper
*
pSW
);
static
void
metaDBWLock
(
SMetaDB
*
pDB
);
static
void
metaDBRLock
(
SMetaDB
*
pDB
);
static
void
metaDBULock
(
SMetaDB
*
pDB
);
#define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
...
...
@@ -130,8 +140,10 @@ void metaCloseDB(SMeta *pMeta) {
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
tb_uid_t
uid
;
char
buf
[
512
];
char
buf1
[
512
];
void
*
pBuf
;
DBT
key
,
value
;
DBT
key1
,
value1
;
DBT
key2
,
value2
;
SSchema
*
pSchema
=
NULL
;
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
...
...
@@ -143,19 +155,17 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
{
// save table info
pBuf
=
buf
;
memset
(
&
key
,
0
,
sizeof
(
key
));
memset
(
&
value
,
0
,
sizeof
(
key
));
memset
(
&
key
1
,
0
,
sizeof
(
key1
));
memset
(
&
value
1
,
0
,
sizeof
(
key1
));
key
.
data
=
&
uid
;
key
.
size
=
sizeof
(
uid
);
key
1
.
data
=
&
uid
;
key
1
.
size
=
sizeof
(
uid
);
metaEncodeTbInfo
(
&
pBuf
,
pTbCfg
);
value
.
data
=
buf
;
value
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
value
.
app_data
=
pTbCfg
;
pMeta
->
pDB
->
pTbDB
->
put
(
pMeta
->
pDB
->
pTbDB
,
NULL
,
&
key
,
&
value
,
0
);
value1
.
data
=
buf
;
value1
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
value1
.
app_data
=
pTbCfg
;
}
// save schema
...
...
@@ -169,22 +179,27 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
}
if
(
pSchema
)
{
pBuf
=
buf
;
memset
(
&
key
,
0
,
sizeof
(
key
));
memset
(
&
value
,
0
,
sizeof
(
key
));
pBuf
=
buf
1
;
memset
(
&
key
2
,
0
,
sizeof
(
key2
));
memset
(
&
value
2
,
0
,
sizeof
(
key2
));
SSchemaKey
schemaKey
=
{
uid
,
0
/*TODO*/
,
0
};
key
.
data
=
&
schemaKey
;
key
.
size
=
sizeof
(
schemaKey
);
key
2
.
data
=
&
schemaKey
;
key
2
.
size
=
sizeof
(
schemaKey
);
SSchemaWrapper
sw
=
{.
nCols
=
ncols
,
.
pSchema
=
pSchema
};
metaEncodeSchema
(
&
pBuf
,
&
sw
);
value
.
data
=
buf
;
value
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
value2
.
data
=
buf1
;
value2
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf1
);
}
pMeta
->
pDB
->
pSchemaDB
->
put
(
pMeta
->
pDB
->
pSchemaDB
,
NULL
,
&
key
,
&
value
,
0
);
metaDBWLock
(
pMeta
->
pDB
);
pMeta
->
pDB
->
pTbDB
->
put
(
pMeta
->
pDB
->
pTbDB
,
NULL
,
&
key1
,
&
value1
,
0
);
if
(
pSchema
)
{
pMeta
->
pDB
->
pSchemaDB
->
put
(
pMeta
->
pDB
->
pSchemaDB
,
NULL
,
&
key2
,
&
value2
,
0
);
}
metaDBULock
(
pMeta
->
pDB
);
return
0
;
}
...
...
@@ -234,11 +249,18 @@ static SMetaDB *metaNewDB() {
return
NULL
;
}
#if IMPL_WITH_LOCK
pthread_rwlock_init
(
&
pDB
->
rwlock
,
NULL
);
#endif
return
pDB
;
}
static
void
metaFreeDB
(
SMetaDB
*
pDB
)
{
if
(
pDB
)
{
#if IMPL_WITH_LOCK
pthread_rwlock_destroy
(
&
pDB
->
rwlock
);
#endif
free
(
pDB
);
}
}
...
...
@@ -467,7 +489,9 @@ STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
key
.
size
=
sizeof
(
uid
);
// Query
metaDBRLock
(
pDB
);
ret
=
pDB
->
pTbDB
->
get
(
pDB
->
pTbDB
,
NULL
,
&
key
,
&
value
,
0
);
metaDBULock
(
pDB
);
if
(
ret
!=
0
)
{
return
NULL
;
}
...
...
@@ -496,7 +520,9 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
key
.
size
=
strlen
(
tbname
);
// Query
metaDBRLock
(
pDB
);
ret
=
pDB
->
pNameIdx
->
pget
(
pDB
->
pNameIdx
,
NULL
,
&
key
,
&
pkey
,
&
pvalue
,
0
);
metaDBULock
(
pDB
);
if
(
ret
!=
0
)
{
return
NULL
;
}
...
...
@@ -529,7 +555,9 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
key
.
size
=
sizeof
(
schemaKey
);
// Query
metaDBRLock
(
pDB
);
ret
=
pDB
->
pSchemaDB
->
get
(
pDB
->
pSchemaDB
,
NULL
,
&
key
,
&
value
,
0
);
metaDBULock
(
pDB
);
if
(
ret
!=
0
)
{
printf
(
"failed to query schema DB since %s================
\n
"
,
db_strerror
(
ret
));
return
NULL
;
...
...
@@ -687,4 +715,22 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
}
else
{
return
0
;
}
}
\ No newline at end of file
}
static
void
metaDBWLock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
pthread_rwlock_wrlock
(
&
(
pDB
->
rwlock
));
#endif
}
static
void
metaDBRLock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
pthread_rwlock_rdlock
(
&
(
pDB
->
rwlock
));
#endif
}
static
void
metaDBULock
(
SMetaDB
*
pDB
)
{
#if IMPL_WITH_LOCK
pthread_rwlock_unlock
(
&
(
pDB
->
rwlock
));
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录