Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
2586095f
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2586095f
编写于
6月 23, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-705] remove table lock in sdb
上级
4ac333b3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
39 deletion
+15
-39
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+15
-39
未找到文件。
src/mnode/src/mnodeSdb.c
浏览文件 @
2586095f
...
...
@@ -63,7 +63,6 @@ typedef struct _SSdbTable {
int32_t
(
*
encodeFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
destroyFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
restoredFp
)();
pthread_mutex_t
mutex
;
}
SSdbTable
;
typedef
struct
{
...
...
@@ -429,24 +428,18 @@ static SSdbRow *sdbGetRowMetaFromObj(SSdbTable *pTable, void *key) {
void
*
sdbGetRow
(
void
*
handle
,
void
*
key
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
handle
;
SSdbRow
*
pMeta
;
if
(
handle
==
NULL
)
return
NULL
;
pthread_mutex_lock
(
&
pTable
->
mutex
);
int32_t
keySize
=
sizeof
(
int32_t
);
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
keySize
=
strlen
((
char
*
)
key
);
}
pMeta
=
taosHashGet
(
pTable
->
iHandle
,
key
,
keySize
);
if
(
pMeta
)
sdbIncRef
(
pTable
,
pMeta
->
row
);
pthread_mutex_unlock
(
&
pTable
->
mutex
);
if
(
pMeta
==
NULL
)
return
NULL
;
return
pMeta
->
row
;
SSdbRow
*
pMeta
=
taosHashGet
(
pTable
->
iHandle
,
key
,
keySize
);
if
(
pMeta
)
{
sdbIncRef
(
pTable
,
pMeta
->
row
);
return
pMeta
->
row
;
}
else
{
return
NULL
;
}
}
static
void
*
sdbGetRowFromObj
(
SSdbTable
*
pTable
,
void
*
key
)
{
...
...
@@ -458,8 +451,6 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
rowMeta
.
rowSize
=
pOper
->
rowSize
;
rowMeta
.
row
=
pOper
->
pObj
;
pthread_mutex_lock
(
&
pTable
->
mutex
);
void
*
key
=
sdbGetObjKey
(
pTable
,
pOper
->
pObj
);
int32_t
keySize
=
sizeof
(
int32_t
);
...
...
@@ -470,16 +461,12 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
taosHashPut
(
pTable
->
iHandle
,
key
,
keySize
,
&
rowMeta
,
sizeof
(
SSdbRow
));
sdbIncRef
(
pTable
,
pOper
->
pObj
);
pTable
->
numOfRows
++
;
atomic_add_fetch_32
(
&
pTable
->
numOfRows
,
1
)
;
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
pTable
->
autoIndex
=
MAX
(
pTable
->
autoIndex
,
*
((
uint32_t
*
)
pOper
->
pObj
));
}
else
{
pTable
->
autoIndex
++
;
if
(
pTable
->
tableId
==
SDB_TABLE_ACCOUNT
)
{
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
}
pthread_mutex_unlock
(
&
pTable
->
mutex
);
sdbTrace
(
"table:%s, insert record:%s to hash, rowSize:%d numOfRows:%"
PRId64
" version:%"
PRIu64
,
pTable
->
tableName
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
),
pOper
->
rowSize
,
pTable
->
numOfRows
,
sdbGetVersion
());
...
...
@@ -490,20 +477,15 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
static
int32_t
sdbDeleteHash
(
SSdbTable
*
pTable
,
SSdbOper
*
pOper
)
{
(
*
pTable
->
deleteFp
)(
pOper
);
pthread_mutex_lock
(
&
pTable
->
mutex
);
void
*
key
=
sdbGetObjKey
(
pTable
,
pOper
->
pObj
);
int32_t
keySize
=
sizeof
(
int32_t
);
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
keySize
=
strlen
((
char
*
)
key
);
}
taosHashRemove
(
pTable
->
iHandle
,
key
,
keySize
);
pTable
->
numOfRows
--
;
pthread_mutex_unlock
(
&
pTable
->
mutex
);
atomic_sub_fetch_32
(
&
pTable
->
numOfRows
,
1
);
sdbTrace
(
"table:%s, delete record:%s from hash, numOfRows:%"
PRId64
" version:%"
PRIu64
,
pTable
->
tableName
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
),
pTable
->
numOfRows
,
sdbGetVersion
());
...
...
@@ -608,14 +590,12 @@ int32_t sdbInsertRow(SSdbOper *pOper) {
}
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
pthread_mutex_lock
(
&
pTable
->
mutex
);
*
((
uint32_t
*
)
pOper
->
pObj
)
=
++
pTable
->
autoIndex
;
*
((
uint32_t
*
)
pOper
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
// let vgId increase from 2
if
(
pTable
->
autoIndex
==
1
&&
strcmp
(
pTable
->
tableName
,
"vgroups"
)
==
0
)
{
*
((
uint32_t
*
)
pOper
->
pObj
)
=
++
pTable
->
autoIndex
;
*
((
uint32_t
*
)
pOper
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
)
;
}
pthread_mutex_unlock
(
&
pTable
->
mutex
);
}
int32_t
code
=
sdbInsertHash
(
pTable
,
pOper
);
...
...
@@ -805,8 +785,6 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
}
pTable
->
iHandle
=
taosHashInit
(
pTable
->
hashSessions
,
hashFp
,
true
);
pthread_mutex_init
(
&
pTable
->
mutex
,
NULL
);
tsSdbObj
.
numOfTables
++
;
tsSdbObj
.
tableList
[
pTable
->
tableId
]
=
pTable
;
return
pTable
;
...
...
@@ -835,8 +813,6 @@ void sdbCloseTable(void *handle) {
taosHashDestroyIter
(
pIter
);
taosHashCleanup
(
pTable
->
iHandle
);
pthread_mutex_destroy
(
&
pTable
->
mutex
);
sdbTrace
(
"table:%s, is closed, numOfTables:%d"
,
pTable
->
tableName
,
tsSdbObj
.
numOfTables
);
free
(
pTable
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录