Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
24a3c817
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看板
提交
24a3c817
编写于
6月 30, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add batch propose
上级
376bf46a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
142 addition
and
4 deletion
+142
-4
include/libs/sync/sync.h
include/libs/sync/sync.h
+2
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+2
-0
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+130
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+5
-2
source/util/src/terror.c
source/util/src/terror.c
+1
-0
未找到文件。
include/libs/sync/sync.h
浏览文件 @
24a3c817
...
...
@@ -26,6 +26,7 @@ extern "C" {
extern
bool
gRaftDetailLog
;
#define SYNC_MAX_BATCH_SIZE 100
#define SYNC_INDEX_BEGIN 0
#define SYNC_INDEX_INVALID -1
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
...
...
@@ -179,6 +180,7 @@ typedef struct SSyncInfo {
bool
isStandBy
;
bool
snapshotEnable
;
SyncGroupId
vgId
;
int32_t
batchSize
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
SWal
*
pWal
;
...
...
include/libs/sync/syncTools.h
浏览文件 @
24a3c817
...
...
@@ -245,6 +245,7 @@ typedef struct SyncClientRequestBatch {
SyncClientRequestBatch
*
syncClientRequestBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
SRaftMeta
*
raftArr
,
int32_t
arrSize
,
int32_t
vgId
);
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
);
// ---------------------------------------------
typedef
struct
SyncClientRequestReply
{
...
...
@@ -600,6 +601,7 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnTimeoutCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
int32_t
syncNodeOnClientRequestBatchCb
(
SSyncNode
*
ths
,
SyncClientRequestBatch
*
pMsg
);
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
...
...
include/util/taoserror.h
浏览文件 @
24a3c817
...
...
@@ -422,6 +422,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910)
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
// tq
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
24a3c817
...
...
@@ -170,6 +170,7 @@ void syncNodeStart(SSyncNode* pSyncNode);
void
syncNodeStartStandBy
(
SSyncNode
*
pSyncNode
);
void
syncNodeClose
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
);
// option
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
24a3c817
...
...
@@ -50,7 +50,6 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths);
// process message ----
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
// life cycle
static
void
syncFreeNode
(
void
*
param
);
...
...
@@ -627,7 +626,93 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
return
ret
;
}
int32_t
syncProposeBatch
(
int64_t
rid
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
)
{
return
0
;
}
int32_t
syncProposeBatch
(
int64_t
rid
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
)
{
if
(
arrSize
<
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
int32_t
ret
=
0
;
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
ASSERT
(
rid
==
pSyncNode
->
rid
);
ret
=
syncNodeProposeBatch
(
pSyncNode
,
pMsgArr
,
pIsWeakArr
,
arrSize
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
ret
;
}
static
bool
syncNodeBatchOK
(
SRpcMsg
*
pMsgArr
,
int32_t
arrSize
)
{
for
(
int32_t
i
=
0
;
i
<
arrSize
;
++
i
)
{
if
(
pMsgArr
[
i
].
msgType
==
TDMT_SYNC_CONFIG_CHANGE
)
{
return
false
;
}
if
(
pMsgArr
[
i
].
msgType
==
TDMT_SYNC_CONFIG_CHANGE_FINISH
)
{
return
false
;
}
}
return
true
;
}
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
)
{
if
(
!
syncNodeBatchOK
(
pMsgArr
,
arrSize
))
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose batch error"
);
terrno
=
TSDB_CODE_SYN_BATCH_ERROR
;
return
-
1
;
}
if
(
arrSize
>
SYNC_MAX_BATCH_SIZE
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose match batch error"
);
terrno
=
TSDB_CODE_SYN_BATCH_ERROR
;
return
-
1
;
}
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose not leader"
);
terrno
=
TSDB_CODE_SYN_NOT_LEADER
;
return
-
1
;
}
if
(
pSyncNode
->
changing
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose not ready"
);
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
return
-
1
;
}
SRaftMeta
raftArr
[
SYNC_MAX_BATCH_SIZE
];
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
SRespStub
stub
;
stub
.
createTime
=
taosGetTimestampMs
();
stub
.
rpcMsg
=
pMsgArr
[
i
];
uint64_t
seqNum
=
syncRespMgrAdd
(
pSyncNode
->
pSyncRespMgr
,
&
stub
);
raftArr
[
i
].
isWeak
=
pIsWeakArr
[
i
];
raftArr
[
i
].
seqNum
=
seqNum
;
}
SyncClientRequestBatch
*
pSyncMsg
=
syncClientRequestBatchBuild
(
pMsgArr
,
raftArr
,
arrSize
,
pSyncNode
->
vgId
);
ASSERT
(
pSyncMsg
!=
NULL
);
SRpcMsg
rpcMsg
;
syncClientRequestBatch2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
taosMemoryFree
(
pSyncMsg
);
// only free msg body, do not free rpc msg content
if
(
pSyncNode
->
FpEqMsg
!=
NULL
&&
(
*
pSyncNode
->
FpEqMsg
)(
pSyncNode
->
msgcb
,
&
rpcMsg
)
==
0
)
{
// enqueue msg ok
}
else
{
sError
(
"enqueue msg error, FpEqMsg is NULL"
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
return
0
;
}
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
0
;
...
...
@@ -2364,6 +2449,49 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
return
ret
;
}
int32_t
syncNodeOnClientRequestBatchCb
(
SSyncNode
*
ths
,
SyncClientRequestBatch
*
pMsg
)
{
int32_t
code
=
0
;
if
(
ths
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
// call FpCommitCb, delete resp mgr
return
-
1
;
}
SyncIndex
index
=
ths
->
pLogStore
->
syncLogWriteIndex
(
ths
->
pLogStore
);
SyncTerm
term
=
ths
->
pRaftStore
->
currentTerm
;
int32_t
raftMetaArrayLen
=
sizeof
(
SRaftMeta
)
*
pMsg
->
dataCount
;
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
pMsg
->
dataCount
;
SRaftMeta
*
raftMetaArr
=
(
SRaftMeta
*
)(
pMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)((
char
*
)(
pMsg
->
data
)
+
raftMetaArrayLen
);
for
(
int32_t
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
msgArr
[
i
].
contLen
);
ASSERT
(
pEntry
!=
NULL
);
pEntry
->
originalRpcType
=
msgArr
[
i
].
msgType
;
pEntry
->
seqNum
=
raftMetaArr
[
i
].
seqNum
;
pEntry
->
isWeak
=
raftMetaArr
[
i
].
isWeak
;
pEntry
->
term
=
term
;
pEntry
->
index
=
index
;
memcpy
(
pEntry
->
data
,
msgArr
[
i
].
pCont
,
msgArr
[
i
].
contLen
);
ASSERT
(
msgArr
[
i
].
contLen
==
pEntry
->
dataLen
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pEntry
);
if
(
code
!=
0
)
{
// del resp mgr, call FpCommitCb
ASSERT
(
0
);
return
-
1
;
}
}
// fsync once
SSyncLogStoreData
*
pData
=
ths
->
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
walFsync
(
pWal
,
true
);
return
0
;
}
static
void
syncFreeNode
(
void
*
param
)
{
SSyncNode
*
pNode
=
param
;
// inner object already free
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
24a3c817
...
...
@@ -968,8 +968,9 @@ SyncClientRequestBatch* syncClientRequestBatchBuild(SRpcMsg* rpcMsgArr, SRaftMet
ASSERT
(
arrSize
>
0
);
int32_t
dataLen
=
0
;
int32_t
raftMetaArrayLen
=
sizeof
(
SRpcMsg
)
*
arrSize
;
int32_t
rpcArrayLen
=
sizeof
(
SRaftMeta
)
*
arrSize
;
int32_t
raftMetaArrayLen
=
sizeof
(
SRaftMeta
)
*
arrSize
;
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
arrSize
;
dataLen
+=
(
raftMetaArrayLen
+
rpcArrayLen
);
uint32_t
bytes
=
sizeof
(
SyncClientRequestBatch
)
+
dataLen
;
SyncClientRequestBatch
*
pMsg
=
taosMemoryMalloc
(
bytes
);
...
...
@@ -995,6 +996,8 @@ SyncClientRequestBatch* syncClientRequestBatchBuild(SRpcMsg* rpcMsgArr, SRaftMet
return
pMsg
;
}
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
)
{}
// ---- message process SyncRequestVote----
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncRequestVote
);
...
...
source/util/src/terror.c
浏览文件 @
24a3c817
...
...
@@ -429,6 +429,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NEW_CONFIG_ERROR, "Sync new config error
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_RECONFIG_NOT_READY
,
"Sync not ready for reconfig"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_PROPOSE_NOT_READY
,
"Sync not ready for propose"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_STANDBY_NOT_READY
,
"Sync not ready for standby"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_BATCH_ERROR
,
"Sync batch error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_INTERNAL_ERROR
,
"Sync internal error"
)
// wal
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录