Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
848fd584
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看板
提交
848fd584
编写于
11月 07, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: adjust sync propose
上级
4ddd25a2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
71 deletion
+44
-71
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+41
-48
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+0
-2
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+3
-21
未找到文件。
source/libs/sync/src/syncMain.c
浏览文件 @
848fd584
...
...
@@ -656,64 +656,57 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
}
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
0
;
sNTrace
(
pSyncNode
,
"propose message, type:%s"
,
TMSG_INFO
(
pMsg
->
msgType
));
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
terrno
=
TSDB_CODE_SYN_NOT_LEADER
;
sNError
(
pSyncNode
,
"sync propose not leader, %s, type:%s"
,
syncStr
(
pSyncNode
->
state
),
TMSG_INFO
(
pMsg
->
msgType
));
return
-
1
;
}
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
// not restored, vnode enable
if
(
!
pSyncNode
->
restoreFinish
&&
pSyncNode
->
vgId
!=
1
)
{
// not restored, vnode enable
if
(
!
pSyncNode
->
restoreFinish
&&
pSyncNode
->
vgId
!=
1
)
{
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
sNError
(
pSyncNode
,
"failed to sync propose since not ready, type:%s, last:%"
PRId64
", cmt:%"
PRId64
,
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeGetLastIndex
(
pSyncNode
),
pSyncNode
->
commitIndex
);
return
-
1
;
}
int32_t
ret
=
0
;
SyncClientRequest
*
pSyncMsg
;
// optimized one replica
if
(
syncNodeIsOptimizedOneReplica
(
pSyncNode
,
pMsg
))
{
pSyncMsg
=
syncClientRequestBuild
(
pMsg
,
0
,
isWeak
,
pSyncNode
->
vgId
);
SyncIndex
retIndex
;
int32_t
code
=
syncNodeOnClientRequest
(
pSyncNode
,
pSyncMsg
,
&
retIndex
);
if
(
code
==
0
)
{
pMsg
->
info
.
conn
.
applyIndex
=
retIndex
;
pMsg
->
info
.
conn
.
applyTerm
=
pSyncNode
->
pRaftStore
->
currentTerm
;
ret
=
1
;
sTrace
(
"vgId:%d, sync optimize index:%"
PRId64
", type:%s"
,
pSyncNode
->
vgId
,
retIndex
,
TMSG_INFO
(
pMsg
->
msgType
));
}
else
{
ret
=
-
1
;
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
sError
(
"vgId:%d, failed to sync propose since not ready, type:%s, last:%"
PRId64
", cmt:%"
PRId64
,
pSyncNode
->
vgId
,
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeGetLastIndex
(
pSyncNode
),
pSyncNode
->
commitIndex
);
goto
_END
;
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
sError
(
"vgId:%d, failed to sync optimize index:%"
PRId64
", type:%s"
,
pSyncNode
->
vgId
,
retIndex
,
TMSG_INFO
(
pMsg
->
msgType
));
}
}
else
{
SRespStub
stub
=
{.
createTime
=
taosGetTimestampMs
(),
.
rpcMsg
=
*
pMsg
};
uint64_t
seqNum
=
syncRespMgrAdd
(
pSyncNode
->
pSyncRespMgr
,
&
stub
);
SyncClientRequest
*
pSyncMsg
=
syncClientRequestBuild
(
pMsg
,
seqNum
,
isWeak
,
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
pSyncMsg
=
syncClientRequestBuild
(
pMsg
,
seqNum
,
isWeak
,
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
syncClientRequest2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
// optimized one replica
if
(
syncNodeIsOptimizedOneReplica
(
pSyncNode
,
pMsg
))
{
SyncIndex
retIndex
;
int32_t
code
=
syncNodeOnClientRequest
(
pSyncNode
,
pSyncMsg
,
&
retIndex
);
if
(
code
==
0
)
{
pMsg
->
info
.
conn
.
applyIndex
=
retIndex
;
pMsg
->
info
.
conn
.
applyTerm
=
pSyncNode
->
pRaftStore
->
currentTerm
;
rpcFreeCont
(
rpcMsg
.
pCont
);
syncRespMgrDel
(
pSyncNode
->
pSyncRespMgr
,
seqNum
);
ret
=
1
;
sDebug
(
"vgId:%d, sync optimize index:%"
PRId64
", type:%s"
,
pSyncNode
->
vgId
,
retIndex
,
TMSG_INFO
(
pMsg
->
msgType
));
}
else
{
ret
=
-
1
;
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
sError
(
"vgId:%d, failed to sync optimize index:%"
PRId64
", type:%s"
,
pSyncNode
->
vgId
,
retIndex
,
TMSG_INFO
(
pMsg
->
msgType
));
}
}
else
{
ret
=
(
*
pSyncNode
->
syncEqMsg
)(
pSyncNode
->
msgcb
,
&
rpcMsg
);
if
(
ret
!=
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
sError
(
"vgId:%d, failed to enqueue msg since its null"
,
pSyncNode
->
vgId
);
}
sNTrace
(
pSyncNode
,
"propose message, type:%s"
,
TMSG_INFO
(
pMsg
->
msgType
));
ret
=
(
*
pSyncNode
->
syncEqMsg
)(
pSyncNode
->
msgcb
,
&
rpcMsg
);
if
(
ret
!=
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
sError
(
"vgId:%d, failed to enqueue msg since %s"
,
pSyncNode
->
vgId
,
terrstr
());
}
syncClientRequestDestroy
(
pSyncMsg
);
goto
_END
;
}
else
{
ret
=
-
1
;
terrno
=
TSDB_CODE_SYN_NOT_LEADER
;
sError
(
"vgId:%d, sync propose not leader, %s, type:%s"
,
pSyncNode
->
vgId
,
syncStr
(
pSyncNode
->
state
),
TMSG_INFO
(
pMsg
->
msgType
));
goto
_END
;
}
_END:
syncClientRequestDestroy
(
pSyncMsg
);
return
ret
;
}
...
...
@@ -2522,7 +2515,7 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncInd
SyncIndex
index
=
ths
->
pLogStore
->
syncLogWriteIndex
(
ths
->
pLogStore
);
SyncTerm
term
=
ths
->
pRaftStore
->
currentTerm
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild2
(
(
SyncClientRequest
*
)
pMsg
,
term
,
index
);
SSyncRaftEntry
*
pEntry
=
syncEntryBuild2
(
pMsg
,
term
,
index
);
ASSERT
(
pEntry
!=
NULL
);
LRUHandle
*
h
=
NULL
;
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
848fd584
...
...
@@ -836,8 +836,6 @@ SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen) {
SyncClientRequest
*
pMsg
=
taosMemoryCalloc
(
1
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pMsg
->
seqNum
=
0
;
pMsg
->
isWeak
=
false
;
pMsg
->
dataLen
=
dataLen
;
return
pMsg
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
848fd584
...
...
@@ -178,29 +178,11 @@ void syncUtilMsgNtoH(void* msg) {
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
}
return
false
;
}
bool
syncUtilUserCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
}
return
false
;
}
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
)
{
return
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
;
}
bool
syncUtilUserRollback
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
}
bool
syncUtilUserCommit
(
tmsg_t
msgType
)
{
return
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
;
}
return
false
;
}
bool
syncUtilUserRollback
(
tmsg_t
msgType
)
{
return
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
;
}
void
syncCfg2SimpleStr
(
const
SSyncCfg
*
pCfg
,
char
*
buf
,
int32_t
bufLen
)
{
int32_t
len
=
snprintf
(
buf
,
bufLen
,
"{r-num:%d, my:%d, "
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录