Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b300b58
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
未验证
提交
5b300b58
编写于
8月 12, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
8月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16044 from taosdata/fix/mnode
fix: deadlock of mnode if its state changed
上级
6e6b06e0
4f905782
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
10 deletion
+54
-10
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+2
-1
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+27
-2
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+2
-1
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+2
-1
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+19
-5
tests/script/tsim/show/basic.sim
tests/script/tsim/show/basic.sim
+2
-0
未找到文件。
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
5b300b58
...
...
@@ -87,10 +87,11 @@ typedef struct {
typedef
struct
{
tsem_t
syncSem
;
int64_t
sync
;
bool
standby
;
SReplica
replica
;
int32_t
errCode
;
int32_t
transId
;
SRWLatch
lock
;
int8_t
standby
;
int8_t
leaderTransferFinish
;
}
SSyncMgmt
;
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
5b300b58
...
...
@@ -60,15 +60,19 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
sdbSetApplyInfo
(
pMnode
->
pSdb
,
cbMeta
.
index
,
cbMeta
.
term
,
cbMeta
.
lastConfigIndex
);
}
taosRLockLatch
(
&
pMgmt
->
lock
);
if
(
transId
<=
0
)
{
taosRUnLockLatch
(
&
pMgmt
->
lock
);
mError
(
"trans:%d, invalid commit msg"
,
transId
);
}
else
if
(
transId
==
pMgmt
->
transId
)
{
taosRUnLockLatch
(
&
pMgmt
->
lock
);
if
(
pMgmt
->
errCode
!=
0
)
{
mError
(
"trans:%d, failed to propose since %s"
,
transId
,
tstrerror
(
pMgmt
->
errCode
));
}
pMgmt
->
transId
=
0
;
tsem_post
(
&
pMgmt
->
syncSem
);
}
else
{
taosRUnLockLatch
(
&
pMgmt
->
lock
);
STrans
*
pTrans
=
mndAcquireTrans
(
pMnode
,
transId
);
if
(
pTrans
!=
NULL
)
{
mDebug
(
"trans:%d, execute in mnode which not leader"
,
transId
);
...
...
@@ -115,6 +119,7 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM
mInfo
(
"trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%"
PRId64
" term:%"
PRId64
,
pMgmt
->
transId
,
cbMeta
.
code
,
cbMeta
.
index
,
cbMeta
.
term
);
taosWLockLatch
(
&
pMgmt
->
lock
);
if
(
pMgmt
->
transId
==
-
1
)
{
if
(
pMgmt
->
errCode
!=
0
)
{
mError
(
"trans:-1, failed to propose sync reconfig since %s"
,
tstrerror
(
pMgmt
->
errCode
));
...
...
@@ -122,6 +127,7 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM
pMgmt
->
transId
=
0
;
tsem_post
(
&
pMgmt
->
syncSem
);
}
taosWUnLockLatch
(
&
pMgmt
->
lock
);
}
int32_t
mndSnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
**
ppReader
)
{
...
...
@@ -170,12 +176,24 @@ static void mndBecomeFollower(struct SSyncFSM *pFsm) {
SMnode
*
pMnode
=
pFsm
->
data
;
mDebug
(
"vgId:1, become follower"
);
// clear old leader resource
taosWLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
if
(
pMnode
->
syncMgmt
.
transId
!=
0
)
{
pMnode
->
syncMgmt
.
transId
=
0
;
tsem_post
(
&
pMnode
->
syncMgmt
.
syncSem
);
}
taosWUnLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
}
static
void
mndBecomeLeader
(
struct
SSyncFSM
*
pFsm
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
mDebug
(
"vgId:1, become leader"
);
SMnode
*
pMnode
=
pFsm
->
data
;
taosWLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
if
(
pMnode
->
syncMgmt
.
transId
!=
0
)
{
pMnode
->
syncMgmt
.
transId
=
0
;
tsem_post
(
&
pMnode
->
syncMgmt
.
syncSem
);
}
taosWUnLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
}
SSyncFSM
*
mndSyncMakeFsm
(
SMnode
*
pMnode
)
{
...
...
@@ -202,6 +220,8 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
int32_t
mndInitSync
(
SMnode
*
pMnode
)
{
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
taosInitRWLatch
(
&
pMgmt
->
lock
);
pMgmt
->
transId
=
0
;
SSyncInfo
syncInfo
=
{.
vgId
=
1
,
.
FpSendMsg
=
mndSyncSendMsg
,
.
FpEqMsg
=
mndSyncEqMsg
};
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s%ssync"
,
pMnode
->
path
,
TD_DIRSEP
);
...
...
@@ -254,11 +274,14 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
memcpy
(
req
.
pCont
,
pRaw
,
req
.
contLen
);
pMgmt
->
errCode
=
0
;
taosWLockLatch
(
&
pMgmt
->
lock
);
pMgmt
->
transId
=
transId
;
taosWUnLockLatch
(
&
pMgmt
->
lock
);
mTrace
(
"trans:%d, will be proposed"
,
pMgmt
->
transId
);
const
bool
isWeak
=
false
;
int32_t
code
=
syncPropose
(
pMgmt
->
sync
,
&
req
,
isWeak
);
if
(
code
==
0
)
{
tsem_wait
(
&
pMgmt
->
syncSem
);
}
else
if
(
code
==
-
1
&&
terrno
==
TSDB_CODE_SYN_NOT_LEADER
)
{
...
...
@@ -286,10 +309,12 @@ void mndSyncStart(SMnode *pMnode) {
}
void
mndSyncStop
(
SMnode
*
pMnode
)
{
taosWLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
if
(
pMnode
->
syncMgmt
.
transId
!=
0
)
{
pMnode
->
syncMgmt
.
transId
=
0
;
tsem_post
(
&
pMnode
->
syncMgmt
.
syncSem
);
}
taosWUnLockLatch
(
&
pMnode
->
syncMgmt
.
lock
);
}
bool
mndIsMaster
(
SMnode
*
pMnode
)
{
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
5b300b58
...
...
@@ -308,7 +308,8 @@ struct SVnode {
SSink
*
pSink
;
tsem_t
canCommit
;
int64_t
sync
;
int32_t
blockCount
;
SRWLatch
lock
;
bool
blocked
;
bool
restored
;
tsem_t
syncSem
;
SQHandle
*
pQuery
;
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
5b300b58
...
...
@@ -85,7 +85,8 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
pVnode
->
state
.
commitTerm
=
info
.
state
.
commitTerm
;
pVnode
->
pTfs
=
pTfs
;
pVnode
->
msgCb
=
msgCb
;
pVnode
->
blockCount
=
0
;
taosInitRWLatch
(
&
pVnode
->
lock
);
pVnode
->
blocked
=
false
;
tsem_init
(
&
pVnode
->
syncSem
,
0
,
0
);
tsem_init
(
&
(
pVnode
->
canCommit
),
0
,
1
);
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
5b300b58
...
...
@@ -28,20 +28,28 @@ static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; }
static
inline
void
vnodeWaitBlockMsg
(
SVnode
*
pVnode
,
const
SRpcMsg
*
pMsg
)
{
if
(
vnodeIsMsgBlock
(
pMsg
->
msgType
))
{
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
vGTrace
(
"vgId:%d, msg:%p wait block, type:%s"
,
pVnode
->
config
.
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
));
pVnode
->
blockCount
=
1
;
tsem_wait
(
&
pVnode
->
syncSem
);
taosWLockLatch
(
&
pVnode
->
lock
);
if
(
!
pVnode
->
blocked
)
{
vGTrace
(
"vgId:%d, msg:%p wait block, type:%s"
,
pVnode
->
config
.
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
));
pVnode
->
blocked
=
true
;
taosWUnLockLatch
(
&
pVnode
->
lock
);
tsem_wait
(
&
pVnode
->
syncSem
);
}
else
{
taosWUnLockLatch
(
&
pVnode
->
lock
);
}
}
}
static
inline
void
vnodePostBlockMsg
(
SVnode
*
pVnode
,
const
SRpcMsg
*
pMsg
)
{
if
(
vnodeIsMsgBlock
(
pMsg
->
msgType
))
{
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
if
(
pVnode
->
blockCount
)
{
taosWLockLatch
(
&
pVnode
->
lock
);
if
(
pVnode
->
blocked
)
{
vGTrace
(
"vgId:%d, msg:%p post block, type:%s"
,
pVnode
->
config
.
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
));
pVnode
->
block
Count
=
0
;
pVnode
->
block
ed
=
false
;
tsem_post
(
&
pVnode
->
syncSem
);
}
taosWUnLockLatch
(
&
pVnode
->
lock
);
}
}
...
...
@@ -677,6 +685,12 @@ static void vnodeBecomeFollower(struct SSyncFSM *pFsm) {
vDebug
(
"vgId:%d, become follower"
,
pVnode
->
config
.
vgId
);
// clear old leader resource
taosWLockLatch
(
&
pVnode
->
lock
);
if
(
pVnode
->
blocked
)
{
pVnode
->
blocked
=
false
;
tsem_post
(
&
pVnode
->
syncSem
);
}
taosWUnLockLatch
(
&
pVnode
->
lock
);
}
static
void
vnodeBecomeLeader
(
struct
SSyncFSM
*
pFsm
)
{
...
...
tests/script/tsim/show/basic.sim
浏览文件 @
5b300b58
...
...
@@ -210,6 +210,8 @@ if $rows != 3 then
return -1
endi
sql_error select * from performance_schema.PERF_OFFSETS;
sql show create stable stb;
if $rows != 1 then
return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录